@ruiapp/rapid-core 0.1.21 → 0.1.22
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/dist/core/facility.d.ts +5 -0
- package/dist/core/server.d.ts +3 -0
- package/dist/index.js +17 -0
- package/dist/server.d.ts +4 -0
- package/package.json +1 -1
- package/src/core/facility.ts +7 -0
- package/src/core/server.ts +6 -0
- package/src/server.ts +24 -1
package/dist/core/server.d.ts
CHANGED
|
@@ -3,11 +3,14 @@ import { IPluginActionHandler, ActionHandler, ActionHandlerContext } from "./act
|
|
|
3
3
|
import { Next, RouteContext } from "./routeContext";
|
|
4
4
|
import EntityManager from "../dataAccess/entityManager";
|
|
5
5
|
import { Logger } from "../facilities/log/LogFacility";
|
|
6
|
+
import { FacilityFactory } from "./facility";
|
|
6
7
|
export interface IRpdServer {
|
|
7
8
|
config: RapidServerConfig;
|
|
8
9
|
databaseConfig: IDatabaseConfig;
|
|
9
10
|
queryBuilder: IQueryBuilder;
|
|
10
11
|
getLogger(): Logger;
|
|
12
|
+
registerFacilityFactory(factory: FacilityFactory): any;
|
|
13
|
+
getFacility<TFacility = any>(name: string, options?: any): Promise<TFacility>;
|
|
11
14
|
queryDatabaseObject: (sql: string, params?: unknown[] | Record<string, unknown>) => Promise<any[]>;
|
|
12
15
|
tryQueryDatabaseObject: (sql: string, params?: unknown[] | Record<string, unknown>) => Promise<any[]>;
|
|
13
16
|
registerMiddleware(middleware: any): void;
|
package/dist/index.js
CHANGED
|
@@ -2374,6 +2374,7 @@ class EntityManager {
|
|
|
2374
2374
|
|
|
2375
2375
|
class RapidServer {
|
|
2376
2376
|
#logger;
|
|
2377
|
+
#facilityFactories;
|
|
2377
2378
|
#pluginManager;
|
|
2378
2379
|
#plugins;
|
|
2379
2380
|
#eventManager;
|
|
@@ -2390,6 +2391,12 @@ class RapidServer {
|
|
|
2390
2391
|
#buildedRoutes;
|
|
2391
2392
|
constructor(options) {
|
|
2392
2393
|
this.#logger = options.logger;
|
|
2394
|
+
this.#facilityFactories = new Map();
|
|
2395
|
+
if (options.facilityFactories) {
|
|
2396
|
+
lodash.forEach(options.facilityFactories, (factory) => {
|
|
2397
|
+
this.registerFacilityFactory(factory);
|
|
2398
|
+
});
|
|
2399
|
+
}
|
|
2393
2400
|
this.#pluginManager = new PluginManager(this);
|
|
2394
2401
|
this.#eventManager = new EventManager();
|
|
2395
2402
|
this.#middlewares = [];
|
|
@@ -2549,6 +2556,16 @@ class RapidServer {
|
|
|
2549
2556
|
await pluginManager.onApplicationLoaded(this.#applicationConfig);
|
|
2550
2557
|
this.#buildedRoutes = await buildRoutes(this, this.#applicationConfig);
|
|
2551
2558
|
}
|
|
2559
|
+
registerFacilityFactory(factory) {
|
|
2560
|
+
this.#facilityFactories.set(factory.name, factory);
|
|
2561
|
+
}
|
|
2562
|
+
async getFacility(name, options) {
|
|
2563
|
+
const factory = this.#facilityFactories.get(name);
|
|
2564
|
+
if (!factory) {
|
|
2565
|
+
throw new Error(`Failed to get facility. Unknown facility name: ${name}`);
|
|
2566
|
+
}
|
|
2567
|
+
return await factory.createFacility(this, options);
|
|
2568
|
+
}
|
|
2552
2569
|
async queryDatabaseObject(sql, params) {
|
|
2553
2570
|
try {
|
|
2554
2571
|
return await this.#databaseAccessor.queryDatabaseObject(sql, params);
|
package/dist/server.d.ts
CHANGED
|
@@ -4,12 +4,14 @@ import { IRpdServer, RapidPlugin } from "./core/server";
|
|
|
4
4
|
import { Next } from "./core/routeContext";
|
|
5
5
|
import EntityManager from "./dataAccess/entityManager";
|
|
6
6
|
import { Logger } from "./facilities/log/LogFacility";
|
|
7
|
+
import { FacilityFactory } from "./core/facility";
|
|
7
8
|
export interface InitServerOptions {
|
|
8
9
|
logger: Logger;
|
|
9
10
|
databaseAccessor: IDatabaseAccessor;
|
|
10
11
|
databaseConfig: IDatabaseConfig;
|
|
11
12
|
serverConfig: RapidServerConfig;
|
|
12
13
|
applicationConfig?: RpdApplicationConfig;
|
|
14
|
+
facilityFactories?: FacilityFactory[];
|
|
13
15
|
plugins?: RapidPlugin[];
|
|
14
16
|
}
|
|
15
17
|
export declare class RapidServer implements IRpdServer {
|
|
@@ -32,6 +34,8 @@ export declare class RapidServer implements IRpdServer {
|
|
|
32
34
|
emitEvent<K extends keyof RpdServerEventTypes>(eventName: K, sender: RapidPlugin, payload: RpdServerEventTypes[K][1]): Promise<void>;
|
|
33
35
|
start(): Promise<void>;
|
|
34
36
|
configureApplication(): Promise<void>;
|
|
37
|
+
registerFacilityFactory(factory: FacilityFactory): void;
|
|
38
|
+
getFacility<TFacility = any>(name: string, options?: any): Promise<TFacility>;
|
|
35
39
|
queryDatabaseObject(sql: string, params?: unknown[] | Record<string, unknown>): Promise<any[]>;
|
|
36
40
|
tryQueryDatabaseObject(sql: string, params?: unknown[] | Record<string, unknown>): Promise<any[]>;
|
|
37
41
|
get middlewares(): any[];
|
package/package.json
CHANGED
package/src/core/server.ts
CHANGED
|
@@ -3,12 +3,18 @@ import { IPluginActionHandler, ActionHandler, ActionHandlerContext } from "./act
|
|
|
3
3
|
import { Next, RouteContext } from "./routeContext";
|
|
4
4
|
import EntityManager from "~/dataAccess/entityManager";
|
|
5
5
|
import { Logger } from "~/facilities/log/LogFacility";
|
|
6
|
+
import { FacilityFactory } from "./facility";
|
|
6
7
|
|
|
7
8
|
export interface IRpdServer {
|
|
8
9
|
config: RapidServerConfig;
|
|
9
10
|
databaseConfig: IDatabaseConfig;
|
|
10
11
|
queryBuilder: IQueryBuilder;
|
|
11
12
|
getLogger(): Logger;
|
|
13
|
+
|
|
14
|
+
registerFacilityFactory(factory: FacilityFactory);
|
|
15
|
+
|
|
16
|
+
getFacility<TFacility=any>(name: string, options?: any): Promise<TFacility>;
|
|
17
|
+
|
|
12
18
|
queryDatabaseObject: (
|
|
13
19
|
sql: string,
|
|
14
20
|
params?: unknown[] | Record<string, unknown>,
|
package/src/server.ts
CHANGED
|
@@ -23,8 +23,9 @@ import { Next, RouteContext } from "./core/routeContext";
|
|
|
23
23
|
import { RapidRequest } from "./core/request";
|
|
24
24
|
import bootstrapApplicationConfig from "./bootstrapApplicationConfig";
|
|
25
25
|
import EntityManager from "./dataAccess/entityManager";
|
|
26
|
-
import { bind, cloneDeep, find, merge, omit } from "lodash";
|
|
26
|
+
import { bind, cloneDeep, find, forEach, merge, omit } from "lodash";
|
|
27
27
|
import { Logger } from "./facilities/log/LogFacility";
|
|
28
|
+
import { FacilityFactory } from "./core/facility";
|
|
28
29
|
|
|
29
30
|
export interface InitServerOptions {
|
|
30
31
|
logger: Logger;
|
|
@@ -32,11 +33,13 @@ export interface InitServerOptions {
|
|
|
32
33
|
databaseConfig: IDatabaseConfig;
|
|
33
34
|
serverConfig: RapidServerConfig;
|
|
34
35
|
applicationConfig?: RpdApplicationConfig;
|
|
36
|
+
facilityFactories?: FacilityFactory[];
|
|
35
37
|
plugins?: RapidPlugin[];
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
export class RapidServer implements IRpdServer {
|
|
39
41
|
#logger: Logger;
|
|
42
|
+
#facilityFactories: Map<string, FacilityFactory>;
|
|
40
43
|
#pluginManager: PluginManager;
|
|
41
44
|
#plugins: RapidPlugin[];
|
|
42
45
|
#eventManager: EventManager<RpdServerEventTypes>;
|
|
@@ -55,6 +58,13 @@ export class RapidServer implements IRpdServer {
|
|
|
55
58
|
constructor(options: InitServerOptions) {
|
|
56
59
|
this.#logger = options.logger;
|
|
57
60
|
|
|
61
|
+
this.#facilityFactories = new Map();
|
|
62
|
+
if (options.facilityFactories) {
|
|
63
|
+
forEach(options.facilityFactories, (factory) => {
|
|
64
|
+
this.registerFacilityFactory(factory);
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
58
68
|
this.#pluginManager = new PluginManager(this);
|
|
59
69
|
this.#eventManager = new EventManager();
|
|
60
70
|
this.#middlewares = [];
|
|
@@ -258,6 +268,19 @@ export class RapidServer implements IRpdServer {
|
|
|
258
268
|
this.#buildedRoutes = await buildRoutes(this, this.#applicationConfig);
|
|
259
269
|
}
|
|
260
270
|
|
|
271
|
+
registerFacilityFactory(factory: FacilityFactory) {
|
|
272
|
+
this.#facilityFactories.set(factory.name, factory);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async getFacility<TFacility=any>(name: string, options?: any): Promise<TFacility> {
|
|
276
|
+
const factory = this.#facilityFactories.get(name);
|
|
277
|
+
if (!factory) {
|
|
278
|
+
throw new Error(`Failed to get facility. Unknown facility name: ${name}`);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return await factory.createFacility(this, options);
|
|
282
|
+
}
|
|
283
|
+
|
|
261
284
|
async queryDatabaseObject(sql: string, params?: unknown[] | Record<string,unknown>) : Promise<any[]> {
|
|
262
285
|
try {
|
|
263
286
|
return await this.#databaseAccessor.queryDatabaseObject(sql, params);
|