oak-domain 1.1.4 → 1.1.7

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.
@@ -4,11 +4,13 @@ export declare type AppendOnlyAction = ReadOnlyAction | 'create';
4
4
  export declare type ExcludeUpdateAction = AppendOnlyAction | 'remove';
5
5
  export declare type ExcludeRemoveAction = AppendOnlyAction | 'update';
6
6
  export declare type GenericAction = 'update' | ExcludeUpdateAction;
7
+ export declare type RelationAction = 'grant' | 'revoke';
7
8
  export declare const readOnlyActions: string[];
8
9
  export declare const appendOnlyActions: string[];
9
10
  export declare const excludeUpdateActions: string[];
10
11
  export declare const exludeRemoveActions: string[];
11
12
  export declare const genericActions: string[];
13
+ export declare const relationActions: string[];
12
14
  export declare type AbleAction = 'enable' | 'disable';
13
15
  export declare type AbleState = 'enabled' | 'disabled';
14
16
  export declare const makeAbleActionDef: (initialState?: AbleState) => ActionDef<AbleAction, AbleState>;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeAbleActionDef = exports.genericActions = exports.exludeRemoveActions = exports.excludeUpdateActions = exports.appendOnlyActions = exports.readOnlyActions = void 0;
3
+ exports.makeAbleActionDef = exports.relationActions = exports.genericActions = exports.exludeRemoveActions = exports.excludeUpdateActions = exports.appendOnlyActions = exports.readOnlyActions = void 0;
4
4
  exports.readOnlyActions = ['count', 'stat', 'download', 'select'];
5
5
  exports.appendOnlyActions = exports.readOnlyActions.concat('create');
6
6
  exports.excludeUpdateActions = exports.appendOnlyActions.concat('remove');
7
7
  exports.exludeRemoveActions = exports.appendOnlyActions.concat('update');
8
8
  exports.genericActions = exports.excludeUpdateActions.concat('update');
9
+ exports.relationActions = ['grant', 'revoke'];
9
10
  var makeAbleActionDef = function (initialState) { return ({
10
11
  stm: {
11
12
  enable: ['disabled', 'enabled'],
@@ -141,7 +141,7 @@ export declare type UpdateOperationData = FormUpdateData<OpSchema> & {
141
141
  modiEntitys$modi?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "modi" | "modiId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "modi" | "modiId">>>;
142
142
  operEntitys$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">>>;
143
143
  };
144
- export declare type UpdateOperation = OakOperation<ParticularAction | "update" | string, UpdateOperationData, Filter, Sorter>;
144
+ export declare type UpdateOperation = OakOperation<"update" | ParticularAction | string, UpdateOperationData, Filter, Sorter>;
145
145
  export declare type RemoveOperationData = {};
146
146
  export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
147
147
  export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation | SelectOperation;
@@ -3,7 +3,7 @@ import { Q_DateValue, Q_StringValue, NodeId, MakeFilter, ExprOp, ExpressionKey }
3
3
  import { OneOf } from "../../types/Polyfill";
4
4
  import * as SubQuery from "../_SubQuery";
5
5
  import { FormCreateData, FormUpdateData, Operation as OakOperation, MakeAction as OakMakeAction } from "../../types/Entity";
6
- import { GenericAction } from "../../actions/action";
6
+ import { GenericAction, RelationAction } from "../../actions/action";
7
7
  import * as Oper from "../Oper/Schema";
8
8
  import * as OperEntity from "../OperEntity/Schema";
9
9
  import * as ModiEntity from "../ModiEntity/Schema";
@@ -118,7 +118,7 @@ export declare type UpdateOperationData = FormUpdateData<OpSchema> & {
118
118
  operEntitys$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">>>;
119
119
  modiEntitys$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>;
120
120
  };
121
- export declare type UpdateOperation = OakOperation<"update" | string, UpdateOperationData, Filter, Sorter>;
121
+ export declare type UpdateOperation = OakOperation<"update" | RelationAction | string, UpdateOperationData, Filter, Sorter>;
122
122
  export declare type RemoveOperationData = {};
123
123
  export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
124
124
  export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation | SelectOperation;
@@ -128,7 +128,7 @@ export declare type FullAttr = NativeAttr | `opers$${number}.${Oper.NativeAttr}`
128
128
  export declare type EntityDef = {
129
129
  Schema: Schema;
130
130
  OpSchema: OpSchema;
131
- Action: OakMakeAction<GenericAction> | string;
131
+ Action: OakMakeAction<GenericAction | RelationAction> | string;
132
132
  Selection: Selection;
133
133
  Operation: Operation;
134
134
  Create: CreateOperation;
@@ -21,5 +21,5 @@ exports.desc = {
21
21
  }
22
22
  },
23
23
  actionType: "crud",
24
- actions: action_1.genericActions
24
+ actions: action_1.genericActions.concat(action_1.relationActions)
25
25
  };
@@ -24,6 +24,7 @@ var ActionImportStatements = function () { return [
24
24
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("ReadOnlyAction")),
25
25
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("ExcludeUpdateAction")),
26
26
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("ExcludeRemoveAction")),
27
+ factory.createImportSpecifier(false, undefined, factory.createIdentifier("RelationAction")),
27
28
  ])), factory.createStringLiteral((0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)()), undefined)
