@elysiumjs/core 0.10.0 → 0.11.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 +149 -0
- package/README.md +61 -3
- package/dist/app.d.ts +120 -13
- package/dist/config.d.ts +74 -0
- package/dist/console.d.ts +46 -9
- package/dist/container.d.ts +71 -15
- package/dist/errors.d.ts +37 -2
- package/dist/filter.d.ts +78 -0
- package/dist/http-client.d.ts +80 -0
- package/dist/http.d.ts +147 -45
- package/dist/index.d.ts +23 -10
- package/dist/index.js +10 -8
- package/dist/interceptor.d.ts +80 -0
- package/dist/kernel.d.ts +15 -1
- package/dist/{event-wiring.d.ts → lifecycle-wiring.d.ts} +4 -4
- package/dist/{event.d.ts → lifecycle.d.ts} +25 -18
- package/dist/middleware.d.ts +24 -5
- package/dist/module-context.d.ts +6 -0
- package/dist/module-graph.d.ts +3 -2
- package/dist/module.d.ts +18 -0
- package/dist/problem.d.ts +815 -0
- package/dist/rate-limit.d.ts +194 -0
- package/dist/resource.d.ts +77 -0
- package/dist/runtime.d.ts +148 -0
- package/dist/security.d.ts +159 -0
- package/dist/service.d.ts +51 -15
- package/dist/testing.d.ts +45 -2
- package/dist/token.d.ts +22 -0
- package/dist/user.d.ts +13 -0
- package/dist/utils.d.ts +3 -3
- package/dist/websocket.d.ts +37 -16
- package/package.json +12 -6
- package/dist/redis.d.ts +0 -86
package/dist/service.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Class } from 'type-fest';
|
|
2
|
+
import type { ModuleNode } from './module-graph';
|
|
3
|
+
import type { ServiceToken } from './token';
|
|
2
4
|
/**
|
|
3
5
|
* The scope of a service.
|
|
4
6
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
@@ -11,7 +13,13 @@ export declare enum ServiceScope {
|
|
|
11
13
|
/**
|
|
12
14
|
* A new instance of the service is created every time it is injected or retrieved.
|
|
13
15
|
*/
|
|
14
|
-
FACTORY = 1
|
|
16
|
+
FACTORY = 1,
|
|
17
|
+
/**
|
|
18
|
+
* One instance of the service is created per request, and shared by everything resolved
|
|
19
|
+
* while handling that request. Resolving it outside a request throws, and so does injecting
|
|
20
|
+
* it into a singleton.
|
|
21
|
+
*/
|
|
22
|
+
REQUEST = 2
|
|
15
23
|
}
|
|
16
24
|
/**
|
|
17
25
|
* A generic service class.
|
|
@@ -34,7 +42,9 @@ type FactoryFn<T> = () => T extends void ? never : T;
|
|
|
34
42
|
*/
|
|
35
43
|
export type ServiceProps = Partial<{
|
|
36
44
|
/**
|
|
37
|
-
* The name of the service.
|
|
45
|
+
* The name (token) of the service. Without one, the service is identified by its class:
|
|
46
|
+
* inject it with `@Service.inject(TheClass)` or by its parameter type, and get it with
|
|
47
|
+
* `Service.get(TheClass)`.
|
|
38
48
|
*/
|
|
39
49
|
name: string;
|
|
40
50
|
/**
|
|
@@ -59,8 +69,8 @@ export type ServiceProps = Partial<{
|
|
|
59
69
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
60
70
|
*/
|
|
61
71
|
export type ServiceFactoryDefinition = {
|
|
62
|
-
/** The
|
|
63
|
-
name:
|
|
72
|
+
/** The token of the service: a name, or a class to register the service by class. */
|
|
73
|
+
name: ServiceToken;
|
|
64
74
|
/** Builds the service from the owning module's config and a resolver for visible services. */
|
|
65
75
|
factory: (config: any, get: <T>(name: string | Class<T>) => T) => unknown;
|
|
66
76
|
/** The service's scope. Defaults to `ServiceScope.SINGLETON`. */
|
|
@@ -84,9 +94,11 @@ export declare namespace Service {
|
|
|
84
94
|
/**
|
|
85
95
|
* Resolves a registered service and set it as a parameter value.
|
|
86
96
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
87
|
-
* @param service
|
|
97
|
+
* @param service The name or class of the service. Without it, the parameter's type is used,
|
|
98
|
+
* which needs the compiler to emit decorator metadata (`emitDecoratorMetadata`).
|
|
99
|
+
* @throws {ElysiumError} When no service is given and the parameter type is unknown.
|
|
88
100
|
*/
|
|
89
|
-
const inject: (service?:
|
|
101
|
+
const inject: (service?: ServiceToken) => ParameterDecorator;
|
|
90
102
|
/**
|
|
91
103
|
* Retrieves a service visible from the current module context (global services only
|
|
92
104
|
* when there is none). Lazy services are built on first access.
|
|
@@ -95,14 +107,14 @@ export declare namespace Service {
|
|
|
95
107
|
* @returns The service, or `null` if none with that name/type is visible.
|
|
96
108
|
* @throws {ServiceNotReadyError} If the service, or its module, is still initialising.
|
|
97
109
|
*/
|
|
98
|
-
const get: <T>(service:
|
|
110
|
+
const get: <T>(service: ServiceToken | TypedServiceClass<T>) => T | null;
|
|
99
111
|
/**
|
|
100
112
|
* Like `get`, but waits for the `onInit` of the service and of its owning module.
|
|
101
113
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
102
114
|
* @param service The name of the service, or its class.
|
|
103
115
|
* @throws {ServiceNotFoundError | ServiceNotVisibleError | EnvironmentSkippedModuleError}
|
|
104
116
|
*/
|
|
105
|
-
const resolve: <T>(service:
|
|
117
|
+
const resolve: <T>(service: ServiceToken | TypedServiceClass<T>) => Promise<T>;
|
|
106
118
|
/**
|
|
107
119
|
* Registers a global lazy service that is only instantiated on first access.
|
|
108
120
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
@@ -127,7 +139,7 @@ export declare namespace Service {
|
|
|
127
139
|
* Binds a service to the global scope and sets it as a singleton.
|
|
128
140
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
129
141
|
* @param service The service class to bind.
|
|
130
|
-
* @param name An optional name for the service.
|
|
142
|
+
* @param name An optional name for the service. Without it, the service is bound to its class.
|
|
131
143
|
*/
|
|
132
144
|
const bind: <T>(service: TypedServiceClass<T>, name?: string) => T;
|
|
133
145
|
/**
|
|
@@ -141,7 +153,7 @@ export declare namespace Service {
|
|
|
141
153
|
* Binds a service to the global scope and sets it as a factory.
|
|
142
154
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
143
155
|
* @param service The service class to bind.
|
|
144
|
-
* @param name An optional name for the service.
|
|
156
|
+
* @param name An optional name for the service. Without it, the service is bound to its class.
|
|
145
157
|
*/
|
|
146
158
|
function factory<T>(service: TypedServiceClass<T>, name?: string): T;
|
|
147
159
|
/**
|
|
@@ -151,29 +163,53 @@ export declare namespace Service {
|
|
|
151
163
|
* @param instance The instance to bind.
|
|
152
164
|
* @throws {DuplicateGlobalServiceError} If a global service with that name exists.
|
|
153
165
|
*/
|
|
154
|
-
const instance: <T>(service:
|
|
166
|
+
const instance: <T>(service: ServiceToken | TypedServiceClass<T>, instance: T) => T;
|
|
155
167
|
/**
|
|
156
168
|
* Removes a service from the global scope.
|
|
157
169
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
158
170
|
* @param service The service class or name to remove.
|
|
159
171
|
*/
|
|
160
|
-
const remove: (service:
|
|
172
|
+
const remove: (service: ServiceToken) => void;
|
|
161
173
|
/**
|
|
162
174
|
* Checks if a service exists in the global scope.
|
|
163
175
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
164
176
|
* @param service The service class or name to check.
|
|
165
177
|
* @returns `true` if the service exists, `false` otherwise.
|
|
166
178
|
*/
|
|
167
|
-
const exists: (service:
|
|
179
|
+
const exists: (service: ServiceToken) => boolean;
|
|
180
|
+
/**
|
|
181
|
+
* The modules that declare a service in their own scope, rather than as a global service, in
|
|
182
|
+
* registration order. Run code in one of them with `ModuleContext.run()` to resolve the service
|
|
183
|
+
* as that module sees it.
|
|
184
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
185
|
+
* @param service The service class or name.
|
|
186
|
+
* @returns The modules, empty when no module declares it.
|
|
187
|
+
*/
|
|
188
|
+
const ownersOf: (service: ServiceToken) => readonly ModuleNode[];
|
|
168
189
|
/**
|
|
169
190
|
* Checks if a service has already been built, without building it.
|
|
170
191
|
* Matches by name in any scope (global or module), not only the global one.
|
|
171
192
|
* Lets modules release only the resources they actually created.
|
|
172
193
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
173
|
-
* @param
|
|
194
|
+
* @param service The name or class of the service to check.
|
|
174
195
|
* @returns `true` if the service has a live instance, `false` otherwise.
|
|
175
196
|
*/
|
|
176
|
-
const isConstructed: (
|
|
197
|
+
const isConstructed: (service: ServiceToken) => boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Runs `fn` in a request scope: request-scoped services resolved inside it, including in the
|
|
200
|
+
* asynchronous work it starts, share one instance. HTTP route handlers already run in one.
|
|
201
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
202
|
+
* @param fn The work to run, such as a job or a test.
|
|
203
|
+
*/
|
|
204
|
+
const runInRequestScope: <T>(fn: () => T) => T;
|
|
205
|
+
/**
|
|
206
|
+
* Ends the request scope started for `key`, calling `onDestroy` on its request-scoped
|
|
207
|
+
* instances, the last created first. Errors are logged, never thrown, and a second call does
|
|
208
|
+
* nothing. Runtimes that keep a scope per request call this once the response is sent.
|
|
209
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
210
|
+
* @param key The request object the scope belongs to.
|
|
211
|
+
*/
|
|
212
|
+
const disposeRequestScope: (key: object) => Promise<void>;
|
|
177
213
|
/**
|
|
178
214
|
* Clears the global scope.
|
|
179
215
|
* @author Axel Nana <axel.nana@workbud.com>
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { Class } from 'type-fest';
|
|
2
|
+
import type { Application } from './app';
|
|
3
|
+
import type { HttpTestClient } from './http-client';
|
|
2
4
|
import type { ConfiguredModule, ModuleClass } from './module';
|
|
5
|
+
import type { ServiceToken } from './token';
|
|
3
6
|
import { Kernel } from './kernel';
|
|
4
7
|
/**
|
|
5
8
|
* Options of {@link Application.testing}.
|
|
@@ -8,8 +11,11 @@ import { Kernel } from './kernel';
|
|
|
8
11
|
export type TestingOptions = {
|
|
9
12
|
/** The modules to boot. */
|
|
10
13
|
modules: (ModuleClass | ConfiguredModule<any>)[];
|
|
11
|
-
/**
|
|
12
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Services registered as globals; they win over module services with the same token.
|
|
16
|
+
* Give named services by name, or any service by class with a `Map`.
|
|
17
|
+
*/
|
|
18
|
+
overrides?: Record<string, unknown> | Map<ServiceToken, unknown>;
|
|
13
19
|
/** The environment to build the graph for. Defaults to `test`. */
|
|
14
20
|
environment?: string;
|
|
15
21
|
/** `eager` initialises every module and builds every service. Defaults to `lazy`. */
|
|
@@ -31,6 +37,43 @@ export type TestingApp = {
|
|
|
31
37
|
/** Destroys the services and modules, and resets the container. */
|
|
32
38
|
shutdown(): Promise<void>;
|
|
33
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Empties the service container and clears its overrides, module visibility rules, module
|
|
42
|
+
* init hook and skipped-module lookup. The container is global to the process: call this
|
|
43
|
+
* between tests or scenarios that each boot their own application.
|
|
44
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
45
|
+
*/
|
|
46
|
+
export declare const resetContainer: () => void;
|
|
47
|
+
/**
|
|
48
|
+
* Options of {@link Application.testing} for a whole application, driven over HTTP.
|
|
49
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
50
|
+
*/
|
|
51
|
+
export type TestingAppOptions = {
|
|
52
|
+
/** The application class to build. It must not be started. */
|
|
53
|
+
app: new () => Application;
|
|
54
|
+
/**
|
|
55
|
+
* Services registered as globals before the application boots; they win over module services
|
|
56
|
+
* with the same token. Give named services by name, or any service by class with a `Map`.
|
|
57
|
+
*/
|
|
58
|
+
overrides?: Record<string, unknown> | Map<ServiceToken, unknown>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* A built application under test, with an HTTP client that drives it in memory.
|
|
62
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
63
|
+
*/
|
|
64
|
+
export type TestingHttpApp = TestingApp & {
|
|
65
|
+
/** The application instance. */
|
|
66
|
+
app: Application;
|
|
67
|
+
/** Sends requests to the application through `app.handle(Request)`, without a server. */
|
|
68
|
+
http: HttpTestClient;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Builds an application, as a host that owns the server would (`app.build()`), and returns an
|
|
72
|
+
* HTTP client for it. Modules boot on the first request.
|
|
73
|
+
* @param options See {@link TestingAppOptions}.
|
|
74
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
75
|
+
*/
|
|
76
|
+
export declare function createTestingHttpApp(options: TestingAppOptions): Promise<TestingHttpApp>;
|
|
34
77
|
/**
|
|
35
78
|
* Boots a module graph without a CLI or an HTTP server.
|
|
36
79
|
* @param options See {@link TestingOptions}.
|
package/dist/token.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Class } from 'type-fest';
|
|
2
|
+
/**
|
|
3
|
+
* What identifies a service in the container: the name it is registered under, or its class.
|
|
4
|
+
*
|
|
5
|
+
* A class registered without a name is identified by the class itself, never by the class name,
|
|
6
|
+
* so services resolve the same way in minified builds, where bundlers rename classes.
|
|
7
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
8
|
+
*/
|
|
9
|
+
export type ServiceToken = string | Class<any>;
|
|
10
|
+
/**
|
|
11
|
+
* The token a service is registered under: a string as given, and for a class the name declared
|
|
12
|
+
* with `@Service.register({ name })`, or else the class itself.
|
|
13
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
14
|
+
* @param service The service name or class.
|
|
15
|
+
*/
|
|
16
|
+
export declare const tokenOf: (service: ServiceToken) => ServiceToken;
|
|
17
|
+
/**
|
|
18
|
+
* A readable label for a token, for messages only: it must never be used to look a service up.
|
|
19
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
20
|
+
* @param token The service token.
|
|
21
|
+
*/
|
|
22
|
+
export declare const tokenLabel: (token: ServiceToken) => string;
|
package/dist/user.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The id of a user as guards leave it in `currentUser`: the user itself when it is a string or a
|
|
3
|
+
* number, else its `id`, else its `sub` (JWT claims).
|
|
4
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
5
|
+
* @param user The user.
|
|
6
|
+
*/
|
|
7
|
+
export declare const userIdOf: (user: unknown) => string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* The id of the user of the current request, read from `currentUser` in its context, which
|
|
10
|
+
* authentication middlewares set. `undefined` outside a request or without a user.
|
|
11
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
12
|
+
*/
|
|
13
|
+
export declare const currentUserId: () => string | undefined;
|
package/dist/utils.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare namespace Symbols {
|
|
|
11
11
|
const arg: unique symbol;
|
|
12
12
|
const elysiaPlugin: unique symbol;
|
|
13
13
|
const middlewareGuards: unique symbol;
|
|
14
|
-
const
|
|
14
|
+
const lifecycleListeners: unique symbol;
|
|
15
15
|
const serviceOptions: unique symbol;
|
|
16
16
|
const module: unique symbol;
|
|
17
17
|
const configuredModule: unique symbol;
|
|
@@ -20,12 +20,12 @@ export declare namespace Symbols {
|
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Gets the current environment name.
|
|
23
|
-
* @returns `NODE_ENV
|
|
23
|
+
* @returns `NODE_ENV` from the runtime, or `development` when unset or when no runtime is set.
|
|
24
24
|
*
|
|
25
25
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
26
26
|
*/
|
|
27
27
|
export declare function currentEnvironment(): string;
|
|
28
|
-
export declare const nextTick: () => Promise<
|
|
28
|
+
export declare const nextTick: () => Promise<void>;
|
|
29
29
|
/** The factory stored on a controller class; builds its Elysia plugin in a module's context. */
|
|
30
30
|
export type ElysiaPlugin = (node: ModuleNode) => Promise<Elysia>;
|
|
31
31
|
/**
|
package/dist/websocket.d.ts
CHANGED
|
@@ -1,27 +1,42 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { Context, ErrorContext } from 'elysia';
|
|
2
|
+
import type { Class } from 'type-fest';
|
|
3
|
+
import type { TSchema } from 'typebox';
|
|
4
4
|
import type { Route } from './http';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* The options of the websocket server, shared by every runtime.
|
|
7
7
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
8
8
|
*/
|
|
9
|
-
export type
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
export type WebSocketHandlerOptions = {
|
|
10
|
+
/** Seconds of inactivity after which a connection is closed. */
|
|
11
|
+
idleTimeout?: number;
|
|
12
|
+
/** The largest message accepted, in bytes. */
|
|
13
|
+
maxPayloadLength?: number;
|
|
14
|
+
/** Whether messages are compressed. */
|
|
15
|
+
perMessageDeflate?: boolean | Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A websocket connection, as seen by controllers. Structural, so that it fits every runtime.
|
|
19
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
20
|
+
* @template TData Data stored in the connection.
|
|
21
|
+
*/
|
|
22
|
+
export type ElysiumWebSocket<TData = unknown> = {
|
|
23
|
+
/** Sends a message to the client. */
|
|
24
|
+
send(data: string | BufferSource, compress?: boolean): unknown;
|
|
25
|
+
/** Closes the connection. */
|
|
26
|
+
close(code?: number, reason?: string): unknown;
|
|
27
|
+
/** The data stored in the connection. */
|
|
28
|
+
data: TData;
|
|
29
|
+
/** Subscribes the connection to a topic. */
|
|
30
|
+
subscribe(topic: string): unknown;
|
|
31
|
+
/** Publishes a message to every subscriber of a topic. */
|
|
32
|
+
publish(topic: string, data: string | BufferSource, compress?: boolean): unknown;
|
|
18
33
|
};
|
|
19
34
|
/**
|
|
20
35
|
* The websocket connection instance.
|
|
21
36
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
22
37
|
* @template TData Additional data stored in the websocket connection.
|
|
23
38
|
*/
|
|
24
|
-
export type WS<TData = unknown> =
|
|
39
|
+
export type WS<TData = unknown> = ElysiumWebSocket<{
|
|
25
40
|
/**
|
|
26
41
|
* Unique identifier for the websocket connection.
|
|
27
42
|
*/
|
|
@@ -43,9 +58,15 @@ export declare namespace Websocket {
|
|
|
43
58
|
* `onAfterResponse` run once the socket is upgraded: there is no response to read or replace.
|
|
44
59
|
*
|
|
45
60
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
46
|
-
* @param
|
|
61
|
+
* @param path The path of the websocket route.
|
|
62
|
+
* @param options The options of the websocket server.
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* @Websocket.controller('/chat', { idleTimeout: 60 })
|
|
66
|
+
* class ChatController {}
|
|
67
|
+
* ```
|
|
47
68
|
*/
|
|
48
|
-
const controller: (
|
|
69
|
+
const controller: (path: Route, options?: WebSocketHandlerOptions) => (target: Class<any>) => void;
|
|
49
70
|
/**
|
|
50
71
|
* Marks a method as the websocket "open" event handler.
|
|
51
72
|
*
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elysiumjs/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"description": "A
|
|
5
|
+
"description": "A structured web framework built on ElysiaJS, for Bun, Node.js and Cloudflare Workers.",
|
|
6
6
|
"private": false,
|
|
7
7
|
"author": "Workbud Technologies Inc.",
|
|
8
8
|
"repository": {
|
|
@@ -17,13 +17,15 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"format": "prettier --write \"./src/**/*.ts\"",
|
|
19
19
|
"clean": "rimraf dist",
|
|
20
|
-
"build:js": "bun build ./src/index.ts --outdir ./dist --target
|
|
20
|
+
"build:js": "bun build ./src/index.ts --outdir ./dist --target node --packages external --root ./src --minify-syntax --minify-whitespace",
|
|
21
21
|
"build:ts": "tsc",
|
|
22
22
|
"build": "bun run clean && bun run build:js && bun run build:ts",
|
|
23
23
|
"typecheck": "tsc --noEmit",
|
|
24
24
|
"prepublishOnly": "bun run build",
|
|
25
25
|
"test": "bun test",
|
|
26
|
-
"test:coverage": "bun test --coverage"
|
|
26
|
+
"test:coverage": "bun test --coverage",
|
|
27
|
+
"check:runtime": "bun scripts/check-runtime.ts",
|
|
28
|
+
"check:minified": "bun scripts/check-minified.ts"
|
|
27
29
|
},
|
|
28
30
|
"keywords": [
|
|
29
31
|
"elysium",
|
|
@@ -43,9 +45,13 @@
|
|
|
43
45
|
"./src/index.ts"
|
|
44
46
|
],
|
|
45
47
|
"dependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"elysia": "^
|
|
48
|
+
"@elysia/openapi": "^2.0.0-rc.0",
|
|
49
|
+
"elysia": "^2.0.0-rc.1",
|
|
50
|
+
"exact-mirror": "^1.2.6",
|
|
51
|
+
"http-status": "^2.1.0",
|
|
52
|
+
"openapi-types": "^12.1.3",
|
|
48
53
|
"radash": "^12.1.1",
|
|
54
|
+
"typebox": "^1.3.0",
|
|
49
55
|
"wampy": "^8.0.2"
|
|
50
56
|
},
|
|
51
57
|
"trustedDependencies": [
|
package/dist/redis.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Properties used to create a new redis connection.
|
|
3
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
4
|
-
*/
|
|
5
|
-
export type RedisConnectionProps = Bun.RedisOptions & {
|
|
6
|
-
url: string;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Configuration of the {@link RedisModule}.
|
|
10
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
11
|
-
*/
|
|
12
|
-
export type RedisModuleConfig = {
|
|
13
|
-
/** The name of the connection that `default` resolves to. */
|
|
14
|
-
default: string;
|
|
15
|
-
/** The connections to declare, by name. */
|
|
16
|
-
connections: Record<string, RedisConnectionProps>;
|
|
17
|
-
};
|
|
18
|
-
export declare namespace Redis {
|
|
19
|
-
/**
|
|
20
|
-
* Creates a service name for a redis connection.
|
|
21
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
22
|
-
* @param name The name of the connection.
|
|
23
|
-
* @returns A service name for the connection.
|
|
24
|
-
*/
|
|
25
|
-
const getConnectionName: (name: string) => string;
|
|
26
|
-
/**
|
|
27
|
-
* Retrieves the client for a redis connection declared by the {@link RedisModule}.
|
|
28
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
29
|
-
* @param name The name of the connection.
|
|
30
|
-
* @returns The Bun.RedisClient for the connection with the given name.
|
|
31
|
-
* @throws {ServiceNotFoundError} If no connection with that name is declared.
|
|
32
|
-
*/
|
|
33
|
-
const getConnection: (name?: string) => Bun.RedisClient;
|
|
34
|
-
/**
|
|
35
|
-
* Checks if a redis connection with the given name exists.
|
|
36
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
37
|
-
* @param name The name of the connection to check.
|
|
38
|
-
* @returns `true` if the connection exists, `false` otherwise.
|
|
39
|
-
*/
|
|
40
|
-
const connectionExists: (name: string) => boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Retrieves the default redis connection.
|
|
43
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
44
|
-
* @returns The default redis connection.
|
|
45
|
-
*/
|
|
46
|
-
const getDefaultConnection: () => Bun.RedisClient;
|
|
47
|
-
}
|
|
48
|
-
declare const RedisModule_base: (abstract new () => {
|
|
49
|
-
get config(): RedisModuleConfig;
|
|
50
|
-
onInit(): Promise<void> | void;
|
|
51
|
-
onDestroy(): Promise<void> | void;
|
|
52
|
-
onServe(_app: import("elysia").default<any>): Promise<void> | void;
|
|
53
|
-
}) & {
|
|
54
|
-
get config(): string;
|
|
55
|
-
with(config: Partial<RedisModuleConfig> | (() => Partial<RedisModuleConfig> | Promise<Partial<RedisModuleConfig>>)): import("./module").ConfiguredModule<RedisModuleConfig>;
|
|
56
|
-
resolveConfig(input?: Partial<RedisModuleConfig>): RedisModuleConfig;
|
|
57
|
-
register<TConfig = any>(props?: import("./module").ModuleProps<TConfig>): (target: import("./module").ModuleClass) => void;
|
|
58
|
-
configurable<TConfig extends object>(options?: {
|
|
59
|
-
defaults?: Partial<TConfig>;
|
|
60
|
-
required?: (keyof TConfig)[];
|
|
61
|
-
}): (abstract new () => {
|
|
62
|
-
get config(): TConfig;
|
|
63
|
-
onInit(): Promise<void> | void;
|
|
64
|
-
onDestroy(): Promise<void> | void;
|
|
65
|
-
onServe(_app: import("elysia").default<any>): Promise<void> | void;
|
|
66
|
-
}) & {
|
|
67
|
-
get config(): string;
|
|
68
|
-
with(config: Partial<TConfig> | (() => Partial<TConfig> | Promise<Partial<TConfig>>)): import("./module").ConfiguredModule<TConfig>;
|
|
69
|
-
resolveConfig(input?: Partial<TConfig>): TConfig;
|
|
70
|
-
register<TConfig_1 = any>(props?: import("./module").ModuleProps<TConfig_1>): (target: import("./module").ModuleClass) => void;
|
|
71
|
-
configurable<TConfig extends object>(options?: {
|
|
72
|
-
defaults?: Partial<TConfig>;
|
|
73
|
-
required?: (keyof TConfig)[];
|
|
74
|
-
}): /*elided*/ any;
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* Declares redis connections as global services named `redis.connection.{name}`, plus
|
|
79
|
-
* `redis.connection.default` aliasing the configured default. Clients are created on first use.
|
|
80
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
81
|
-
*/
|
|
82
|
-
export declare class RedisModule extends RedisModule_base {
|
|
83
|
-
/** Closes the clients that were created. */
|
|
84
|
-
onDestroy(): Promise<void>;
|
|
85
|
-
}
|
|
86
|
-
export {};
|