oak-domain 5.1.15 → 5.1.16

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.
@@ -1132,36 +1132,37 @@ class CascadeStore extends RowStore_1.RowStore {
1132
1132
  }
1133
1133
  // 说明没有已有的modi,必须要创建新的,此时应当在option中有相应的parentEntity/Id
1134
1134
  const { modiParentEntity, modiParentId } = option;
1135
- (0, assert_1.default)(modiParentEntity && modiParentId);
1136
- return {
1137
- id: 'dummy',
1138
- action: 'create',
1139
- data: {
1140
- id: operId,
1141
- targetEntity: entity,
1142
- entity: modiParentEntity,
1143
- entityId: modiParentId,
1144
- action,
1145
- data,
1146
- iState: 'active',
1147
- filter: ids.length > 0 ? {
1148
- id: {
1149
- $in: ids,
1135
+ if (modiParentEntity && modiParentId) {
1136
+ return {
1137
+ id: 'dummy',
1138
+ action: 'create',
1139
+ data: {
1140
+ id: operId,
1141
+ targetEntity: entity,
1142
+ entity: modiParentEntity,
1143
+ entityId: modiParentId,
1144
+ action,
1145
+ data,
1146
+ iState: 'active',
1147
+ filter: ids.length > 0 ? {
1148
+ id: {
1149
+ $in: ids,
1150
+ },
1151
+ } : {
1152
+ id: ids[0],
1150
1153
  },
1151
- } : {
1152
- id: ids[0],
1154
+ modiEntity$modi: {
1155
+ id: 'dummy',
1156
+ action: 'create',
1157
+ data: await Promise.all(ids.map(async (id) => ({
1158
+ id: await (0, uuid_1.generateNewIdAsync)(),
1159
+ entity: entity,
1160
+ entityId: id,
1161
+ }))),
1162
+ }
1153
1163
  },
1154
- modiEntity$modi: {
1155
- id: 'dummy',
1156
- action: 'create',
1157
- data: await Promise.all(ids.map(async (id) => ({
1158
- id: await (0, uuid_1.generateNewIdAsync)(),
1159
- entity: entity,
1160
- entityId: id,
1161
- }))),
1162
- }
1163
- },
1164
- };
1164
+ };
1165
+ }
1165
1166
  }
1166
1167
  /**
1167
1168
  * 和具体的update过程无关的例程放在这里,包括对later动作的处理、对oper的记录以及对record的收集等
@@ -1396,14 +1397,18 @@ class CascadeStore extends RowStore_1.RowStore {
1396
1397
  }
1397
1398
  const createModi = async () => {
1398
1399
  const modiOperation = await this.tryMergeModi(entity, operation, context, ids, option);
1399
- const closeRootMode = context.openRootMode();
1400
- await this.cascadeUpdateAsync('modi', modiOperation, context, option);
1401
- closeRootMode();
1402
- return {
1403
- modi: {
1404
- ['create']: 1,
1405
- },
1406
- };
1400
+ if (modiOperation) {
1401
+ const closeRootMode = context.openRootMode();
1402
+ await this.cascadeUpdateAsync('modi', modiOperation, context, option);
1403
+ closeRootMode();
1404
+ return {
1405
+ modi: {
1406
+ ['create']: 1,
1407
+ },
1408
+ };
1409
+ }
1410
+ console.warn(`destination includes modies can not be found here: [${entity}], [${JSON.stringify(operation)}]`);
1411
+ return {};
1407
1412
  };
1408
1413
  const saveRecordAndCreateOper = async () => {
1409
1414
  if (action === 'remove') {
@@ -44,7 +44,7 @@ function translateCheckerInAsyncContext(checker, schema) {
44
44
  };
45
45
  }
46
46
  case 'row': {
47
- const { filter, errMsg, inconsistentRows } = checker;
47
+ const { filter, errMsg, err, inconsistentRows } = checker;
48
48
  const fn = (async ({ operation }, context, option) => {
49
49
  const { filter: operationFilter, data, action, bornAt } = operation;
50
50
  const filter2 = typeof filter === 'function' ? await filter(operation, context, option) : filter;
@@ -66,7 +66,7 @@ function translateCheckerInAsyncContext(checker, schema) {
66
66
  dontCollect: true,
67
67
  blockTrigger: true,
68
68
  });
69
- const e = new Exception_1.OakRowInconsistencyException(errMsg);
69
+ const e = new (err || (Exception_1.OakRowInconsistencyException))(errMsg);
70
70
  e.addData(entity2, rows2, context.getSchema());
71
71
  throw e;
72
72
  }
@@ -81,7 +81,7 @@ function translateCheckerInAsyncContext(checker, schema) {
81
81
  dontCollect: true,
82
82
  blockTrigger: true,
83
83
  }); */
84
- const e = new Exception_1.OakRowInconsistencyException(errMsg);
84
+ const e = new (err || (Exception_1.OakRowInconsistencyException))(errMsg);
85
85
  // e.addData(entity, rows2);
86
86
  throw e;
87
87
  }
