@ruiapp/rapid-core 0.1.71 → 0.1.73
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/dataAccess/dataAccessTypes.d.ts +11 -0
- package/dist/dataAccess/propertyMapper.d.ts +3 -2
- package/dist/helpers/metaHelper.d.ts +1 -0
- package/dist/index.js +138 -52
- package/dist/queryBuilder/queryBuilder.d.ts +2 -1
- package/package.json +1 -1
- package/src/dataAccess/dataAccessTypes.ts +122 -109
- package/src/dataAccess/entityManager.ts +1342 -1298
- package/src/dataAccess/propertyMapper.ts +28 -27
- package/src/helpers/metaHelper.ts +13 -0
- package/src/plugins/fileManage/actionHandlers/downloadFile.ts +33 -28
- package/src/queryBuilder/queryBuilder.ts +512 -473
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import { RpdDataModel } from "~/types";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import { RpdDataModel } from "~/types";
|
|
2
|
+
import { getEntityPropertyByCode, isOneRelationProperty } from "../helpers/metaHelper";
|
|
3
|
+
import { IRpdServer } from "~/core/server";
|
|
4
|
+
|
|
5
|
+
export function mapPropertyNameToColumnName(server: IRpdServer, model: RpdDataModel, propertyName: string) {
|
|
6
|
+
if (!model.properties) {
|
|
7
|
+
return propertyName;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const property = getEntityPropertyByCode(server, model, propertyName);
|
|
11
|
+
if (!property) {
|
|
12
|
+
return propertyName;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (isOneRelationProperty(property)) {
|
|
16
|
+
return property.targetIdColumnName!;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return property.columnName || property.code;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function mapPropertyNamesToColumnNames(server: IRpdServer, model: RpdDataModel, propertyNames: string[]) {
|
|
23
|
+
if (!propertyNames || !propertyNames.length) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return propertyNames.map((fieldName) => mapPropertyNameToColumnName(server, model, fieldName));
|
|
28
|
+
}
|
|
@@ -61,3 +61,16 @@ export function getEntityProperty(server: IRpdServer, model: RpdDataModel, predi
|
|
|
61
61
|
|
|
62
62
|
return property;
|
|
63
63
|
}
|
|
64
|
+
|
|
65
|
+
export function getEntityPropertyByFieldName(server: IRpdServer, model: RpdDataModel, fieldName: string) {
|
|
66
|
+
let property = getEntityPropertyByCode(server, model, fieldName);
|
|
67
|
+
if (!property) {
|
|
68
|
+
property = getEntityProperty(server, model, (item) => item.relation === "one" && item.targetIdColumnName === fieldName);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!property) {
|
|
72
|
+
property = getEntityProperty(server, model, (item) => item.columnName === fieldName);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return property;
|
|
76
|
+
}
|
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { readFile } from "~/utilities/fsUtility";
|
|
3
|
-
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
4
|
-
import { RapidPlugin } from "~/core/server";
|
|
5
|
-
|
|
6
|
-
export const code = "downloadFile";
|
|
7
|
-
|
|
8
|
-
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
|
|
9
|
-
const { server, applicationConfig, routerContext, input } = ctx;
|
|
10
|
-
const { request, response } = routerContext;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { readFile } from "~/utilities/fsUtility";
|
|
3
|
+
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
4
|
+
import { RapidPlugin } from "~/core/server";
|
|
5
|
+
|
|
6
|
+
export const code = "downloadFile";
|
|
7
|
+
|
|
8
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
|
|
9
|
+
const { server, applicationConfig, routerContext, input } = ctx;
|
|
10
|
+
const { request, response } = routerContext;
|
|
11
|
+
//TODO: only public files can download by this handler
|
|
12
|
+
|
|
13
|
+
let fileKey: string = input.fileKey;
|
|
14
|
+
|
|
15
|
+
if (!fileKey && input.fileId) {
|
|
16
|
+
const dataAccessor = ctx.server.getDataAccessor({
|
|
17
|
+
singularCode: "ecm_storage_object",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const storageObject = await dataAccessor.findById(input.fileId);
|
|
21
|
+
if (!storageObject) {
|
|
22
|
+
ctx.output = { error: new Error("Storage object not found.") };
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
fileKey = storageObject.key;
|
|
27
|
+
}
|
|
28
|
+
const filePathName = path.join(server.config.localFileStoragePath, fileKey);
|
|
29
|
+
const attachmentFileName = input.fileName || path.basename(fileKey);
|
|
30
|
+
|
|
31
|
+
response.body = await readFile(filePathName);
|
|
32
|
+
response.headers.set("Content-Disposition", `attachment; filename="${encodeURIComponent(attachmentFileName)}"`);
|
|
33
|
+
}
|