oak-domain 2.5.2 → 2.6.1

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.
@@ -11,6 +11,7 @@ var types_1 = require("../types");
11
11
  var lodash_1 = require("../utils/lodash");
12
12
  var filter_2 = require("./filter");
13
13
  var uuid_1 = require("../utils/uuid");
14
+ var selection_1 = require("./selection");
14
15
  /**这个用来处理级联的select和update,对不同能力的 */
15
16
  var CascadeStore = /** @class */ (function (_super) {
16
17
  tslib_1.__extends(CascadeStore, _super);
@@ -1252,6 +1253,7 @@ var CascadeStore = /** @class */ (function (_super) {
1252
1253
  };
1253
1254
  CascadeStore.prototype.cascadeUpdate = function (entity, operation, context, option) {
1254
1255
  var e_5, _a, e_6, _b, e_7, _c;
1256
+ (0, selection_1.reinforceOperation)(this.getSchema(), entity, operation);
1255
1257
  var action = operation.action, data = operation.data, filter = operation.filter, id = operation.id;
1256
1258
  var opData;
1257
1259
  var wholeBeforeFns = [];
@@ -1328,6 +1330,7 @@ var CascadeStore = /** @class */ (function (_super) {
1328
1330
  return tslib_1.__generator(this, function (_h) {
1329
1331
  switch (_h.label) {
1330
1332
  case 0:
1333
+ (0, selection_1.reinforceOperation)(this.getSchema(), entity, operation);
1331
1334
  action = operation.action, data = operation.data, filter = operation.filter, id = operation.id;
1332
1335
  wholeBeforeFns = [];
1333
1336
  wholeAfterFns = [];
@@ -1426,6 +1429,7 @@ var CascadeStore = /** @class */ (function (_super) {
1426
1429
  });
1427
1430
  };
1428
1431
  CascadeStore.prototype.cascadeSelect = function (entity, selection, context, option) {
1432
+ (0, selection_1.reinforceSelection)(this.getSchema(), entity, selection);
1429
1433
  var data = selection.data, filter = selection.filter, indexFrom = selection.indexFrom, count = selection.count, sorter = selection.sorter;
1430
1434
  var _a = this.destructCascadeSelect(entity, data, context, this.cascadeSelect, this.aggregateSync, option), projection = _a.projection, cascadeSelectionFns = _a.cascadeSelectionFns;
1431
1435
  var rows = this.selectAbjointRow(entity, {
@@ -1547,6 +1551,7 @@ var CascadeStore = /** @class */ (function (_super) {
1547
1551
  return tslib_1.__generator(this, function (_b) {
1548
1552
  switch (_b.label) {
1549
1553
  case 0:
1554
+ (0, selection_1.reinforceSelection)(this.getSchema(), entity, selection);
1550
1555
  data = selection.data, filter = selection.filter, indexFrom = selection.indexFrom, count = selection.count, sorter = selection.sorter;
1551
1556
  _a = this.destructCascadeSelect(entity, data, context, this.cascadeSelectAsync, this.aggregateAsync, option), projection = _a.projection, cascadeSelectionFns = _a.cascadeSelectionFns;
1552
1557
  return [4 /*yield*/, this.selectAbjointRowAsync(entity, {
@@ -44,20 +44,19 @@ function translateCheckerInAsyncContext(checker) {
44
44
  var fn = (function (_a, context, option) {
45
45
  var operation = _a.operation;
46
46
  return tslib_1.__awaiter(_this, void 0, void 0, function () {
47
- var operationFilter, action, filter2, _b, entity2, selection2, rows2, data_1, rows2, data_2;
48
- var _c, _d;
49
- return tslib_1.__generator(this, function (_e) {
50
- switch (_e.label) {
47
+ var operationFilter, action, filter2, _b, entity2, selection2, rows2, e, rows2, e;
48
+ return tslib_1.__generator(this, function (_c) {
49
+ switch (_c.label) {
51
50
  case 0:
52
51
  operationFilter = operation.filter, action = operation.action;
53
52
  if (!(typeof filter_2 === 'function')) return [3 /*break*/, 2];
54
53
  return [4 /*yield*/, filter_2(operation, context, option)];
55
54
  case 1:
56
- _b = _e.sent();
55
+ _b = _c.sent();
57
56
  return [3 /*break*/, 3];
58
57
  case 2:
59
58
  _b = filter_2;
60
- _e.label = 3;
59
+ _c.label = 3;
61
60
  case 3:
62
61
  filter2 = _b;
63
62
  if (!['select', 'count', 'stat'].includes(action)) return [3 /*break*/, 4];
@@ -65,7 +64,7 @@ function translateCheckerInAsyncContext(checker) {
65
64
  return [2 /*return*/, 0];
66
65
  case 4: return [4 /*yield*/, (0, filter_1.checkFilterContains)(entity, context, filter2, operationFilter || {}, true)];
67
66
  case 5:
68
- if (_e.sent()) {
67
+ if (_c.sent()) {
69
68
  return [2 /*return*/, 0];
70
69
  }
71
70
  if (!inconsistentRows_1) return [3 /*break*/, 7];
@@ -75,20 +74,10 @@ function translateCheckerInAsyncContext(checker) {
75
74
  blockTrigger: true,
76
75
  })];
77
76
  case 6:
78
- rows2 = _e.sent();
79
- data_1 = {};
80
- rows2.forEach(function (ele) {
81
- var _a;
82
- return Object.assign(data_1, (_a = {},
83
- _a[ele.id] = ele,
84
- _a));
85
- });
86
- throw new Exception_1.OakRowInconsistencyException({
87
- a: 's',
88
- d: (_c = {},
89
- _c[entity2] = data_1,
90
- _c)
91
- }, errMsg_1);
77
+ rows2 = _c.sent();
78
+ e = new Exception_1.OakRowInconsistencyException(undefined, errMsg_1);
79
+ e.addData(entity2, rows2);
80
+ throw e;
92
81
  case 7: return [4 /*yield*/, context.select(entity, {
93
82
  data: (0, actionDef_1.getFullProjection)(entity, context.getSchema()),
94
83
  filter: Object.assign({}, operationFilter, {
@@ -99,20 +88,10 @@ function translateCheckerInAsyncContext(checker) {
99
88
  blockTrigger: true,
100
89
  })];
101
90
  case 8:
102
- rows2 = _e.sent();
103
- data_2 = {};
104
- rows2.forEach(function (ele) {
105
- var _a;
106
- return Object.assign(data_2, (_a = {},
107
- _a[ele.id] = ele,
108
- _a));
109
- });
110
- throw new Exception_1.OakRowInconsistencyException({
111
- a: 's',
112
- d: (_d = {},
113
- _d[entity] = data_2,
114
- _d)
115
- }, errMsg_1);
91
+ rows2 = _c.sent();
92
+ e = new Exception_1.OakRowInconsistencyException(undefined, errMsg_1);
93
+ e.addData(entity, rows2);
94
+ throw e;
116
95
  }
117
96
  });
118
97
  });
@@ -228,7 +207,8 @@ function translateCheckerInSyncContext(checker) {
228
207
  if ((0, filter_1.checkFilterContains)(entity, context, filter2, operationFilter, true)) {
229
208
  return;
230
209
  }
231
- throw new Exception_1.OakRowInconsistencyException(undefined, errMsg_3);
210
+ var e = new Exception_1.OakRowInconsistencyException(undefined, errMsg_3);
211
+ throw e;
232
212
  }
233
213
  };
234
214
  return {
@@ -578,8 +558,8 @@ function createRemoveCheckers(schema, authDict) {
578
558
  var promises = [];
579
559
  if (OneToManyMatrix[entity]) {
580
560
  var _loop_5 = function (otm) {
581
- var _g, _h, _j, _k;
582
- var _l = tslib_1.__read(otm, 2), e = _l[0], attr = _l[1];
561
+ var _g, _h;
562
+ var _j = tslib_1.__read(otm, 2), e = _j[0], attr = _j[1];
583
563
  var proj = (_g = {
584
564
  id: 1
585
565
  },
@@ -596,33 +576,20 @@ function createRemoveCheckers(schema, authDict) {
596
576
  }, { dontCollect: true });
597
577
  if (result instanceof Promise) {
598
578
  promises.push(result.then(function (_a) {
599
- var _b, _c;
600
- var _d = tslib_1.__read(_a, 1), row = _d[0];
579
+ var _b = tslib_1.__read(_a, 1), row = _b[0];
601
580
  if (row) {
602
- var record = {
603
- a: 's',
604
- d: (_b = {},
605
- _b[e] = (_c = {},
606
- _c[row.id] = row,
607
- _c),
608
- _b)
609
- };
610
- throw new Exception_1.OakRowInconsistencyException(record, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(e, "\u300D\u5173\u8054\u7684\u884C"));
581
+ var err = new Exception_1.OakRowInconsistencyException(undefined, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(e, "\u300D\u5173\u8054\u7684\u884C"));
582
+ err.addData(e, [row]);
583
+ throw err;
611
584
  }
612
585
  }));
613
586
  }
614
587
  else {
615
- var _m = tslib_1.__read(result, 1), row = _m[0];
588
+ var _k = tslib_1.__read(result, 1), row = _k[0];
616
589
  if (row) {
617
- var record = {
618
- a: 's',
619
- d: (_j = {},
620
- _j[e] = (_k = {},
621
- _k[row.id] = row,
622
- _k),
623
- _j)
624
- };
625
- throw new Exception_1.OakRowInconsistencyException(record, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(e, "\u300D\u5173\u8054\u7684\u884C"));
590
+ var err = new Exception_1.OakRowInconsistencyException(undefined, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(e, "\u300D\u5173\u8054\u7684\u884C"));
591
+ err.addData(e, [row]);
592
+ throw err;
626
593
  }
627
594
  }
628
595
  };
@@ -642,15 +609,15 @@ function createRemoveCheckers(schema, authDict) {
642
609
  }
643
610
  if (OneToManyOnEntityMatrix[entity]) {
644
611
  var _loop_6 = function (otm) {
645
- var _o, _p, _q;
612
+ var _l, _m, _o;
646
613
  var proj = {
647
614
  id: 1,
648
615
  entity: 1,
649
616
  entityId: 1,
650
617
  };
651
- var filter = operation.filter && (_o = {},
652
- _o[entity] = operation.filter,
653
- _o);
618
+ var filter = operation.filter && (_l = {},
619
+ _l[entity] = operation.filter,
620
+ _l);
654
621
  var result = context.select(otm, {
655
622
  data: proj,
656
623
  filter: filter,
@@ -659,33 +626,28 @@ function createRemoveCheckers(schema, authDict) {
659
626
  }, { dontCollect: true });
660
627
  if (result instanceof Promise) {
661
628
  promises.push(result.then(function (_a) {
662
- var _b, _c;
663
- var _d = tslib_1.__read(_a, 1), row = _d[0];
629
+ var _b = tslib_1.__read(_a, 1), row = _b[0];
664
630
  if (row) {
665
- var record = {
666
- a: 's',
667
- d: (_b = {},
668
- _b[otm] = (_c = {},
669
- _c[row.id] = row,
670
- _c),
671
- _b)
672
- };
673
- throw new Exception_1.OakRowInconsistencyException(record, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(otm, "\u300D\u5173\u8054\u7684\u884C"));
631
+ var e = new Exception_1.OakRowInconsistencyException(undefined, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(otm, "\u300D\u5173\u8054\u7684\u884C"));
632
+ e.addData(otm, [row]);
633
+ throw e;
674
634
  }
675
635
  }));
676
636
  }
677
637
  else {
678
- var _r = tslib_1.__read(result, 1), row = _r[0];
638
+ var _p = tslib_1.__read(result, 1), row = _p[0];
679
639
  if (row) {
680
640
  var record = {
681
641
  a: 's',
682
- d: (_p = {},
683
- _p[otm] = (_q = {},
684
- _q[row.id] = row,
685
- _q),
686
- _p)
642
+ d: (_m = {},
643
+ _m[otm] = (_o = {},
644
+ _o[row.id] = row,
645
+ _o),
646
+ _m)
687
647
  };
688
- throw new Exception_1.OakRowInconsistencyException(record, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(otm, "\u300D\u5173\u8054\u7684\u884C"));
648
+ var e = new Exception_1.OakRowInconsistencyException(undefined, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(otm, "\u300D\u5173\u8054\u7684\u884C"));
649
+ e.addData(otm, [row]);
650
+ throw e;
689
651
  }
690
652
  }
691
653
  };
@@ -1,7 +1,19 @@
1
1
  import { StorageSchema } from '../types';
2
2
  import { EntityDict } from '../types/Entity';
3
+ declare type SelectionRewriter<ED extends EntityDict> = (schema: StorageSchema<ED>, entity: keyof ED, selection: ED[keyof ED]['Selection']) => void;
4
+ export declare function registerSelectionRewriter<ED extends EntityDict>(rewriter: SelectionRewriter<ED>): void;
5
+ declare type OperationRewriter<ED extends EntityDict> = (schema: StorageSchema<ED>, entity: keyof ED, operate: ED[keyof ED]['Operation']) => void;
6
+ export declare function registerOperationRewriter<ED extends EntityDict>(rewriter: OperationRewriter<ED>): void;
3
7
  /**
4
8
  * 对selection进行一些完善,避免编程人员的疏漏
5
9
  * @param selection
6
10
  */
7
11
  export declare function reinforceSelection<ED extends EntityDict>(schema: StorageSchema<ED>, entity: keyof ED, selection: ED[keyof ED]['Selection']): void;
12
+ /**
13
+ * 对operation进行一些完善,作为operation算子的注入点
14
+ * @param schema
15
+ * @param entity
16
+ * @param selection
17
+ */
18
+ export declare function reinforceOperation<ED extends EntityDict>(schema: StorageSchema<ED>, entity: keyof ED, operation: ED[keyof ED]['Operation']): void;
19
+ export {};
@@ -1,18 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reinforceSelection = void 0;
3
+ exports.reinforceOperation = exports.reinforceSelection = exports.registerOperationRewriter = exports.registerSelectionRewriter = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var assert_1 = tslib_1.__importDefault(require("assert"));
6
6
  var types_1 = require("../types");
7
7
  var Demand_1 = require("../types/Demand");
8
8
  var filter_1 = require("./filter");
9
9
  var relation_1 = require("./relation");
10
+ var SelectionRewriters = [];
11
+ function registerSelectionRewriter(rewriter) {
12
+ SelectionRewriters.push(rewriter);
13
+ }
14
+ exports.registerSelectionRewriter = registerSelectionRewriter;
15
+ function getSelectionRewriters() {
16
+ return SelectionRewriters;
17
+ }
18
+ var OperationRewriters = [];
19
+ function registerOperationRewriter(rewriter) {
20
+ OperationRewriters.push(rewriter);
21
+ }
22
+ exports.registerOperationRewriter = registerOperationRewriter;
23
+ function getOperationRewriters() {
24
+ return OperationRewriters;
25
+ }
10
26
  /**
11
27
  * 对selection进行一些完善,避免编程人员的疏漏
12
28
  * @param selection
13
29
  */
14
30
  function reinforceSelection(schema, entity, selection) {
15
31
  var filter = selection.filter, data = selection.data, sorter = selection.sorter;
32
+ Object.assign(data, {
33
+ '$$createAt$$': 1,
34
+ }); // 有的页面依赖于其它页面取数据,有时两个页面的filter的差异会导致有一个加createAt,有一个不加,此时可能产生前台取数据不完整的异常。先统一加上
16
35
  var checkNode = function (projectionNode, attrs) {
17
36
  attrs.forEach(function (attr) {
18
37
  var _a;
@@ -234,5 +253,16 @@ function reinforceSelection(schema, entity, selection) {
234
253
  $$createAt$$: 1,
235
254
  });
236
255
  }
256
+ SelectionRewriters.forEach(function (ele) { return ele(schema, entity, selection); });
237
257
  }
238
258
  exports.reinforceSelection = reinforceSelection;
259
+ /**
260
+ * 对operation进行一些完善,作为operation算子的注入点
261
+ * @param schema
262
+ * @param entity
263
+ * @param selection
264
+ */
265
+ function reinforceOperation(schema, entity, operation) {
266
+ OperationRewriters.forEach(function (ele) { return ele(schema, entity, operation); });
267
+ }
268
+ exports.reinforceOperation = reinforceOperation;
@@ -61,7 +61,7 @@ export declare type AuthDef<ED extends EntityDict, T extends keyof ED> = {
61
61
  relationAuth?: CascadeRelationAuth<NonNullable<ED[T]['Relation']>>;
62
62
  actionAuth?: CascadeActionAuth<ED[T]['Action']>;
63
63
  cascadeRemove?: {
64
- [E in keyof ED[T]['OpSchema'] | '@entity']?: ActionOnRemove;
64
+ [E in (keyof ED | '@entity')]?: ActionOnRemove;
65
65
  };
66
66
  };
67
67
  export declare type AuthDefDict<ED extends EntityDict> = {
@@ -19,7 +19,7 @@ export declare abstract class Connector<ED extends EntityDict, BackCxt extends A
19
19
  body: any;
20
20
  headers?: Record<string, any>;
21
21
  };
22
- abstract serializeException(exception: OakException, headers: IncomingHttpHeaders, body: any): {
22
+ abstract serializeException(exception: OakException<ED>, headers: IncomingHttpHeaders, body: any): {
23
23
  body: any;
24
24
  headers?: Record<string, any>;
25
25
  };
@@ -165,7 +165,7 @@ export declare type SelectOpResult<ED extends EntityDict> = {
165
165
  a: 's';
166
166
  d: {
167
167
  [T in keyof ED]?: {
168
- [ID: string]: ED[T]['OpSchema'];
168
+ [ID: string]: Partial<ED[T]['OpSchema']>;
169
169
  };
170
170
  };
171
171
  };
@@ -1,11 +1,14 @@
1
- import { EntityDict, OpRecord } from "./Entity";
2
- export declare class OakException extends Error {
1
+ import { EntityDict, OpRecord, SelectOpResult } from "./Entity";
2
+ export declare class OakException<ED extends EntityDict> extends Error {
3
+ opRecord: SelectOpResult<ED>;
3
4
  constructor(message?: string);
5
+ addData<T extends keyof ED>(entity: T, rows: Partial<ED[T]['OpSchema']>[]): void;
6
+ setOpRecords(opRecord: SelectOpResult<ED>): void;
4
7
  toString(): string;
5
8
  }
6
- export declare class OakDataException extends OakException {
9
+ export declare class OakDataException<ED extends EntityDict> extends OakException<ED> {
7
10
  }
8
- export declare class OakUniqueViolationException extends OakException {
11
+ export declare class OakUniqueViolationException<ED extends EntityDict> extends OakException<ED> {
9
12
  rows: Array<{
10
13
  id?: string;
11
14
  attrs: string[];
@@ -15,14 +18,14 @@ export declare class OakUniqueViolationException extends OakException {
15
18
  attrs: string[];
16
19
  }>, message?: string);
17
20
  }
18
- export declare class OakImportDataParseException extends OakException {
21
+ export declare class OakImportDataParseException<ED extends EntityDict> extends OakException<ED> {
19
22
  line: number;
20
23
  header?: string;
21
24
  constructor(message: string, line: number, header?: string);
22
25
  }
23
- export declare class OakOperExistedException extends OakDataException {
26
+ export declare class OakOperExistedException<ED extends EntityDict> extends OakDataException<ED> {
24
27
  }
25
- export declare class OakRowUnexistedException extends OakDataException {
28
+ export declare class OakRowUnexistedException<ED extends EntityDict> extends OakDataException<ED> {
26
29
  private rows;
27
30
  constructor(rows: Array<{
28
31
  entity: any;
@@ -36,22 +39,20 @@ export declare class OakRowUnexistedException extends OakDataException {
36
39
  }
37
40
  export declare class OakExternalException extends Error {
38
41
  }
39
- export declare class OakUserException extends OakException {
42
+ export declare class OakUserException<ED extends EntityDict> extends OakException<ED> {
40
43
  }
41
44
  /**
42
45
  * 数据不一致异常,系统认为现有的数据不允许相应的动作时抛此异常
43
46
  *
44
47
  */
45
- export declare class OakRowInconsistencyException<ED extends EntityDict> extends OakUserException {
46
- private data?;
48
+ export declare class OakRowInconsistencyException<ED extends EntityDict> extends OakUserException<ED> {
47
49
  constructor(data?: OpRecord<ED>, message?: string);
48
- getData(): OpRecord<ED> | undefined;
49
50
  toString(): string;
50
51
  }
51
52
  /**
52
53
  * 当输入的数据非法时抛此异常,attributes表示非法的属性
53
54
  */
54
- export declare class OakInputIllegalException extends OakUserException {
55
+ export declare class OakInputIllegalException<ED extends EntityDict> extends OakUserException<ED> {
55
56
  private attributes;
56
57
  private entity;
57
58
  constructor(entity: string, attributes: string[], message?: string);
@@ -63,24 +64,24 @@ export declare class OakInputIllegalException extends OakUserException {
63
64
  /**
64
65
  * 用户权限不够时抛的异常
65
66
  */
66
- export declare class OakUserUnpermittedException extends OakUserException {
67
+ export declare class OakUserUnpermittedException<ED extends EntityDict> extends OakUserException<ED> {
67
68
  }
68
69
  /**
69
70
  * 用户未登录抛的异常
70
71
  */
71
- export declare class OakUnloggedInException extends OakUserException {
72
+ export declare class OakUnloggedInException<ED extends EntityDict> extends OakUserException<ED> {
72
73
  constructor(message?: string);
73
74
  }
74
75
  /**
75
76
  * 用户未登录抛的异常
76
77
  */
77
- export declare class OakRowLockedException extends OakUserException {
78
+ export declare class OakRowLockedException<ED extends EntityDict> extends OakUserException<ED> {
78
79
  constructor(message?: string);
79
80
  }
80
81
  /**
81
82
  * 要插入行时,发现已经有相同的行数据
82
83
  */
83
- export declare class OakCongruentRowExists<ED extends EntityDict, T extends keyof ED> extends OakUserException {
84
+ export declare class OakCongruentRowExists<ED extends EntityDict, T extends keyof ED> extends OakUserException<ED> {
84
85
  private data;
85
86
  private entity;
86
87
  constructor(entity: T, data: ED[T]['OpSchema'], message?: string);
@@ -88,11 +89,12 @@ export declare class OakCongruentRowExists<ED extends EntityDict, T extends keyo
88
89
  getEntity(): T;
89
90
  toString(): string;
90
91
  }
91
- export declare class OakDeadlock extends OakUserException {
92
+ export declare class OakDeadlock<ED extends EntityDict> extends OakUserException<ED> {
92
93
  constructor(message?: string | undefined);
93
94
  }
94
- export declare function makeException(data: {
95
+ export declare function makeException<ED extends EntityDict>(data: {
95
96
  name: string;
96
97
  message?: string;
98
+ opRecords: SelectOpResult<ED>;
97
99
  [A: string]: any;
98
- }): OakException | OakExternalException | undefined;
100
+ }): OakException<EntityDict> | undefined;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeException = exports.OakDeadlock = exports.OakCongruentRowExists = exports.OakRowLockedException = exports.OakUnloggedInException = exports.OakUserUnpermittedException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakUserException = exports.OakExternalException = exports.OakRowUnexistedException = exports.OakOperExistedException = exports.OakImportDataParseException = exports.OakUniqueViolationException = exports.OakDataException = exports.OakException = void 0;
4
4
  var tslib_1 = require("tslib");
5
+ var assert_1 = tslib_1.__importDefault(require("assert"));
5
6
  var OakException = /** @class */ (function (_super) {
6
7
  tslib_1.__extends(OakException, _super);
7
8
  function OakException(message) {
@@ -17,12 +18,36 @@ var OakException = /** @class */ (function (_super) {
17
18
  else {
18
19
  _this.__proto__ = _newTarget.prototype;
19
20
  }
21
+ _this.opRecord = {
22
+ a: 's',
23
+ d: {},
24
+ };
20
25
  return _this;
21
26
  }
27
+ OakException.prototype.addData = function (entity, rows) {
28
+ var d = this.opRecord.d;
29
+ var addSingleRow = function (rowRoot, row) {
30
+ var id = row.id;
31
+ if (rowRoot[id]) {
32
+ Object.assign(rowRoot[id], row);
33
+ }
34
+ else {
35
+ rowRoot[id] = row;
36
+ }
37
+ };
38
+ if (!d[entity]) {
39
+ d[entity] = {};
40
+ }
41
+ rows.forEach(function (row) { return addSingleRow(d[entity], row); });
42
+ };
43
+ OakException.prototype.setOpRecords = function (opRecord) {
44
+ this.opRecord = opRecord;
45
+ };
22
46
  OakException.prototype.toString = function () {
23
47
  return JSON.stringify({
24
48
  name: this.constructor.name,
25
49
  message: this.message,
50
+ opRecord: this.opRecord,
26
51
  });
27
52
  };
28
53
  return OakException;
@@ -109,17 +134,13 @@ var OakRowInconsistencyException = /** @class */ (function (_super) {
109
134
  tslib_1.__extends(OakRowInconsistencyException, _super);
110
135
  function OakRowInconsistencyException(data, message) {
111
136
  var _this = _super.call(this, message) || this;
112
- _this.data = data;
137
+ (0, assert_1.default)(!data, '现在使用addData接口来传数据');
113
138
  return _this;
114
139
  }
115
- OakRowInconsistencyException.prototype.getData = function () {
116
- return this.data;
117
- };
118
140
  OakRowInconsistencyException.prototype.toString = function () {
119
141
  return JSON.stringify({
120
142
  name: this.constructor.name,
121
143
  message: this.message,
122
- data: this.data,
123
144
  });
124
145
  };
125
146
  return OakRowInconsistencyException;
@@ -235,46 +256,69 @@ function makeException(data) {
235
256
  var name = data.name;
236
257
  switch (name) {
237
258
  case 'OakException': {
238
- return new OakException(data.message);
259
+ var e = new OakException(data.message);
260
+ e.setOpRecords(data.opRecords);
261
+ return e;
239
262
  }
240
263
  case 'OakUserException': {
241
- return new OakUserException(data.message);
242
- }
243
- case 'OakExternalException': {
244
- return new OakExternalException(data.message);
264
+ var e = new OakUserException(data.message);
265
+ e.setOpRecords(data.opRecords);
266
+ return e;
245
267
  }
246
268
  case 'OakRowInconsistencyException': {
247
- return new OakRowInconsistencyException(data.data, data.message);
269
+ var e = new OakRowInconsistencyException(data.data, data.message);
270
+ e.setOpRecords(data.opRecords);
271
+ return e;
248
272
  }
249
273
  case 'OakInputIllegalException': {
250
- return new OakInputIllegalException(data.entity, data.attributes, data.message);
274
+ var e = new OakInputIllegalException(data.entity, data.attributes, data.message);
275
+ e.setOpRecords(data.opRecords);
276
+ return e;
251
277
  }
252
278
  case 'OakUserUnpermittedException': {
253
- return new OakUserUnpermittedException(data.message);
279
+ var e = new OakUserUnpermittedException(data.message);
280
+ e.setOpRecords(data.opRecords);
281
+ return e;
254
282
  }
255
283
  case 'OakUnloggedInException': {
256
- return new OakUnloggedInException(data.message);
284
+ var e = new OakUnloggedInException(data.message);
285
+ e.setOpRecords(data.opRecords);
286
+ return e;
257
287
  }
258
288
  case 'OakCongruentRowExists': {
259
- return new OakCongruentRowExists(data.entity, data.data, data.message);
289
+ var e = new OakCongruentRowExists(data.entity, data.data, data.message);
290
+ e.setOpRecords(data.opRecords);
291
+ return e;
260
292
  }
261
293
  case 'OakRowLockedException': {
262
- return new OakRowLockedException(data.message);
294
+ var e = new OakRowLockedException(data.message);
295
+ e.setOpRecords(data.opRecords);
296
+ return e;
263
297
  }
264
298
  case 'OakRowUnexistedException': {
265
- return new OakRowUnexistedException(data.rows);
299
+ var e = new OakRowUnexistedException(data.rows);
300
+ e.setOpRecords(data.opRecords);
301
+ return e;
266
302
  }
267
303
  case 'OakDeadlock': {
268
- return new OakDeadlock(data.message);
304
+ var e = new OakDeadlock(data.message);
305
+ e.setOpRecords(data.opRecords);
306
+ return e;
269
307
  }
270
308
  case 'OakDataException': {
271
- return new OakDataException(data.message);
309
+ var e = new OakDataException(data.message);
310
+ e.setOpRecords(data.opRecords);
311
+ return e;
272
312
  }
273
313
  case 'OakUniqueViolationException': {
274
- return new OakUniqueViolationException(data.rows, data.message);
314
+ var e = new OakUniqueViolationException(data.rows, data.message);
315
+ e.setOpRecords(data.opRecords);
316
+ return e;
275
317
  }
276
318
  case 'OakImportDataParseException': {
277
- return new OakImportDataParseException(data.message, data.line, data.header);
319
+ var e = new OakImportDataParseException(data.message, data.line, data.header);
320
+ e.setOpRecords(data.opRecords);
321
+ return e;
278
322
  }
279
323
  default:
280
324
  return;
@@ -8,7 +8,7 @@ export declare class SimpleConnector<ED extends EntityDict, BackCxt extends Asyn
8
8
  private serverUrl;
9
9
  private makeException;
10
10
  private contextBuilder;
11
- constructor(serverUrl: string, makeException: (exceptionData: any) => OakException, contextBuilder: (str: string | undefined) => (store: AsyncRowStore<ED, BackCxt>) => Promise<BackCxt>);
11
+ constructor(serverUrl: string, makeException: (exceptionData: any) => OakException<ED>, contextBuilder: (str: string | undefined) => (store: AsyncRowStore<ED, BackCxt>) => Promise<BackCxt>);
12
12
  callAspect(name: string, params: any, context: FrontCxt): Promise<{
13
13
  result: any;
14
14
  opRecords: OpRecord<ED>[];
@@ -23,7 +23,7 @@ export declare class SimpleConnector<ED extends EntityDict, BackCxt extends Asyn
23
23
  body: any;
24
24
  headers?: Record<string, any> | undefined;
25
25
  };
26
- serializeException(exception: OakException, headers: IncomingHttpHeaders, body: any): {
26
+ serializeException(exception: OakException<ED>, headers: IncomingHttpHeaders, body: any): {
27
27
  body: any;
28
28
  headers?: Record<string, any> | undefined;
29
29
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-domain",
3
- "version": "2.5.2",
3
+ "version": "2.6.1",
4
4
  "author": {
5
5
  "name": "XuChang"
6
6
  },