@ruiapp/rapid-core 0.1.22 → 0.1.23
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/server.d.ts +1 -1
- package/dist/dataAccess/entityManager.d.ts +5 -5
- package/dist/index.js +19 -14
- package/dist/server.d.ts +2 -2
- package/package.json +1 -1
- package/src/core/request.ts +1 -1
- package/src/core/server.ts +1 -1
- package/src/dataAccess/entityManager.ts +11 -11
- package/src/server.ts +7 -3
package/dist/core/server.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface IRpdServer {
|
|
|
23
23
|
appendModelProperties(modelSingularCode: string, properties: RpdDataModelProperty[]): any;
|
|
24
24
|
getModel(options: GetModelOptions): RpdDataModel | undefined;
|
|
25
25
|
registerEventHandler<K extends keyof RpdServerEventTypes>(eventName: K, listener: (...args: RpdServerEventTypes[K]) => void): this;
|
|
26
|
-
emitEvent<K extends keyof RpdServerEventTypes>(eventName: K,
|
|
26
|
+
emitEvent<K extends keyof RpdServerEventTypes>(eventName: K, payload: RpdServerEventTypes[K][1], sender?: RapidPlugin): void;
|
|
27
27
|
handleRequest(request: Request, next: Next): Promise<Response>;
|
|
28
28
|
beforeRunRouteActions(handlerContext: ActionHandlerContext): Promise<void>;
|
|
29
29
|
}
|
|
@@ -7,10 +7,10 @@ export default class EntityManager<TEntity = any> {
|
|
|
7
7
|
findEntities(options: FindEntityOptions): Promise<TEntity[]>;
|
|
8
8
|
findEntity(options: FindEntityOptions): Promise<TEntity | null>;
|
|
9
9
|
findById(id: any, keepNonPropertyFields?: boolean): Promise<TEntity | null>;
|
|
10
|
-
createEntity(options: CreateEntityOptions, plugin
|
|
11
|
-
updateEntityById(options: UpdateEntityByIdOptions, plugin
|
|
10
|
+
createEntity(options: CreateEntityOptions, plugin?: RapidPlugin): Promise<TEntity>;
|
|
11
|
+
updateEntityById(options: UpdateEntityByIdOptions, plugin?: RapidPlugin): Promise<TEntity>;
|
|
12
12
|
count(options: CountEntityOptions): Promise<CountEntityResult>;
|
|
13
|
-
deleteById(id: any, plugin
|
|
14
|
-
addRelations(options: AddEntityRelationsOptions, plugin
|
|
15
|
-
removeRelations(options: RemoveEntityRelationsOptions, plugin
|
|
13
|
+
deleteById(id: any, plugin?: RapidPlugin): Promise<void>;
|
|
14
|
+
addRelations(options: AddEntityRelationsOptions, plugin?: RapidPlugin): Promise<void>;
|
|
15
|
+
removeRelations(options: RemoveEntityRelationsOptions, plugin?: RapidPlugin): Promise<void>;
|
|
16
16
|
}
|
package/dist/index.js
CHANGED
|
@@ -1041,7 +1041,7 @@ class RapidRequest {
|
|
|
1041
1041
|
const requestMethod = this.method;
|
|
1042
1042
|
if (requestMethod === "POST" || requestMethod === "PUT" || requestMethod === "PATCH") {
|
|
1043
1043
|
const req = this.#raw;
|
|
1044
|
-
const contentType = this.#headers.get("Content-Type");
|
|
1044
|
+
const contentType = this.#headers.get("Content-Type") || "application/json";
|
|
1045
1045
|
if (contentType.includes("json")) {
|
|
1046
1046
|
this.#body = {
|
|
1047
1047
|
type: "json",
|
|
@@ -2245,13 +2245,13 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
|
|
|
2245
2245
|
}
|
|
2246
2246
|
updatedEntity[property.code] = relatedEntities;
|
|
2247
2247
|
}
|
|
2248
|
-
server.emitEvent("entity.update",
|
|
2248
|
+
server.emitEvent("entity.update", {
|
|
2249
2249
|
namespace: model.namespace,
|
|
2250
2250
|
modelSingularCode: model.singularCode,
|
|
2251
2251
|
before: entity,
|
|
2252
2252
|
after: updatedEntity,
|
|
2253
2253
|
changes: changes,
|
|
2254
|
-
});
|
|
2254
|
+
}, plugin);
|
|
2255
2255
|
return updatedEntity;
|
|
2256
2256
|
}
|
|
2257
2257
|
class EntityManager {
|
|
@@ -2276,11 +2276,11 @@ class EntityManager {
|
|
|
2276
2276
|
async createEntity(options, plugin) {
|
|
2277
2277
|
const model = this.getModel();
|
|
2278
2278
|
const newEntity = await createEntity(this.#server, this.#dataAccessor, options);
|
|
2279
|
-
this.#server.emitEvent("entity.create",
|
|
2279
|
+
this.#server.emitEvent("entity.create", {
|
|
2280
2280
|
namespace: model.namespace,
|
|
2281
2281
|
modelSingularCode: model.singularCode,
|
|
2282
2282
|
after: newEntity,
|
|
2283
|
-
});
|
|
2283
|
+
}, plugin);
|
|
2284
2284
|
return newEntity;
|
|
2285
2285
|
}
|
|
2286
2286
|
async updateEntityById(options, plugin) {
|
|
@@ -2296,11 +2296,11 @@ class EntityManager {
|
|
|
2296
2296
|
return;
|
|
2297
2297
|
}
|
|
2298
2298
|
await this.#dataAccessor.deleteById(id);
|
|
2299
|
-
this.#server.emitEvent("entity.delete",
|
|
2299
|
+
this.#server.emitEvent("entity.delete", {
|
|
2300
2300
|
namespace: model.namespace,
|
|
2301
2301
|
modelSingularCode: model.singularCode,
|
|
2302
2302
|
before: entity,
|
|
2303
|
-
});
|
|
2303
|
+
}, plugin);
|
|
2304
2304
|
}
|
|
2305
2305
|
async addRelations(options, plugin) {
|
|
2306
2306
|
const model = this.getModel();
|
|
@@ -2330,13 +2330,13 @@ class EntityManager {
|
|
|
2330
2330
|
await server.queryDatabaseObject(command, params);
|
|
2331
2331
|
}
|
|
2332
2332
|
}
|
|
2333
|
-
server.emitEvent("entity.addRelations",
|
|
2333
|
+
server.emitEvent("entity.addRelations", {
|
|
2334
2334
|
namespace: model.namespace,
|
|
2335
2335
|
modelSingularCode: model.singularCode,
|
|
2336
2336
|
entity,
|
|
2337
2337
|
property,
|
|
2338
2338
|
relations,
|
|
2339
|
-
});
|
|
2339
|
+
}, plugin);
|
|
2340
2340
|
}
|
|
2341
2341
|
async removeRelations(options, plugin) {
|
|
2342
2342
|
const model = this.getModel();
|
|
@@ -2362,13 +2362,13 @@ class EntityManager {
|
|
|
2362
2362
|
await server.queryDatabaseObject(command, params);
|
|
2363
2363
|
}
|
|
2364
2364
|
}
|
|
2365
|
-
server.emitEvent("entity.removeRelations",
|
|
2365
|
+
server.emitEvent("entity.removeRelations", {
|
|
2366
2366
|
namespace: model.namespace,
|
|
2367
2367
|
modelSingularCode: model.singularCode,
|
|
2368
2368
|
entity,
|
|
2369
2369
|
property,
|
|
2370
2370
|
relations,
|
|
2371
|
-
});
|
|
2371
|
+
}, plugin);
|
|
2372
2372
|
}
|
|
2373
2373
|
}
|
|
2374
2374
|
|
|
@@ -2519,7 +2519,7 @@ class RapidServer {
|
|
|
2519
2519
|
this.#eventManager.on(eventName, listener);
|
|
2520
2520
|
return this;
|
|
2521
2521
|
}
|
|
2522
|
-
async emitEvent(eventName,
|
|
2522
|
+
async emitEvent(eventName, payload, sender) {
|
|
2523
2523
|
this.#logger.debug(`Emitting '${eventName}' event.`, { eventName, payload });
|
|
2524
2524
|
await this.#eventManager.emit(eventName, sender, payload);
|
|
2525
2525
|
// TODO: should move this logic into metaManager
|
|
@@ -2559,10 +2559,15 @@ class RapidServer {
|
|
|
2559
2559
|
registerFacilityFactory(factory) {
|
|
2560
2560
|
this.#facilityFactories.set(factory.name, factory);
|
|
2561
2561
|
}
|
|
2562
|
-
async getFacility(name, options) {
|
|
2562
|
+
async getFacility(name, options, nullIfUnknownFacility) {
|
|
2563
2563
|
const factory = this.#facilityFactories.get(name);
|
|
2564
2564
|
if (!factory) {
|
|
2565
|
-
|
|
2565
|
+
if (nullIfUnknownFacility) {
|
|
2566
|
+
return null;
|
|
2567
|
+
}
|
|
2568
|
+
else {
|
|
2569
|
+
throw new Error(`Failed to get facility. Unknown facility name: ${name}`);
|
|
2570
|
+
}
|
|
2566
2571
|
}
|
|
2567
2572
|
return await factory.createFacility(this, options);
|
|
2568
2573
|
}
|
package/dist/server.d.ts
CHANGED
|
@@ -31,11 +31,11 @@ export declare class RapidServer implements IRpdServer {
|
|
|
31
31
|
getModel(options: GetModelOptions): RpdDataModel | undefined;
|
|
32
32
|
getEntityManager<TEntity = any>(singularCode: string): EntityManager<TEntity>;
|
|
33
33
|
registerEventHandler<K extends keyof RpdServerEventTypes>(eventName: K, listener: (...args: RpdServerEventTypes[K]) => void): this;
|
|
34
|
-
emitEvent<K extends keyof RpdServerEventTypes>(eventName: K,
|
|
34
|
+
emitEvent<K extends keyof RpdServerEventTypes>(eventName: K, payload: RpdServerEventTypes[K][1], sender?: RapidPlugin): Promise<void>;
|
|
35
35
|
start(): Promise<void>;
|
|
36
36
|
configureApplication(): Promise<void>;
|
|
37
37
|
registerFacilityFactory(factory: FacilityFactory): void;
|
|
38
|
-
getFacility<TFacility = any>(name: string, options?: any): Promise<TFacility>;
|
|
38
|
+
getFacility<TFacility = any>(name: string, options?: any, nullIfUnknownFacility?: boolean): Promise<TFacility>;
|
|
39
39
|
queryDatabaseObject(sql: string, params?: unknown[] | Record<string, unknown>): Promise<any[]>;
|
|
40
40
|
tryQueryDatabaseObject(sql: string, params?: unknown[] | Record<string, unknown>): Promise<any[]>;
|
|
41
41
|
get middlewares(): any[];
|
package/package.json
CHANGED
package/src/core/request.ts
CHANGED
|
@@ -38,7 +38,7 @@ export class RapidRequest {
|
|
|
38
38
|
const requestMethod = this.method;
|
|
39
39
|
if (requestMethod === "POST" || requestMethod === "PUT" || requestMethod === "PATCH") {
|
|
40
40
|
const req = this.#raw;
|
|
41
|
-
const contentType = this.#headers.get("Content-Type");
|
|
41
|
+
const contentType = this.#headers.get("Content-Type") || "application/json";
|
|
42
42
|
if (contentType.includes("json")) {
|
|
43
43
|
this.#body = {
|
|
44
44
|
type: "json",
|
package/src/core/server.ts
CHANGED
|
@@ -43,8 +43,8 @@ export interface IRpdServer {
|
|
|
43
43
|
): this;
|
|
44
44
|
emitEvent<K extends keyof RpdServerEventTypes>(
|
|
45
45
|
eventName: K,
|
|
46
|
-
sender: RapidPlugin,
|
|
47
46
|
payload: RpdServerEventTypes[K][1],
|
|
47
|
+
sender?: RapidPlugin,
|
|
48
48
|
): void;
|
|
49
49
|
handleRequest(request: Request, next: Next): Promise<Response>;
|
|
50
50
|
beforeRunRouteActions(handlerContext: ActionHandlerContext): Promise<void>;
|
|
@@ -553,7 +553,7 @@ async function updateEntityById(
|
|
|
553
553
|
server: IRpdServer,
|
|
554
554
|
dataAccessor: IRpdDataAccessor,
|
|
555
555
|
options: UpdateEntityByIdOptions,
|
|
556
|
-
plugin
|
|
556
|
+
plugin?: RapidPlugin
|
|
557
557
|
) {
|
|
558
558
|
const model = dataAccessor.getModel();
|
|
559
559
|
const { id, entityToSave } = options;
|
|
@@ -685,7 +685,6 @@ async function updateEntityById(
|
|
|
685
685
|
|
|
686
686
|
server.emitEvent(
|
|
687
687
|
"entity.update",
|
|
688
|
-
plugin,
|
|
689
688
|
{
|
|
690
689
|
namespace: model.namespace,
|
|
691
690
|
modelSingularCode: model.singularCode,
|
|
@@ -693,6 +692,7 @@ async function updateEntityById(
|
|
|
693
692
|
after: updatedEntity,
|
|
694
693
|
changes: changes,
|
|
695
694
|
},
|
|
695
|
+
plugin,
|
|
696
696
|
);
|
|
697
697
|
return updatedEntity;
|
|
698
698
|
}
|
|
@@ -722,24 +722,24 @@ export default class EntityManager<TEntity=any> {
|
|
|
722
722
|
return await findById(this.#server, this.#dataAccessor, id, keepNonPropertyFields);
|
|
723
723
|
}
|
|
724
724
|
|
|
725
|
-
async createEntity(options: CreateEntityOptions, plugin
|
|
725
|
+
async createEntity(options: CreateEntityOptions, plugin?: RapidPlugin): Promise<TEntity> {
|
|
726
726
|
const model = this.getModel();
|
|
727
727
|
const newEntity = await createEntity(this.#server, this.#dataAccessor, options);
|
|
728
728
|
|
|
729
729
|
this.#server.emitEvent(
|
|
730
730
|
"entity.create",
|
|
731
|
-
plugin,
|
|
732
731
|
{
|
|
733
732
|
namespace: model.namespace,
|
|
734
733
|
modelSingularCode: model.singularCode,
|
|
735
734
|
after: newEntity,
|
|
736
735
|
},
|
|
736
|
+
plugin,
|
|
737
737
|
);
|
|
738
738
|
|
|
739
739
|
return newEntity;
|
|
740
740
|
}
|
|
741
741
|
|
|
742
|
-
async updateEntityById(options: UpdateEntityByIdOptions, plugin
|
|
742
|
+
async updateEntityById(options: UpdateEntityByIdOptions, plugin?: RapidPlugin): Promise<TEntity> {
|
|
743
743
|
return await updateEntityById(this.#server, this.#dataAccessor, options, plugin);
|
|
744
744
|
}
|
|
745
745
|
|
|
@@ -747,7 +747,7 @@ export default class EntityManager<TEntity=any> {
|
|
|
747
747
|
return await this.#dataAccessor.count(options);
|
|
748
748
|
}
|
|
749
749
|
|
|
750
|
-
async deleteById(id: any, plugin
|
|
750
|
+
async deleteById(id: any, plugin?: RapidPlugin): Promise<void> {
|
|
751
751
|
const model = this.getModel();
|
|
752
752
|
const entity = await this.findById(id, true);
|
|
753
753
|
if (!entity) {
|
|
@@ -757,16 +757,16 @@ export default class EntityManager<TEntity=any> {
|
|
|
757
757
|
await this.#dataAccessor.deleteById(id);
|
|
758
758
|
this.#server.emitEvent(
|
|
759
759
|
"entity.delete",
|
|
760
|
-
plugin,
|
|
761
760
|
{
|
|
762
761
|
namespace: model.namespace,
|
|
763
762
|
modelSingularCode: model.singularCode,
|
|
764
763
|
before: entity,
|
|
765
764
|
},
|
|
765
|
+
plugin,
|
|
766
766
|
);
|
|
767
767
|
}
|
|
768
768
|
|
|
769
|
-
async addRelations(options: AddEntityRelationsOptions, plugin
|
|
769
|
+
async addRelations(options: AddEntityRelationsOptions, plugin?: RapidPlugin): Promise<void> {
|
|
770
770
|
const model = this.getModel();
|
|
771
771
|
const {id, property, relations} = options;
|
|
772
772
|
const entity = await this.findById(id);
|
|
@@ -800,7 +800,6 @@ export default class EntityManager<TEntity=any> {
|
|
|
800
800
|
|
|
801
801
|
server.emitEvent(
|
|
802
802
|
"entity.addRelations",
|
|
803
|
-
plugin,
|
|
804
803
|
{
|
|
805
804
|
namespace: model.namespace,
|
|
806
805
|
modelSingularCode: model.singularCode,
|
|
@@ -808,10 +807,11 @@ export default class EntityManager<TEntity=any> {
|
|
|
808
807
|
property,
|
|
809
808
|
relations,
|
|
810
809
|
},
|
|
810
|
+
plugin,
|
|
811
811
|
);
|
|
812
812
|
}
|
|
813
813
|
|
|
814
|
-
async removeRelations(options: RemoveEntityRelationsOptions, plugin
|
|
814
|
+
async removeRelations(options: RemoveEntityRelationsOptions, plugin?: RapidPlugin): Promise<void> {
|
|
815
815
|
const model = this.getModel();
|
|
816
816
|
const {id, property, relations} = options;
|
|
817
817
|
const entity = await this.findById(id);
|
|
@@ -841,7 +841,6 @@ export default class EntityManager<TEntity=any> {
|
|
|
841
841
|
|
|
842
842
|
server.emitEvent(
|
|
843
843
|
"entity.removeRelations",
|
|
844
|
-
plugin,
|
|
845
844
|
{
|
|
846
845
|
namespace: model.namespace,
|
|
847
846
|
modelSingularCode: model.singularCode,
|
|
@@ -849,6 +848,7 @@ export default class EntityManager<TEntity=any> {
|
|
|
849
848
|
property,
|
|
850
849
|
relations,
|
|
851
850
|
},
|
|
851
|
+
plugin,
|
|
852
852
|
);
|
|
853
853
|
}
|
|
854
854
|
}
|
package/src/server.ts
CHANGED
|
@@ -215,8 +215,8 @@ export class RapidServer implements IRpdServer {
|
|
|
215
215
|
|
|
216
216
|
async emitEvent<K extends keyof RpdServerEventTypes>(
|
|
217
217
|
eventName: K,
|
|
218
|
-
sender: RapidPlugin,
|
|
219
218
|
payload: RpdServerEventTypes[K][1],
|
|
219
|
+
sender?: RapidPlugin,
|
|
220
220
|
) {
|
|
221
221
|
this.#logger.debug(`Emitting '${eventName}' event.`, { eventName, payload });
|
|
222
222
|
await this.#eventManager.emit<K>(eventName, sender, payload as any);
|
|
@@ -272,10 +272,14 @@ export class RapidServer implements IRpdServer {
|
|
|
272
272
|
this.#facilityFactories.set(factory.name, factory);
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
async getFacility<TFacility=any>(name: string, options?: any): Promise<TFacility> {
|
|
275
|
+
async getFacility<TFacility=any>(name: string, options?: any, nullIfUnknownFacility?: boolean): Promise<TFacility> {
|
|
276
276
|
const factory = this.#facilityFactories.get(name);
|
|
277
277
|
if (!factory) {
|
|
278
|
-
|
|
278
|
+
if (nullIfUnknownFacility) {
|
|
279
|
+
return null;
|
|
280
|
+
} else {
|
|
281
|
+
throw new Error(`Failed to get facility. Unknown facility name: ${name}`);
|
|
282
|
+
}
|
|
279
283
|
}
|
|
280
284
|
|
|
281
285
|
return await factory.createFacility(this, options);
|