@elysiumjs/core 0.4.3 → 0.5.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/README.md +26 -17
- package/dist/app.d.ts +180 -0
- package/dist/cache.d.ts +113 -0
- package/dist/command.d.ts +272 -0
- package/dist/console.d.ts +166 -0
- package/dist/database.d.ts +112 -0
- package/dist/env.d.ts +33 -0
- package/dist/event.d.ts +93 -0
- package/dist/http.d.ts +246 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +19 -0
- package/dist/job.d.ts +105 -0
- package/dist/macros.d.ts +8 -0
- package/dist/middleware.d.ts +69 -0
- package/dist/model.d.ts +4802 -0
- package/dist/module.d.ts +44 -0
- package/dist/redis.d.ts +133 -0
- package/dist/repository.d.ts +163 -0
- package/dist/service.d.ts +131 -0
- package/dist/utils.d.ts +25 -0
- package/dist/wamp.d.ts +272 -0
- package/dist/websocket.d.ts +91 -0
- package/dist/worker.d.ts +219 -0
- package/package.json +16 -9
- package/tsconfig.json +34 -33
- package/index.ts +0 -54
- package/macros.ts +0 -16
- package/src/app.ts +0 -647
- package/src/cache.ts +0 -218
- package/src/command.ts +0 -908
- package/src/console.ts +0 -493
- package/src/database.ts +0 -257
- package/src/env.ts +0 -62
- package/src/event.ts +0 -227
- package/src/http.ts +0 -736
- package/src/job.ts +0 -196
- package/src/middleware.ts +0 -164
- package/src/model.ts +0 -386
- package/src/module.ts +0 -108
- package/src/redis.ts +0 -408
- package/src/repository.ts +0 -295
- package/src/service.ts +0 -351
- package/src/utils.ts +0 -95
- package/src/wamp.ts +0 -569
- package/src/websocket.ts +0 -191
- package/src/worker.ts +0 -849
- package/types.d.ts +0 -35
package/dist/wamp.d.ts
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import type { Class, Primitive } from 'type-fest';
|
|
2
|
+
/**
|
|
3
|
+
* Options used to register a WAMP RPC for invocation.
|
|
4
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
5
|
+
*/
|
|
6
|
+
export type WampRegistrationOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* The match policy to use for the registration.
|
|
9
|
+
* @default 'exact'
|
|
10
|
+
*/
|
|
11
|
+
match?: 'prefix' | 'exact' | 'wildcard';
|
|
12
|
+
/**
|
|
13
|
+
* The invocation policy to use for the registration.
|
|
14
|
+
* @default 'single'
|
|
15
|
+
*/
|
|
16
|
+
invoke?: 'single' | 'first' | 'last' | 'roundrobin' | 'random';
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Options used to subscribe to a WAMP topic.
|
|
20
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
21
|
+
*/
|
|
22
|
+
export type WampSubscriptionOptions = Omit<WampRegistrationOptions, 'invoke'>;
|
|
23
|
+
/**
|
|
24
|
+
* Properties required when declaring a WAMP controller using the `@wamp()` decorator.
|
|
25
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
26
|
+
*/
|
|
27
|
+
export type WampProps = {
|
|
28
|
+
/**
|
|
29
|
+
* The name of the connection to use. This connection must be registered in the application properties.
|
|
30
|
+
* @default 'default'
|
|
31
|
+
*/
|
|
32
|
+
connection?: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Properties required when declaring a WAMP client in the application properties.
|
|
36
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
37
|
+
*/
|
|
38
|
+
export type WampClientProps = {
|
|
39
|
+
/**
|
|
40
|
+
* The URL to the WAMP server.
|
|
41
|
+
*/
|
|
42
|
+
url: string;
|
|
43
|
+
/**
|
|
44
|
+
* The name of the realm to connect to.
|
|
45
|
+
*/
|
|
46
|
+
realm: string;
|
|
47
|
+
/**
|
|
48
|
+
* Whether to automatically reconnect to the WAMP server on connection loss.
|
|
49
|
+
*/
|
|
50
|
+
autoReconnect?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* The maximum number of times to retry connecting to the WAMP server.
|
|
53
|
+
*/
|
|
54
|
+
maxRetries?: number;
|
|
55
|
+
/**
|
|
56
|
+
* The interval to wait between retries when connecting to the WAMP server.
|
|
57
|
+
*/
|
|
58
|
+
retryInterval?: number;
|
|
59
|
+
/**
|
|
60
|
+
* The authentication ID to use in challenges.
|
|
61
|
+
*/
|
|
62
|
+
authid?: string;
|
|
63
|
+
/**
|
|
64
|
+
* An array of supported authentication methods.
|
|
65
|
+
*/
|
|
66
|
+
authmethods?: string[];
|
|
67
|
+
/**
|
|
68
|
+
* Callback for handling WAMP authentication challenges.
|
|
69
|
+
* @param method The authentication method.
|
|
70
|
+
* @param extra Authentication metadata.
|
|
71
|
+
*/
|
|
72
|
+
onChallenge?(method: string, extra: any): string | null;
|
|
73
|
+
/**
|
|
74
|
+
* Callback for handling the WAMP connection open event.
|
|
75
|
+
*/
|
|
76
|
+
onOpen?(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Callback for handling the WAMP connection close event.
|
|
79
|
+
*/
|
|
80
|
+
onClose?(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Callback for handling the WAMP connection error event.
|
|
83
|
+
*/
|
|
84
|
+
onError?(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Callback for handling the WAMP connection reconnect event.
|
|
87
|
+
*/
|
|
88
|
+
onReconnect?(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Callback for handling the WAMP connection reconnect success event.
|
|
91
|
+
*/
|
|
92
|
+
onReconnectSuccess?(): void;
|
|
93
|
+
};
|
|
94
|
+
export type WampClient = {
|
|
95
|
+
/**
|
|
96
|
+
* Disconnects from WAMP server. Clears all queues, subscriptions and calls.
|
|
97
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
98
|
+
*/
|
|
99
|
+
disconnect(): Promise<void>;
|
|
100
|
+
subscribe(topic: string, handler: WampSubscriptionHandler, options?: WampSubscriptionOptions): Promise<{
|
|
101
|
+
topic: string;
|
|
102
|
+
requestId: string;
|
|
103
|
+
subscriptionId: string;
|
|
104
|
+
subscriptionKey: string;
|
|
105
|
+
}>;
|
|
106
|
+
unsubscribe(subscriptionIdOrKey: string, handler?: WampSubscriptionHandler): Promise<{
|
|
107
|
+
topic: string;
|
|
108
|
+
requestId: string;
|
|
109
|
+
}>;
|
|
110
|
+
publish(topic: string, params?: Primitive | Array<any> | Record<string, Primitive | Array<any>> | {
|
|
111
|
+
argsList: Array<any>;
|
|
112
|
+
argsDict: Record<string, any>;
|
|
113
|
+
}, options?: {
|
|
114
|
+
exclude?: number | number[];
|
|
115
|
+
exclude_authid?: string | string[];
|
|
116
|
+
exclude_authrole?: string | string[];
|
|
117
|
+
eligible?: number | number[];
|
|
118
|
+
eligible_authid?: string | string[];
|
|
119
|
+
eligible_authrole?: string | string[];
|
|
120
|
+
exclude_me?: boolean;
|
|
121
|
+
disclose_me?: boolean;
|
|
122
|
+
ppt_scheme?: string;
|
|
123
|
+
ppt_serializer?: string;
|
|
124
|
+
ppt_cipher?: string;
|
|
125
|
+
ppt_keyid?: string;
|
|
126
|
+
}): Promise<{
|
|
127
|
+
topic: string;
|
|
128
|
+
requestId: string;
|
|
129
|
+
publicationId: string;
|
|
130
|
+
}>;
|
|
131
|
+
call(procedure: string, params?: Primitive | Array<any> | Record<string, Primitive | Array<any>> | {
|
|
132
|
+
argsList: Array<any>;
|
|
133
|
+
argsDict: Record<string, any>;
|
|
134
|
+
}, options?: {
|
|
135
|
+
disclose_me?: boolean;
|
|
136
|
+
progress_callback?(args: {
|
|
137
|
+
argsList: Array<any>;
|
|
138
|
+
argsDict: Record<string, any>;
|
|
139
|
+
}): void;
|
|
140
|
+
timeout?: number;
|
|
141
|
+
ppt_scheme?: string;
|
|
142
|
+
ppt_serializer?: string;
|
|
143
|
+
ppt_cipher?: string;
|
|
144
|
+
ppt_keyid?: string;
|
|
145
|
+
}): Promise<{
|
|
146
|
+
details: Record<string, any>;
|
|
147
|
+
argsList?: Array<any>;
|
|
148
|
+
argsDict?: Record<string, any>;
|
|
149
|
+
}>;
|
|
150
|
+
cancel(requestId: string, options?: {
|
|
151
|
+
mode?: 'kill' | 'killnowait' | 'skip';
|
|
152
|
+
}): true;
|
|
153
|
+
register(topic: string, handler: WampRegistrationHandler, options?: WampRegistrationOptions): Promise<{
|
|
154
|
+
topic: string;
|
|
155
|
+
requestId: string;
|
|
156
|
+
registrationId: string;
|
|
157
|
+
}>;
|
|
158
|
+
unregister(registrationId: string): Promise<{
|
|
159
|
+
topic: string;
|
|
160
|
+
requestId: string;
|
|
161
|
+
}>;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Data sent to a WAMP RPC.
|
|
165
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
166
|
+
*/
|
|
167
|
+
export type WampRegistrationHandlerArgs<TList = any[], TDict = any> = {
|
|
168
|
+
/**
|
|
169
|
+
* The arguments passed to the RPC or subscription.
|
|
170
|
+
*/
|
|
171
|
+
argsList: TList;
|
|
172
|
+
/**
|
|
173
|
+
* The keyword arguments passed to the RPC or subscription.
|
|
174
|
+
*/
|
|
175
|
+
argsDict: TDict;
|
|
176
|
+
/**
|
|
177
|
+
* The WAMP details object.
|
|
178
|
+
*/
|
|
179
|
+
details: {
|
|
180
|
+
receive_progress?: boolean;
|
|
181
|
+
trustlevel?: number;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* The result handler for the RPC. Use this to send progressive results.
|
|
185
|
+
* @param value
|
|
186
|
+
*/
|
|
187
|
+
result_handler: (value: any) => void;
|
|
188
|
+
/**
|
|
189
|
+
* The error handler for the RPC when working with progressive results.
|
|
190
|
+
* @param error The thrown error.
|
|
191
|
+
*/
|
|
192
|
+
error_handler: (error: any) => void;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Data sent to a WAMP subscription.
|
|
196
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
197
|
+
*/
|
|
198
|
+
export type WampSubscriptionHandlerArgs = Omit<WampRegistrationHandlerArgs, 'result_handler' | 'error_handler'>;
|
|
199
|
+
/**
|
|
200
|
+
* The WAMP RPC handler function.
|
|
201
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
202
|
+
* @param data The data sent to the handler.
|
|
203
|
+
*/
|
|
204
|
+
export type WampRegistrationHandler = <T = any>(data: WampRegistrationHandlerArgs) => T;
|
|
205
|
+
/**
|
|
206
|
+
* The WAMP subscription handler function.
|
|
207
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
208
|
+
* @param data The data sent to the handler.
|
|
209
|
+
*/
|
|
210
|
+
export type WampSubscriptionHandler = <T = any>(data: WampSubscriptionHandlerArgs) => T;
|
|
211
|
+
export declare namespace Wamp {
|
|
212
|
+
/**
|
|
213
|
+
* Retrieves the client for a WAMP connection.
|
|
214
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
215
|
+
* @param name The name of the connection.
|
|
216
|
+
* @returns The Wampy client for the connection with the given name.
|
|
217
|
+
*/
|
|
218
|
+
const getConnection: (name: string) => WampClient;
|
|
219
|
+
/**
|
|
220
|
+
* Creates and registers a new WAMP client.
|
|
221
|
+
*
|
|
222
|
+
* This will make the registered connection available for dependency injection with
|
|
223
|
+
* the key `wamp.connection.{name}`, where `{name}` is replaced with the given name.
|
|
224
|
+
*
|
|
225
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
226
|
+
*
|
|
227
|
+
* @param name The name of the connection.
|
|
228
|
+
* @param config The configuration for the WAMP client.
|
|
229
|
+
* @returns The newly created and configured WAMP client for the given connection.
|
|
230
|
+
*/
|
|
231
|
+
const registerConnection: (name: string, config: WampClientProps) => WampClient;
|
|
232
|
+
/**
|
|
233
|
+
* Checks if a WAMP connection with the given name exists.
|
|
234
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
235
|
+
* @param name The name of the connection.
|
|
236
|
+
* @returns `true` if the connection exists, `false` otherwise.
|
|
237
|
+
*/
|
|
238
|
+
const connectionExists: (name: string) => boolean;
|
|
239
|
+
/**
|
|
240
|
+
* Retrieves the default WAMP connection.
|
|
241
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
242
|
+
* @returns The default WAMP connection.
|
|
243
|
+
*/
|
|
244
|
+
const getDefaultConnection: () => WampClient;
|
|
245
|
+
/**
|
|
246
|
+
* Sets the default WAMP connection.
|
|
247
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
248
|
+
* @param name The name of the connection to set as default.
|
|
249
|
+
* @returns The default WAMP connection.
|
|
250
|
+
*/
|
|
251
|
+
const setDefaultConnection: (name: string) => WampClient;
|
|
252
|
+
/**
|
|
253
|
+
* Marks a class as a WAMP controller.
|
|
254
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
255
|
+
* @param options The decorator options.
|
|
256
|
+
*/
|
|
257
|
+
const controller: (options: WampProps) => (target: Class<any>) => void;
|
|
258
|
+
/**
|
|
259
|
+
* Registers a method as a WAMP RPC.
|
|
260
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
261
|
+
* @param topic The RPC topic to register.
|
|
262
|
+
* @param options The registration options.
|
|
263
|
+
*/
|
|
264
|
+
const register: (topic: string, options?: WampRegistrationOptions) => MethodDecorator;
|
|
265
|
+
/**
|
|
266
|
+
* Subscribes to a WAMP topic.
|
|
267
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
268
|
+
* @param topic The topic to subscribe to.
|
|
269
|
+
* @param options The subscription options.
|
|
270
|
+
*/
|
|
271
|
+
const subscribe: (topic: string, options?: WampSubscriptionOptions) => MethodDecorator;
|
|
272
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { ServerWebSocket } from 'bun';
|
|
2
|
+
import type { Context, ErrorContext, TSchema } from 'elysia';
|
|
3
|
+
import type { Class, ConditionalPick, JsonObject, Primitive } from 'type-fest';
|
|
4
|
+
import type { Route } from './http';
|
|
5
|
+
/**
|
|
6
|
+
* Properties required when declaring a websocket controller using the `@websocket()` decorator.
|
|
7
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
8
|
+
*/
|
|
9
|
+
export type WebsocketProps = {
|
|
10
|
+
/**
|
|
11
|
+
* The path of the websocket route.
|
|
12
|
+
*/
|
|
13
|
+
path: Route;
|
|
14
|
+
/**
|
|
15
|
+
* The options for the websocket server.
|
|
16
|
+
*/
|
|
17
|
+
options?: ConditionalPick<Bun.WebSocketHandler, Primitive | JsonObject>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The websocket connection instance.
|
|
21
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
22
|
+
* @template TData Additional data stored in the websocket connection.
|
|
23
|
+
*/
|
|
24
|
+
export type WS<TData = unknown> = ServerWebSocket<{
|
|
25
|
+
/**
|
|
26
|
+
* Unique identifier for the websocket connection.
|
|
27
|
+
*/
|
|
28
|
+
id: string;
|
|
29
|
+
} & Context & TData>;
|
|
30
|
+
/**
|
|
31
|
+
* The data generated when an error occurs in a websocket connection.
|
|
32
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
33
|
+
*/
|
|
34
|
+
export type WSError = ErrorContext & {
|
|
35
|
+
error: Readonly<Error>;
|
|
36
|
+
};
|
|
37
|
+
export declare namespace Websocket {
|
|
38
|
+
/**
|
|
39
|
+
* Marks a class as a websocket controller.
|
|
40
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
41
|
+
* @param props The websocket route properties.
|
|
42
|
+
*/
|
|
43
|
+
const controller: (props: WebsocketProps) => (target: Class<any>) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Marks a method as the websocket "open" event handler.
|
|
46
|
+
*
|
|
47
|
+
* This decorator should be used on a websocket controller method. Only one "open" event handler
|
|
48
|
+
* can be defined per websocket controller.
|
|
49
|
+
*
|
|
50
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
51
|
+
*/
|
|
52
|
+
const onOpen: () => MethodDecorator;
|
|
53
|
+
/**
|
|
54
|
+
* Marks a method as the websocket "close" event handler.
|
|
55
|
+
*
|
|
56
|
+
* This decorator should be used on a websocket controller method. Only one "close" event handler
|
|
57
|
+
* can be defined per websocket controller.
|
|
58
|
+
*
|
|
59
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
60
|
+
*/
|
|
61
|
+
const onClose: () => MethodDecorator;
|
|
62
|
+
/**
|
|
63
|
+
* Marks a method as the websocket "message" event handler.
|
|
64
|
+
*
|
|
65
|
+
* This decorator should be used on a websocket controller method. Only one "message" event handler
|
|
66
|
+
* can be defined per websocket controller.
|
|
67
|
+
*
|
|
68
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
69
|
+
*
|
|
70
|
+
* @param schema The schema of the message body.
|
|
71
|
+
*/
|
|
72
|
+
const onMessage: (schema?: TSchema) => MethodDecorator;
|
|
73
|
+
/**
|
|
74
|
+
* Marks a method as the websocket "drain" event handler.
|
|
75
|
+
*
|
|
76
|
+
* This decorator should be used on a websocket controller method. Only one "drain" event handler
|
|
77
|
+
* can be defined per websocket controller.
|
|
78
|
+
*
|
|
79
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
80
|
+
*/
|
|
81
|
+
const onDrain: () => MethodDecorator;
|
|
82
|
+
/**
|
|
83
|
+
* Marks a method as the websocket "error" event handler.
|
|
84
|
+
*
|
|
85
|
+
* This decorator should be used on a websocket controller method. Only one "error" event handler
|
|
86
|
+
* can be defined per websocket controller.
|
|
87
|
+
*
|
|
88
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
89
|
+
*/
|
|
90
|
+
const onError: () => MethodDecorator;
|
|
91
|
+
}
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import type { Class } from 'type-fest';
|
|
2
|
+
import type { Job } from './job';
|
|
3
|
+
import { InteractsWithConsole } from './console';
|
|
4
|
+
declare const BunWorker: {
|
|
5
|
+
new (scriptURL: string | URL, options?: WorkerOptions): globalThis.Worker;
|
|
6
|
+
prototype: globalThis.Worker;
|
|
7
|
+
};
|
|
8
|
+
type BunWorker = InstanceType<typeof BunWorker>;
|
|
9
|
+
/**
|
|
10
|
+
* Configuration options for a job queue.
|
|
11
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
12
|
+
*/
|
|
13
|
+
export interface QueueOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The name of the queue.
|
|
16
|
+
*/
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* The maximum number of concurrent jobs to process in this queue.
|
|
20
|
+
* @default 1
|
|
21
|
+
*/
|
|
22
|
+
concurrency?: number;
|
|
23
|
+
/**
|
|
24
|
+
* The maximum number of retries for failed jobs.
|
|
25
|
+
* @default 0
|
|
26
|
+
*/
|
|
27
|
+
maxRetries?: number;
|
|
28
|
+
/**
|
|
29
|
+
* The delay in milliseconds between retries.
|
|
30
|
+
* @default 1000
|
|
31
|
+
*/
|
|
32
|
+
retryDelay?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Whether to pause processing when an error occurs.
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
pauseOnError?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Worker class that manages multiple job queues and processes them in parallel.
|
|
41
|
+
* Each queue processes its jobs sequentially by default, but can be configured for concurrency.
|
|
42
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
43
|
+
*/
|
|
44
|
+
export declare class Worker extends InteractsWithConsole {
|
|
45
|
+
#private;
|
|
46
|
+
/**
|
|
47
|
+
* The queues managed by this worker.
|
|
48
|
+
*/
|
|
49
|
+
private queues;
|
|
50
|
+
/**
|
|
51
|
+
* The default queue name.
|
|
52
|
+
*/
|
|
53
|
+
private defaultQueueName;
|
|
54
|
+
static spawn(thread: BunWorker, queues?: string[], options?: Omit<QueueOptions, 'name'>): Worker;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a new Worker instance.
|
|
57
|
+
*/
|
|
58
|
+
constructor();
|
|
59
|
+
/**
|
|
60
|
+
* Gets the worker ID.
|
|
61
|
+
* @returns The worker ID.
|
|
62
|
+
*/
|
|
63
|
+
get id(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new queue with the specified options.
|
|
66
|
+
*
|
|
67
|
+
* @param options The queue configuration options.
|
|
68
|
+
* @returns The Worker instance for method chaining.
|
|
69
|
+
*/
|
|
70
|
+
createQueue(options: QueueOptions): Worker;
|
|
71
|
+
/**
|
|
72
|
+
* Adds a job to the specified queue or the default queue if not specified.
|
|
73
|
+
*
|
|
74
|
+
* @param job The job to add to the queue.
|
|
75
|
+
* @param queueName Optional name of the queue to add the job to. Defaults to the default queue.
|
|
76
|
+
* @returns The Worker instance for method chaining.
|
|
77
|
+
* @throws Error if the specified queue does not exist.
|
|
78
|
+
*/
|
|
79
|
+
addJob(job: Job, queueName?: string): Worker;
|
|
80
|
+
/**
|
|
81
|
+
* Pauses a queue, preventing it from processing new jobs.
|
|
82
|
+
*
|
|
83
|
+
* @param queueName The name of the queue to pause. If not specified, pauses all queues.
|
|
84
|
+
* @returns The Worker instance for method chaining.
|
|
85
|
+
*/
|
|
86
|
+
pause(queueName?: string): Worker;
|
|
87
|
+
/**
|
|
88
|
+
* Resumes a paused queue.
|
|
89
|
+
*
|
|
90
|
+
* @param queueName The name of the queue to resume. If not specified, resumes all queues.
|
|
91
|
+
* @returns The Worker instance for method chaining.
|
|
92
|
+
*/
|
|
93
|
+
resume(queueName?: string): Worker;
|
|
94
|
+
/**
|
|
95
|
+
* Drains a queue, completing all current jobs but not accepting new ones.
|
|
96
|
+
*
|
|
97
|
+
* @param queueName The name of the queue to drain. If not specified, drains all queues.
|
|
98
|
+
* @returns The Worker instance for method chaining.
|
|
99
|
+
*/
|
|
100
|
+
drain(queueName?: string): Worker;
|
|
101
|
+
/**
|
|
102
|
+
* Clears all jobs from a queue.
|
|
103
|
+
*
|
|
104
|
+
* @param queueName The name of the queue to clear. If not specified, clears all queues.
|
|
105
|
+
* @returns The Worker instance for method chaining.
|
|
106
|
+
*/
|
|
107
|
+
clear(queueName?: string): Worker;
|
|
108
|
+
/**
|
|
109
|
+
* Gets the number of jobs in a queue.
|
|
110
|
+
*
|
|
111
|
+
* @param queueName The name of the queue to get the size of.
|
|
112
|
+
* @returns The number of jobs in the queue.
|
|
113
|
+
* @throws Error if the specified queue does not exist.
|
|
114
|
+
*/
|
|
115
|
+
size(queueName?: string): number;
|
|
116
|
+
/**
|
|
117
|
+
* Gets the total number of jobs across all queues.
|
|
118
|
+
*
|
|
119
|
+
* @returns The total number of jobs.
|
|
120
|
+
*/
|
|
121
|
+
totalSize(): number;
|
|
122
|
+
/**
|
|
123
|
+
* Processes the next job in the specified queue.
|
|
124
|
+
*
|
|
125
|
+
* @param queueName The name of the queue to process.
|
|
126
|
+
*/
|
|
127
|
+
private processNextJob;
|
|
128
|
+
/**
|
|
129
|
+
* Processes jobs in a queue up to the concurrency limit.
|
|
130
|
+
*
|
|
131
|
+
* @param queueName The name of the queue to process.
|
|
132
|
+
*/
|
|
133
|
+
private processQueueJobs;
|
|
134
|
+
/**
|
|
135
|
+
* Gets statistics about all queues.
|
|
136
|
+
*
|
|
137
|
+
* @returns An object containing statistics about each queue.
|
|
138
|
+
*/
|
|
139
|
+
getStats(): Record<string, {
|
|
140
|
+
waiting: number;
|
|
141
|
+
processing: number;
|
|
142
|
+
paused: boolean;
|
|
143
|
+
draining: boolean;
|
|
144
|
+
}>;
|
|
145
|
+
/**
|
|
146
|
+
* Cancels a job by its ID.
|
|
147
|
+
*
|
|
148
|
+
* @param jobId The ID of the job to cancel.
|
|
149
|
+
* @param queueName Optional queue name to search in. If not provided, searches all queues.
|
|
150
|
+
* @returns `true` if the job was found and canceled, false otherwise.
|
|
151
|
+
*/
|
|
152
|
+
cancelJob(jobId: string, queueName?: string): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Cancels a job in a specific queue.
|
|
155
|
+
*
|
|
156
|
+
* @param jobId The ID of the job to cancel.
|
|
157
|
+
* @param queueName The name of the queue to search in.
|
|
158
|
+
* @returns `true` if the job was found and canceled, false otherwise.
|
|
159
|
+
*/
|
|
160
|
+
private cancelJobInQueue;
|
|
161
|
+
/**
|
|
162
|
+
* Cancels all jobs in a queue.
|
|
163
|
+
*
|
|
164
|
+
* @param queueName The name of the queue to cancel jobs from. If not provided, cancels jobs in all queues.
|
|
165
|
+
* @returns The number of jobs canceled.
|
|
166
|
+
*/
|
|
167
|
+
cancelAllJobs(queueName?: string): number;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* A pool of worker threads.
|
|
171
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
172
|
+
*/
|
|
173
|
+
export declare class WorkerPool extends InteractsWithConsole {
|
|
174
|
+
private workers;
|
|
175
|
+
private currentWorkerIndex;
|
|
176
|
+
private queueWorkerMap;
|
|
177
|
+
static readonly instance: WorkerPool;
|
|
178
|
+
private constructor();
|
|
179
|
+
/**
|
|
180
|
+
* Initialize the worker pool.
|
|
181
|
+
*/
|
|
182
|
+
init(): Promise<void>;
|
|
183
|
+
/**
|
|
184
|
+
* Add a new worker to the pool.
|
|
185
|
+
* @param queues The queues to listen from the worker.
|
|
186
|
+
*/
|
|
187
|
+
addWorker(queues?: string[]): Promise<void>;
|
|
188
|
+
/**
|
|
189
|
+
* Removes a worker from the pool.
|
|
190
|
+
* @param w The worker to be removed. If not provided, the last worker will be removed.
|
|
191
|
+
*/
|
|
192
|
+
removeWorker(w?: BunWorker): void;
|
|
193
|
+
/**
|
|
194
|
+
* Terminates all workers in the pool.
|
|
195
|
+
*/
|
|
196
|
+
terminate(): void;
|
|
197
|
+
/**
|
|
198
|
+
* Runs a job in a worker.
|
|
199
|
+
* @param job The job class to run.
|
|
200
|
+
* @param args The class constructor arguments to pass to the job.
|
|
201
|
+
*/
|
|
202
|
+
runJob<T extends Job, TClass extends Class<T>>(job: TClass, ...args: ConstructorParameters<TClass>): void;
|
|
203
|
+
/**
|
|
204
|
+
* Cancels a job in the worker pool.
|
|
205
|
+
*
|
|
206
|
+
* @param jobId The ID of the job to cancel.
|
|
207
|
+
* @param queue Optional queue name to search in.
|
|
208
|
+
* @returns `true` if a cancellation message was sent to workers.
|
|
209
|
+
*/
|
|
210
|
+
cancelJob(jobId: string, queue?: string): boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Cancels all jobs in a queue.
|
|
213
|
+
*
|
|
214
|
+
* @param queue Optional queue name to cancel jobs from. If not provided, cancels jobs in all queues.
|
|
215
|
+
* @returns `true` if a cancellation message was sent to workers.
|
|
216
|
+
*/
|
|
217
|
+
cancelAllJobs(queue?: string): boolean;
|
|
218
|
+
}
|
|
219
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elysiumjs/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "A super-charged web framework for Bun, built on top of ElysiaJS.",
|
|
6
6
|
"private": false,
|
|
7
7
|
"author": "Workbud Technologies Inc.",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/
|
|
10
|
+
"url": "https://github.com/workbud/elysium"
|
|
11
11
|
},
|
|
12
|
-
"homepage": "https://github.com/
|
|
12
|
+
"homepage": "https://github.com/workbud/elysium",
|
|
13
13
|
"scripts": {
|
|
14
|
-
"format": "prettier --write \"./src/**/*.ts\""
|
|
14
|
+
"format": "prettier --write \"./src/**/*.ts\"",
|
|
15
|
+
"clean": "rimraf dist",
|
|
16
|
+
"build:js": "bun build ./src/index.ts --outdir ./dist --target bun --packages external --root ./src --minify",
|
|
17
|
+
"build:ts": "tsc",
|
|
18
|
+
"build": "bun run clean && bun run build:js && bun run build:ts",
|
|
19
|
+
"prepublishOnly": "bun run build"
|
|
15
20
|
},
|
|
16
21
|
"keywords": [
|
|
17
22
|
"elysium",
|
|
@@ -20,22 +25,24 @@
|
|
|
20
25
|
"api",
|
|
21
26
|
"typescript"
|
|
22
27
|
],
|
|
23
|
-
"module": "index.
|
|
28
|
+
"module": "dist/index.js",
|
|
24
29
|
"type": "module",
|
|
30
|
+
"types": "dist/index.d.ts",
|
|
25
31
|
"dependencies": {
|
|
26
32
|
"@elysiajs/swagger": "^1.3.0",
|
|
27
33
|
"cache-manager": "^6.4.3",
|
|
28
34
|
"cacheable": "^1.9.0",
|
|
29
|
-
"drizzle-orm": "0.
|
|
35
|
+
"drizzle-orm": "^0.44.2",
|
|
30
36
|
"elysia": "latest",
|
|
31
37
|
"radash": "^12.1.0",
|
|
32
38
|
"reflect-metadata": "^0.2.2",
|
|
33
39
|
"wampy": "^7.1.1"
|
|
34
40
|
},
|
|
35
41
|
"devDependencies": {
|
|
36
|
-
"@ianvs/prettier-plugin-sort-imports": "^4.4.
|
|
37
|
-
"
|
|
38
|
-
"
|
|
42
|
+
"@ianvs/prettier-plugin-sort-imports": "^4.4.2",
|
|
43
|
+
"@types/bun": "latest",
|
|
44
|
+
"rimraf": "^6.0.1",
|
|
45
|
+
"type-fest": "^4.41.0"
|
|
39
46
|
},
|
|
40
47
|
"peerDependencies": {
|
|
41
48
|
"typescript": "^5.8.3"
|