@ruiapp/rapid-core 0.1.50 → 0.1.52
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 +3 -2
- package/dist/index.js +39 -16
- package/dist/server.d.ts +1 -1
- package/dist/types.d.ts +7 -0
- package/package.json +1 -1
- package/src/core/server.ts +3 -2
- package/src/dataAccess/entityManager.ts +26 -13
- package/src/dataAccess/metaHelper.ts +11 -2
- package/src/server.ts +8 -2
- package/src/types.ts +8 -0
package/dist/core/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateEntityOptions, GetDataAccessorOptions, GetModelOptions, IDatabaseConfig, IQueryBuilder, IRpdDataAccessor, RapidServerConfig, RpdApplicationConfig, RpdDataModel, RpdDataModelProperty, RpdServerEventTypes, UpdateEntityByIdOptions } from "../types";
|
|
1
|
+
import { CreateEntityOptions, EntityWatcherType, GetDataAccessorOptions, GetModelOptions, IDatabaseConfig, IQueryBuilder, IRpdDataAccessor, RapidServerConfig, RpdApplicationConfig, RpdDataModel, RpdDataModelProperty, RpdServerEventTypes, UpdateEntityByIdOptions } from "../types";
|
|
2
2
|
import { IPluginActionHandler, ActionHandler, ActionHandlerContext } from "./actionHandler";
|
|
3
3
|
import { Next, RouteContext } from "./routeContext";
|
|
4
4
|
import EntityManager from "../dataAccess/entityManager";
|
|
@@ -24,7 +24,8 @@ export interface IRpdServer {
|
|
|
24
24
|
appendApplicationConfig(config: Partial<RpdApplicationConfig>): any;
|
|
25
25
|
appendModelProperties(modelSingularCode: string, properties: RpdDataModelProperty[]): any;
|
|
26
26
|
getModel(options: GetModelOptions): RpdDataModel | undefined;
|
|
27
|
-
registerEventHandler<K extends keyof RpdServerEventTypes>(eventName: K, listener: (...args: RpdServerEventTypes[K]) => void):
|
|
27
|
+
registerEventHandler<K extends keyof RpdServerEventTypes>(eventName: K, listener: (...args: RpdServerEventTypes[K]) => void): any;
|
|
28
|
+
registerEntityWatcher(entityWatcher: EntityWatcherType): any;
|
|
28
29
|
emitEvent<K extends keyof RpdServerEventTypes>(eventName: K, payload: RpdServerEventTypes[K][1], sender?: RapidPlugin): void;
|
|
29
30
|
handleRequest(request: Request, next: Next): Promise<Response>;
|
|
30
31
|
beforeRunRouteActions(handlerContext: ActionHandlerContext): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -1804,9 +1804,16 @@ function getEntityPropertiesIncludingBase(server, model) {
|
|
|
1804
1804
|
const baseModel = server.getModel({
|
|
1805
1805
|
singularCode: model.base,
|
|
1806
1806
|
});
|
|
1807
|
-
|
|
1807
|
+
let baseProperties = [];
|
|
1808
|
+
if (baseModel) {
|
|
1809
|
+
baseModel.properties.map((property) => {
|
|
1810
|
+
property = lodash.cloneDeep(property);
|
|
1811
|
+
property.isBaseProperty = true;
|
|
1812
|
+
return property;
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1808
1815
|
return [
|
|
1809
|
-
...
|
|
1816
|
+
...baseProperties,
|
|
1810
1817
|
...model.properties,
|
|
1811
1818
|
];
|
|
1812
1819
|
}
|
|
@@ -1823,6 +1830,7 @@ function getEntityProperty(server, model, predicate) {
|
|
|
1823
1830
|
});
|
|
1824
1831
|
property = baseModel.properties.find(predicate);
|
|
1825
1832
|
if (property) {
|
|
1833
|
+
property = lodash.cloneDeep(property);
|
|
1826
1834
|
property.isBaseProperty = true;
|
|
1827
1835
|
}
|
|
1828
1836
|
}
|
|
@@ -2050,11 +2058,11 @@ async function findEntities(server, dataAccessor, options) {
|
|
|
2050
2058
|
pagination: options.pagination,
|
|
2051
2059
|
fields: columnsToSelect,
|
|
2052
2060
|
};
|
|
2053
|
-
const
|
|
2054
|
-
if (!
|
|
2061
|
+
const rows = await dataAccessor.find(findRowOptions);
|
|
2062
|
+
if (!rows.length) {
|
|
2055
2063
|
return [];
|
|
2056
2064
|
}
|
|
2057
|
-
const entityIds =
|
|
2065
|
+
const entityIds = rows.map((row) => row.id);
|
|
2058
2066
|
if (relationPropertiesToSelect.length) {
|
|
2059
2067
|
for (const relationProperty of relationPropertiesToSelect) {
|
|
2060
2068
|
const isManyRelation = relationProperty.relation === "many";
|
|
@@ -2065,9 +2073,9 @@ async function findEntities(server, dataAccessor, options) {
|
|
|
2065
2073
|
}
|
|
2066
2074
|
if (isManyRelation) {
|
|
2067
2075
|
const relationLinks = await findManyRelationLinksViaLinkTable(server, targetModel, relationProperty, entityIds);
|
|
2068
|
-
lodash.forEach(
|
|
2069
|
-
|
|
2070
|
-
return link[relationProperty.selfIdColumnName] ==
|
|
2076
|
+
lodash.forEach(rows, (row) => {
|
|
2077
|
+
row[relationProperty.code] = lodash.filter(relationLinks, (link) => {
|
|
2078
|
+
return link[relationProperty.selfIdColumnName] == row["id"];
|
|
2071
2079
|
}).map((link) => mapDbRowToEntity(server, targetModel, link.targetEntity, false));
|
|
2072
2080
|
});
|
|
2073
2081
|
}
|
|
@@ -2078,29 +2086,36 @@ async function findEntities(server, dataAccessor, options) {
|
|
|
2078
2086
|
relatedEntities = await findManyRelatedEntitiesViaIdPropertyCode(server, model, relationProperty, entityIds);
|
|
2079
2087
|
}
|
|
2080
2088
|
else {
|
|
2081
|
-
const targetEntityIds = lodash.uniq(lodash.reject(lodash.map(
|
|
2089
|
+
const targetEntityIds = lodash.uniq(lodash.reject(lodash.map(rows, (entity) => entity[relationProperty.targetIdColumnName]), isNullOrUndefined));
|
|
2082
2090
|
relatedEntities = await findOneRelatedEntitiesViaIdPropertyCode(server, model, relationProperty, targetEntityIds);
|
|
2083
2091
|
}
|
|
2084
2092
|
const targetModel = server.getModel({
|
|
2085
2093
|
singularCode: relationProperty.targetSingularCode,
|
|
2086
2094
|
});
|
|
2087
|
-
|
|
2095
|
+
rows.forEach((row) => {
|
|
2088
2096
|
if (isManyRelation) {
|
|
2089
|
-
|
|
2090
|
-
return relatedEntity[relationProperty.selfIdColumnName] ==
|
|
2097
|
+
row[relationProperty.code] = lodash.filter(relatedEntities, (relatedEntity) => {
|
|
2098
|
+
return relatedEntity[relationProperty.selfIdColumnName] == row.id;
|
|
2091
2099
|
}).map((item) => mapDbRowToEntity(server, targetModel, item, false));
|
|
2092
2100
|
}
|
|
2093
2101
|
else {
|
|
2094
|
-
|
|
2102
|
+
row[relationProperty.code] = mapDbRowToEntity(server, targetModel, lodash.find(relatedEntities, (relatedEntity) => {
|
|
2095
2103
|
// TODO: id property code should be configurable.
|
|
2096
|
-
return relatedEntity["id"] ==
|
|
2104
|
+
return relatedEntity["id"] == row[relationProperty.targetIdColumnName];
|
|
2097
2105
|
}), false);
|
|
2098
2106
|
}
|
|
2099
2107
|
});
|
|
2100
2108
|
}
|
|
2101
2109
|
}
|
|
2102
2110
|
}
|
|
2103
|
-
|
|
2111
|
+
const entities = rows.map((item) => mapDbRowToEntity(server, model, item, options.keepNonPropertyFields));
|
|
2112
|
+
await server.emitEvent("entity.beforeResponse", {
|
|
2113
|
+
namespace: model.namespace,
|
|
2114
|
+
modelSingularCode: model.singularCode,
|
|
2115
|
+
baseModelSingularCode: model.base,
|
|
2116
|
+
entities,
|
|
2117
|
+
}, null);
|
|
2118
|
+
return entities;
|
|
2104
2119
|
}
|
|
2105
2120
|
async function findEntity(server, dataAccessor, options) {
|
|
2106
2121
|
const entities = await findEntities(server, dataAccessor, options);
|
|
@@ -2867,6 +2882,7 @@ class RapidServer {
|
|
|
2867
2882
|
#entityDeleteEventEmitters;
|
|
2868
2883
|
#entityAddRelationsEventEmitters;
|
|
2869
2884
|
#entityRemoveRelationsEventEmitters;
|
|
2885
|
+
#entityBeforeResponseEventEmitters;
|
|
2870
2886
|
#entityWatchers;
|
|
2871
2887
|
#appEntityWatchers;
|
|
2872
2888
|
#cachedEntityManager;
|
|
@@ -2900,6 +2916,7 @@ class RapidServer {
|
|
|
2900
2916
|
this.#entityDeleteEventEmitters = new EventManager();
|
|
2901
2917
|
this.#entityAddRelationsEventEmitters = new EventManager();
|
|
2902
2918
|
this.#entityRemoveRelationsEventEmitters = new EventManager();
|
|
2919
|
+
this.#entityBeforeResponseEventEmitters = new EventManager();
|
|
2903
2920
|
this.registerEventHandler("entity.beforeCreate", this.#handleEntityEvent.bind(this, "entity.beforeCreate"));
|
|
2904
2921
|
this.registerEventHandler("entity.create", this.#handleEntityEvent.bind(this, "entity.create"));
|
|
2905
2922
|
this.registerEventHandler("entity.beforeUpdate", this.#handleEntityEvent.bind(this, "entity.beforeUpdate"));
|
|
@@ -2908,6 +2925,7 @@ class RapidServer {
|
|
|
2908
2925
|
this.registerEventHandler("entity.delete", this.#handleEntityEvent.bind(this, "entity.delete"));
|
|
2909
2926
|
this.registerEventHandler("entity.addRelations", this.#handleEntityEvent.bind(this, "entity.addRelations"));
|
|
2910
2927
|
this.registerEventHandler("entity.removeRelations", this.#handleEntityEvent.bind(this, "entity.removeRelations"));
|
|
2928
|
+
this.registerEventHandler("entity.beforeResponse", this.#handleEntityEvent.bind(this, "entity.beforeResponse"));
|
|
2911
2929
|
this.#entityWatchers = [];
|
|
2912
2930
|
this.#appEntityWatchers = options.entityWatchers || [];
|
|
2913
2931
|
this.#services = new Map();
|
|
@@ -3022,7 +3040,6 @@ class RapidServer {
|
|
|
3022
3040
|
}
|
|
3023
3041
|
registerEventHandler(eventName, listener) {
|
|
3024
3042
|
this.#eventManager.on(eventName, listener);
|
|
3025
|
-
return this;
|
|
3026
3043
|
}
|
|
3027
3044
|
registerEntityWatcher(entityWatcher) {
|
|
3028
3045
|
this.#entityWatchers.push(entityWatcher);
|
|
@@ -3081,6 +3098,9 @@ class RapidServer {
|
|
|
3081
3098
|
else if (entityWatcher.eventName === "entity.removeRelations") {
|
|
3082
3099
|
this.#entityRemoveRelationsEventEmitters.on(entityWatcher.modelSingularCode, entityWatcher.handler);
|
|
3083
3100
|
}
|
|
3101
|
+
else if (entityWatcher.eventName === "entity.beforeResponse") {
|
|
3102
|
+
this.#entityBeforeResponseEventEmitters.on(entityWatcher.modelSingularCode, entityWatcher.handler);
|
|
3103
|
+
}
|
|
3084
3104
|
}
|
|
3085
3105
|
await this.configureApplication();
|
|
3086
3106
|
this.#logger.info(`Rapid server ready.`);
|
|
@@ -3192,6 +3212,9 @@ class RapidServer {
|
|
|
3192
3212
|
else if (eventName === "entity.removeRelations") {
|
|
3193
3213
|
emitter = this.#entityRemoveRelationsEventEmitters;
|
|
3194
3214
|
}
|
|
3215
|
+
else if (eventName === "entity.beforeResponse") {
|
|
3216
|
+
emitter = this.#entityBeforeResponseEventEmitters;
|
|
3217
|
+
}
|
|
3195
3218
|
emitter.emit(modelSingularCode, entityWatchHandlerContext);
|
|
3196
3219
|
if (baseModelSingularCode) {
|
|
3197
3220
|
emitter.emit(baseModelSingularCode, entityWatchHandlerContext);
|
package/dist/server.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare class RapidServer implements IRpdServer {
|
|
|
31
31
|
getDataAccessor<T = any>(options: GetDataAccessorOptions): IRpdDataAccessor<T>;
|
|
32
32
|
getModel(options: GetModelOptions): RpdDataModel | undefined;
|
|
33
33
|
getEntityManager<TEntity = any>(singularCode: string): EntityManager<TEntity>;
|
|
34
|
-
registerEventHandler<K extends keyof RpdServerEventTypes>(eventName: K, listener: (...args: RpdServerEventTypes[K]) => void):
|
|
34
|
+
registerEventHandler<K extends keyof RpdServerEventTypes>(eventName: K, listener: (...args: RpdServerEventTypes[K]) => void): void;
|
|
35
35
|
registerEntityWatcher(entityWatcher: EntityWatcherType): void;
|
|
36
36
|
emitEvent<K extends keyof RpdServerEventTypes>(eventName: K, payload: RpdServerEventTypes[K][1], sender?: RapidPlugin): Promise<void>;
|
|
37
37
|
registerService(name: string, service: any): void;
|
package/dist/types.d.ts
CHANGED
|
@@ -63,6 +63,7 @@ export type RpdServerEventTypes = {
|
|
|
63
63
|
"entity.delete": [RapidPlugin, RpdEntityDeleteEventPayload];
|
|
64
64
|
"entity.addRelations": [RapidPlugin, RpdEntityAddRelationsEventPayload];
|
|
65
65
|
"entity.removeRelations": [RapidPlugin, RpdEntityRemoveRelationsEventPayload];
|
|
66
|
+
"entity.beforeResponse": [RapidPlugin, RpdEntityBeforeResponseEventPayload];
|
|
66
67
|
};
|
|
67
68
|
export interface RpdEntityBeforeCreateEventPayload {
|
|
68
69
|
namespace: string;
|
|
@@ -119,6 +120,12 @@ export interface RpdEntityRemoveRelationsEventPayload {
|
|
|
119
120
|
property: string;
|
|
120
121
|
relations: any[];
|
|
121
122
|
}
|
|
123
|
+
export interface RpdEntityBeforeResponseEventPayload {
|
|
124
|
+
namespace: string;
|
|
125
|
+
modelSingularCode: string;
|
|
126
|
+
baseModelSingularCode?: string;
|
|
127
|
+
entities: any[];
|
|
128
|
+
}
|
|
122
129
|
export interface QuoteTableOptions {
|
|
123
130
|
schema?: string;
|
|
124
131
|
tableName: string;
|
package/package.json
CHANGED
package/src/core/server.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateEntityOptions, GetDataAccessorOptions, GetModelOptions, IDatabaseConfig, IQueryBuilder, IRpdDataAccessor, RapidServerConfig, RpdApplicationConfig, RpdDataModel, RpdDataModelProperty, RpdServerEventTypes, UpdateEntityByIdOptions } from "~/types";
|
|
1
|
+
import { CreateEntityOptions, EntityWatcherType, GetDataAccessorOptions, GetModelOptions, IDatabaseConfig, IQueryBuilder, IRpdDataAccessor, RapidServerConfig, RpdApplicationConfig, RpdDataModel, RpdDataModelProperty, RpdServerEventTypes, UpdateEntityByIdOptions } from "~/types";
|
|
2
2
|
import { IPluginActionHandler, ActionHandler, ActionHandlerContext } from "./actionHandler";
|
|
3
3
|
import { Next, RouteContext } from "./routeContext";
|
|
4
4
|
import EntityManager from "~/dataAccess/entityManager";
|
|
@@ -28,7 +28,8 @@ export interface IRpdServer {
|
|
|
28
28
|
appendApplicationConfig(config: Partial<RpdApplicationConfig>);
|
|
29
29
|
appendModelProperties(modelSingularCode: string, properties: RpdDataModelProperty[]);
|
|
30
30
|
getModel(options: GetModelOptions): RpdDataModel | undefined;
|
|
31
|
-
registerEventHandler<K extends keyof RpdServerEventTypes>(eventName: K, listener: (...args: RpdServerEventTypes[K]) => void)
|
|
31
|
+
registerEventHandler<K extends keyof RpdServerEventTypes>(eventName: K, listener: (...args: RpdServerEventTypes[K]) => void);
|
|
32
|
+
registerEntityWatcher(entityWatcher: EntityWatcherType);
|
|
32
33
|
emitEvent<K extends keyof RpdServerEventTypes>(eventName: K, payload: RpdServerEventTypes[K][1], sender?: RapidPlugin): void;
|
|
33
34
|
handleRequest(request: Request, next: Next): Promise<Response>;
|
|
34
35
|
beforeRunRouteActions(handlerContext: ActionHandlerContext): Promise<void>;
|
|
@@ -129,12 +129,12 @@ async function findEntities(server: IRpdServer, dataAccessor: IRpdDataAccessor,
|
|
|
129
129
|
pagination: options.pagination,
|
|
130
130
|
fields: columnsToSelect,
|
|
131
131
|
};
|
|
132
|
-
const
|
|
133
|
-
if (!
|
|
132
|
+
const rows = await dataAccessor.find(findRowOptions);
|
|
133
|
+
if (!rows.length) {
|
|
134
134
|
return [];
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
const entityIds =
|
|
137
|
+
const entityIds = rows.map((row) => row.id);
|
|
138
138
|
if (relationPropertiesToSelect.length) {
|
|
139
139
|
for (const relationProperty of relationPropertiesToSelect) {
|
|
140
140
|
const isManyRelation = relationProperty.relation === "many";
|
|
@@ -148,9 +148,9 @@ async function findEntities(server: IRpdServer, dataAccessor: IRpdDataAccessor,
|
|
|
148
148
|
if (isManyRelation) {
|
|
149
149
|
const relationLinks = await findManyRelationLinksViaLinkTable(server, targetModel, relationProperty, entityIds);
|
|
150
150
|
|
|
151
|
-
forEach(
|
|
152
|
-
|
|
153
|
-
return link[relationProperty.selfIdColumnName!] ==
|
|
151
|
+
forEach(rows, (row: any) => {
|
|
152
|
+
row[relationProperty.code] = filter(relationLinks, (link: any) => {
|
|
153
|
+
return link[relationProperty.selfIdColumnName!] == row["id"];
|
|
154
154
|
}).map((link) => mapDbRowToEntity(server, targetModel, link.targetEntity, false));
|
|
155
155
|
});
|
|
156
156
|
}
|
|
@@ -161,7 +161,7 @@ async function findEntities(server: IRpdServer, dataAccessor: IRpdDataAccessor,
|
|
|
161
161
|
} else {
|
|
162
162
|
const targetEntityIds = uniq(
|
|
163
163
|
reject(
|
|
164
|
-
map(
|
|
164
|
+
map(rows, (entity: any) => entity[relationProperty.targetIdColumnName!]),
|
|
165
165
|
isNullOrUndefined,
|
|
166
166
|
),
|
|
167
167
|
);
|
|
@@ -171,18 +171,18 @@ async function findEntities(server: IRpdServer, dataAccessor: IRpdDataAccessor,
|
|
|
171
171
|
const targetModel = server.getModel({
|
|
172
172
|
singularCode: relationProperty.targetSingularCode!,
|
|
173
173
|
});
|
|
174
|
-
|
|
174
|
+
rows.forEach((row) => {
|
|
175
175
|
if (isManyRelation) {
|
|
176
|
-
|
|
177
|
-
return relatedEntity[relationProperty.selfIdColumnName!] ==
|
|
176
|
+
row[relationProperty.code] = filter(relatedEntities, (relatedEntity: any) => {
|
|
177
|
+
return relatedEntity[relationProperty.selfIdColumnName!] == row.id;
|
|
178
178
|
}).map((item) => mapDbRowToEntity(server, targetModel!, item, false));
|
|
179
179
|
} else {
|
|
180
|
-
|
|
180
|
+
row[relationProperty.code] = mapDbRowToEntity(
|
|
181
181
|
server,
|
|
182
182
|
targetModel!,
|
|
183
183
|
find(relatedEntities, (relatedEntity: any) => {
|
|
184
184
|
// TODO: id property code should be configurable.
|
|
185
|
-
return relatedEntity["id"] ==
|
|
185
|
+
return relatedEntity["id"] == row[relationProperty.targetIdColumnName!];
|
|
186
186
|
}),
|
|
187
187
|
false,
|
|
188
188
|
);
|
|
@@ -191,7 +191,20 @@ async function findEntities(server: IRpdServer, dataAccessor: IRpdDataAccessor,
|
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
|
|
194
|
+
const entities = rows.map((item) => mapDbRowToEntity(server, model, item, options.keepNonPropertyFields));
|
|
195
|
+
|
|
196
|
+
await server.emitEvent(
|
|
197
|
+
"entity.beforeResponse",
|
|
198
|
+
{
|
|
199
|
+
namespace: model.namespace,
|
|
200
|
+
modelSingularCode: model.singularCode,
|
|
201
|
+
baseModelSingularCode: model.base,
|
|
202
|
+
entities,
|
|
203
|
+
},
|
|
204
|
+
null,
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
return entities;
|
|
195
208
|
}
|
|
196
209
|
|
|
197
210
|
async function findEntity(server: IRpdServer, dataAccessor: IRpdDataAccessor, options: FindEntityOptions) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { cloneDeep } from "lodash";
|
|
1
2
|
import { IRpdServer } from "~/core/server";
|
|
2
3
|
import { RpdDataModel, RpdDataModelProperty } from "~/types";
|
|
3
4
|
|
|
@@ -13,10 +14,17 @@ export function getEntityPropertiesIncludingBase(server: IRpdServer, model: RpdD
|
|
|
13
14
|
const baseModel = server.getModel({
|
|
14
15
|
singularCode: model.base,
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
+
let baseProperties: RpdDataModelProperty[] = [];
|
|
18
|
+
if (baseModel) {
|
|
19
|
+
baseModel.properties.map((property) => {
|
|
20
|
+
property = cloneDeep(property);
|
|
21
|
+
property.isBaseProperty = true;
|
|
22
|
+
return property;
|
|
23
|
+
})
|
|
24
|
+
}
|
|
17
25
|
|
|
18
26
|
return [
|
|
19
|
-
...
|
|
27
|
+
...baseProperties,
|
|
20
28
|
...model.properties,
|
|
21
29
|
]
|
|
22
30
|
}
|
|
@@ -36,6 +44,7 @@ export function getEntityProperty(server: IRpdServer, model: RpdDataModel, predi
|
|
|
36
44
|
|
|
37
45
|
property = baseModel.properties.find(predicate);
|
|
38
46
|
if (property) {
|
|
47
|
+
property = cloneDeep(property);
|
|
39
48
|
property.isBaseProperty = true;
|
|
40
49
|
}
|
|
41
50
|
}
|
package/src/server.ts
CHANGED
|
@@ -47,6 +47,7 @@ export class RapidServer implements IRpdServer {
|
|
|
47
47
|
#entityDeleteEventEmitters: EventManager<Record<string, [EntityWatchHandlerContext<any>]>>;
|
|
48
48
|
#entityAddRelationsEventEmitters: EventManager<Record<string, [EntityWatchHandlerContext<any>]>>;
|
|
49
49
|
#entityRemoveRelationsEventEmitters: EventManager<Record<string, [EntityWatchHandlerContext<any>]>>;
|
|
50
|
+
#entityBeforeResponseEventEmitters: EventManager<Record<string, [EntityWatchHandlerContext<any>]>>;
|
|
50
51
|
#entityWatchers: EntityWatcherType[];
|
|
51
52
|
#appEntityWatchers: EntityWatcherType[];
|
|
52
53
|
|
|
@@ -87,6 +88,7 @@ export class RapidServer implements IRpdServer {
|
|
|
87
88
|
this.#entityDeleteEventEmitters = new EventManager();
|
|
88
89
|
this.#entityAddRelationsEventEmitters = new EventManager();
|
|
89
90
|
this.#entityRemoveRelationsEventEmitters = new EventManager();
|
|
91
|
+
this.#entityBeforeResponseEventEmitters = new EventManager();
|
|
90
92
|
|
|
91
93
|
this.registerEventHandler("entity.beforeCreate", this.#handleEntityEvent.bind(this, "entity.beforeCreate"));
|
|
92
94
|
this.registerEventHandler("entity.create", this.#handleEntityEvent.bind(this, "entity.create"));
|
|
@@ -96,6 +98,7 @@ export class RapidServer implements IRpdServer {
|
|
|
96
98
|
this.registerEventHandler("entity.delete", this.#handleEntityEvent.bind(this, "entity.delete"));
|
|
97
99
|
this.registerEventHandler("entity.addRelations", this.#handleEntityEvent.bind(this, "entity.addRelations"));
|
|
98
100
|
this.registerEventHandler("entity.removeRelations", this.#handleEntityEvent.bind(this, "entity.removeRelations"));
|
|
101
|
+
this.registerEventHandler("entity.beforeResponse", this.#handleEntityEvent.bind(this, "entity.beforeResponse"));
|
|
99
102
|
|
|
100
103
|
this.#entityWatchers = [];
|
|
101
104
|
this.#appEntityWatchers = options.entityWatchers || [];
|
|
@@ -226,9 +229,8 @@ export class RapidServer implements IRpdServer {
|
|
|
226
229
|
return entityManager;
|
|
227
230
|
}
|
|
228
231
|
|
|
229
|
-
registerEventHandler<K extends keyof RpdServerEventTypes>(eventName: K, listener: (...args: RpdServerEventTypes[K]) => void)
|
|
232
|
+
registerEventHandler<K extends keyof RpdServerEventTypes>(eventName: K, listener: (...args: RpdServerEventTypes[K]) => void) {
|
|
230
233
|
this.#eventManager.on(eventName, listener);
|
|
231
|
-
return this;
|
|
232
234
|
}
|
|
233
235
|
|
|
234
236
|
registerEntityWatcher(entityWatcher: EntityWatcherType) {
|
|
@@ -288,6 +290,8 @@ export class RapidServer implements IRpdServer {
|
|
|
288
290
|
this.#entityAddRelationsEventEmitters.on(entityWatcher.modelSingularCode, entityWatcher.handler);
|
|
289
291
|
} else if (entityWatcher.eventName === "entity.removeRelations") {
|
|
290
292
|
this.#entityRemoveRelationsEventEmitters.on(entityWatcher.modelSingularCode, entityWatcher.handler);
|
|
293
|
+
} else if (entityWatcher.eventName === "entity.beforeResponse") {
|
|
294
|
+
this.#entityBeforeResponseEventEmitters.on(entityWatcher.modelSingularCode, entityWatcher.handler);
|
|
291
295
|
}
|
|
292
296
|
}
|
|
293
297
|
|
|
@@ -412,6 +416,8 @@ export class RapidServer implements IRpdServer {
|
|
|
412
416
|
emitter = this.#entityAddRelationsEventEmitters;
|
|
413
417
|
} else if (eventName === "entity.removeRelations") {
|
|
414
418
|
emitter = this.#entityRemoveRelationsEventEmitters;
|
|
419
|
+
} else if (eventName === "entity.beforeResponse") {
|
|
420
|
+
emitter = this.#entityBeforeResponseEventEmitters;
|
|
415
421
|
}
|
|
416
422
|
|
|
417
423
|
emitter.emit(modelSingularCode, entityWatchHandlerContext);
|
package/src/types.ts
CHANGED
|
@@ -75,6 +75,7 @@ export type RpdServerEventTypes = {
|
|
|
75
75
|
"entity.delete": [RapidPlugin, RpdEntityDeleteEventPayload];
|
|
76
76
|
"entity.addRelations": [RapidPlugin, RpdEntityAddRelationsEventPayload];
|
|
77
77
|
"entity.removeRelations": [RapidPlugin, RpdEntityRemoveRelationsEventPayload];
|
|
78
|
+
"entity.beforeResponse": [RapidPlugin, RpdEntityBeforeResponseEventPayload];
|
|
78
79
|
};
|
|
79
80
|
|
|
80
81
|
export interface RpdEntityBeforeCreateEventPayload {
|
|
@@ -140,6 +141,13 @@ export interface RpdEntityRemoveRelationsEventPayload {
|
|
|
140
141
|
relations: any[];
|
|
141
142
|
}
|
|
142
143
|
|
|
144
|
+
export interface RpdEntityBeforeResponseEventPayload {
|
|
145
|
+
namespace: string;
|
|
146
|
+
modelSingularCode: string;
|
|
147
|
+
baseModelSingularCode?: string;
|
|
148
|
+
entities: any[];
|
|
149
|
+
}
|
|
150
|
+
|
|
143
151
|
export interface QuoteTableOptions {
|
|
144
152
|
schema?: string;
|
|
145
153
|
tableName: string;
|