@elysiumjs/core 0.4.3 → 0.5.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/README.md +26 -17
- package/dist/app.d.ts +180 -0
- package/dist/cache.d.ts +114 -0
- package/dist/command.d.ts +273 -0
- package/dist/console.d.ts +167 -0
- package/dist/database.d.ts +113 -0
- package/dist/env.d.ts +30 -0
- package/dist/event.d.ts +94 -0
- package/dist/http.d.ts +242 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +24 -0
- package/dist/job.d.ts +106 -0
- package/dist/macros.d.ts +2 -0
- package/dist/middleware.d.ts +70 -0
- package/dist/model.d.ts +4803 -0
- package/dist/module.d.ts +45 -0
- package/dist/redis.d.ts +134 -0
- package/dist/repository.d.ts +164 -0
- package/dist/service.d.ts +132 -0
- package/dist/utils.d.ts +26 -0
- package/dist/wamp.d.ts +273 -0
- package/dist/websocket.d.ts +92 -0
- package/dist/worker.d.ts +220 -0
- package/package.json +15 -8
- 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/module.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Class } from 'type-fest';
|
|
2
|
+
import type { Route } from './http';
|
|
3
|
+
/**
|
|
4
|
+
* Properties required when declaring a module using the `@module()` decorator.
|
|
5
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
6
|
+
*/
|
|
7
|
+
export type ModuleProps = {
|
|
8
|
+
/**
|
|
9
|
+
* The list of controllers provided by the module.
|
|
10
|
+
*/
|
|
11
|
+
controllers?: Class<any>[];
|
|
12
|
+
/**
|
|
13
|
+
* The base path for all the controllers registered by this module.
|
|
14
|
+
* This value will be prefixed to each controllers path.
|
|
15
|
+
*/
|
|
16
|
+
prefix?: Route;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Type for a module class.
|
|
20
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
21
|
+
*/
|
|
22
|
+
export type ModuleClass = Class<Module>;
|
|
23
|
+
/**
|
|
24
|
+
* Base class for all modules.
|
|
25
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
26
|
+
*
|
|
27
|
+
* This class provides base features for modules, such as hooks and lifecycle methods.
|
|
28
|
+
*/
|
|
29
|
+
export declare abstract class Module {
|
|
30
|
+
/**
|
|
31
|
+
* Marks a class as a module.
|
|
32
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
33
|
+
* @param options The decorator options.
|
|
34
|
+
*/
|
|
35
|
+
static register(options?: ModuleProps): (target: ModuleClass) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Hooks that are executed before the module is registered.
|
|
38
|
+
*/
|
|
39
|
+
beforeRegister(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Hooks that are executed after the module is registered.
|
|
42
|
+
*/
|
|
43
|
+
afterRegister(): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=module.d.ts.map
|
package/dist/redis.d.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { KeyvStoreAdapter } from 'cacheable';
|
|
2
|
+
import type { KeyvEntry, StoredData } from 'keyv';
|
|
3
|
+
import { EventEmitter } from 'node:events';
|
|
4
|
+
/**
|
|
5
|
+
* Properties used to create a new redis connection.
|
|
6
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
7
|
+
*/
|
|
8
|
+
export type RedisConnectionProps = Bun.RedisOptions & {
|
|
9
|
+
url: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Keyv adapter for redis. This adapter is based on the Bun's Redis client.
|
|
13
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
14
|
+
*/
|
|
15
|
+
export declare class KeyvRedis extends EventEmitter implements KeyvStoreAdapter {
|
|
16
|
+
#private;
|
|
17
|
+
constructor(props: {
|
|
18
|
+
/**
|
|
19
|
+
* The Redis connection to use.
|
|
20
|
+
*/
|
|
21
|
+
connection: string;
|
|
22
|
+
/**
|
|
23
|
+
* Namespace for the connection.
|
|
24
|
+
*/
|
|
25
|
+
namespace?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Separator to use between namespace and key.
|
|
28
|
+
*/
|
|
29
|
+
keyPrefixSeparator?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Number of keys to delete in a single batch.
|
|
32
|
+
*/
|
|
33
|
+
clearBatchSize?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Enable Unlink instead of using Del for clearing keys. This is more performant but may not be supported by all Redis versions.
|
|
36
|
+
*/
|
|
37
|
+
useUnlink?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Whether to allow clearing all keys when no namespace is set.
|
|
40
|
+
* If set to true and no namespace is set, iterate() will return all keys.
|
|
41
|
+
* Defaults to `false`.
|
|
42
|
+
*/
|
|
43
|
+
noNamespaceAffectsAll?: boolean;
|
|
44
|
+
});
|
|
45
|
+
get client(): Bun.RedisClient;
|
|
46
|
+
/**
|
|
47
|
+
* Get the options for the adapter.
|
|
48
|
+
*/
|
|
49
|
+
get opts(): {
|
|
50
|
+
namespace: string | undefined;
|
|
51
|
+
keyPrefixSeparator: string;
|
|
52
|
+
clearBatchSize: number;
|
|
53
|
+
noNamespaceAffectsAll: boolean;
|
|
54
|
+
dialect: string;
|
|
55
|
+
url: string;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Gets the namespace for the adapter. If undefined, it will not use a namespace including keyPrefixing.
|
|
59
|
+
* @default undefined
|
|
60
|
+
*/
|
|
61
|
+
get namespace(): string | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Sets the namespace for the adapter. If undefined, it will not use a namespace including keyPrefixing.
|
|
64
|
+
*/
|
|
65
|
+
set namespace(value: string | undefined);
|
|
66
|
+
get<Value>(key: string): Promise<StoredData<Value> | undefined>;
|
|
67
|
+
set(key: string, value: any, ttl?: number): Promise<void>;
|
|
68
|
+
setMany(values: Array<KeyvEntry>): Promise<void>;
|
|
69
|
+
delete(key: string): Promise<boolean>;
|
|
70
|
+
clear(): Promise<void>;
|
|
71
|
+
has(key: string): Promise<boolean>;
|
|
72
|
+
hasMany(keys: string[]): Promise<boolean[]>;
|
|
73
|
+
getMany<Value>(keys: string[]): Promise<Array<StoredData<Value | undefined>>>;
|
|
74
|
+
disconnect(): Promise<void>;
|
|
75
|
+
deleteMany(keys: string[]): Promise<boolean>;
|
|
76
|
+
iterator<Value>(namespace?: string): AsyncGenerator<Array<string | Awaited<Value> | undefined>, void>;
|
|
77
|
+
/**
|
|
78
|
+
* Helper function to create a key with a namespace.
|
|
79
|
+
* @param key The key to prefix.
|
|
80
|
+
* @param namespace The namespace to prefix the key with.
|
|
81
|
+
* @returns The key with the namespace such as 'namespace::key'.
|
|
82
|
+
*/
|
|
83
|
+
createKeyPrefix(key: string, namespace?: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* Helper function to remove the namespace from a key.
|
|
86
|
+
* @param key The key to remove the namespace from.
|
|
87
|
+
* @param namespace The namespace to remove from the key.
|
|
88
|
+
* @returns The key without the namespace.
|
|
89
|
+
*/
|
|
90
|
+
getKeyWithoutPrefix(key: string, namespace?: string): string;
|
|
91
|
+
}
|
|
92
|
+
export declare namespace Redis {
|
|
93
|
+
/**
|
|
94
|
+
* Retrieves the client for a redis connection.
|
|
95
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
96
|
+
* @param name The name of the connection.
|
|
97
|
+
* @returns The Bun.RedisClient for the connection with the given name.
|
|
98
|
+
*/
|
|
99
|
+
const getConnection: (name: string) => Bun.RedisClient;
|
|
100
|
+
/**
|
|
101
|
+
* Creates and registers a new redis connection.
|
|
102
|
+
*
|
|
103
|
+
* This will make the registered connection available for dependency injection with
|
|
104
|
+
* the key `redis.connection.{name}`, where `{name}` is replaced with the given name.
|
|
105
|
+
*
|
|
106
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
107
|
+
*
|
|
108
|
+
* @param name The name of the connection.
|
|
109
|
+
* @param config The configuration for the redis connection.
|
|
110
|
+
* @returns The newly created and registered redis connection.
|
|
111
|
+
*/
|
|
112
|
+
const registerConnection: (name: string, config: RedisConnectionProps) => Bun.RedisClient;
|
|
113
|
+
/**
|
|
114
|
+
* Checks if a redis connection with the given name exists.
|
|
115
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
116
|
+
* @param name The name of the connection to check.
|
|
117
|
+
* @returns `true` if the connection exists, `false` otherwise.
|
|
118
|
+
*/
|
|
119
|
+
const connectionExists: (name: string) => boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Retrieves the default redis connection.
|
|
122
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
123
|
+
* @returns The default redis connection.
|
|
124
|
+
*/
|
|
125
|
+
const getDefaultConnection: () => Bun.RedisClient;
|
|
126
|
+
/**
|
|
127
|
+
* Sets the default redis connection.
|
|
128
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
129
|
+
* @param name The name of the connection to set as default.
|
|
130
|
+
* @returns The default redis connection.
|
|
131
|
+
*/
|
|
132
|
+
const setDefaultConnection: (name: string) => Bun.RedisClient;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=redis.d.ts.map
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { PgColumnBuilderBase } from 'drizzle-orm/pg-core';
|
|
2
|
+
import type { Class } from 'type-fest';
|
|
3
|
+
import type { DatabaseConnection } from './database';
|
|
4
|
+
import type { ModelClass } from './model';
|
|
5
|
+
/**
|
|
6
|
+
* Database's primary column type.
|
|
7
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
8
|
+
*/
|
|
9
|
+
export type IdType = number | string;
|
|
10
|
+
/**
|
|
11
|
+
* Interface of a repository.
|
|
12
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
13
|
+
* @template TModel The type of the model class wrapped by the repository.
|
|
14
|
+
* @template TId The primary column type.
|
|
15
|
+
* @template TColumnsMap The table columns config.
|
|
16
|
+
*/
|
|
17
|
+
export interface RepositoryInterface<TModel extends ModelClass<TTableName, TColumnsMap>, TId extends IdType = string, TTableName extends string = TModel extends ModelClass<infer TTableName, infer _> ? TTableName : string, TColumnsMap extends Record<string, PgColumnBuilderBase> = TModel extends ModelClass<TTableName, infer TColumnsMap> ? TColumnsMap : Record<string, PgColumnBuilderBase>> {
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves all the records in the database.
|
|
20
|
+
* @returns All the records in the database.
|
|
21
|
+
*/
|
|
22
|
+
all(): Promise<TModel['$inferSelect'][]>;
|
|
23
|
+
/**
|
|
24
|
+
* Retrieves a record by its id.
|
|
25
|
+
* @param id The id of the record to retrieve.
|
|
26
|
+
* @returns The record with the given id.
|
|
27
|
+
*/
|
|
28
|
+
find(id: TId): Promise<TModel['$inferSelect'] | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Inserts a new record in the database.
|
|
31
|
+
* @param data The data to insert.
|
|
32
|
+
* @returns The inserted record.
|
|
33
|
+
*/
|
|
34
|
+
insert(data: TModel['$inferInsert']): Promise<TModel['$inferSelect']>;
|
|
35
|
+
/**
|
|
36
|
+
* Updates a record in the database.
|
|
37
|
+
* @param id The id of the record to update.
|
|
38
|
+
* @param data The data to update.
|
|
39
|
+
* @returns The updated record.
|
|
40
|
+
*/
|
|
41
|
+
update(id: TId, data: TModel['$inferUpdate']): Promise<TModel['$inferSelect']>;
|
|
42
|
+
/**
|
|
43
|
+
* Updates all the records in the database.
|
|
44
|
+
* @param data The data to update.
|
|
45
|
+
* @returns The updated records.
|
|
46
|
+
*/
|
|
47
|
+
updateAll(data: TModel['$inferUpdate']): Promise<TModel['$inferSelect'][]>;
|
|
48
|
+
/**
|
|
49
|
+
* Deletes a record from the database.
|
|
50
|
+
* @param id The ID of the record to delete.
|
|
51
|
+
* @returns The deleted record.
|
|
52
|
+
*/
|
|
53
|
+
delete(id: TId): Promise<TModel['$inferSelect']>;
|
|
54
|
+
/**
|
|
55
|
+
* Deletes all the records from the database.
|
|
56
|
+
* @returns All the records in the database.
|
|
57
|
+
*/
|
|
58
|
+
deleteAll(): Promise<TModel['$inferSelect'][]>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Type of a repository class.
|
|
62
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
63
|
+
* @template TModel The type of the model class wrapped by the repository.
|
|
64
|
+
* @template TId The primary column type.
|
|
65
|
+
* @template TColumnsMap The table columns config.
|
|
66
|
+
*/
|
|
67
|
+
export type RepositoryClass<TModel extends ModelClass<TTableName, TColumnsMap>, TId extends IdType = string, TTableName extends string = TModel extends ModelClass<infer TTableName, infer _> ? TTableName : string, TColumnsMap extends Record<string, PgColumnBuilderBase> = TModel extends ModelClass<TTableName, infer TColumnsMap> ? TColumnsMap : Record<string, PgColumnBuilderBase>> = Class<RepositoryInterface<TModel, TId, TTableName, TColumnsMap>> & {
|
|
68
|
+
/**
|
|
69
|
+
* The drizzle's table schema wrapped by the repository.
|
|
70
|
+
*/
|
|
71
|
+
readonly Model: TModel;
|
|
72
|
+
/**
|
|
73
|
+
* The database connection name to use in the repository.
|
|
74
|
+
*
|
|
75
|
+
* Update this value to change the database connection used by this repository.
|
|
76
|
+
*/
|
|
77
|
+
readonly connection: string;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Mixin used to create a new repository class over a model.
|
|
81
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
82
|
+
* @template TModel The type of the model class wrapped by the repository.
|
|
83
|
+
* @template TId The primary column type.
|
|
84
|
+
* @template TColumnsMap The table columns config.
|
|
85
|
+
* @template model The model class wrapped by the repository.
|
|
86
|
+
*/
|
|
87
|
+
export declare const Repository: <TModel extends ModelClass<TTableName, TColumnsMap>, TId extends IdType = string, TTableName extends string = TModel extends ModelClass<infer TTableName_1, infer _> ? TTableName_1 : string, TColumnsMap extends Record<string, PgColumnBuilderBase> = TModel extends ModelClass<TTableName, infer TColumnsMap_1> ? TColumnsMap_1 : Record<string, PgColumnBuilderBase>>(model: TModel) => {
|
|
88
|
+
new (): {
|
|
89
|
+
/**
|
|
90
|
+
* The database connection used by this repository.
|
|
91
|
+
*/
|
|
92
|
+
readonly db: DatabaseConnection;
|
|
93
|
+
/**
|
|
94
|
+
* Retrieves all the records in the database.
|
|
95
|
+
* @returns All the records in the database.
|
|
96
|
+
*/
|
|
97
|
+
all(): Promise<TModel["$inferSelect"][]>;
|
|
98
|
+
/**
|
|
99
|
+
* Get a paginated subset of the records in the database.
|
|
100
|
+
* @param page The page number to retrieve.
|
|
101
|
+
* @param count The number of records to retrieve per page.
|
|
102
|
+
* @returns A paginated response containing the records and the total number of records.
|
|
103
|
+
*/
|
|
104
|
+
paginate(count: number, page?: number): Promise<{
|
|
105
|
+
page: number;
|
|
106
|
+
data: TModel["$inferSelect"][];
|
|
107
|
+
total: number;
|
|
108
|
+
}>;
|
|
109
|
+
/**
|
|
110
|
+
* Retrieves a record by its id.
|
|
111
|
+
* @param id The id of the record to retrieve.
|
|
112
|
+
* @returns The record with the given id.
|
|
113
|
+
*/
|
|
114
|
+
find(id: TId): Promise<TModel["$inferSelect"] | null>;
|
|
115
|
+
/**
|
|
116
|
+
* Finds the first record with a column matching the given value.
|
|
117
|
+
* @param column The column to filter by.
|
|
118
|
+
* @param value The value the column should match.
|
|
119
|
+
* @returns The first record with a column matching the given value.
|
|
120
|
+
*/
|
|
121
|
+
findBy<TKey extends keyof TModel["$inferSelect"]>(column: TKey, value: TModel["$inferSelect"][TKey]): Promise<TModel["$inferSelect"] | null>;
|
|
122
|
+
/**
|
|
123
|
+
* Inserts a new record in the database.
|
|
124
|
+
* @param data The data to insert.
|
|
125
|
+
* @returns The inserted record.
|
|
126
|
+
*/
|
|
127
|
+
insert(data: TModel["$inferInsert"]): Promise<TModel["$inferSelect"]>;
|
|
128
|
+
/**
|
|
129
|
+
* Updates a record in the database.
|
|
130
|
+
* @param id The id of the record to update.
|
|
131
|
+
* @param data The data to update.
|
|
132
|
+
* @returns The updated record.
|
|
133
|
+
*/
|
|
134
|
+
update(id: TId, data: TModel["$inferUpdate"]): Promise<TModel["$inferSelect"]>;
|
|
135
|
+
/**
|
|
136
|
+
* Updates all the records in the database.
|
|
137
|
+
* @param data The data to update.
|
|
138
|
+
* @returns The updated records.
|
|
139
|
+
*/
|
|
140
|
+
updateAll(data: TModel["$inferUpdate"]): Promise<TModel["$inferSelect"][]>;
|
|
141
|
+
/**
|
|
142
|
+
* Deletes a record from the database.
|
|
143
|
+
* @param id The ID of the record to delete.
|
|
144
|
+
* @returns The deleted record.
|
|
145
|
+
*/
|
|
146
|
+
delete(id: TId): Promise<TModel["$inferSelect"]>;
|
|
147
|
+
/**
|
|
148
|
+
* Deletes all the records from the database.
|
|
149
|
+
* @returns All the records in the database.
|
|
150
|
+
*/
|
|
151
|
+
deleteAll(): Promise<TModel["$inferSelect"][]>;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* The drizzle's table schema wrapped by this repository.
|
|
155
|
+
*/
|
|
156
|
+
readonly Model: TModel;
|
|
157
|
+
/**
|
|
158
|
+
* The database connection name to use.
|
|
159
|
+
*
|
|
160
|
+
* Update this value to change the database connection used by this repository.
|
|
161
|
+
*/
|
|
162
|
+
readonly connection: string;
|
|
163
|
+
};
|
|
164
|
+
//# sourceMappingURL=repository.d.ts.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { Class } from 'type-fest';
|
|
2
|
+
/**
|
|
3
|
+
* The scope of a service.
|
|
4
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
5
|
+
*/
|
|
6
|
+
export declare enum ServiceScope {
|
|
7
|
+
/**
|
|
8
|
+
* A single instance of the service is created and shared everywhere it is injected or retrieved.
|
|
9
|
+
*/
|
|
10
|
+
SINGLETON = 0,
|
|
11
|
+
/**
|
|
12
|
+
* A new instance of the service is created every time it is injected or retrieved.
|
|
13
|
+
*/
|
|
14
|
+
FACTORY = 1
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A generic service class.
|
|
18
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
19
|
+
*/
|
|
20
|
+
type ServiceClass = Class<any>;
|
|
21
|
+
/**
|
|
22
|
+
* A typed service class.
|
|
23
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
24
|
+
*/
|
|
25
|
+
type TypedServiceClass<T> = Class<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Type for a factory function.
|
|
28
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
29
|
+
*/
|
|
30
|
+
type FactoryFn<T> = () => T extends void ? never : T;
|
|
31
|
+
/**
|
|
32
|
+
* Properties required when declaring a service using the `@service()` decorator.
|
|
33
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
34
|
+
*/
|
|
35
|
+
export type ServiceProps = Partial<{
|
|
36
|
+
/**
|
|
37
|
+
* The name of the service. If not set, it will default to the service class name.
|
|
38
|
+
*/
|
|
39
|
+
name: string;
|
|
40
|
+
/**
|
|
41
|
+
* The service's scope.
|
|
42
|
+
*
|
|
43
|
+
* Set it to `Scope.SINGLETON` to ensure that only one instance of this service is
|
|
44
|
+
* used everywhere it is injected or retrieved.
|
|
45
|
+
*
|
|
46
|
+
* Set it to `Scope.FACTORY` to ensure that every time you inject or retrieve this
|
|
47
|
+
* service, you have a new instance created.
|
|
48
|
+
*
|
|
49
|
+
* @see ServiceScope
|
|
50
|
+
*/
|
|
51
|
+
scope: ServiceScope;
|
|
52
|
+
}>;
|
|
53
|
+
export declare namespace Service {
|
|
54
|
+
/**
|
|
55
|
+
* Marks a class as a service
|
|
56
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
57
|
+
* @param options The decorator options.
|
|
58
|
+
*/
|
|
59
|
+
const register: (options?: ServiceProps) => (target: ServiceClass) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Resolves a registered service and set it as a parameter value.
|
|
62
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
63
|
+
* @param service An optional name for the service. If not set, the name of the parameter's type is used instead.
|
|
64
|
+
*/
|
|
65
|
+
const inject: (service?: string | ServiceClass) => ParameterDecorator;
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves a registered service's instance from the container.
|
|
68
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
69
|
+
* @param service The name of the service, or its class.
|
|
70
|
+
* @returns An instance of the registered service, or `null` if no service with that name/type was registered.
|
|
71
|
+
*/
|
|
72
|
+
const get: <T>(service: string | TypedServiceClass<T>) => T | null;
|
|
73
|
+
/**
|
|
74
|
+
* Instantiates a service with its dependencies.
|
|
75
|
+
*
|
|
76
|
+
* This function always create a new instance of the service, even if the service's scope is `ServiceScope.SINGLETON`
|
|
77
|
+
* and it has already been registered in the container.
|
|
78
|
+
*
|
|
79
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
80
|
+
*
|
|
81
|
+
* @param service The service class to instantiate.
|
|
82
|
+
*/
|
|
83
|
+
const make: <T>(service: TypedServiceClass<T>) => T;
|
|
84
|
+
/**
|
|
85
|
+
* Binds a service to the container and sets it as a singleton.
|
|
86
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
87
|
+
* @param service The service class to bind.
|
|
88
|
+
* @param name An optional name for the service. If not set, the name of the service class is used instead.
|
|
89
|
+
*/
|
|
90
|
+
const bind: <T>(service: TypedServiceClass<T>, name?: string) => T;
|
|
91
|
+
/**
|
|
92
|
+
* Binds a service to the container and sets it as a factory.
|
|
93
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
94
|
+
* @param name A name for the service.
|
|
95
|
+
* @param factory The factory function used to instantiate the service.
|
|
96
|
+
*/
|
|
97
|
+
function factory<T>(name: string, factory: FactoryFn<T>): T;
|
|
98
|
+
/**
|
|
99
|
+
* Binds a service to the container and sets it as a factory.
|
|
100
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
101
|
+
* @param service The service class to bind.
|
|
102
|
+
* @param name An optional name for the service. If not set, the name of the service class is used instead.
|
|
103
|
+
*/
|
|
104
|
+
function factory<T>(service: TypedServiceClass<T>, name?: string): T;
|
|
105
|
+
/**
|
|
106
|
+
* Binds a service's instance to the container.
|
|
107
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
108
|
+
* @param service The service class or name to bind.
|
|
109
|
+
* @param instance The instance to bind.
|
|
110
|
+
*/
|
|
111
|
+
const instance: <T>(service: string | TypedServiceClass<T>, instance: T) => T;
|
|
112
|
+
/**
|
|
113
|
+
* Removes a service from the container.
|
|
114
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
115
|
+
* @param service The service class or name to remove.
|
|
116
|
+
*/
|
|
117
|
+
const remove: (service: string | TypedServiceClass<any>) => void;
|
|
118
|
+
/**
|
|
119
|
+
* Checks if a service exists in the container.
|
|
120
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
121
|
+
* @param service The service class or name to check.
|
|
122
|
+
* @returns `true` if the service exists, `false` otherwise.
|
|
123
|
+
*/
|
|
124
|
+
const exists: (service: string | TypedServiceClass<any>) => boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Clears the container.
|
|
127
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
128
|
+
*/
|
|
129
|
+
const clear: () => void;
|
|
130
|
+
}
|
|
131
|
+
export {};
|
|
132
|
+
//# sourceMappingURL=service.d.ts.map
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Elysia } from 'elysia';
|
|
2
|
+
export declare namespace Symbols {
|
|
3
|
+
const app: unique symbol;
|
|
4
|
+
const controller: unique symbol;
|
|
5
|
+
const middlewares: unique symbol;
|
|
6
|
+
const services: unique symbol;
|
|
7
|
+
const websocket: unique symbol;
|
|
8
|
+
const wamp: unique symbol;
|
|
9
|
+
const http: unique symbol;
|
|
10
|
+
const job: unique symbol;
|
|
11
|
+
const arg: unique symbol;
|
|
12
|
+
const elysiaPlugin: unique symbol;
|
|
13
|
+
const middlewareGuards: unique symbol;
|
|
14
|
+
}
|
|
15
|
+
export declare const nextTick: () => Promise<unknown>;
|
|
16
|
+
export type ElysiaPlugin = () => Promise<Elysia>;
|
|
17
|
+
/**
|
|
18
|
+
* Deeply merges objects from right to left
|
|
19
|
+
* Arrays are also merged if they are found in child objects
|
|
20
|
+
*
|
|
21
|
+
* @param target The target object to merge into
|
|
22
|
+
* @param sources One or more source objects to merge from
|
|
23
|
+
* @returns The merged object (same reference as target)
|
|
24
|
+
*/
|
|
25
|
+
export declare function deepMerge<T extends Record<string, any | any[]>>(target: T, ...sources: T[]): T;
|
|
26
|
+
//# sourceMappingURL=utils.d.ts.map
|