28
29
  ]; };
29
30
  var ActionAsts = {};
@@ -201,7 +202,7 @@ function getStringTextFromUnionStringLiterals(moduleName, filename, node, progra
201
202
  return [action];
202
203
  }
203
204
  }
204
- var RESERVED_ACTION_NAMES = ['GenericAction', 'ParticularAction', 'ExcludeRemoveAction', 'ExcludeUpdateAction', 'ReadOnlyAction', 'AppendOnlyAction'];
205
+ var RESERVED_ACTION_NAMES = ['GenericAction', 'ParticularAction', 'ExcludeRemoveAction', 'ExcludeUpdateAction', 'ReadOnlyAction', 'AppendOnlyAction', 'RelationAction'];
205
206
  var action_1 = require("../actions/action");
206
207
  var DataType_1 = require("../types/DataType");
207
208
  var Entity_1 = require("../types/Entity");
@@ -212,8 +213,11 @@ var OriginActionDict = {
212
213
  'appendOnly': 'AppendOnlyAction',
213
214
  'readOnly': 'ReadOnlyAction',
214
215
  };
215
- function dealWithActions(moduleName, filename, node, program, sourceFile) {
216
+ function dealWithActions(moduleName, filename, node, program, sourceFile, hasRelationDef) {
216
217
  var actionTexts = action_1.genericActions.map(function (ele) { return ele; });
218
+ if (hasRelationDef) {
219
+ actionTexts.push.apply(actionTexts, tslib_1.__spreadArray([], tslib_1.__read(action_1.relationActions), false));
220
+ }
217
221
  if (ts.isUnionTypeNode(node)) {
218
222
  var actionNames = node.types.map(function (ele) {
219
223
  if (ts.isTypeReferenceNode(ele) && ts.isIdentifier(ele.typeName)) {
@@ -494,13 +498,18 @@ function analyzeEntity(filename, path, program) {
494
498
  hasActionDef = true;
495
499
  var modifiers = [factory.createModifier(ts.SyntaxKind.ExportKeyword)];
496
500
  pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node, node.decorators, modifiers, factory.createIdentifier('ParticularAction'), node.typeParameters, node.type), sourceFile);
497
- pushStatementIntoActionAst(moduleName, factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Action"), undefined, factory.createUnionTypeNode([
501
+ var actionDefNodes = [
498
502
  factory.createTypeReferenceNode(OriginActionDict[actionType], undefined),
499
503
  factory.createTypeReferenceNode('ParticularAction', undefined)
500
- ])), sourceFile);
501
- dealWithActions(moduleName, filename, node.type, program, sourceFile);
504
+ ];
505
+ if (hasRelationDef || moduleName === 'User') {
506
+ actionDefNodes.push(factory.createTypeReferenceNode('RelationAction', undefined));
507
+ }
508
+ pushStatementIntoActionAst(moduleName, factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Action"), undefined, factory.createUnionTypeNode(actionDefNodes)), sourceFile);
509
+ dealWithActions(moduleName, filename, node.type, program, sourceFile, hasRelationDef || moduleName === 'User');
502
510
  }
503
511
  else if (node.name.text === 'Relation') {
512
+ (0, assert_1.default)(!hasActionDef, "\u3010".concat(filename, "\u3011action\u5B9A\u4E49\u987B\u5728Relation\u4E4B\u540E"));
504
513
  (0, assert_1.default)(!localeDef, "\u3010".concat(filename, "\u3011locale\u5B9A\u4E49\u987B\u5728Relation\u4E4B\u540E"));
505
514
  // 增加userXXX对象的描述
506
515
  if (ts.isLiteralTypeNode(node.type)) {
@@ -783,6 +792,7 @@ function analyzeEntity(filename, path, program) {
783
792
  toModi: toModi,
784
793
  actionType: actionType,
785
794
  static: _static,
795
+ hasRelationDef: hasRelationDef,
786
796
  };
787
797
  if (hasFulltextIndex) {
788
798
  (0, lodash_1.assign)(schema, {
@@ -2244,12 +2254,13 @@ function constructActions(statements, entity) {
2244
2254
  }
2245
2255
  statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("UpdateOperationData"), undefined, factory.createIntersectionTypeNode(adNodes)));
2246
2256
  // UpdateOperation
2247
- var actionTypeNodes = ActionAsts[entity] ? [
2248
- factory.createTypeReferenceNode('ParticularAction'),
2249
- factory.createLiteralTypeNode(factory.createStringLiteral("update"))
2250
- ] : [
2251
- factory.createLiteralTypeNode(factory.createStringLiteral("update"))
2252
- ];
2257
+ var actionTypeNodes = [factory.createLiteralTypeNode(factory.createStringLiteral("update"))];
2258
+ if (ActionAsts[entity]) {
2259
+ actionTypeNodes.push(factory.createTypeReferenceNode('ParticularAction'));
2260
+ }
2261
+ if (Schema[entity].hasRelationDef || entity === 'User') {
2262
+ actionTypeNodes.push(factory.createTypeReferenceNode('RelationAction'));
2263
+ }
2253
2264
  if (process.env.COMPLING_AS_LIB) {
2254
2265
  actionTypeNodes.push(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
2255
2266
  }
@@ -2603,7 +2614,9 @@ function outputSchema(outputDir, printer) {
2603
2614
  ])), moduleSpecifier, undefined));
2604
2615
  }
2605
2616
  }
