@ruiapp/rapid-core 0.1.19 → 0.1.21
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/actionHandler.d.ts +2 -0
- package/dist/core/pluginManager.d.ts +3 -0
- package/dist/core/request.d.ts +2 -1
- package/dist/core/routeContext.d.ts +4 -1
- package/dist/core/server.d.ts +8 -2
- package/dist/dataAccess/dataAccessor.d.ts +2 -1
- package/dist/facilities/log/LogFacility.d.ts +33 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +288 -264
- package/dist/plugins/auth/AuthPlugin.d.ts +0 -9
- package/dist/plugins/dataManage/DataManagePlugin.d.ts +0 -10
- package/dist/plugins/entityAccessControl/EntityAccessControlPlugin.d.ts +17 -0
- package/dist/plugins/fileManage/FileManagePlugin.d.ts +0 -10
- package/dist/plugins/metaManage/MetaManagePlugin.d.ts +0 -8
- package/dist/plugins/routeManage/RouteManagePlugin.d.ts +0 -9
- package/dist/plugins/webhooks/WebhooksPlugin.d.ts +0 -6
- package/dist/server.d.ts +8 -3
- package/dist/types.d.ts +11 -0
- package/dist/utilities/accessControlUtility.d.ts +5 -0
- package/package.json +5 -2
- package/rollup.config.js +1 -18
- package/src/core/actionHandler.ts +2 -0
- package/src/core/pluginManager.ts +12 -0
- package/src/core/request.ts +6 -2
- package/src/core/routeContext.ts +6 -1
- package/src/core/routesBuilder.ts +16 -6
- package/src/core/server.ts +8 -2
- package/src/dataAccess/dataAccessor.ts +13 -9
- package/src/dataAccess/entityManager.ts +24 -24
- package/src/facilities/log/LogFacility.ts +36 -0
- package/src/helpers/inputHelper.ts +3 -3
- package/src/helpers/runCollectionEntityActionHandler.ts +4 -9
- package/src/index.ts +2 -1
- package/src/plugins/auth/AuthPlugin.ts +3 -31
- package/src/plugins/dataManage/DataManagePlugin.ts +0 -32
- package/src/plugins/dataManage/actionHandlers/addEntityRelations.ts +3 -7
- package/src/plugins/dataManage/actionHandlers/createCollectionEntitiesBatch.ts +3 -7
- package/src/plugins/dataManage/actionHandlers/createCollectionEntity.ts +3 -7
- package/src/plugins/dataManage/actionHandlers/deleteCollectionEntityById.ts +2 -2
- package/src/plugins/dataManage/actionHandlers/findCollectionEntities.ts +0 -1
- package/src/plugins/dataManage/actionHandlers/findCollectionEntityById.ts +2 -2
- package/src/plugins/dataManage/actionHandlers/queryDatabase.ts +5 -9
- package/src/plugins/dataManage/actionHandlers/removeEntityRelations.ts +2 -6
- package/src/plugins/dataManage/actionHandlers/updateCollectionEntityById.ts +3 -8
- package/src/plugins/entityAccessControl/EntityAccessControlPlugin.ts +107 -0
- package/src/plugins/fileManage/FileManagePlugin.ts +0 -31
- package/src/plugins/metaManage/MetaManagePlugin.ts +16 -39
- package/src/plugins/routeManage/RouteManagePlugin.ts +4 -30
- package/src/plugins/routeManage/actionHandlers/httpProxy.ts +2 -1
- package/src/plugins/webhooks/WebhooksPlugin.ts +26 -36
- package/src/queryBuilder/queryBuilder.ts +3 -3
- package/src/server.ts +53 -17
- package/src/types.ts +13 -0
- package/src/utilities/accessControlUtility.ts +33 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as _ from "lodash";
|
|
2
1
|
import {
|
|
3
2
|
AddEntityRelationsOptions,
|
|
4
3
|
CountEntityOptions,
|
|
@@ -20,6 +19,7 @@ import { mapPropertyNameToColumnName } from "./propertyMapper";
|
|
|
20
19
|
import { isRelationProperty } from "~/utilities/rapidUtility";
|
|
21
20
|
import { IRpdServer, RapidPlugin } from "~/core/server";
|
|
22
21
|
import { getEntityPartChanges } from "~/helpers/entityHelpers";
|
|
22
|
+
import { filter, find, first, forEach, isArray, isObject, keys, map, reject, uniq } from "lodash";
|
|
23
23
|
|
|
24
24
|
function convertToDataAccessOrderBy(model: RpdDataModel, orderByList?: FindEntityOrderByOptions[]) {
|
|
25
25
|
if (!orderByList) {
|
|
@@ -43,7 +43,7 @@ async function findEntities(
|
|
|
43
43
|
const fieldsToSelect: string[] = [];
|
|
44
44
|
const relationPropertiesToSelect: RpdDataModelProperty[] = [];
|
|
45
45
|
if (options.properties) {
|
|
46
|
-
|
|
46
|
+
forEach(options.properties, (propertyCode: string) => {
|
|
47
47
|
const property = model.properties.find((e) => e.code === propertyCode);
|
|
48
48
|
if (!property) {
|
|
49
49
|
throw new Error(
|
|
@@ -104,8 +104,8 @@ async function findEntities(
|
|
|
104
104
|
entityIds,
|
|
105
105
|
);
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
entity[relationProperty.code] =
|
|
107
|
+
forEach(entities, (entity: any) => {
|
|
108
|
+
entity[relationProperty.code] = filter(relationLinks, (link: any) => {
|
|
109
109
|
return link[relationProperty.selfIdColumnName!] == entity["id"];
|
|
110
110
|
}).map(link => mapDbRowToEntity(targetModel, link.targetEntity, false));
|
|
111
111
|
});
|
|
@@ -120,9 +120,9 @@ async function findEntities(
|
|
|
120
120
|
entityIds,
|
|
121
121
|
);
|
|
122
122
|
} else {
|
|
123
|
-
const targetEntityIds =
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
const targetEntityIds = uniq(
|
|
124
|
+
reject(
|
|
125
|
+
map(
|
|
126
126
|
entities,
|
|
127
127
|
(entity: any) => entity[relationProperty.targetIdColumnName!],
|
|
128
128
|
),
|
|
@@ -142,14 +142,14 @@ async function findEntities(
|
|
|
142
142
|
});
|
|
143
143
|
entities.forEach((entity) => {
|
|
144
144
|
if (isManyRelation) {
|
|
145
|
-
entity[relationProperty.code] =
|
|
145
|
+
entity[relationProperty.code] = filter(
|
|
146
146
|
relatedEntities,
|
|
147
147
|
(relatedEntity: any) => {
|
|
148
148
|
return relatedEntity[relationProperty.selfIdColumnName!] == entity.id;
|
|
149
149
|
},
|
|
150
150
|
).map(item => mapDbRowToEntity(targetModel!, item, false));
|
|
151
151
|
} else {
|
|
152
|
-
entity[relationProperty.code] = mapDbRowToEntity(targetModel!,
|
|
152
|
+
entity[relationProperty.code] = mapDbRowToEntity(targetModel!, find(
|
|
153
153
|
relatedEntities,
|
|
154
154
|
(relatedEntity: any) => {
|
|
155
155
|
// TODO: id property code should be configurable.
|
|
@@ -170,7 +170,7 @@ async function findEntity(
|
|
|
170
170
|
options: FindEntityOptions,
|
|
171
171
|
) {
|
|
172
172
|
const entities = await findEntities(server, dataAccessor, options);
|
|
173
|
-
return
|
|
173
|
+
return first(entities);
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
async function findById(
|
|
@@ -211,7 +211,7 @@ async function replaceFiltersWithFiltersOperator(
|
|
|
211
211
|
);
|
|
212
212
|
replacedFilters.push(filter);
|
|
213
213
|
} else if (operator === "exists" || operator === "notExists") {
|
|
214
|
-
const relationProperty: RpdDataModelProperty =
|
|
214
|
+
const relationProperty: RpdDataModelProperty = find(
|
|
215
215
|
model.properties,
|
|
216
216
|
(property: RpdDataModelProperty) => property.code === filter.field,
|
|
217
217
|
);
|
|
@@ -269,7 +269,7 @@ async function replaceFiltersWithFiltersOperator(
|
|
|
269
269
|
filters: filter.filters,
|
|
270
270
|
properties: ["id"],
|
|
271
271
|
});
|
|
272
|
-
const entityIds =
|
|
272
|
+
const entityIds = map(entities, (entity: any) => entity["id"]);
|
|
273
273
|
replacedFilters.push({
|
|
274
274
|
field: relationProperty.targetIdColumnName as string,
|
|
275
275
|
operator: operator === "exists" ? "in" : "notIn",
|
|
@@ -291,7 +291,7 @@ async function replaceFiltersWithFiltersOperator(
|
|
|
291
291
|
filters: filter.filters,
|
|
292
292
|
properties: [relationProperty.selfIdColumnName],
|
|
293
293
|
});
|
|
294
|
-
const selfEntityIds =
|
|
294
|
+
const selfEntityIds = map(targetEntities, (entity: any) => entity[relationProperty.selfIdColumnName!]);
|
|
295
295
|
replacedFilters.push({
|
|
296
296
|
field: "id",
|
|
297
297
|
operator: operator === "exists" ? "in" : "notIn",
|
|
@@ -322,7 +322,7 @@ async function replaceFiltersWithFiltersOperator(
|
|
|
322
322
|
filters: filter.filters,
|
|
323
323
|
properties: ['id'],
|
|
324
324
|
});
|
|
325
|
-
const targetEntityIds =
|
|
325
|
+
const targetEntityIds = map(targetEntities, (entity: any) => entity['id']);
|
|
326
326
|
|
|
327
327
|
const command = `SELECT * FROM ${server.queryBuilder.quoteTable({schema: relationProperty.linkSchema, tableName: relationProperty.linkTableName!})} WHERE ${server.queryBuilder.quoteObject(relationProperty.targetIdColumnName!)} = ANY($1::int[])`;
|
|
328
328
|
const params = [targetEntityIds];
|
|
@@ -368,8 +368,8 @@ async function findManyRelationLinksViaLinkTable(
|
|
|
368
368
|
});
|
|
369
369
|
const targetEntities = await dataAccessor.find(findEntityOptions);
|
|
370
370
|
|
|
371
|
-
|
|
372
|
-
link.targetEntity =
|
|
371
|
+
forEach(links, (link: any) => {
|
|
372
|
+
link.targetEntity = find(targetEntities, (e: any) => e["id"] == link[relationProperty.targetIdColumnName!]);
|
|
373
373
|
});
|
|
374
374
|
|
|
375
375
|
return links;
|
|
@@ -429,7 +429,7 @@ async function createEntity(
|
|
|
429
429
|
|
|
430
430
|
const oneRelationPropertiesToCreate: RpdDataModelProperty[] = [];
|
|
431
431
|
const manyRelationPropertiesToCreate: RpdDataModelProperty[] = [];
|
|
432
|
-
|
|
432
|
+
keys(entity).forEach((propertyCode) => {
|
|
433
433
|
const property = model.properties.find((e) => e.code === propertyCode);
|
|
434
434
|
if (!property) {
|
|
435
435
|
// Unknown property
|
|
@@ -450,7 +450,7 @@ async function createEntity(
|
|
|
450
450
|
// save one-relation properties
|
|
451
451
|
for (const property of oneRelationPropertiesToCreate) {
|
|
452
452
|
const fieldValue = entity[property.code];
|
|
453
|
-
if (
|
|
453
|
+
if (isObject(fieldValue)) {
|
|
454
454
|
if (!fieldValue["id"]) {
|
|
455
455
|
const targetDataAccessor = server.getDataAccessor({
|
|
456
456
|
singularCode: property.targetSingularCode!,
|
|
@@ -481,13 +481,13 @@ async function createEntity(
|
|
|
481
481
|
});
|
|
482
482
|
|
|
483
483
|
const relatedEntitiesToBeSaved = entity[property.code];
|
|
484
|
-
if (!
|
|
484
|
+
if (!isArray(relatedEntitiesToBeSaved)) {
|
|
485
485
|
throw new Error(`Value of field '${property.code}' should be an array.`);
|
|
486
486
|
}
|
|
487
487
|
|
|
488
488
|
for (const relatedEntityToBeSaved of relatedEntitiesToBeSaved) {
|
|
489
489
|
let relatedEntityId: any;
|
|
490
|
-
if (
|
|
490
|
+
if (isObject(relatedEntityToBeSaved)) {
|
|
491
491
|
relatedEntityId = relatedEntityToBeSaved["id"];
|
|
492
492
|
if (!relatedEntityId) {
|
|
493
493
|
// related entity is to be created
|
|
@@ -573,7 +573,7 @@ async function updateEntityById(
|
|
|
573
573
|
|
|
574
574
|
const oneRelationPropertiesToUpdate: RpdDataModelProperty[] = [];
|
|
575
575
|
const manyRelationPropertiesToUpdate: RpdDataModelProperty[] = [];
|
|
576
|
-
|
|
576
|
+
keys(changes).forEach((propertyCode) => {
|
|
577
577
|
const property = model.properties.find((e) => e.code === propertyCode);
|
|
578
578
|
if (!property) {
|
|
579
579
|
// Unknown property
|
|
@@ -592,7 +592,7 @@ async function updateEntityById(
|
|
|
592
592
|
const row = mapEntityToDbRow(model, changes);
|
|
593
593
|
oneRelationPropertiesToUpdate.forEach(property => {
|
|
594
594
|
const fieldValue = changes[property.code];
|
|
595
|
-
if (
|
|
595
|
+
if (isObject(fieldValue)) {
|
|
596
596
|
row[property.targetIdColumnName!] = fieldValue["id"];
|
|
597
597
|
} else {
|
|
598
598
|
row[property.targetIdColumnName!] = fieldValue;
|
|
@@ -612,7 +612,7 @@ async function updateEntityById(
|
|
|
612
612
|
});
|
|
613
613
|
|
|
614
614
|
const relatedEntitiesToBeSaved = changes[property.code];
|
|
615
|
-
if (!
|
|
615
|
+
if (!isArray(relatedEntitiesToBeSaved)) {
|
|
616
616
|
throw new Error(`Value of field '${property.code}' should be an array.`);
|
|
617
617
|
}
|
|
618
618
|
|
|
@@ -623,7 +623,7 @@ async function updateEntityById(
|
|
|
623
623
|
|
|
624
624
|
for (const relatedEntityToBeSaved of relatedEntitiesToBeSaved) {
|
|
625
625
|
let relatedEntityId: any;
|
|
626
|
-
if (
|
|
626
|
+
if (isObject(relatedEntityToBeSaved)) {
|
|
627
627
|
relatedEntityId = relatedEntityToBeSaved["id"];
|
|
628
628
|
if (!relatedEntityId) {
|
|
629
629
|
// related entity is to be created
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import winston from "winston";
|
|
2
|
+
|
|
3
|
+
export interface Logger {
|
|
4
|
+
log: winston.LogMethod;
|
|
5
|
+
/**
|
|
6
|
+
* The service/app is going to stop or become unusable now. An operator should definitely look into this immediately.
|
|
7
|
+
*/
|
|
8
|
+
emerg: winston.LeveledLogMethod;
|
|
9
|
+
/**
|
|
10
|
+
* Fatal for a particular service, but the app continues servicing other requests. An operator should look at this immediately.
|
|
11
|
+
*/
|
|
12
|
+
crit: winston.LeveledLogMethod;
|
|
13
|
+
/**
|
|
14
|
+
* Fatal for a particular request, but the service/app continues servicing other requests. An operator should look at this soon(ish).
|
|
15
|
+
*/
|
|
16
|
+
error: winston.LeveledLogMethod;
|
|
17
|
+
/**
|
|
18
|
+
* A note on something that should probably be looked at by an operator eventually.
|
|
19
|
+
*/
|
|
20
|
+
warn: winston.LeveledLogMethod;
|
|
21
|
+
/**
|
|
22
|
+
* Detail on regular operation.
|
|
23
|
+
*/
|
|
24
|
+
info: winston.LeveledLogMethod;
|
|
25
|
+
/**
|
|
26
|
+
* Anything else, i.e. too verbose to be included in "info" level.
|
|
27
|
+
*/
|
|
28
|
+
debug: winston.LeveledLogMethod;
|
|
29
|
+
/**
|
|
30
|
+
* Logging from external libraries used by your app or very detailed application logging.
|
|
31
|
+
*/
|
|
32
|
+
verbose: winston.LeveledLogMethod;
|
|
33
|
+
|
|
34
|
+
child(options: Object): Logger;
|
|
35
|
+
}
|
|
36
|
+
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isArray, mergeWith } from "lodash";
|
|
2
2
|
|
|
3
3
|
export function mergeInput(defaultInput: any, input: any, fixedInput: any) {
|
|
4
|
-
return
|
|
4
|
+
return mergeWith({}, defaultInput, input, fixedInput, doNotMergeArray);
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
function doNotMergeArray(objValue: any, srcValue: any) {
|
|
8
|
-
if (
|
|
8
|
+
if (isArray(srcValue)) {
|
|
9
9
|
return srcValue;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { IRpdDataAccessor, RunEntityActionHandlerOptions } from "~/types";
|
|
1
|
+
import { RunEntityActionHandlerOptions } from "~/types";
|
|
3
2
|
import { mergeInput } from "./inputHelper";
|
|
4
3
|
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
5
4
|
import EntityManager from "~/dataAccess/entityManager";
|
|
@@ -15,15 +14,11 @@ export default async function runCollectionEntityActionHandler(
|
|
|
15
14
|
code: string,
|
|
16
15
|
handleEntityAction: EntityActionHandler,
|
|
17
16
|
) {
|
|
18
|
-
const { server, input } = ctx;
|
|
19
|
-
const { defaultInput, fixedInput } = options;
|
|
20
|
-
|
|
21
|
-
console.debug(`Running ${code} handler...`);
|
|
17
|
+
const { logger, server, input } = ctx;
|
|
22
18
|
|
|
23
|
-
|
|
19
|
+
const { defaultInput, fixedInput } = options;
|
|
24
20
|
const mergedInput = mergeInput(defaultInput, input, fixedInput);
|
|
25
|
-
|
|
26
|
-
console.debug(`mergedInput: ${JSON.stringify(mergedInput)}`);
|
|
21
|
+
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
|
|
27
22
|
|
|
28
23
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
29
24
|
const result = handleEntityAction(entityManager, mergedInput);
|
package/src/index.ts
CHANGED
|
@@ -23,4 +23,5 @@ export { default as FileManagePlugin } from "./plugins/fileManage/FileManagePlug
|
|
|
23
23
|
export { default as ServerOperationPlugin } from "./plugins/serverOperation/ServerOperationPlugin";
|
|
24
24
|
export * from "./plugins/serverOperation/ServerOperationPluginTypes";
|
|
25
25
|
export { default as EntityWatchPlugin } from "./plugins/entityWatch/EntityWatchPlugin";
|
|
26
|
-
export * from "./plugins/entityWatch/EntityWatchPluginTypes";
|
|
26
|
+
export * from "./plugins/entityWatch/EntityWatchPluginTypes";
|
|
27
|
+
export { default as EntityAccessControlPlugin } from "./plugins/entityAccessControl/EntityAccessControlPlugin";
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* Auth manager plugin
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import * as _ from "lodash";
|
|
6
5
|
import {
|
|
7
6
|
RpdApplicationConfig,
|
|
8
7
|
} from "~/types";
|
|
@@ -36,48 +35,20 @@ class AuthPlugin implements RapidPlugin {
|
|
|
36
35
|
return [];
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
async initPlugin(server: IRpdServer): Promise<any> {
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async registerMiddlewares(server: IRpdServer): Promise<any> {
|
|
43
|
-
}
|
|
44
|
-
|
|
45
38
|
async registerActionHandlers(server: IRpdServer): Promise<any> {
|
|
46
39
|
for (const actionHandler of pluginActionHandlers) {
|
|
47
40
|
server.registerActionHandler(this, actionHandler);
|
|
48
41
|
}
|
|
49
42
|
}
|
|
50
43
|
|
|
51
|
-
async registerEventHandlers(server: IRpdServer): Promise<any> {
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async registerMessageHandlers(server: IRpdServer): Promise<any> {
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async registerTaskProcessors(server: IRpdServer): Promise<any> {
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
61
|
-
}
|
|
62
|
-
|
|
63
44
|
async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
64
45
|
server.appendApplicationConfig({ models: pluginModels });
|
|
65
46
|
}
|
|
66
47
|
|
|
67
|
-
async configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
68
|
-
}
|
|
69
|
-
|
|
70
48
|
async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
71
49
|
server.appendApplicationConfig({ routes: pluginRoutes });
|
|
72
50
|
}
|
|
73
51
|
|
|
74
|
-
async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
75
|
-
console.log("authManager.onApplicationLoaded");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
79
|
-
}
|
|
80
|
-
|
|
81
52
|
async onPrepareRouteContext(server: IRpdServer, routeContext: RouteContext) {
|
|
82
53
|
const request = routeContext.request;
|
|
83
54
|
let token: string;
|
|
@@ -101,8 +72,9 @@ class AuthPlugin implements RapidPlugin {
|
|
|
101
72
|
const tokenPayload = verifyJwt(token, secretKey);
|
|
102
73
|
routeContext.state.userId = tokenPayload.aud as string;
|
|
103
74
|
routeContext.state.userLogin = tokenPayload.act as string;
|
|
104
|
-
} catch (
|
|
105
|
-
|
|
75
|
+
} catch (error) {
|
|
76
|
+
const logger = server.getLogger();
|
|
77
|
+
logger.debug("Verify JWT failed.", { error });
|
|
106
78
|
}
|
|
107
79
|
}
|
|
108
80
|
}
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* - routes for manage data in database.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import * as _ from "lodash";
|
|
8
7
|
import {
|
|
9
8
|
RpdApplicationConfig,
|
|
10
9
|
RpdHttpMethod,
|
|
@@ -108,12 +107,6 @@ class DataManager implements RapidPlugin {
|
|
|
108
107
|
return [];
|
|
109
108
|
}
|
|
110
109
|
|
|
111
|
-
async initPlugin(server: IRpdServer): Promise<any> {
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async registerMiddlewares(server: IRpdServer): Promise<any> {
|
|
115
|
-
}
|
|
116
|
-
|
|
117
110
|
async registerActionHandlers(server: IRpdServer): Promise<any> {
|
|
118
111
|
server.registerActionHandler(this, findCollectionEntities);
|
|
119
112
|
server.registerActionHandler(this, findCollectionEntityById);
|
|
@@ -127,24 +120,6 @@ class DataManager implements RapidPlugin {
|
|
|
127
120
|
server.registerActionHandler(this, queryDatabase);
|
|
128
121
|
}
|
|
129
122
|
|
|
130
|
-
async registerEventHandlers(server: IRpdServer): Promise<any> {
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
async registerMessageHandlers(server: IRpdServer): Promise<any> {
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async registerTaskProcessors(server: IRpdServer): Promise<any> {
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async onLoadingApplication(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async configureModels(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async configureModelProperties(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
146
|
-
}
|
|
147
|
-
|
|
148
123
|
async configureRoutes(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
149
124
|
const { models } = applicationConfig;
|
|
150
125
|
const routes: RpdRoute[] = [];
|
|
@@ -175,13 +150,6 @@ class DataManager implements RapidPlugin {
|
|
|
175
150
|
|
|
176
151
|
server.appendApplicationConfig({ routes });
|
|
177
152
|
}
|
|
178
|
-
|
|
179
|
-
async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
180
|
-
console.log("[dataManager.onApplicationLoaded]");
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
184
|
-
}
|
|
185
153
|
}
|
|
186
154
|
|
|
187
155
|
export default DataManager;
|
|
@@ -10,15 +10,11 @@ export async function handler(
|
|
|
10
10
|
ctx: ActionHandlerContext,
|
|
11
11
|
options: RunEntityActionHandlerOptions,
|
|
12
12
|
) {
|
|
13
|
-
const { server, input } = ctx;
|
|
14
|
-
const { defaultInput, fixedInput } = options;
|
|
15
|
-
|
|
16
|
-
console.debug(`Running ${code} handler...`);
|
|
13
|
+
const { logger, server, input } = ctx;
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
const { defaultInput, fixedInput } = options;
|
|
19
16
|
const mergedInput = mergeInput(defaultInput, input, fixedInput);
|
|
20
|
-
|
|
21
|
-
console.debug(`mergedInput: ${JSON.stringify(mergedInput)}`);
|
|
17
|
+
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
|
|
22
18
|
|
|
23
19
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
24
20
|
await entityManager.addRelations(mergedInput, plugin);
|
|
@@ -11,23 +11,19 @@ export async function handler(
|
|
|
11
11
|
ctx: ActionHandlerContext,
|
|
12
12
|
options: RunEntityActionHandlerOptions,
|
|
13
13
|
) {
|
|
14
|
-
const { server, input } = ctx;
|
|
15
|
-
const { defaultInput, fixedInput } = options;
|
|
14
|
+
const { logger, server, input } = ctx;
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
const { defaultInput, fixedInput } = options;
|
|
17
|
+
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, input });
|
|
18
18
|
|
|
19
19
|
const { entities } = input;
|
|
20
20
|
if (!isArray(entities)) {
|
|
21
21
|
throw new Error("input.entities should be an array.");
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
console.debug(`defaultInput: ${JSON.stringify(defaultInput)}`);
|
|
25
|
-
console.debug(`fixedInput: ${JSON.stringify(fixedInput)}`);
|
|
26
|
-
|
|
27
24
|
const output: any[] = [];
|
|
28
25
|
for(const entity of entities) {
|
|
29
26
|
const mergedEntity = mergeInput(defaultInput?.entity || {}, entity, fixedInput?.entity);
|
|
30
|
-
console.debug(`mergedEntity: ${JSON.stringify(mergedEntity)}`);
|
|
31
27
|
|
|
32
28
|
const userId = ctx.routerContext.state?.userId;
|
|
33
29
|
if (userId) {
|
|
@@ -10,15 +10,11 @@ export async function handler(
|
|
|
10
10
|
ctx: ActionHandlerContext,
|
|
11
11
|
options: RunEntityActionHandlerOptions,
|
|
12
12
|
) {
|
|
13
|
-
const { server, input } = ctx;
|
|
14
|
-
const { defaultInput, fixedInput } = options;
|
|
15
|
-
|
|
16
|
-
console.debug(`Running ${code} handler...`);
|
|
13
|
+
const { logger, server, input } = ctx;
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
const { defaultInput, fixedInput } = options;
|
|
19
16
|
const mergedInput = mergeInput(defaultInput, input, fixedInput);
|
|
20
|
-
|
|
21
|
-
console.debug(`mergedInput: ${JSON.stringify(mergedInput)}`);
|
|
17
|
+
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
|
|
22
18
|
|
|
23
19
|
const userId = ctx.routerContext.state?.userId;
|
|
24
20
|
if (userId) {
|
|
@@ -9,8 +9,8 @@ export async function handler(
|
|
|
9
9
|
ctx: ActionHandlerContext,
|
|
10
10
|
options: RunEntityActionHandlerOptions,
|
|
11
11
|
) {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const { logger, server, input } = ctx;
|
|
13
|
+
logger.debug(`Running ${code} handler...`);
|
|
14
14
|
|
|
15
15
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
16
16
|
await entityManager.deleteById(input.id, plugin);
|
|
@@ -9,8 +9,8 @@ export async function handler(
|
|
|
9
9
|
ctx: ActionHandlerContext,
|
|
10
10
|
options: RunEntityActionHandlerOptions,
|
|
11
11
|
) {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const { logger, server, input } = ctx;
|
|
13
|
+
logger.debug(`Running ${code} handler...`, { input });
|
|
14
14
|
const { id } = input;
|
|
15
15
|
|
|
16
16
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as _ from "lodash";
|
|
2
1
|
import { RunQueryDatabaseHandlerOptions } from "~/types";
|
|
3
2
|
import { mergeInput } from "~/helpers/inputHelper";
|
|
4
3
|
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
5
4
|
import { RapidPlugin } from "~/core/server";
|
|
5
|
+
import { first } from "lodash";
|
|
6
6
|
|
|
7
7
|
export const code = "queryDatabase";
|
|
8
8
|
|
|
@@ -11,19 +11,15 @@ export async function handler(
|
|
|
11
11
|
ctx: ActionHandlerContext,
|
|
12
12
|
options: RunQueryDatabaseHandlerOptions,
|
|
13
13
|
) {
|
|
14
|
-
const { server, input } = ctx;
|
|
15
|
-
const { sql, querySingle, defaultInput, fixedInput } = options;
|
|
16
|
-
|
|
17
|
-
console.debug(`Running ${code} handler...`);
|
|
14
|
+
const { logger, server, input } = ctx;
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
const { sql, querySingle, defaultInput, fixedInput } = options;
|
|
20
17
|
const mergedInput = mergeInput(defaultInput, input, fixedInput);
|
|
21
|
-
|
|
22
|
-
console.debug(`mergedInput: ${JSON.stringify(mergedInput)}`);
|
|
18
|
+
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
|
|
23
19
|
|
|
24
20
|
const result = await server.queryDatabaseObject(sql, mergedInput);
|
|
25
21
|
if (querySingle) {
|
|
26
|
-
ctx.output =
|
|
22
|
+
ctx.output = first(result);
|
|
27
23
|
} else {
|
|
28
24
|
ctx.output = result;
|
|
29
25
|
}
|
|
@@ -10,15 +10,11 @@ export async function handler(
|
|
|
10
10
|
ctx: ActionHandlerContext,
|
|
11
11
|
options: RunEntityActionHandlerOptions,
|
|
12
12
|
) {
|
|
13
|
-
const { server, input } = ctx;
|
|
13
|
+
const { logger, server, input } = ctx;
|
|
14
14
|
const { defaultInput, fixedInput } = options;
|
|
15
15
|
|
|
16
|
-
console.debug(`Running ${code} handler...`);
|
|
17
|
-
|
|
18
|
-
console.debug(`defaultInput: ${JSON.stringify(defaultInput)}`);
|
|
19
16
|
const mergedInput = mergeInput(defaultInput, input, fixedInput);
|
|
20
|
-
|
|
21
|
-
console.debug(`mergedInput: ${JSON.stringify(mergedInput)}`);
|
|
17
|
+
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
|
|
22
18
|
|
|
23
19
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
24
20
|
await entityManager.removeRelations(mergedInput, plugin);
|
|
@@ -10,18 +10,13 @@ export async function handler(
|
|
|
10
10
|
ctx: ActionHandlerContext,
|
|
11
11
|
options: RunEntityActionHandlerOptions,
|
|
12
12
|
) {
|
|
13
|
-
const { server, input } = ctx;
|
|
14
|
-
const { defaultInput, fixedInput } = options;
|
|
15
|
-
|
|
16
|
-
console.debug(`Running ${code} handler...`);
|
|
13
|
+
const { logger, server, input } = ctx;
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
const { defaultInput, fixedInput } = options;
|
|
19
16
|
const mergedInput = mergeInput(defaultInput, input, fixedInput);
|
|
20
|
-
|
|
21
|
-
console.debug(`mergedInput: ${JSON.stringify(mergedInput)}`);
|
|
17
|
+
logger.debug(`Running ${code} handler...`, { defaultInput, fixedInput, mergedInput });
|
|
22
18
|
|
|
23
19
|
const entityManager = server.getEntityManager(options.singularCode);
|
|
24
|
-
|
|
25
20
|
const output = await entityManager.updateEntityById({ id: mergedInput.id, entityToSave: mergedInput }, plugin);
|
|
26
21
|
ctx.output = output;
|
|
27
22
|
}
|