@ruiapp/rapid-core 0.2.10 → 0.2.12
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.
|
@@ -20,6 +20,7 @@ declare const _default: {
|
|
|
20
20
|
relation?: undefined;
|
|
21
21
|
targetSingularCode?: undefined;
|
|
22
22
|
selfIdColumnName?: undefined;
|
|
23
|
+
defaultValue?: undefined;
|
|
23
24
|
} | {
|
|
24
25
|
name: string;
|
|
25
26
|
code: string;
|
|
@@ -30,6 +31,7 @@ declare const _default: {
|
|
|
30
31
|
relation?: undefined;
|
|
31
32
|
targetSingularCode?: undefined;
|
|
32
33
|
selfIdColumnName?: undefined;
|
|
34
|
+
defaultValue?: undefined;
|
|
33
35
|
} | {
|
|
34
36
|
name: string;
|
|
35
37
|
code: string;
|
|
@@ -40,6 +42,7 @@ declare const _default: {
|
|
|
40
42
|
relation?: undefined;
|
|
41
43
|
targetSingularCode?: undefined;
|
|
42
44
|
selfIdColumnName?: undefined;
|
|
45
|
+
defaultValue?: undefined;
|
|
43
46
|
} | {
|
|
44
47
|
name: string;
|
|
45
48
|
code: string;
|
|
@@ -50,6 +53,7 @@ declare const _default: {
|
|
|
50
53
|
columnName?: undefined;
|
|
51
54
|
required?: undefined;
|
|
52
55
|
autoIncrement?: undefined;
|
|
56
|
+
defaultValue?: undefined;
|
|
53
57
|
} | {
|
|
54
58
|
name: string;
|
|
55
59
|
code: string;
|
|
@@ -60,6 +64,18 @@ declare const _default: {
|
|
|
60
64
|
relation?: undefined;
|
|
61
65
|
targetSingularCode?: undefined;
|
|
62
66
|
selfIdColumnName?: undefined;
|
|
67
|
+
defaultValue?: undefined;
|
|
68
|
+
} | {
|
|
69
|
+
name: string;
|
|
70
|
+
code: string;
|
|
71
|
+
columnName: string;
|
|
72
|
+
type: "boolean";
|
|
73
|
+
required: true;
|
|
74
|
+
defaultValue: string;
|
|
75
|
+
autoIncrement?: undefined;
|
|
76
|
+
relation?: undefined;
|
|
77
|
+
targetSingularCode?: undefined;
|
|
78
|
+
selfIdColumnName?: undefined;
|
|
63
79
|
})[];
|
|
64
80
|
indexes: ({
|
|
65
81
|
name: string;
|
package/dist/index.js
CHANGED
|
@@ -1539,6 +1539,14 @@ var bootstrapApplicationConfig = {
|
|
|
1539
1539
|
type: "json",
|
|
1540
1540
|
required: false,
|
|
1541
1541
|
},
|
|
1542
|
+
{
|
|
1543
|
+
name: "softDelete",
|
|
1544
|
+
code: "softDelete",
|
|
1545
|
+
columnName: "soft_delete",
|
|
1546
|
+
type: "boolean",
|
|
1547
|
+
required: true,
|
|
1548
|
+
defaultValue: "false",
|
|
1549
|
+
},
|
|
1542
1550
|
],
|
|
1543
1551
|
indexes: [
|
|
1544
1552
|
{
|
|
@@ -3559,13 +3567,16 @@ async function willEntityDuplicate(server, dataAccessor, options) {
|
|
|
3559
3567
|
routeContext,
|
|
3560
3568
|
});
|
|
3561
3569
|
if (entityId) {
|
|
3562
|
-
return entityInDb && entityInDb.
|
|
3570
|
+
return entityInDb && entityInDb.id !== entityId;
|
|
3563
3571
|
}
|
|
3564
3572
|
else {
|
|
3565
3573
|
return !!entityInDb;
|
|
3566
3574
|
}
|
|
3567
3575
|
}
|
|
3568
3576
|
function getEntityDuplicatedErrorMessage(server, model, indexConfig) {
|
|
3577
|
+
if (indexConfig.duplicateErrorMessage) {
|
|
3578
|
+
return indexConfig.duplicateErrorMessage;
|
|
3579
|
+
}
|
|
3569
3580
|
const propertyNames = indexConfig.properties.map((propConfig) => {
|
|
3570
3581
|
let propCode;
|
|
3571
3582
|
if (lodash.isString(propConfig)) {
|
|
@@ -3653,12 +3664,26 @@ class EntityManager {
|
|
|
3653
3664
|
sender: plugin,
|
|
3654
3665
|
routeContext,
|
|
3655
3666
|
});
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3667
|
+
if (model.softDelete) {
|
|
3668
|
+
let dataAccessor = model.base
|
|
3669
|
+
? this.#server.getDataAccessor({
|
|
3670
|
+
singularCode: model.base,
|
|
3671
|
+
})
|
|
3672
|
+
: this.#dataAccessor;
|
|
3673
|
+
const currentUserId = routeContext?.state?.userId;
|
|
3674
|
+
await dataAccessor.updateById(id, {
|
|
3675
|
+
deleted_at: getNowStringWithTimezone(),
|
|
3676
|
+
deleter_id: currentUserId,
|
|
3660
3677
|
});
|
|
3661
|
-
|
|
3678
|
+
}
|
|
3679
|
+
else {
|
|
3680
|
+
await this.#dataAccessor.deleteById(id);
|
|
3681
|
+
if (model.base) {
|
|
3682
|
+
const baseDataAccessor = this.#server.getDataAccessor({
|
|
3683
|
+
singularCode: model.base,
|
|
3684
|
+
});
|
|
3685
|
+
await baseDataAccessor.deleteById(id);
|
|
3686
|
+
}
|
|
3662
3687
|
}
|
|
3663
3688
|
await this.#server.emitEvent({
|
|
3664
3689
|
eventName: "entity.delete",
|
package/dist/types.d.ts
CHANGED
|
@@ -186,6 +186,10 @@ export interface RpdDataModel {
|
|
|
186
186
|
indexes?: RpdDataModelIndex[];
|
|
187
187
|
extensions?: RpdDataModelExtension[];
|
|
188
188
|
permissionPolicies?: RpdDataModelPermissionPolicies;
|
|
189
|
+
/**
|
|
190
|
+
* 是否使用软删除
|
|
191
|
+
*/
|
|
192
|
+
softDelete?: boolean;
|
|
189
193
|
}
|
|
190
194
|
export interface RpdDataModelPermissionPolicies {
|
|
191
195
|
find?: PermissionPolicy;
|
|
@@ -349,6 +353,10 @@ export interface RpdDataModelIndex {
|
|
|
349
353
|
unique?: boolean;
|
|
350
354
|
properties: RpdDataModelIndexPropertyConfig[];
|
|
351
355
|
conditions?: RpdDataModelIndexOptions[];
|
|
356
|
+
/**
|
|
357
|
+
* 重复时的错误信息。
|
|
358
|
+
*/
|
|
359
|
+
duplicateErrorMessage?: string;
|
|
352
360
|
}
|
|
353
361
|
export type RpdDataModelIndexPropertyConfig = string | {
|
|
354
362
|
code: string;
|
package/package.json
CHANGED
|
@@ -121,6 +121,14 @@ export default {
|
|
|
121
121
|
type: "json",
|
|
122
122
|
required: false,
|
|
123
123
|
},
|
|
124
|
+
{
|
|
125
|
+
name: "softDelete",
|
|
126
|
+
code: "softDelete",
|
|
127
|
+
columnName: "soft_delete",
|
|
128
|
+
type: "boolean",
|
|
129
|
+
required: true,
|
|
130
|
+
defaultValue: "false",
|
|
131
|
+
},
|
|
124
132
|
],
|
|
125
133
|
indexes: [
|
|
126
134
|
{
|
|
@@ -1466,13 +1466,17 @@ async function willEntityDuplicate(server: IRpdServer, dataAccessor: IRpdDataAcc
|
|
|
1466
1466
|
});
|
|
1467
1467
|
|
|
1468
1468
|
if (entityId) {
|
|
1469
|
-
return entityInDb && entityInDb.
|
|
1469
|
+
return entityInDb && entityInDb.id !== entityId;
|
|
1470
1470
|
} else {
|
|
1471
1471
|
return !!entityInDb;
|
|
1472
1472
|
}
|
|
1473
1473
|
}
|
|
1474
1474
|
|
|
1475
1475
|
function getEntityDuplicatedErrorMessage(server: IRpdServer, model: RpdDataModel, indexConfig: RpdDataModelIndex) {
|
|
1476
|
+
if (indexConfig.duplicateErrorMessage) {
|
|
1477
|
+
return indexConfig.duplicateErrorMessage;
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1476
1480
|
const propertyNames = indexConfig.properties.map((propConfig) => {
|
|
1477
1481
|
let propCode: string;
|
|
1478
1482
|
if (isString(propConfig)) {
|
|
@@ -1576,12 +1580,25 @@ export default class EntityManager<TEntity = any> {
|
|
|
1576
1580
|
routeContext,
|
|
1577
1581
|
});
|
|
1578
1582
|
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
+
if (model.softDelete) {
|
|
1584
|
+
let dataAccessor = model.base
|
|
1585
|
+
? this.#server.getDataAccessor({
|
|
1586
|
+
singularCode: model.base,
|
|
1587
|
+
})
|
|
1588
|
+
: this.#dataAccessor;
|
|
1589
|
+
const currentUserId = routeContext?.state?.userId;
|
|
1590
|
+
await dataAccessor.updateById(id, {
|
|
1591
|
+
deleted_at: getNowStringWithTimezone(),
|
|
1592
|
+
deleter_id: currentUserId,
|
|
1583
1593
|
});
|
|
1584
|
-
|
|
1594
|
+
} else {
|
|
1595
|
+
await this.#dataAccessor.deleteById(id);
|
|
1596
|
+
if (model.base) {
|
|
1597
|
+
const baseDataAccessor = this.#server.getDataAccessor({
|
|
1598
|
+
singularCode: model.base,
|
|
1599
|
+
});
|
|
1600
|
+
await baseDataAccessor.deleteById(id);
|
|
1601
|
+
}
|
|
1585
1602
|
}
|
|
1586
1603
|
|
|
1587
1604
|
await this.#server.emitEvent({
|
package/src/types.ts
CHANGED
|
@@ -212,6 +212,10 @@ export interface RpdDataModel {
|
|
|
212
212
|
indexes?: RpdDataModelIndex[];
|
|
213
213
|
extensions?: RpdDataModelExtension[];
|
|
214
214
|
permissionPolicies?: RpdDataModelPermissionPolicies;
|
|
215
|
+
/**
|
|
216
|
+
* 是否使用软删除
|
|
217
|
+
*/
|
|
218
|
+
softDelete?: boolean;
|
|
215
219
|
}
|
|
216
220
|
|
|
217
221
|
export interface RpdDataModelPermissionPolicies {
|
|
@@ -415,6 +419,11 @@ export interface RpdDataModelIndex {
|
|
|
415
419
|
unique?: boolean;
|
|
416
420
|
properties: RpdDataModelIndexPropertyConfig[];
|
|
417
421
|
conditions?: RpdDataModelIndexOptions[];
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* 重复时的错误信息。
|
|
425
|
+
*/
|
|
426
|
+
duplicateErrorMessage?: string;
|
|
418
427
|
}
|
|
419
428
|
|
|
420
429
|
export type RpdDataModelIndexPropertyConfig =
|