package/lib/store/modi.js CHANGED
@@ -73,42 +73,79 @@ function createModiRelatedCheckers(schema) {
73
73
  continue;
74
74
  }
75
75
  const restActions = (0, lodash_1.difference)(actions, action_1.appendOnlyActions);
76
- checkers.push({
77
- entity,
78
- action: restActions,
79
- type: 'row',
80
- filter: (operation, context, option) => {
81
- /**
82
- * 只有一种情况可以通过,即当前是在更新和active的modi所指向同一个父更新对象。
83
- * 比如:先申请了一个公司(company),再申请修改公司(companyApplyment),这时所有的active modi都指向此条companyApplyment
84
- * 这时:
85
- * 1)再申请一条新的修改公司(create companyApplyment),应被拒绝
86
- * 2)申请修改原来的companyApplyment(update companyApplyment),可以通过
87
- * 3)在其它路径上对此company对象进行直接的更新,应被拒绝
88
- */
89
- if (option.modiParentEntity) {
90
- const { modiParentEntity, modiParentId } = option;
91
- (0, assert_1.default)(modiParentEntity);
92
- (0, assert_1.default)(modiParentId);
76
+ if (!process.env.OAK_DISABLE_MODI_LOCK) {
77
+ checkers.push({
78
+ entity,
79
+ action: restActions,
80
+ type: 'row',
81
+ filter: (operation, context, option) => {
82
+ /**
83
+ * 只有一种情况可以通过,即当前是在更新和activemodi所指向同一个父更新对象。
84
+ * 比如:先申请了一个公司(company),再申请修改公司(companyApplyment),这时所有的active modi都指向此条companyApplyment
85
+ * 这时:
86
+ * 1)再申请一条新的修改公司(create companyApplyment),应被拒绝
87
+ * 2)申请修改原来的companyApplyment(update companyApplyment),可以通过
88
+ * 3)在其它路径上对此company对象进行直接的更新,应被拒绝
89
+ */
90
+ if (option.modiParentEntity) {
91
+ const { modiParentEntity, modiParentId } = option;
92
+ (0, assert_1.default)(modiParentEntity);
93
+ (0, assert_1.default)(modiParentId);
94
+ return {
95
+ modiEntity$entity: {
96
+ '#sqp': 'not in',
97
+ entity,
98
+ modi: {
99
+ iState: 'active',
100
+ $or: [
101
+ {
102
+ entity: {
103
+ $ne: modiParentEntity,
104
+ },
105
+ },
106
+ {
107
+ entityId: {
108
+ $ne: modiParentId,
109
+ },
110
+ }
111
+ ],
112
+ },
113
+ },
114
+ /* id: {
115
+ $nin: {
116
+ entity: 'modiEntity',
117
+ data: {
118
+ entityId: 1,
119
+ },
120
+ filter: {
121
+ entity,
122
+ modi: {
123
+ iState: 'active',
124
+ $or: [
125
+ {
126
+ entity: {
127
+ $ne: modiParentEntity,
128
+ },
129
+ },
130
+ {
131
+ entityId: {
132
+ $ne: modiParentId,
133
+ },
134
+ }
135
+ ],
136
+ },
137
+ },
138
+ },
139
+ } */
140
+ };
141
+ }
93
142
  return {
94
143
  modiEntity$entity: {
95
144
  '#sqp': 'not in',
96
145
  entity,
97
146
  modi: {
98
147
  iState: 'active',
99
- $or: [
100
- {
101
- entity: {
102
- $ne: modiParentEntity,
103
- },
104
- },
105
- {
106
- entityId: {
107
- $ne: modiParentId,
108
- },
109
- }
110
- ],
111
- },
148
+ }
112
149
  },
113
150
  /* id: {
114
151
  $nin: {
@@ -120,50 +157,15 @@ function createModiRelatedCheckers(schema) {
120
157
  entity,
121
158
  modi: {
122
159
  iState: 'active',
123
- $or: [
124
- {
125
- entity: {
126
- $ne: modiParentEntity,
127
- },
128
- },
129
- {
130
- entityId: {
131
- $ne: modiParentId,
132
- },
133
- }
134
- ],
135
- },
160
+ }
136
161
  },
137
162
  },
138
163
  } */
139
164
  };
140
- }
141
- return {
142
- modiEntity$entity: {
143
- '#sqp': 'not in',
144
- entity,
145
- modi: {
146
- iState: 'active',
147
- }
148
- },
149
- /* id: {
150
- $nin: {
151
- entity: 'modiEntity',
152
- data: {
153
- entityId: 1,
154
- },
155
- filter: {
156
- entity,
157
- modi: {
158
- iState: 'active',
159
- }
160
- },
161
- },
162
- } */
163
- };
164
- },
165
- errMsg: '您请求的更新对象上还有正在申请的更新,请等该更新结束后再试',
166
- });
165
+ },
166
+ errMsg: '您请求的更新对象上还有正在申请的更新,请等该更新结束后再试',
167
+ });
168
+ }
167
169
  }
