oak-domain 1.1.2 → 1.1.5

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.
@@ -1,3 +1,3 @@
1
1
  import { EntityDict } from '../base-app-domain';
2
2
  import { StorageSchema, EntityDict as BaseEntityDict, Context } from '../types';
3
- export declare function createCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>): import("../types").Checker<ED, keyof ED, Cxt>[];
3
+ export declare function createDynamicCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>): import("../types").Checker<ED, keyof ED, Cxt>[];
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCheckers = void 0;
3
+ exports.createDynamicCheckers = void 0;
4
4
  var modi_1 = require("../store/modi");
5
- function createCheckers(schema) {
5
+ function createDynamicCheckers(schema) {
6
6
  return (0, modi_1.createModiRelatedCheckers)(schema);
7
7
  }
8
- exports.createCheckers = createCheckers;
8
+ exports.createDynamicCheckers = createDynamicCheckers;
@@ -680,9 +680,9 @@ var CascadeStore = /** @class */ (function (_super) {
680
680
  }
681
681
  _loop_2 = function (attr) {
682
682
  var relation, operationMto, actionMto, dataMto, filterMto, fkId, entity_1, result2, operationMto, actionMto, dataMto, filterMto, _d, _e, fkId, result2, _f, entityOtm_1, foreignKey_2, otmOperations, dealWithOneToMany, otmOperations_1, otmOperations_1_1, oper, e_2_1;
683
- var _g, _h, e_2, _j;
684
- return tslib_1.__generator(this, function (_k) {
685
- switch (_k.label) {
683
+ var _g, _h, _j, e_2, _k;
684
+ return tslib_1.__generator(this, function (_l) {
685
+ switch (_l.label) {
686
686
  case 0:
687
687
  relation = (0, relation_1.judgeRelation)(this_2.storageSchema, entity, attr);
688
688
  if (!(relation === 1)) return [3 /*break*/, 1];
@@ -702,37 +702,50 @@ var CascadeStore = /** @class */ (function (_super) {
702
702
  }
703
703
  else if (action === 'create') {
704
704
  fkId = data.entityId, entity_1 = data.entity;
705
- (0, assert_1.default)(typeof fkId === 'string' || entity_1 === attr); // A中data的entityId作为B中filter的主键
706
- (0, assert_1.default)(filterMto.id && filterMto.id === fkId);
707
- /* Object.assign(operationMto, {
708
- filter: addFilterSegment({
709
- id: fkId,
710
- }), filterMto,
711
- }); */
705
+ (0, assert_1.default)(typeof fkId === 'string' || entity_1 === attr);
706
+ if (filterMto.id) {
707
+ // 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
708
+ (0, assert_1.default)(filterMto.id === fkId);
709
+ }
710
+ else {
711
+ // A中data的entityId作为B中filter的主键
712
+ Object.assign(operationMto, {
713
+ filter: (0, filter_1.addFilterSegment)({
714
+ id: fkId,
715
+ }),
716
+ filterMto: filterMto,
717
+ });
718
+ }
712
719
  }
713
720
  else {
714
721
  // 剩下三种情况都是B中的filter的id来自A中row的entityId
715
- (0, assert_1.default)(!data.hasOwnProperty('entityId') && !data.hasOwnProperty('entity')); // 这里不能再addFilterSegment,否则会造成后面判断不出来对应的id是多少。在实际情况中跑到这里应该不可能没有id
716
- (0, assert_1.default)(filterMto.id && typeof filterMto.id === 'string');
717
- /* Object.assign(operationMto, {
718
- filter: addFilterSegment({
719
- id: {
720
- $in: {
721
- entity,
722
- data: {
723
- entityId: 1,
724
- },
725
- filter: addFilterSegment({
726
- entity: attr,
727
- } as any, filter),
728
- }
729
- },
730
- }, filterMto),
731
- }); */
722
+ (0, assert_1.default)(!data.hasOwnProperty('entityId') && !data.hasOwnProperty('entity'));
723
+ if (filterMto.id) {
724
+ // 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
725
+ (0, assert_1.default)(typeof filterMto.id === 'string');
726
+ }
727
+ else {
728
+ // A中data的entityId作为B中filter的主键
729
+ Object.assign(operationMto, {
730
+ filter: (0, filter_1.addFilterSegment)({
731
+ id: {
732
+ $in: {
733
+ entity: entity,
734
+ data: {
735
+ entityId: 1,
736
+ },
737
+ filter: (0, filter_1.addFilterSegment)({
738
+ entity: attr,
739
+ }, filter),
740
+ }
741
+ },
742
+ }, filterMto),
743
+ });
744
+ }
732
745
  }
733
746
  return [4 /*yield*/, this_2.cascadeUpdate(attr, operationMto, context, option2)];
734
747
  case 2:
735
- result2 = _k.sent();
748
+ result2 = _l.sent();
736
749
  this_2.mergeOperationResult(result, result2);
737
750
  return [3 /*break*/, 16];
738
751
  case 3:
@@ -747,33 +760,45 @@ var CascadeStore = /** @class */ (function (_super) {
747
760
  else if (action === 'create') {
748
761
  _d = data, _e = "".concat(attr, "Id"), fkId = _d[_e];
749
762
  (0, assert_1.default)(typeof fkId === 'string');
750
- (0, assert_1.default)((filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) && filterMto.id === fkId); // 这里不能再addFilterSegment,否则会造成后面判断不出来对应的id是多少。在实际情况中跑到这里应该不可能没有id
751
- /* Object.assign(operationMto, {
752
- filter: addFilterSegment(filterMto || {}, {
753
- id: fkId,
754
- }),
755
- }); */
763
+ if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
764
+ // 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
765
+ (0, assert_1.default)(filterMto.id === fkId);
766
+ }
767
+ else {
768
+ // A中data的entityId作为B中filter的主键
769
+ Object.assign(operationMto, {
770
+ filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
771
+ id: fkId,
772
+ }),
773
+ });
774
+ }
756
775
  }
757
776
  else {
758
777
  (0, assert_1.default)(!data.hasOwnProperty("".concat(attr, "Id")));
759
- (0, assert_1.default)((filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) && typeof filterMto.id === 'string'); // 这里不能再addFilterSegment,否则会造成后面判断不出来对应的id是多少。在实际情况中跑到这里应该不可能没有id
760
- /* Object.assign(operationMto, {
761
- filter: addFilterSegment(filterMto || {}, {
762
- id: {
763
- $in: {
764
- entity,
765
- data: {
766
- [`${attr}Id`]: 1,
767
- },
768
- filter,
769
- }
770
- },
771
- }),
772
- }); */
778
+ if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
779
+ // 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
780
+ (0, assert_1.default)(typeof filterMto.id === 'string');
781
+ }
782
+ else {
783
+ // A中data的entityId作为B中filter的主键
784
+ Object.assign(operationMto, {
785
+ filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
786
+ id: {
787
+ $in: {
788
+ entity: entity,
789
+ data: (_j = {},
790
+ _j["".concat(attr, "Id")] = 1,
791
+ _j),
792
+ filter: filter,
793
+ }
794
+ },
795
+ }),
796
+ });
797
+ }
773
798
  }
774
799
  return [4 /*yield*/, this_2.cascadeUpdate(relation, operationMto, context, option2)];
775
800
  case 4:
776
- result2 = _k.sent();
801
+ result2 = _l.sent();
777
802
  this_2.mergeOperationResult(result, result2);
778
803
  return [3 /*break*/, 16];
779
804
  case 5:
@@ -894,37 +919,37 @@ var CascadeStore = /** @class */ (function (_super) {
894
919
  });
895
920
  }); };
896
921
  if (!(otmOperations instanceof Array)) return [3 /*break*/, 14];
897
- _k.label = 6;
922
+ _l.label = 6;
898
923
  case 6:
899
- _k.trys.push([6, 11, 12, 13]);
924
+ _l.trys.push([6, 11, 12, 13]);
900
925
  otmOperations_1 = (e_2 = void 0, tslib_1.__values(otmOperations)), otmOperations_1_1 = otmOperations_1.next();
901
- _k.label = 7;
926
+ _l.label = 7;
902
927
  case 7:
903
928
  if (!!otmOperations_1_1.done) return [3 /*break*/, 10];
904
929
  oper = otmOperations_1_1.value;
905
930
  return [4 /*yield*/, dealWithOneToMany(oper)];
906
931
  case 8:
907
- _k.sent();
908
- _k.label = 9;
932
+ _l.sent();
933
+ _l.label = 9;
909
934
  case 9:
910
935
  otmOperations_1_1 = otmOperations_1.next();
911
936
  return [3 /*break*/, 7];
912
937
  case 10: return [3 /*break*/, 13];
913
938
  case 11:
914
- e_2_1 = _k.sent();
939
+ e_2_1 = _l.sent();
915
940
  e_2 = { error: e_2_1 };
916
941
  return [3 /*break*/, 13];
917
942
  case 12:
918
943
  try {
919
- if (otmOperations_1_1 && !otmOperations_1_1.done && (_j = otmOperations_1.return)) _j.call(otmOperations_1);
944
+ if (otmOperations_1_1 && !otmOperations_1_1.done && (_k = otmOperations_1.return)) _k.call(otmOperations_1);
920
945
  }
921
946
  finally { if (e_2) throw e_2.error; }
922
947
  return [7 /*endfinally*/];
923
948
  case 13: return [3 /*break*/, 16];
924
949
  case 14: return [4 /*yield*/, dealWithOneToMany(otmOperations)];
925
950
  case 15:
926
- _k.sent();
927
- _k.label = 16;
951
+ _l.sent();
952
+ _l.label = 16;
928
953
  case 16: return [2 /*return*/];
929
954
  }
930
955
  });
