@ruiapp/rapid-core 0.10.0 → 0.10.2
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/helpers/entityHelper.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +16 -3
- package/dist/types.d.ts +4 -0
- package/package.json +1 -1
- package/src/bootstrapApplicationConfig.ts +7 -0
- package/src/dataAccess/entityManager.ts +2 -2
- package/src/helpers/entityHelper.ts +15 -2
- package/src/index.ts +1 -0
- package/src/types.ts +6 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IRpdServer } from "../core/server";
|
|
2
|
-
import { RpdDataModel } from "../types";
|
|
3
|
-
export declare function detectChangedFieldsOfEntity(server: IRpdServer, model: RpdDataModel, before: any, after: any): Record<string, any> | null;
|
|
2
|
+
import { RpdDataModel, UpdateEntityByIdOptions } from "../types";
|
|
3
|
+
export declare function detectChangedFieldsOfEntity(server: IRpdServer, model: RpdDataModel, before: any, after: any, relationPropertiesToUpdate: UpdateEntityByIdOptions["relationPropertiesToUpdate"]): Record<string, any> | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./core/routeContext";
|
|
|
7
7
|
export * from "./core/server";
|
|
8
8
|
export * from "./core/http-types";
|
|
9
9
|
export * from "./core/actionHandler";
|
|
10
|
+
export { default as EventManager } from "./core/eventManager";
|
|
10
11
|
export { default as DataAccessor } from "./dataAccess/dataAccessor";
|
|
11
12
|
export * from "./dataAccess/dataAccessor";
|
|
12
13
|
export { default as EntityManager } from "./dataAccess/entityManager";
|
package/dist/index.js
CHANGED
|
@@ -1385,6 +1385,13 @@ var bootstrapApplicationConfig = {
|
|
|
1385
1385
|
required: true,
|
|
1386
1386
|
defaultValue: "false",
|
|
1387
1387
|
},
|
|
1388
|
+
{
|
|
1389
|
+
name: "defaultOrderBy",
|
|
1390
|
+
code: "defaultOrderBy",
|
|
1391
|
+
columnName: "default_order_by",
|
|
1392
|
+
type: "json",
|
|
1393
|
+
required: false,
|
|
1394
|
+
},
|
|
1388
1395
|
],
|
|
1389
1396
|
indexes: [
|
|
1390
1397
|
{
|
|
@@ -2354,7 +2361,7 @@ function mapPropertyNameToColumnName(server, model, propertyName) {
|
|
|
2354
2361
|
return property.columnName || property.code;
|
|
2355
2362
|
}
|
|
2356
2363
|
|
|
2357
|
-
function detectChangedFieldsOfEntity(server, model, before, after) {
|
|
2364
|
+
function detectChangedFieldsOfEntity(server, model, before, after, relationPropertiesToUpdate) {
|
|
2358
2365
|
if (!before) {
|
|
2359
2366
|
throw new Error("Argument 'before' can not be null.");
|
|
2360
2367
|
}
|
|
@@ -2369,6 +2376,11 @@ function detectChangedFieldsOfEntity(server, model, before, after) {
|
|
|
2369
2376
|
const afterValue = after[key];
|
|
2370
2377
|
const beforeValue = before[key] || before[property.targetIdColumnName];
|
|
2371
2378
|
if (afterValue) {
|
|
2379
|
+
if (relationPropertiesToUpdate && relationPropertiesToUpdate[property.code]) {
|
|
2380
|
+
changed = true;
|
|
2381
|
+
changes[key] = afterValue;
|
|
2382
|
+
continue;
|
|
2383
|
+
}
|
|
2372
2384
|
if (lodash.isNumber(afterValue)) {
|
|
2373
2385
|
if (beforeValue) {
|
|
2374
2386
|
if (lodash.isNumber(beforeValue)) {
|
|
@@ -3359,7 +3371,7 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
|
|
|
3359
3371
|
if (!entity) {
|
|
3360
3372
|
throw new Error(`${model.namespace}.${model.singularCode} with id "${id}" was not found.`);
|
|
3361
3373
|
}
|
|
3362
|
-
let changes = detectChangedFieldsOfEntity(server, model, entity, entityToSave);
|
|
3374
|
+
let changes = detectChangedFieldsOfEntity(server, model, entity, entityToSave, options.relationPropertiesToUpdate);
|
|
3363
3375
|
if (!changes && !options.operation) {
|
|
3364
3376
|
return entity;
|
|
3365
3377
|
}
|
|
@@ -3389,7 +3401,7 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
|
|
|
3389
3401
|
sender: plugin,
|
|
3390
3402
|
routeContext: options.routeContext,
|
|
3391
3403
|
});
|
|
3392
|
-
changes = detectChangedFieldsOfEntity(server, model, entity, entityToSave);
|
|
3404
|
+
changes = detectChangedFieldsOfEntity(server, model, entity, entityToSave, options.relationPropertiesToUpdate);
|
|
3393
3405
|
// check readonly properties
|
|
3394
3406
|
Object.keys(changes).forEach((propertyName) => {
|
|
3395
3407
|
let isReadonlyProperty = false;
|
|
@@ -9909,6 +9921,7 @@ exports.DataAccessor = DataAccessor;
|
|
|
9909
9921
|
exports.DataManagePlugin = DataManager;
|
|
9910
9922
|
exports.EntityAccessControlPlugin = EntityAccessControlPlugin;
|
|
9911
9923
|
exports.EntityManager = EntityManager;
|
|
9924
|
+
exports.EventManager = EventManager;
|
|
9912
9925
|
exports.FileManagePlugin = FileManager;
|
|
9913
9926
|
exports.GlobalRequest = GlobalRequest;
|
|
9914
9927
|
exports.LicensePlugin = LicensePlugin;
|
package/dist/types.d.ts
CHANGED
|
@@ -211,6 +211,10 @@ export interface RpdDataModel {
|
|
|
211
211
|
* Configure the property code used to display the entity.
|
|
212
212
|
*/
|
|
213
213
|
displayPropertyCode?: string;
|
|
214
|
+
/**
|
|
215
|
+
* 默认排序方式
|
|
216
|
+
*/
|
|
217
|
+
defaultOrderBy?: FindEntityOrderByOptions[];
|
|
214
218
|
properties: RpdDataModelProperty[];
|
|
215
219
|
indexes?: RpdDataModelIndex[];
|
|
216
220
|
extensions?: RpdDataModelExtension[];
|
package/package.json
CHANGED
|
@@ -153,6 +153,13 @@ export default {
|
|
|
153
153
|
required: true,
|
|
154
154
|
defaultValue: "false",
|
|
155
155
|
},
|
|
156
|
+
{
|
|
157
|
+
name: "defaultOrderBy",
|
|
158
|
+
code: "defaultOrderBy",
|
|
159
|
+
columnName: "default_order_by",
|
|
160
|
+
type: "json",
|
|
161
|
+
required: false,
|
|
162
|
+
},
|
|
156
163
|
],
|
|
157
164
|
indexes: [
|
|
158
165
|
{
|
|
@@ -1066,7 +1066,7 @@ async function updateEntityById(server: IRpdServer, dataAccessor: IRpdDataAccess
|
|
|
1066
1066
|
throw new Error(`${model.namespace}.${model.singularCode} with id "${id}" was not found.`);
|
|
1067
1067
|
}
|
|
1068
1068
|
|
|
1069
|
-
let changes = detectChangedFieldsOfEntity(server, model, entity, entityToSave);
|
|
1069
|
+
let changes = detectChangedFieldsOfEntity(server, model, entity, entityToSave, options.relationPropertiesToUpdate);
|
|
1070
1070
|
if (!changes && !options.operation) {
|
|
1071
1071
|
return entity;
|
|
1072
1072
|
}
|
|
@@ -1101,7 +1101,7 @@ async function updateEntityById(server: IRpdServer, dataAccessor: IRpdDataAccess
|
|
|
1101
1101
|
routeContext: options.routeContext,
|
|
1102
1102
|
});
|
|
1103
1103
|
|
|
1104
|
-
changes = detectChangedFieldsOfEntity(server, model, entity, entityToSave);
|
|
1104
|
+
changes = detectChangedFieldsOfEntity(server, model, entity, entityToSave, options.relationPropertiesToUpdate);
|
|
1105
1105
|
|
|
1106
1106
|
// check readonly properties
|
|
1107
1107
|
Object.keys(changes).forEach((propertyName) => {
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { isNumber, isObject } from "lodash";
|
|
2
2
|
import { IRpdServer } from "~/core/server";
|
|
3
3
|
import { getEntityPropertyByCode, isOneRelationProperty } from "~/helpers/metaHelper";
|
|
4
|
-
import { RpdDataModel } from "~/types";
|
|
4
|
+
import { RpdDataModel, UpdateEntityByIdOptions } from "~/types";
|
|
5
5
|
|
|
6
|
-
export function detectChangedFieldsOfEntity(
|
|
6
|
+
export function detectChangedFieldsOfEntity(
|
|
7
|
+
server: IRpdServer,
|
|
8
|
+
model: RpdDataModel,
|
|
9
|
+
before: any,
|
|
10
|
+
after: any,
|
|
11
|
+
relationPropertiesToUpdate: UpdateEntityByIdOptions["relationPropertiesToUpdate"],
|
|
12
|
+
): Record<string, any> | null {
|
|
7
13
|
if (!before) {
|
|
8
14
|
throw new Error("Argument 'before' can not be null.");
|
|
9
15
|
}
|
|
@@ -19,7 +25,14 @@ export function detectChangedFieldsOfEntity(server: IRpdServer, model: RpdDataMo
|
|
|
19
25
|
if (property && isOneRelationProperty(property)) {
|
|
20
26
|
const afterValue: number | { id: number } | null = after[key];
|
|
21
27
|
const beforeValue: number | { id: number } | null = before[key] || before[property.targetIdColumnName];
|
|
28
|
+
|
|
22
29
|
if (afterValue) {
|
|
30
|
+
if (relationPropertiesToUpdate && relationPropertiesToUpdate[property.code]) {
|
|
31
|
+
changed = true;
|
|
32
|
+
changes[key] = afterValue;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
23
36
|
if (isNumber(afterValue)) {
|
|
24
37
|
if (beforeValue) {
|
|
25
38
|
if (isNumber(beforeValue)) {
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./core/routeContext";
|
|
|
11
11
|
export * from "./core/server";
|
|
12
12
|
export * from "./core/http-types";
|
|
13
13
|
export * from "./core/actionHandler";
|
|
14
|
+
export { default as EventManager } from "./core/eventManager";
|
|
14
15
|
|
|
15
16
|
export { default as DataAccessor } from "./dataAccess/dataAccessor";
|
|
16
17
|
export * from "./dataAccess/dataAccessor";
|
package/src/types.ts
CHANGED
|
@@ -244,6 +244,12 @@ export interface RpdDataModel {
|
|
|
244
244
|
* Configure the property code used to display the entity.
|
|
245
245
|
*/
|
|
246
246
|
displayPropertyCode?: string;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* 默认排序方式
|
|
250
|
+
*/
|
|
251
|
+
defaultOrderBy?: FindEntityOrderByOptions[];
|
|
252
|
+
|
|
247
253
|
properties: RpdDataModelProperty[];
|
|
248
254
|
indexes?: RpdDataModelIndex[];
|
|
249
255
|
extensions?: RpdDataModelExtension[];
|