168
170
  return checkers;
169
171
  }
@@ -1,4 +1,4 @@
1
- import { CascadeActionAuth, CascadeRelationAuth, ActionOnRemove, SyncOrAsync } from ".";
1
+ import { CascadeActionAuth, CascadeRelationAuth, ActionOnRemove, SyncOrAsync, OakException } from ".";
2
2
  import { AsyncContext } from "../store/AsyncRowStore";
3
3
  import { SyncContext } from "../store/SyncRowStore";
4
4
  import { EntityDict, OperateOption, SelectOption } from "../types/Entity";
@@ -25,6 +25,7 @@ export type RowChecker<ED extends EntityDict & BaseEntityDict, T extends keyof E
25
25
  action: ED[T]['Action'] | Array<ED[T]['Action']>;
26
26
  filter: ED[T]['Selection']['filter'] | ((operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option: OperateOption | SelectOption) => SyncOrAsync<ED[T]['Selection']['filter']>);
27
27
  errMsg?: string;
28
+ err?: new (msg?: string) => OakException<ED>;
28
29
  inconsistentRows?: {
29
30
  entity: keyof ED;
30
31
  selection: (filter?: ED[T]['Selection']['filter']) => ED[keyof ED]['Selection'];
@@ -1,6 +1,14 @@
1
1
  import { EntityDict } from '../types/Entity';
2
2
  import { EntityDict as BaseEntityDict } from '../base-app-domain';
3
3
  import { StorageSchema } from '../types';
4
+ /**
5
+ * 比较两行是否完全相等
6
+ * @param schema
7
+ * @param entity
8
+ * @param row1
9
+ * @param row2
10
+ * @returns 相等返回true,否则返回false
11
+ */
4
12
  export declare function compareRow<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(schema: StorageSchema<ED>, entity: T, row1: Partial<ED[T]['Schema']>, row2: Partial<ED[T]['Schema']>): boolean;
5
13
  /**
6
14
  * 比较两行数据是否完全相等
package/lib/utils/row.js CHANGED
@@ -5,6 +5,14 @@ const tslib_1 = require("tslib");
5
5
  const lodash_1 = require("./lodash");
6
6
  const relation_1 = require("../store/relation");
7
7
  const assert_1 = tslib_1.__importDefault(require("assert"));
8
+ /**
9
+ * 比较两行是否完全相等
10
+ * @param schema
11
+ * @param entity
12
+ * @param row1
13
+ * @param row2
14
+ * @returns 相等返回true,否则返回false
15
+ */
8
16
  function compareRow(schema, entity, row1, row2) {
9
17
  const attrs1 = Object.keys(row1 || {}).filter(ele => !ele.startsWith('$$'));
10
18
  const attrs2 = Object.keys(row2 || {}).filter(ele => !ele.startsWith('$$'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-domain",
3
- "version": "5.1.15",
3
+ "version": "5.1.16",
4
4
  "author": {
5
5
  "name": "XuChang"
6
6
  },