@@ -1,7 +1,7 @@
1
1
  import { EntityDict as BaseEntityDict } from '../base-app-domain';
2
2
  import { UniversalContext } from '../store/UniversalContext';
3
3
  import { OpSchema as Modi } from '../base-app-domain/Modi/Schema';
4
- import { Checker, Operation, StorageSchema, EntityDict, Context, OperateOption } from '../types';
4
+ import { Checker, Operation, StorageSchema, EntityDict, Context, OperateOption, Trigger } from '../types';
5
5
  export declare function createOperationsFromModies(modies: Modi[]): Array<{
6
6
  operation: Operation<string, Object, Object>;
7
7
  entity: string;
@@ -9,4 +9,4 @@ export declare function createOperationsFromModies(modies: Modi[]): Array<{
9
9
  export declare function applyModis<ED extends EntityDict & BaseEntityDict, Cxt extends UniversalContext<ED>, Op extends OperateOption>(filter: ED['modi']['Selection']['filter'], context: Cxt, option: Op): Promise<import("../types").OperationResult<ED>>;
10
10
  export declare function abandonModis<ED extends EntityDict & BaseEntityDict, Cxt extends UniversalContext<ED>, Op extends OperateOption>(filter: ED['modi']['Selection']['filter'], context: Cxt, option: Op): Promise<import("../types").OperationResult<ED>>;
11
11
  export declare function createModiRelatedCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>): Checker<ED, keyof ED, Cxt>[];
12
- export declare function createModiRelatedTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>): void;
12
+ export declare function createModiRelatedTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>): Trigger<ED, keyof ED, Cxt>[];
package/lib/store/modi.js CHANGED
@@ -186,5 +186,6 @@ function createModiRelatedTriggers(schema) {
186
186
  for (var entity in schema) {
187
187
  _loop_2(entity);
188
188
  }
189
+ return triggers;
189
190
  }
190
191
  exports.createModiRelatedTriggers = createModiRelatedTriggers;
@@ -2,4 +2,4 @@ import { EntityDict as BaseEntityDict } from '../base-app-domain';
2
2
  import { StorageSchema, EntityDict, Context } from '../types';
3
3
  declare const _default: import("../types").Trigger<BaseEntityDict, "modi", import("../store/UniversalContext").UniversalContext<BaseEntityDict>>[];
4
4
  export default _default;
5
- export declare function createDynamicTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>): void;
5
+ export declare function createDynamicTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>): import("../types").Trigger<ED, keyof ED, Cxt>[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-domain",
3
- "version": "1.1.2",
3
+ "version": "1.1.5",
4
4
  "author": {
5
5
  "name": "XuChang"
6
6
  },