@elysiumjs/core 0.6.1 → 0.8.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 +37 -0
- package/README.md +36 -21
- package/dist/app.d.ts +65 -67
- package/dist/command.d.ts +20 -4
- package/dist/connections.d.ts +17 -0
- package/dist/container.d.ts +128 -0
- package/dist/errors.d.ts +159 -0
- package/dist/event-wiring.d.ts +23 -0
- package/dist/event.d.ts +38 -1
- package/dist/http.d.ts +3 -3
- package/dist/index.d.ts +11 -13
- package/dist/index.js +14 -14
- package/dist/kernel.d.ts +71 -0
- package/dist/metadata.d.ts +46 -0
- package/dist/middleware.d.ts +12 -2
- 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 +53 -100
- 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/package.json +5 -9
- package/dist/cache.d.ts +0 -113
- package/dist/database.d.ts +0 -112
- package/dist/job.d.ts +0 -105
- package/dist/model.d.ts +0 -2413
- package/dist/repository.d.ts +0 -175
- package/dist/tenancy.d.ts +0 -244
- package/dist/worker.d.ts +0 -219
package/dist/wamp.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { Class
|
|
1
|
+
import type { Class } from 'type-fest';
|
|
2
|
+
import { Elysia } from 'elysia';
|
|
3
|
+
import Wampy from 'wampy';
|
|
2
4
|
/**
|
|
3
5
|
* Options used to register a WAMP RPC for invocation.
|
|
4
6
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
@@ -69,11 +71,11 @@ export type WampClientProps = {
|
|
|
69
71
|
* @param method The authentication method.
|
|
70
72
|
* @param extra Authentication metadata.
|
|
71
73
|
*/
|
|
72
|
-
onChallenge?(method: string, extra:
|
|
74
|
+
onChallenge?(method: string, extra: Record<string, unknown>): string | Promise<string>;
|
|
73
75
|
/**
|
|
74
|
-
*
|
|
76
|
+
* Called once the first connection is established; not on wampy reconnects.
|
|
75
77
|
*/
|
|
76
|
-
onOpen?(): void
|
|
78
|
+
onOpen?(): void | Promise<void>;
|
|
77
79
|
/**
|
|
78
80
|
* Callback for handling the WAMP connection close event.
|
|
79
81
|
*/
|
|
@@ -81,7 +83,7 @@ export type WampClientProps = {
|
|
|
81
83
|
/**
|
|
82
84
|
* Callback for handling the WAMP connection error event.
|
|
83
85
|
*/
|
|
84
|
-
onError?(): void;
|
|
86
|
+
onError?(error: Error): void;
|
|
85
87
|
/**
|
|
86
88
|
* Callback for handling the WAMP connection reconnect event.
|
|
87
89
|
*/
|
|
@@ -89,77 +91,13 @@ export type WampClientProps = {
|
|
|
89
91
|
/**
|
|
90
92
|
* Callback for handling the WAMP connection reconnect success event.
|
|
91
93
|
*/
|
|
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
|
-
}>;
|
|
94
|
+
onReconnectSuccess?(details: Record<string, unknown>): void;
|
|
162
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
* The WAMP client, as provided by Wampy.
|
|
98
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
99
|
+
*/
|
|
100
|
+
export type WampClient = Wampy;
|
|
163
101
|
/**
|
|
164
102
|
* Data sent to a WAMP RPC.
|
|
165
103
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
@@ -210,25 +148,20 @@ export type WampRegistrationHandler = <T = any>(data: WampRegistrationHandlerArg
|
|
|
210
148
|
export type WampSubscriptionHandler = <T = any>(data: WampSubscriptionHandlerArgs) => T;
|
|
211
149
|
export declare namespace Wamp {
|
|
212
150
|
/**
|
|
213
|
-
*
|
|
151
|
+
* Creates a service name for a WAMP connection.
|
|
214
152
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
215
153
|
* @param name The name of the connection.
|
|
216
|
-
* @returns
|
|
154
|
+
* @returns A service name for the connection.
|
|
217
155
|
*/
|
|
218
|
-
const
|
|
156
|
+
const getConnectionName: (name: string) => string;
|
|
219
157
|
/**
|
|
220
|
-
*
|
|
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
|
-
*
|
|
158
|
+
* Retrieves the client for a WAMP connection declared by the {@link WampModule}.
|
|
225
159
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
226
|
-
*
|
|
227
160
|
* @param name The name of the connection.
|
|
228
|
-
* @
|
|
229
|
-
* @
|
|
161
|
+
* @returns The Wampy client for the connection with the given name.
|
|
162
|
+
* @throws {ServiceNotFoundError} If no connection with that name is declared.
|
|
230
163
|
*/
|
|
231
|
-
const
|
|
164
|
+
const getConnection: (name?: string) => Wampy;
|
|
232
165
|
/**
|
|
233
166
|
* Checks if a WAMP connection with the given name exists.
|
|
234
167
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
@@ -241,14 +174,12 @@ export declare namespace Wamp {
|
|
|
241
174
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
242
175
|
* @returns The default WAMP connection.
|
|
243
176
|
*/
|
|
244
|
-
const getDefaultConnection: () =>
|
|
177
|
+
const getDefaultConnection: () => Wampy;
|
|
245
178
|
/**
|
|
246
|
-
*
|
|
179
|
+
* Creates a WAMP client and starts connecting it, retrying on failure.
|
|
247
180
|
* @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
181
|
*/
|
|
251
|
-
const
|
|
182
|
+
const createClient: (name: string, config: WampClientProps) => WampClient;
|
|
252
183
|
/**
|
|
253
184
|
* Marks a class as a WAMP controller.
|
|
254
185
|
* @author Axel Nana <axel.nana@workbud.com>
|
|
@@ -270,3 +201,52 @@ export declare namespace Wamp {
|
|
|
270
201
|
*/
|
|
271
202
|
const subscribe: (topic: string, options?: WampSubscriptionOptions) => MethodDecorator;
|
|
272
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Configuration of the {@link WampModule}.
|
|
206
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
207
|
+
*/
|
|
208
|
+
export type WampModuleConfig = {
|
|
209
|
+
/** The name of the connection that `default` resolves to. */
|
|
210
|
+
default: string;
|
|
211
|
+
/** The connections to declare, by name. */
|
|
212
|
+
connections: Record<string, WampClientProps>;
|
|
213
|
+
};
|
|
214
|
+
declare const WampModule_base: (abstract new () => {
|
|
215
|
+
get config(): WampModuleConfig;
|
|
216
|
+
onInit(): Promise<void> | void;
|
|
217
|
+
onDestroy(): Promise<void> | void;
|
|
218
|
+
onServe(_app: Elysia<any>): Promise<void> | void;
|
|
219
|
+
}) & {
|
|
220
|
+
get config(): string;
|
|
221
|
+
with(config: Partial<WampModuleConfig> | (() => Partial<WampModuleConfig> | Promise<Partial<WampModuleConfig>>)): import("./module").ConfiguredModule<WampModuleConfig>;
|
|
222
|
+
resolveConfig(input?: Partial<WampModuleConfig>): WampModuleConfig;
|
|
223
|
+
register<TConfig = any>(props?: import("./module").ModuleProps<TConfig>): (target: import("./module").ModuleClass) => void;
|
|
224
|
+
configurable<TConfig extends object>(options?: {
|
|
225
|
+
defaults?: Partial<TConfig>;
|
|
226
|
+
required?: (keyof TConfig)[];
|
|
227
|
+
}): (abstract new () => {
|
|
228
|
+
get config(): TConfig;
|
|
229
|
+
onInit(): Promise<void> | void;
|
|
230
|
+
onDestroy(): Promise<void> | void;
|
|
231
|
+
onServe(_app: Elysia<any>): Promise<void> | void;
|
|
232
|
+
}) & {
|
|
233
|
+
get config(): string;
|
|
234
|
+
with(config: Partial<TConfig> | (() => Partial<TConfig> | Promise<Partial<TConfig>>)): import("./module").ConfiguredModule<TConfig>;
|
|
235
|
+
resolveConfig(input?: Partial<TConfig>): TConfig;
|
|
236
|
+
register<TConfig_1 = any>(props?: import("./module").ModuleProps<TConfig_1>): (target: import("./module").ModuleClass) => void;
|
|
237
|
+
configurable<TConfig extends object>(options?: {
|
|
238
|
+
defaults?: Partial<TConfig>;
|
|
239
|
+
required?: (keyof TConfig)[];
|
|
240
|
+
}): /*elided*/ any;
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* Declares WAMP connections as global services named `wamp.connection.{name}`, plus
|
|
245
|
+
* `wamp.connection.default` aliasing the configured default. Clients are created on first use.
|
|
246
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
247
|
+
*/
|
|
248
|
+
export declare class WampModule extends WampModule_base {
|
|
249
|
+
/** Disconnects the clients that were created. */
|
|
250
|
+
onDestroy(): Promise<void>;
|
|
251
|
+
}
|
|
252
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elysiumjs/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
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,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"format": "prettier --write \"./src/**/*.ts\"",
|
|
15
15
|
"clean": "rimraf dist",
|
|
16
|
-
"build:js": "bun build ./src/index.ts --outdir ./dist --target bun --packages external --root ./src --minify",
|
|
16
|
+
"build:js": "bun build ./src/index.ts --outdir ./dist --target bun --packages external --root ./src --minify-syntax --minify-whitespace",
|
|
17
17
|
"build:ts": "tsc",
|
|
18
18
|
"build": "bun run clean && bun run build:js && bun run build:ts",
|
|
19
19
|
"typecheck": "tsc --noEmit",
|
|
@@ -33,14 +33,10 @@
|
|
|
33
33
|
"./src/index.ts"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@elysiajs/
|
|
37
|
-
"
|
|
38
|
-
"cacheable": "^2.0.3",
|
|
39
|
-
"drizzle-orm": "^0.44.6",
|
|
40
|
-
"elysia": "^1.4.9",
|
|
36
|
+
"@elysiajs/openapi": "^1.4.16",
|
|
37
|
+
"elysia": "^1.4.30",
|
|
41
38
|
"radash": "^12.1.1",
|
|
42
|
-
"
|
|
43
|
-
"wampy": "^7.2.0"
|
|
39
|
+
"wampy": "^8.0.2"
|
|
44
40
|
},
|
|
45
41
|
"trustedDependencies": [
|
|
46
42
|
"es5-ext"
|
package/dist/cache.d.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface for a cache storage.
|
|
3
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
4
|
-
*/
|
|
5
|
-
export interface CacheInterface {
|
|
6
|
-
/**
|
|
7
|
-
* Retrieves the cached data for a given key.
|
|
8
|
-
* @typeParam T The type of the cached data.
|
|
9
|
-
*
|
|
10
|
-
* @param key The key of the cached data.
|
|
11
|
-
*/
|
|
12
|
-
get<T>(key: string): Promise<T | undefined>;
|
|
13
|
-
/**
|
|
14
|
-
* Retrieves the cached data for a given list of keys.
|
|
15
|
-
* @typeParam T The type of the cached data.
|
|
16
|
-
*
|
|
17
|
-
* @param keys The list of cached data keys.
|
|
18
|
-
*/
|
|
19
|
-
mget<T>(keys: string[]): Promise<Array<T | undefined>>;
|
|
20
|
-
/**
|
|
21
|
-
* Gets the TTL of the cached data with the given key.
|
|
22
|
-
* @param key The key of the cached data.
|
|
23
|
-
* @returns The TTL of the cached data, or `undefined` if the data does not exist.
|
|
24
|
-
*/
|
|
25
|
-
ttl(key: string): Promise<number | undefined>;
|
|
26
|
-
/**
|
|
27
|
-
* Caches data under the given key and an optional TTL.
|
|
28
|
-
* @typeParam T The type of the data to cache.
|
|
29
|
-
*
|
|
30
|
-
* @param key The key of the cached data.
|
|
31
|
-
* @param data The data to cache.
|
|
32
|
-
* @param ttl The optional TTL of the cached data. If not defined, the data is cached forever.
|
|
33
|
-
* @returns The cached data.
|
|
34
|
-
*/
|
|
35
|
-
set<T>(key: string, data: T, ttl?: number): Promise<T>;
|
|
36
|
-
/**
|
|
37
|
-
* Caches data under the given list of keys and an optional TTL.
|
|
38
|
-
* @typeParam T The type of the data to cache.
|
|
39
|
-
*
|
|
40
|
-
* @param data The list of data to cache.
|
|
41
|
-
* @returns The list of cached data.
|
|
42
|
-
*/
|
|
43
|
-
mset<T>(data: Array<{
|
|
44
|
-
key: string;
|
|
45
|
-
value: T;
|
|
46
|
-
ttl?: number;
|
|
47
|
-
}>): Promise<Array<{
|
|
48
|
-
key: string;
|
|
49
|
-
value: T;
|
|
50
|
-
ttl?: number;
|
|
51
|
-
}>>;
|
|
52
|
-
/**
|
|
53
|
-
* Deletes the cached data with the given key.
|
|
54
|
-
* @typeParam T The type of the data to cache.
|
|
55
|
-
*
|
|
56
|
-
* @param key The key of the cached data.
|
|
57
|
-
* @returns `true` if the data was deleted, `false` otherwise.
|
|
58
|
-
*/
|
|
59
|
-
del(key: string): Promise<boolean>;
|
|
60
|
-
/**
|
|
61
|
-
* Deletes the cached data with the given list of keys.
|
|
62
|
-
* @typeParam T The type of the data to cache.
|
|
63
|
-
*
|
|
64
|
-
* @param keys The list of cached data keys.
|
|
65
|
-
* @returns `true` if the data was deleted, `false` otherwise.
|
|
66
|
-
*/
|
|
67
|
-
mdel(keys: string[]): Promise<boolean>;
|
|
68
|
-
/**
|
|
69
|
-
* Deletes all cached data.
|
|
70
|
-
* @returns `true` if the data was deleted, `false` otherwise.
|
|
71
|
-
*/
|
|
72
|
-
clear(): Promise<boolean>;
|
|
73
|
-
/**
|
|
74
|
-
* Creates a sub-cache with the given tags.
|
|
75
|
-
* @param tags The list of tags for the sub-cache.
|
|
76
|
-
*/
|
|
77
|
-
tags(...tags: string[]): Omit<CacheInterface, 'tags'>;
|
|
78
|
-
}
|
|
79
|
-
export declare abstract class Cache {
|
|
80
|
-
#private;
|
|
81
|
-
/**
|
|
82
|
-
* A weak cache storage for simple non-intrusive caching of data.
|
|
83
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
84
|
-
*/
|
|
85
|
-
static readonly weak: {
|
|
86
|
-
/**
|
|
87
|
-
* INTERNAL USAGE ONLY.
|
|
88
|
-
* @private
|
|
89
|
-
*/
|
|
90
|
-
map: WeakMap<object, unknown>;
|
|
91
|
-
/**
|
|
92
|
-
* Gets the cached data for a given context.
|
|
93
|
-
* @param ctx The cache context.
|
|
94
|
-
* @returns The cached data.
|
|
95
|
-
*/
|
|
96
|
-
get<T extends object>(ctx: object): T;
|
|
97
|
-
/**
|
|
98
|
-
* Deletes the cached data for a given context.
|
|
99
|
-
* @param ctx The cache context.
|
|
100
|
-
*/
|
|
101
|
-
del(ctx: object): void;
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* Redis-based cache storage.
|
|
105
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
106
|
-
*/
|
|
107
|
-
static get redis(): CacheInterface;
|
|
108
|
-
/**
|
|
109
|
-
* Memory-based cache storage.
|
|
110
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
111
|
-
*/
|
|
112
|
-
static get memory(): CacheInterface;
|
|
113
|
-
}
|
package/dist/database.d.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import type { DrizzleConfig } from 'drizzle-orm';
|
|
2
|
-
import type { BunSQLDatabase } from 'drizzle-orm/bun-sql';
|
|
3
|
-
import type { CacheConfig } from 'drizzle-orm/cache/core/types';
|
|
4
|
-
import { Table } from 'drizzle-orm';
|
|
5
|
-
import { Cache as DrizzleCache } from 'drizzle-orm/cache/core';
|
|
6
|
-
/**
|
|
7
|
-
* Properties used to create a new database connection.
|
|
8
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
9
|
-
*/
|
|
10
|
-
export type DatabaseConnectionProps<TSchema extends Record<string, unknown> = Record<string, never>> = Omit<DrizzleConfig<TSchema>, 'cache'> & ({
|
|
11
|
-
connection: string | ({
|
|
12
|
-
url?: string;
|
|
13
|
-
} & Bun.SQLOptions);
|
|
14
|
-
} | {
|
|
15
|
-
client: Bun.SQL;
|
|
16
|
-
}) & {
|
|
17
|
-
/**
|
|
18
|
-
* Configures caching behavior for the database connection.
|
|
19
|
-
* Set it to `true` to enable caching with default configurations.
|
|
20
|
-
*/
|
|
21
|
-
cache?: true | {
|
|
22
|
-
/**
|
|
23
|
-
* Whether to enable caching.
|
|
24
|
-
*/
|
|
25
|
-
enabled?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* The default TTL for cached data, in seconds.
|
|
28
|
-
* @default 1
|
|
29
|
-
*/
|
|
30
|
-
ttl?: number;
|
|
31
|
-
/**
|
|
32
|
-
* The caching strategy.
|
|
33
|
-
* Set it to `all` to cache all queries automatically.
|
|
34
|
-
* Set it to `explicit` to cache queries manually.
|
|
35
|
-
* @default 'explicit'
|
|
36
|
-
*/
|
|
37
|
-
strategy?: 'explicit' | 'all';
|
|
38
|
-
/**
|
|
39
|
-
* The storage engine to use.
|
|
40
|
-
* @default 'redis'
|
|
41
|
-
*/
|
|
42
|
-
storage?: 'redis' | 'memory';
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* A database connection.
|
|
47
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
48
|
-
*/
|
|
49
|
-
export type DatabaseConnection = BunSQLDatabase<Record<string, never>> & {
|
|
50
|
-
$client: Bun.SQL;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Database cache implementation for Drizzle.
|
|
54
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
55
|
-
*/
|
|
56
|
-
export declare class DatabaseCache extends DrizzleCache {
|
|
57
|
-
#private;
|
|
58
|
-
private readonly cacheStrategy;
|
|
59
|
-
private readonly globalTtl;
|
|
60
|
-
private usedTablesPerKey;
|
|
61
|
-
constructor(cacheStrategy?: 'explicit' | 'all', globalTtl?: number, storageEngine?: 'redis' | 'memory');
|
|
62
|
-
strategy(): 'explicit' | 'all';
|
|
63
|
-
get(key: string): Promise<any[] | undefined>;
|
|
64
|
-
put(key: string, response: any, tables: string[], _isTag: boolean, config?: CacheConfig): Promise<void>;
|
|
65
|
-
onMutate(params: {
|
|
66
|
-
tags: string | string[];
|
|
67
|
-
tables: string | string[] | Table<any> | Table<any>[];
|
|
68
|
-
}): Promise<void>;
|
|
69
|
-
}
|
|
70
|
-
export declare namespace Database {
|
|
71
|
-
/**
|
|
72
|
-
* Retrieves the connection with the given name.
|
|
73
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
74
|
-
* @param name The connection name.
|
|
75
|
-
* @returns The connection with the given name.
|
|
76
|
-
*/
|
|
77
|
-
const getConnection: (name: string) => DatabaseConnection;
|
|
78
|
-
/**
|
|
79
|
-
* Creates and registers a new connection.
|
|
80
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
81
|
-
*
|
|
82
|
-
* This will make the registered connection available for dependency injection with
|
|
83
|
-
* the key `db.connection.{name}`, where `{name}` is replaced with the given name.
|
|
84
|
-
*
|
|
85
|
-
* @param name The connection name.
|
|
86
|
-
* @param config The connection properties.
|
|
87
|
-
* @returns The newly created and registered connection.
|
|
88
|
-
*/
|
|
89
|
-
const registerConnection: (name: string, config: DatabaseConnectionProps) => BunSQLDatabase<Record<string, never>> & {
|
|
90
|
-
$client: Bun.SQL;
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Checks if a connection with the given name exists.
|
|
94
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
95
|
-
* @param name The name of the connection to check.
|
|
96
|
-
* @returns `true` if the connection exists, `false` otherwise.
|
|
97
|
-
*/
|
|
98
|
-
const connectionExists: (name: string) => boolean;
|
|
99
|
-
/**
|
|
100
|
-
* Retrieves the default connection.
|
|
101
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
102
|
-
* @returns The default connection.
|
|
103
|
-
*/
|
|
104
|
-
const getDefaultConnection: () => DatabaseConnection;
|
|
105
|
-
/**
|
|
106
|
-
* Sets the default connection.
|
|
107
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
108
|
-
* @param name The name of the connection to set as default.
|
|
109
|
-
* @returns The default connection.
|
|
110
|
-
*/
|
|
111
|
-
const setDefaultConnection: (name: string) => DatabaseConnection;
|
|
112
|
-
}
|
package/dist/job.d.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import type { Class } from 'type-fest';
|
|
3
|
-
import { InteractsWithConsole } from './console';
|
|
4
|
-
/**
|
|
5
|
-
* Properties required when declaring a job using the `@job()` decorator.
|
|
6
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
7
|
-
*/
|
|
8
|
-
export type JobProps = {
|
|
9
|
-
/**
|
|
10
|
-
* The name of the job.
|
|
11
|
-
*/
|
|
12
|
-
name?: string;
|
|
13
|
-
/**
|
|
14
|
-
* The queue on which the job should be processed.
|
|
15
|
-
*/
|
|
16
|
-
queue?: string;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Base class for background jobs.
|
|
20
|
-
*
|
|
21
|
-
* Jobs are classes that can be executed in the background. They provide
|
|
22
|
-
* an abstract execute method that serves as the entry point for the job.
|
|
23
|
-
*
|
|
24
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
25
|
-
*/
|
|
26
|
-
export declare abstract class Job extends InteractsWithConsole {
|
|
27
|
-
#private;
|
|
28
|
-
/**
|
|
29
|
-
* Marks a class as a job.
|
|
30
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
31
|
-
* @param options The decorator options.
|
|
32
|
-
*/
|
|
33
|
-
static register(options?: JobProps): (target: Class<Job>) => void;
|
|
34
|
-
/**
|
|
35
|
-
* Unique identifier for the job.
|
|
36
|
-
*/
|
|
37
|
-
readonly id: string;
|
|
38
|
-
/**
|
|
39
|
-
* The timestamp when the job was created.
|
|
40
|
-
*/
|
|
41
|
-
readonly createdAt: Date;
|
|
42
|
-
/**
|
|
43
|
-
* The timestamp when the job started execution.
|
|
44
|
-
*/
|
|
45
|
-
get startedAt(): Date | undefined;
|
|
46
|
-
/**
|
|
47
|
-
* The timestamp when the job completed execution.
|
|
48
|
-
*/
|
|
49
|
-
get completedAt(): Date | undefined;
|
|
50
|
-
/**
|
|
51
|
-
* The current status of the job.
|
|
52
|
-
*/
|
|
53
|
-
get status(): JobStatus;
|
|
54
|
-
/**
|
|
55
|
-
* Creates a new job instance.
|
|
56
|
-
*
|
|
57
|
-
* @param id Optional job ID. If not provided, a random ID will be generated.
|
|
58
|
-
*/
|
|
59
|
-
constructor(id?: string);
|
|
60
|
-
/**
|
|
61
|
-
* Run the job.
|
|
62
|
-
* This method handles the job lifecycle and calls the execute method.
|
|
63
|
-
*/
|
|
64
|
-
run(): Promise<void>;
|
|
65
|
-
/**
|
|
66
|
-
* Cancels the job.
|
|
67
|
-
*/
|
|
68
|
-
cancel(): void;
|
|
69
|
-
/**
|
|
70
|
-
* The main execution method for the job.
|
|
71
|
-
* This must be implemented by all job classes.
|
|
72
|
-
*/
|
|
73
|
-
protected abstract execute(): Promise<void>;
|
|
74
|
-
/**
|
|
75
|
-
* Generate a random job ID.
|
|
76
|
-
* @returns A random job ID.
|
|
77
|
-
*/
|
|
78
|
-
private generateJobId;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Possible statuses for a job.
|
|
82
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
83
|
-
*/
|
|
84
|
-
export declare enum JobStatus {
|
|
85
|
-
/**
|
|
86
|
-
* The job is in pending state, meaning it has been added to the queue but has not yet been processed.
|
|
87
|
-
*/
|
|
88
|
-
PENDING = "pending",
|
|
89
|
-
/**
|
|
90
|
-
* The job is in running state, meaning it is currently being processed.
|
|
91
|
-
*/
|
|
92
|
-
RUNNING = "running",
|
|
93
|
-
/**
|
|
94
|
-
* The job has completed successfully.
|
|
95
|
-
*/
|
|
96
|
-
COMPLETED = "completed",
|
|
97
|
-
/**
|
|
98
|
-
* The job has failed to complete successfully. If there are enough retries left, the job will be restarted.
|
|
99
|
-
*/
|
|
100
|
-
FAILED = "failed",
|
|
101
|
-
/**
|
|
102
|
-
* The job has been cancelled by the user or another job.
|
|
103
|
-
*/
|
|
104
|
-
CANCELLED = "cancelled"
|
|
105
|
-
}
|