2606
- statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports(localActions.map(function (ele) { return factory.createImportSpecifier(false, undefined, factory.createIdentifier(ele)); }))), factory.createStringLiteral('./Action'), undefined));
2617
+ statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports(localActions.map(function (ele) { return factory.createImportSpecifier(false, undefined, factory.createIdentifier(ele)); }))), factory.createStringLiteral('./Action'), undefined), factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
2618
+ factory.createImportSpecifier(false, undefined, factory.createIdentifier("RelationAction")),
2619
+ ])), factory.createStringLiteral((0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)()), undefined));
2607
2620
  }
2608
2621
  else {
2609
2622
  statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
@@ -2612,6 +2625,7 @@ function outputSchema(outputDir, printer) {
2612
2625
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("ReadOnlyAction")),
2613
2626
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("ExcludeUpdateAction")),
2614
2627
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("ExcludeRemoveAction")),
2628
+ factory.createImportSpecifier(false, undefined, factory.createIdentifier("RelationAction")),
2615
2629
  ])), factory.createStringLiteral((0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)()), undefined));
2616
2630
  }
2617
2631
  constructSchema(statements, entity);
@@ -2621,9 +2635,17 @@ function outputSchema(outputDir, printer) {
2621
2635
  constructActions(statements, entity);
2622
2636
  constructQuery(statements, entity);
2623
2637
  constructFullAttrs(statements, entity);
2624
- var actionTypeNode = factory.createTypeReferenceNode(factory.createIdentifier('OakMakeAction'), [
2625
- ActionAsts[entity] ? factory.createTypeReferenceNode('Action') : factory.createTypeReferenceNode(OriginActionDict[Schema[entity].actionType])
2626
- ]);
2638
+ var makeActionArguments = [];
2639
+ if (ActionAsts[entity]) {
2640
+ makeActionArguments.push(factory.createTypeReferenceNode('Action'));
2641
+ }
2642
+ else {
2643
+ makeActionArguments.push(factory.createTypeReferenceNode(OriginActionDict[Schema[entity].actionType]));
2644
+ }
2645
+ if (Schema[entity].hasRelationDef || entity === 'User') {
2646
+ makeActionArguments.push(factory.createTypeReferenceNode('RelationAction'));
2647
+ }
2648
+ var actionTypeNode = factory.createTypeReferenceNode(factory.createIdentifier('OakMakeAction'), makeActionArguments.length === 1 ? makeActionArguments : [factory.createUnionTypeNode(makeActionArguments)]);
2627
2649
  var EntityDefAttrs = [
2628
2650
  factory.createPropertySignature(undefined, factory.createIdentifier("Schema"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Schema"), undefined)),
2629
2651
  factory.createPropertySignature(undefined, factory.createIdentifier("OpSchema"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OpSchema"), undefined)),
@@ -2906,17 +2928,18 @@ function outputStorage(outputDir, printer) {
2906
2928
  factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("StorageDesc"))])), factory.createStringLiteral("".concat((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(), "Storage")), undefined),
2907
2929
  factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("OpSchema"))])), factory.createStringLiteral("./Schema"), undefined)
