@ruiapp/rapid-core 0.1.32 → 0.1.34
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/index.js +32 -14
- package/dist/types.d.ts +19 -0
- package/package.json +1 -1
- package/src/dataAccess/entityManager.ts +50 -17
- package/src/plugins/cronJob/CronJobPlugin.ts +2 -0
- package/src/types.ts +22 -0
package/dist/index.js
CHANGED
|
@@ -2056,9 +2056,15 @@ function findOneRelatedEntitiesViaIdPropertyCode(server, model, relationProperty
|
|
|
2056
2056
|
});
|
|
2057
2057
|
return dataAccessor.find(findEntityOptions);
|
|
2058
2058
|
}
|
|
2059
|
-
async function createEntity(server, dataAccessor, options) {
|
|
2059
|
+
async function createEntity(server, dataAccessor, options, plugin) {
|
|
2060
2060
|
const model = dataAccessor.getModel();
|
|
2061
2061
|
const { entity } = options;
|
|
2062
|
+
await server.beforeCreateEntity(model, options);
|
|
2063
|
+
await server.emitEvent("entity.beforeCreate", {
|
|
2064
|
+
namespace: model.namespace,
|
|
2065
|
+
modelSingularCode: model.singularCode,
|
|
2066
|
+
before: entity,
|
|
2067
|
+
}, plugin);
|
|
2062
2068
|
const oneRelationPropertiesToCreate = [];
|
|
2063
2069
|
const manyRelationPropertiesToCreate = [];
|
|
2064
2070
|
lodash.keys(entity).forEach((propertyCode) => {
|
|
@@ -2170,6 +2176,11 @@ async function createEntity(server, dataAccessor, options) {
|
|
|
2170
2176
|
}
|
|
2171
2177
|
}
|
|
2172
2178
|
}
|
|
2179
|
+
await server.emitEvent("entity.create", {
|
|
2180
|
+
namespace: model.namespace,
|
|
2181
|
+
modelSingularCode: model.singularCode,
|
|
2182
|
+
after: newEntity,
|
|
2183
|
+
}, plugin);
|
|
2173
2184
|
return newEntity;
|
|
2174
2185
|
}
|
|
2175
2186
|
async function updateEntityById(server, dataAccessor, options, plugin) {
|
|
@@ -2188,6 +2199,12 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
|
|
|
2188
2199
|
}
|
|
2189
2200
|
options.entityToSave = changes || {};
|
|
2190
2201
|
await server.beforeUpdateEntity(model, options, entity);
|
|
2202
|
+
await server.emitEvent("entity.beforeUpdate", {
|
|
2203
|
+
namespace: model.namespace,
|
|
2204
|
+
modelSingularCode: model.singularCode,
|
|
2205
|
+
before: entity,
|
|
2206
|
+
changes: options.entityToSave,
|
|
2207
|
+
}, plugin);
|
|
2191
2208
|
changes = options.entityToSave;
|
|
2192
2209
|
const oneRelationPropertiesToUpdate = [];
|
|
2193
2210
|
const manyRelationPropertiesToUpdate = [];
|
|
@@ -2295,7 +2312,7 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
|
|
|
2295
2312
|
}
|
|
2296
2313
|
updatedEntity[property.code] = relatedEntities;
|
|
2297
2314
|
}
|
|
2298
|
-
server.emitEvent("entity.update", {
|
|
2315
|
+
await server.emitEvent("entity.update", {
|
|
2299
2316
|
namespace: model.namespace,
|
|
2300
2317
|
modelSingularCode: model.singularCode,
|
|
2301
2318
|
before: entity,
|
|
@@ -2324,14 +2341,8 @@ class EntityManager {
|
|
|
2324
2341
|
return await findById(this.#server, this.#dataAccessor, id, keepNonPropertyFields);
|
|
2325
2342
|
}
|
|
2326
2343
|
async createEntity(options, plugin) {
|
|
2327
|
-
|
|
2328
|
-
await this.#server
|
|
2329
|
-
const newEntity = await createEntity(this.#server, this.#dataAccessor, options);
|
|
2330
|
-
this.#server.emitEvent("entity.create", {
|
|
2331
|
-
namespace: model.namespace,
|
|
2332
|
-
modelSingularCode: model.singularCode,
|
|
2333
|
-
after: newEntity,
|
|
2334
|
-
}, plugin);
|
|
2344
|
+
this.getModel();
|
|
2345
|
+
const newEntity = await createEntity(this.#server, this.#dataAccessor, options, plugin);
|
|
2335
2346
|
return newEntity;
|
|
2336
2347
|
}
|
|
2337
2348
|
async updateEntityById(options, plugin) {
|
|
@@ -2346,8 +2357,13 @@ class EntityManager {
|
|
|
2346
2357
|
if (!entity) {
|
|
2347
2358
|
return;
|
|
2348
2359
|
}
|
|
2360
|
+
await this.#server.emitEvent("entity.beforeDelete", {
|
|
2361
|
+
namespace: model.namespace,
|
|
2362
|
+
modelSingularCode: model.singularCode,
|
|
2363
|
+
before: entity,
|
|
2364
|
+
}, plugin);
|
|
2349
2365
|
await this.#dataAccessor.deleteById(id);
|
|
2350
|
-
this.#server.emitEvent("entity.delete", {
|
|
2366
|
+
await this.#server.emitEvent("entity.delete", {
|
|
2351
2367
|
namespace: model.namespace,
|
|
2352
2368
|
modelSingularCode: model.singularCode,
|
|
2353
2369
|
before: entity,
|
|
@@ -2381,7 +2397,7 @@ class EntityManager {
|
|
|
2381
2397
|
await server.queryDatabaseObject(command, params);
|
|
2382
2398
|
}
|
|
2383
2399
|
}
|
|
2384
|
-
server.emitEvent("entity.addRelations", {
|
|
2400
|
+
await server.emitEvent("entity.addRelations", {
|
|
2385
2401
|
namespace: model.namespace,
|
|
2386
2402
|
modelSingularCode: model.singularCode,
|
|
2387
2403
|
entity,
|
|
@@ -2413,7 +2429,7 @@ class EntityManager {
|
|
|
2413
2429
|
await server.queryDatabaseObject(command, params);
|
|
2414
2430
|
}
|
|
2415
2431
|
}
|
|
2416
|
-
server.emitEvent("entity.removeRelations", {
|
|
2432
|
+
await server.emitEvent("entity.removeRelations", {
|
|
2417
2433
|
namespace: model.namespace,
|
|
2418
2434
|
modelSingularCode: model.singularCode,
|
|
2419
2435
|
entity,
|
|
@@ -4981,12 +4997,14 @@ class CronJobPlugin {
|
|
|
4981
4997
|
}
|
|
4982
4998
|
async onApplicationReady(server, applicationConfig) {
|
|
4983
4999
|
for (const job of this.#jobs) {
|
|
4984
|
-
cron__namespace.CronJob.from({
|
|
5000
|
+
const jobInstance = cron__namespace.CronJob.from({
|
|
4985
5001
|
cronTime: job.cronTime,
|
|
4986
5002
|
onTick: async () => {
|
|
5003
|
+
server.getLogger().info(`Executing cron job '${job.code}'...`);
|
|
4987
5004
|
await this.executeJob(server, job);
|
|
4988
5005
|
},
|
|
4989
5006
|
});
|
|
5007
|
+
jobInstance.start();
|
|
4990
5008
|
}
|
|
4991
5009
|
}
|
|
4992
5010
|
getJobConfigurationByCode(code) {
|
package/dist/types.d.ts
CHANGED
|
@@ -50,17 +50,31 @@ export interface GetModelOptions {
|
|
|
50
50
|
singularCode: string;
|
|
51
51
|
}
|
|
52
52
|
export type RpdServerEventTypes = {
|
|
53
|
+
"entity.beforeCreate": [RapidPlugin, RpdEntityBeforeCreateEventPayload];
|
|
53
54
|
"entity.create": [RapidPlugin, RpdEntityCreateEventPayload];
|
|
55
|
+
"entity.beforeUpdate": [RapidPlugin, RpdEntityBeforeUpdateEventPayload];
|
|
54
56
|
"entity.update": [RapidPlugin, RpdEntityUpdateEventPayload];
|
|
57
|
+
"entity.beforeDelete": [RapidPlugin, RpdEntityBeforeDeleteEventPayload];
|
|
55
58
|
"entity.delete": [RapidPlugin, RpdEntityDeleteEventPayload];
|
|
56
59
|
"entity.addRelations": [RapidPlugin, RpdEntityAddRelationsEventPayload];
|
|
57
60
|
"entity.removeRelations": [RapidPlugin, RpdEntityRemoveRelationsEventPayload];
|
|
58
61
|
};
|
|
62
|
+
export interface RpdEntityBeforeCreateEventPayload {
|
|
63
|
+
namespace: string;
|
|
64
|
+
modelSingularCode: string;
|
|
65
|
+
before: any;
|
|
66
|
+
}
|
|
59
67
|
export interface RpdEntityCreateEventPayload {
|
|
60
68
|
namespace: string;
|
|
61
69
|
modelSingularCode: string;
|
|
62
70
|
after: any;
|
|
63
71
|
}
|
|
72
|
+
export interface RpdEntityBeforeUpdateEventPayload {
|
|
73
|
+
namespace: string;
|
|
74
|
+
modelSingularCode: string;
|
|
75
|
+
before: any;
|
|
76
|
+
changes: any;
|
|
77
|
+
}
|
|
64
78
|
export interface RpdEntityUpdateEventPayload {
|
|
65
79
|
namespace: string;
|
|
66
80
|
modelSingularCode: string;
|
|
@@ -68,6 +82,11 @@ export interface RpdEntityUpdateEventPayload {
|
|
|
68
82
|
after: any;
|
|
69
83
|
changes: any;
|
|
70
84
|
}
|
|
85
|
+
export interface RpdEntityBeforeDeleteEventPayload {
|
|
86
|
+
namespace: string;
|
|
87
|
+
modelSingularCode: string;
|
|
88
|
+
before: any;
|
|
89
|
+
}
|
|
71
90
|
export interface RpdEntityDeleteEventPayload {
|
|
72
91
|
namespace: string;
|
|
73
92
|
modelSingularCode: string;
|
package/package.json
CHANGED
|
@@ -431,10 +431,23 @@ async function createEntity(
|
|
|
431
431
|
server: IRpdServer,
|
|
432
432
|
dataAccessor: IRpdDataAccessor,
|
|
433
433
|
options: CreateEntityOptions,
|
|
434
|
+
plugin?: RapidPlugin
|
|
434
435
|
) {
|
|
435
436
|
const model = dataAccessor.getModel();
|
|
436
437
|
const { entity } = options;
|
|
437
438
|
|
|
439
|
+
await server.beforeCreateEntity(model, options);
|
|
440
|
+
|
|
441
|
+
await server.emitEvent(
|
|
442
|
+
"entity.beforeCreate",
|
|
443
|
+
{
|
|
444
|
+
namespace: model.namespace,
|
|
445
|
+
modelSingularCode: model.singularCode,
|
|
446
|
+
before: entity,
|
|
447
|
+
},
|
|
448
|
+
plugin,
|
|
449
|
+
);
|
|
450
|
+
|
|
438
451
|
const oneRelationPropertiesToCreate: RpdDataModelProperty[] = [];
|
|
439
452
|
const manyRelationPropertiesToCreate: RpdDataModelProperty[] = [];
|
|
440
453
|
keys(entity).forEach((propertyCode) => {
|
|
@@ -553,6 +566,15 @@ async function createEntity(
|
|
|
553
566
|
}
|
|
554
567
|
}
|
|
555
568
|
|
|
569
|
+
await server.emitEvent(
|
|
570
|
+
"entity.create",
|
|
571
|
+
{
|
|
572
|
+
namespace: model.namespace,
|
|
573
|
+
modelSingularCode: model.singularCode,
|
|
574
|
+
after: newEntity,
|
|
575
|
+
},
|
|
576
|
+
plugin,
|
|
577
|
+
);
|
|
556
578
|
|
|
557
579
|
return newEntity;
|
|
558
580
|
}
|
|
@@ -581,6 +603,18 @@ async function updateEntityById(
|
|
|
581
603
|
|
|
582
604
|
options.entityToSave = changes || {};
|
|
583
605
|
await server.beforeUpdateEntity(model, options, entity);
|
|
606
|
+
|
|
607
|
+
await server.emitEvent(
|
|
608
|
+
"entity.beforeUpdate",
|
|
609
|
+
{
|
|
610
|
+
namespace: model.namespace,
|
|
611
|
+
modelSingularCode: model.singularCode,
|
|
612
|
+
before: entity,
|
|
613
|
+
changes: options.entityToSave,
|
|
614
|
+
},
|
|
615
|
+
plugin,
|
|
616
|
+
);
|
|
617
|
+
|
|
584
618
|
changes = options.entityToSave;
|
|
585
619
|
|
|
586
620
|
const oneRelationPropertiesToUpdate: RpdDataModelProperty[] = [];
|
|
@@ -695,7 +729,7 @@ async function updateEntityById(
|
|
|
695
729
|
updatedEntity[property.code] = relatedEntities;
|
|
696
730
|
}
|
|
697
731
|
|
|
698
|
-
server.emitEvent(
|
|
732
|
+
await server.emitEvent(
|
|
699
733
|
"entity.update",
|
|
700
734
|
{
|
|
701
735
|
namespace: model.namespace,
|
|
@@ -737,19 +771,7 @@ export default class EntityManager<TEntity=any> {
|
|
|
737
771
|
async createEntity(options: CreateEntityOptions, plugin?: RapidPlugin): Promise<TEntity> {
|
|
738
772
|
const model = this.getModel();
|
|
739
773
|
|
|
740
|
-
await this.#server
|
|
741
|
-
|
|
742
|
-
const newEntity = await createEntity(this.#server, this.#dataAccessor, options);
|
|
743
|
-
|
|
744
|
-
this.#server.emitEvent(
|
|
745
|
-
"entity.create",
|
|
746
|
-
{
|
|
747
|
-
namespace: model.namespace,
|
|
748
|
-
modelSingularCode: model.singularCode,
|
|
749
|
-
after: newEntity,
|
|
750
|
-
},
|
|
751
|
-
plugin,
|
|
752
|
-
);
|
|
774
|
+
const newEntity = await createEntity(this.#server, this.#dataAccessor, options, plugin);
|
|
753
775
|
|
|
754
776
|
return newEntity;
|
|
755
777
|
}
|
|
@@ -769,8 +791,19 @@ export default class EntityManager<TEntity=any> {
|
|
|
769
791
|
return;
|
|
770
792
|
}
|
|
771
793
|
|
|
794
|
+
await this.#server.emitEvent(
|
|
795
|
+
"entity.beforeDelete",
|
|
796
|
+
{
|
|
797
|
+
namespace: model.namespace,
|
|
798
|
+
modelSingularCode: model.singularCode,
|
|
799
|
+
before: entity,
|
|
800
|
+
},
|
|
801
|
+
plugin,
|
|
802
|
+
);
|
|
803
|
+
|
|
772
804
|
await this.#dataAccessor.deleteById(id);
|
|
773
|
-
|
|
805
|
+
|
|
806
|
+
await this.#server.emitEvent(
|
|
774
807
|
"entity.delete",
|
|
775
808
|
{
|
|
776
809
|
namespace: model.namespace,
|
|
@@ -813,7 +846,7 @@ export default class EntityManager<TEntity=any> {
|
|
|
813
846
|
}
|
|
814
847
|
}
|
|
815
848
|
|
|
816
|
-
server.emitEvent(
|
|
849
|
+
await server.emitEvent(
|
|
817
850
|
"entity.addRelations",
|
|
818
851
|
{
|
|
819
852
|
namespace: model.namespace,
|
|
@@ -854,7 +887,7 @@ export default class EntityManager<TEntity=any> {
|
|
|
854
887
|
}
|
|
855
888
|
}
|
|
856
889
|
|
|
857
|
-
server.emitEvent(
|
|
890
|
+
await server.emitEvent(
|
|
858
891
|
"entity.removeRelations",
|
|
859
892
|
{
|
|
860
893
|
namespace: model.namespace,
|
|
@@ -76,9 +76,11 @@ class CronJobPlugin implements RapidPlugin {
|
|
|
76
76
|
const jobInstance = cron.CronJob.from({
|
|
77
77
|
cronTime: job.cronTime,
|
|
78
78
|
onTick: async () => {
|
|
79
|
+
server.getLogger().info(`Executing cron job '${job.code}'...`);
|
|
79
80
|
await this.executeJob(server, job);
|
|
80
81
|
},
|
|
81
82
|
});
|
|
83
|
+
jobInstance.start();
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
|
package/src/types.ts
CHANGED
|
@@ -62,19 +62,35 @@ export interface GetModelOptions {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export type RpdServerEventTypes = {
|
|
65
|
+
"entity.beforeCreate": [RapidPlugin, RpdEntityBeforeCreateEventPayload];
|
|
65
66
|
"entity.create": [RapidPlugin, RpdEntityCreateEventPayload];
|
|
67
|
+
"entity.beforeUpdate": [RapidPlugin, RpdEntityBeforeUpdateEventPayload];
|
|
66
68
|
"entity.update": [RapidPlugin, RpdEntityUpdateEventPayload];
|
|
69
|
+
"entity.beforeDelete": [RapidPlugin, RpdEntityBeforeDeleteEventPayload];
|
|
67
70
|
"entity.delete": [RapidPlugin, RpdEntityDeleteEventPayload];
|
|
68
71
|
"entity.addRelations": [RapidPlugin, RpdEntityAddRelationsEventPayload];
|
|
69
72
|
"entity.removeRelations": [RapidPlugin, RpdEntityRemoveRelationsEventPayload];
|
|
70
73
|
};
|
|
71
74
|
|
|
75
|
+
export interface RpdEntityBeforeCreateEventPayload {
|
|
76
|
+
namespace: string;
|
|
77
|
+
modelSingularCode: string;
|
|
78
|
+
before: any;
|
|
79
|
+
}
|
|
80
|
+
|
|
72
81
|
export interface RpdEntityCreateEventPayload {
|
|
73
82
|
namespace: string;
|
|
74
83
|
modelSingularCode: string;
|
|
75
84
|
after: any;
|
|
76
85
|
}
|
|
77
86
|
|
|
87
|
+
export interface RpdEntityBeforeUpdateEventPayload {
|
|
88
|
+
namespace: string;
|
|
89
|
+
modelSingularCode: string;
|
|
90
|
+
before: any;
|
|
91
|
+
changes: any;
|
|
92
|
+
}
|
|
93
|
+
|
|
78
94
|
export interface RpdEntityUpdateEventPayload {
|
|
79
95
|
namespace: string;
|
|
80
96
|
modelSingularCode: string;
|
|
@@ -83,6 +99,12 @@ export interface RpdEntityUpdateEventPayload {
|
|
|
83
99
|
changes: any;
|
|
84
100
|
}
|
|
85
101
|
|
|
102
|
+
export interface RpdEntityBeforeDeleteEventPayload {
|
|
103
|
+
namespace: string;
|
|
104
|
+
modelSingularCode: string;
|
|
105
|
+
before: any;
|
|
106
|
+
}
|
|
107
|
+
|
|
86
108
|
export interface RpdEntityDeleteEventPayload {
|
|
87
109
|
namespace: string;
|
|
88
110
|
modelSingularCode: string;
|