2908
2930
  ];
2931
+ var needImportActions = [];
2909
2932
  switch (actionType) {
2910
2933
  case 'readOnly': {
2911
- statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("readOnlyActions"), factory.createIdentifier("actions"))])), factory.createStringLiteral((0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)()), undefined));
2934
+ needImportActions.push(factory.createImportSpecifier(false, factory.createIdentifier("readOnlyActions"), factory.createIdentifier("actions")));
2912
2935
  break;
2913
2936
  }
2914
2937
  case 'appendOnly': {
2915
- statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("appendOnlyActions"), factory.createIdentifier("actions"))])), factory.createStringLiteral((0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)()), undefined));
2938
+ needImportActions.push(factory.createImportSpecifier(false, factory.createIdentifier("appendOnlyActions"), factory.createIdentifier("actions")));
2916
2939
  break;
2917
2940
  }
2918
2941
  case 'excludeUpdate': {
2919
- statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("excludeUpdateActions"), factory.createIdentifier("actions"))])), factory.createStringLiteral((0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)()), undefined));
2942
+ needImportActions.push(factory.createImportSpecifier(false, factory.createIdentifier("excludeUpdateActions"), factory.createIdentifier("actions")));
2920
2943
  break;
2921
2944
  }
2922
2945
  default: {
@@ -2924,10 +2947,16 @@ function outputStorage(outputDir, printer) {
2924
2947
  statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("actions"))])), factory.createStringLiteral("./Action"), undefined));
2925
2948
  }
2926
2949
  else {
2927
- statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("genericActions"), factory.createIdentifier("actions"))])), factory.createStringLiteral((0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)()), undefined));
2950
+ needImportActions.push(factory.createImportSpecifier(false, factory.createIdentifier("genericActions"), factory.createIdentifier("actions")));
2928
2951
  }
2929
2952
  }
2930
2953
  }
2954
+ if (Schema[entity].hasRelationDef || entity === 'User') {
2955
+ needImportActions.push(factory.createImportSpecifier(false, undefined, factory.createIdentifier("relationActions")));
2956
+ }
2957
+ if (needImportActions.length > 0) {
2958
+ statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports(needImportActions)), factory.createStringLiteral((0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)()), undefined));
2959
+ }
2931
2960
  var propertyAssignments = [];
2932
2961
  var attributes = constructAttributes(entity);
2933
2962
  propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("attributes"), factory.createObjectLiteralExpression(attributes, true)));
@@ -2943,7 +2972,13 @@ function outputStorage(outputDir, printer) {
2943
2972
  if (_static || actionType === 'readOnly') {
2944
2973
  propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("static"), factory.createTrue()));
2945
2974
  }
2946
- propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("actionType"), factory.createStringLiteral(actionType)), factory.createShorthandPropertyAssignment(factory.createIdentifier("actions"), undefined));
2975
+ propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("actionType"), factory.createStringLiteral(actionType)));
2976
+ if (Schema[entity].hasRelationDef || entity === 'User') {
2977
+ propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("actions"), factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("actions"), factory.createIdentifier("concat")), undefined, [factory.createIdentifier("relationActions")])));
2978
+ }
2979
+ else {
2980
+ propertyAssignments.push(factory.createShorthandPropertyAssignment(factory.createIdentifier("actions"), undefined));
2981
+ }
2947
2982
  if (indexExpressions.length > 0) {
2948
2983
  propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("indexes"), factory.createArrayLiteralExpression(indexExpressions, true)));
2949
2984
  }
@@ -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 === null || filterMto === void 0 ? void 0 : 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 === null || filterMto === void 0 ? void 0 : 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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-domain",
3
- "version": "1.1.4",
3
+ "version": "1.1.7",
4
4
  "author": {
5
5
  "name": "XuChang"
6
6
  },