oak-domain 3.0.2 → 3.0.4

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.
Files changed (157) hide show
  1. package/lib/actions/action.d.ts +8 -8
  2. package/lib/actions/action.js +2 -2
  3. package/lib/actions/relation.d.ts +1 -1
  4. package/lib/actions/relation.js +9 -22
  5. package/lib/base-app-domain/ActionAuth/Schema.d.ts +68 -42
  6. package/lib/base-app-domain/ActionAuth/Storage.js +12 -15
  7. package/lib/base-app-domain/ActionDefDict.d.ts +2 -3
  8. package/lib/base-app-domain/ActionDefDict.js +3 -5
  9. package/lib/base-app-domain/EntityDict.d.ts +5 -1
  10. package/lib/base-app-domain/I18n/Schema.d.ts +24 -24
  11. package/lib/base-app-domain/I18n/Storage.js +5 -5
  12. package/lib/base-app-domain/Modi/Action.d.ts +4 -4
  13. package/lib/base-app-domain/Modi/Action.js +3 -3
  14. package/lib/base-app-domain/Modi/Schema.d.ts +24 -24
  15. package/lib/base-app-domain/Modi/Storage.js +3 -3
  16. package/lib/base-app-domain/ModiEntity/Schema.d.ts +128 -55
  17. package/lib/base-app-domain/ModiEntity/Storage.js +2 -2
  18. package/lib/base-app-domain/Oper/Schema.d.ts +30 -29
  19. package/lib/base-app-domain/Oper/Storage.js +1 -1
  20. package/lib/base-app-domain/OperEntity/Schema.d.ts +126 -53
  21. package/lib/base-app-domain/OperEntity/Storage.js +2 -2
  22. package/lib/base-app-domain/Path/Schema.d.ts +149 -0
  23. package/lib/base-app-domain/Path/Schema.js +2 -0
  24. package/lib/base-app-domain/Path/Storage.d.ts +3 -0
  25. package/lib/base-app-domain/Path/Storage.js +54 -0
  26. package/lib/base-app-domain/Relation/Schema.d.ts +34 -34
  27. package/lib/base-app-domain/Relation/Storage.js +6 -6
  28. package/lib/base-app-domain/Relation.d.ts +0 -8
  29. package/lib/base-app-domain/Relation.js +1 -7
  30. package/lib/base-app-domain/RelationAuth/Schema.d.ts +74 -40
  31. package/lib/base-app-domain/RelationAuth/Storage.js +9 -11
  32. package/lib/base-app-domain/Storage.js +20 -16
  33. package/lib/base-app-domain/User/Action.d.ts +4 -4
  34. package/lib/base-app-domain/User/Action.js +3 -3
  35. package/lib/base-app-domain/User/Schema.d.ts +40 -27
  36. package/lib/base-app-domain/User/Storage.js +1 -1
  37. package/lib/base-app-domain/UserEntityClaim/Schema.d.ts +264 -0
  38. package/lib/base-app-domain/UserEntityClaim/Schema.js +2 -0
  39. package/lib/base-app-domain/UserEntityClaim/Storage.d.ts +3 -0
  40. package/lib/base-app-domain/UserEntityClaim/Storage.js +37 -0
  41. package/lib/base-app-domain/UserEntityGrant/Action.d.ts +2 -2
  42. package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +55 -81
  43. package/lib/base-app-domain/UserEntityGrant/Storage.js +7 -11
  44. package/lib/base-app-domain/UserRelation/Schema.d.ts +50 -36
  45. package/lib/base-app-domain/UserRelation/Storage.js +7 -7
  46. package/lib/base-app-domain/_SubQuery.d.ts +45 -15
  47. package/lib/base-app-domain/index.js +1 -1
  48. package/lib/checkers/index.js +6 -7
  49. package/lib/compiler/env.js +16 -18
  50. package/lib/compiler/localeBuilder.js +83 -79
  51. package/lib/compiler/schemalBuilder.d.ts +16 -0
  52. package/lib/compiler/schemalBuilder.js +1160 -1378
  53. package/lib/entities/ActionAuth.d.ts +3 -5
  54. package/lib/entities/ActionAuth.js +9 -7
  55. package/lib/entities/I18n.js +1 -1
  56. package/lib/entities/Modi.js +2 -2
  57. package/lib/entities/ModiEntity.js +1 -1
  58. package/lib/entities/Oper.js +1 -1
  59. package/lib/entities/OperEntity.js +1 -1
  60. package/lib/entities/Path.d.ts +8 -0
  61. package/lib/entities/Path.js +35 -0
  62. package/lib/entities/Relation.js +1 -1
  63. package/lib/entities/RelationAuth.d.ts +2 -2
  64. package/lib/entities/RelationAuth.js +1 -1
  65. package/lib/entities/User.js +2 -2
  66. package/lib/entities/UserEntityClaim.d.ts +13 -0
  67. package/lib/entities/UserEntityClaim.js +17 -0
  68. package/lib/entities/UserEntityGrant.d.ts +5 -4
  69. package/lib/entities/UserEntityGrant.js +4 -7
  70. package/lib/entities/UserRelation.js +1 -1
  71. package/lib/index.d.ts +23 -0
  72. package/lib/index.js +37 -0
  73. package/lib/store/AsyncRowStore.d.ts +2 -1
  74. package/lib/store/AsyncRowStore.js +75 -149
  75. package/lib/store/CascadeStore.js +968 -1341
  76. package/lib/store/RelationAuth.d.ts +9 -16
  77. package/lib/store/RelationAuth.js +752 -910
  78. package/lib/store/SyncRowStore.d.ts +1 -1
  79. package/lib/store/SyncRowStore.js +27 -26
  80. package/lib/store/TriggerExecutor.d.ts +17 -10
  81. package/lib/store/TriggerExecutor.js +350 -423
  82. package/lib/store/actionAuth.js +13 -28
  83. package/lib/store/actionDef.js +142 -215
  84. package/lib/store/checker.js +225 -361
  85. package/lib/store/filter.d.ts +2 -3
  86. package/lib/store/filter.js +451 -589
  87. package/lib/store/modi.js +116 -177
  88. package/lib/store/relation.js +17 -17
  89. package/lib/timers/oper.d.ts +1 -1
  90. package/lib/timers/oper.js +44 -47
  91. package/lib/timers/vaccum.d.ts +2 -2
  92. package/lib/timers/vaccum.js +100 -165
  93. package/lib/triggers/index.js +1 -1
  94. package/lib/types/Action.d.ts +7 -7
  95. package/lib/types/AppLoader.d.ts +8 -2
  96. package/lib/types/AppLoader.js +4 -4
  97. package/lib/types/Auth.d.ts +15 -19
  98. package/lib/types/Connector.d.ts +19 -14
  99. package/lib/types/Connector.js +0 -7
  100. package/lib/types/DataType.d.ts +19 -18
  101. package/lib/types/DataType.js +1 -1
  102. package/lib/types/Demand.d.ts +25 -25
  103. package/lib/types/Endpoint.d.ts +1 -1
  104. package/lib/types/Entity.d.ts +62 -53
  105. package/lib/types/Entity.js +4 -3
  106. package/lib/types/EntityDesc.d.ts +2 -1
  107. package/lib/types/Environment.d.ts +4 -4
  108. package/lib/types/Exception.d.ts +34 -2
  109. package/lib/types/Exception.js +214 -197
  110. package/lib/types/Expression.d.ts +14 -14
  111. package/lib/types/Expression.js +54 -87
  112. package/lib/types/Geo.d.ts +6 -6
  113. package/lib/types/Locale.d.ts +5 -5
  114. package/lib/types/Polyfill.d.ts +9 -9
  115. package/lib/types/Port.d.ts +4 -4
  116. package/lib/types/RowStore.d.ts +3 -3
  117. package/lib/types/RowStore.js +18 -19
  118. package/lib/types/Storage.d.ts +5 -4
  119. package/lib/types/Style.d.ts +2 -2
  120. package/lib/types/Timer.d.ts +3 -3
  121. package/lib/types/Trigger.d.ts +30 -14
  122. package/lib/types/Trigger.js +6 -2
  123. package/lib/types/Watcher.d.ts +2 -2
  124. package/lib/types/index.d.ts +1 -0
  125. package/lib/types/index.js +2 -1
  126. package/lib/types/schema/DataTypes.d.ts +7 -7
  127. package/lib/utils/SimpleConnector.d.ts +26 -10
  128. package/lib/utils/SimpleConnector.js +167 -141
  129. package/lib/utils/assert.js +2 -2
  130. package/lib/utils/concurrent.d.ts +1 -1
  131. package/lib/utils/concurrent.js +31 -57
  132. package/lib/utils/date.js +2 -2
  133. package/lib/utils/geo.js +8 -8
  134. package/lib/utils/lodash.d.ts +3 -1
  135. package/lib/utils/lodash.js +21 -34
  136. package/lib/utils/mask.js +12 -13
  137. package/lib/utils/money.d.ts +1 -1
  138. package/lib/utils/money.js +22 -11
  139. package/lib/utils/projection.d.ts +4 -0
  140. package/lib/utils/projection.js +15 -0
  141. package/lib/utils/random/random.js +11 -16
  142. package/lib/utils/random/random.mp.js +7 -18
  143. package/lib/utils/random/random.web.js +6 -12
  144. package/lib/utils/string.d.ts +4 -4
  145. package/lib/utils/string.js +19 -32
  146. package/lib/utils/url.js +5 -4
  147. package/lib/utils/uuid.d.ts +1 -1
  148. package/lib/utils/uuid.js +46 -85
  149. package/lib/utils/validator.d.ts +4 -3
  150. package/lib/utils/validator.js +35 -32
  151. package/lib/utils/version.js +6 -6
  152. package/package.json +7 -7
  153. package/src/entities/ActionAuth.ts +10 -10
  154. package/src/entities/Path.ts +43 -0
  155. package/src/entities/RelationAuth.ts +2 -1
  156. package/src/entities/UserEntityClaim.ts +30 -0
  157. package/src/entities/UserEntityGrant.ts +9 -12
@@ -1,24 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildSchema = exports.analyzeEntities = exports.registerDeducedRelationMap = exports.registerFixedDestinationPathMap = exports.registerIgnoredRelationPathMap = exports.registerFreeEntities = exports.registerIgnoredForeignKeyMap = void 0;
4
- var tslib_1 = require("tslib");
5
- var path_1 = tslib_1.__importDefault(require("path"));
6
- var assert_1 = tslib_1.__importDefault(require("assert"));
7
- var fs_1 = require("fs");
8
- var fs_extra_1 = require("fs-extra");
9
- var lodash_1 = require("lodash");
10
- var ts = tslib_1.__importStar(require("typescript"));
11
- var factory = ts.factory;
12
- var env_1 = require("./env");
13
- var string_1 = require("../utils/string");
14
- var Schema = {};
15
- var OneToMany = {};
16
- var ManyToOne = {};
17
- var ReversePointerEntities = {};
18
- var ReversePointerRelations = {};
19
- var ActionImportStatements = function () { return [
20
- factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("ActionDef"))])), factory.createStringLiteral("".concat((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(), "Action")), undefined),
21
- factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const assert_1 = tslib_1.__importDefault(require("assert"));
7
+ const fs_1 = require("fs");
8
+ const fs_extra_1 = require("fs-extra");
9
+ const lodash_1 = require("lodash");
10
+ const ts = tslib_1.__importStar(require("typescript"));
11
+ const { factory } = ts;
12
+ const env_1 = require("./env");
13
+ const string_1 = require("../utils/string");
14
+ const Schema = {};
15
+ const OneToMany = {};
16
+ const ManyToOne = {};
17
+ const ReversePointerEntities = {};
18
+ const ReversePointerRelations = {};
19
+ const ActionImportStatements = () => [
20
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("ActionDef"))])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)()}Action`), undefined),
21
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
22
22
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("GenericAction")),
23
23
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("AppendOnlyAction")),
24
24
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("ReadOnlyAction")),
@@ -26,42 +26,41 @@ var ActionImportStatements = function () { return [
26
26
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("ExcludeRemoveAction")),
27
27
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("RelationAction")),
28
28
  ])), factory.createStringLiteral((0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)()), undefined)
29
- ]; };
30
- var ActionAsts = {};
31
- var SchemaAsts = {};
29
+ ];
30
+ const ActionAsts = {};
31
+ const SchemaAsts = {};
32
32
  function addRelationship(many, one, key, notNull) {
33
- var _a, _b;
34
- var _c = ManyToOne, _d = many, manySet = _c[_d];
35
- var one2 = one === 'Schema' ? many : one;
33
+ const { [many]: manySet } = ManyToOne;
34
+ const one2 = one === 'Schema' ? many : one;
36
35
  if (manySet) {
37
36
  manySet.push([one2, key, notNull]);
38
37
  }
39
38
  else {
40
- (0, lodash_1.assign)(ManyToOne, (_a = {},
41
- _a[many] = [[one2, key, notNull]],
42
- _a));
39
+ (0, lodash_1.assign)(ManyToOne, {
40
+ [many]: [[one2, key, notNull]],
41
+ });
43
42
  }
44
- var _e = OneToMany, _f = one2, oneSet = _e[_f];
43
+ const { [one2]: oneSet } = OneToMany;
45
44
  if (oneSet) {
46
45
  oneSet.push([many, key, notNull]);
47
46
  }
48
47
  else {
49
- (0, lodash_1.assign)(OneToMany, (_b = {},
50
- _b[one2] = [[many, key, notNull]],
51
- _b));
48
+ (0, lodash_1.assign)(OneToMany, {
49
+ [one2]: [[many, key, notNull]],
50
+ });
52
51
  }
53
52
  }
54
53
  /**
55
54
  * 对relationship去重。一旦发生对象重定义这里就有可能重复
56
55
  */
57
56
  function uniqRelationships() {
58
- for (var entity in ManyToOne) {
59
- ManyToOne[entity] = (0, lodash_1.uniqBy)(ManyToOne[entity], function (ele) { return "".concat(ele[0], "-").concat(ele[1]); });
57
+ for (const entity in ManyToOne) {
58
+ ManyToOne[entity] = (0, lodash_1.uniqBy)(ManyToOne[entity], (ele) => `${ele[0]}-${ele[1]}`);
60
59
  }
61
- for (var entity in OneToMany) {
62
- OneToMany[entity] = (0, lodash_1.uniqBy)(OneToMany[entity], function (ele) { return "".concat(ele[0], "-").concat(ele[1]); });
60
+ for (const entity in OneToMany) {
61
+ OneToMany[entity] = (0, lodash_1.uniqBy)(OneToMany[entity], (ele) => `${ele[0]}-${ele[1]}`);
63
62
  }
64
- for (var entity in ReversePointerRelations) {
63
+ for (const entity in ReversePointerRelations) {
65
64
  OneToMany[entity] = (0, lodash_1.uniq)(OneToMany[entity]);
66
65
  }
67
66
  }
@@ -72,9 +71,8 @@ function createForeignRef(entity, foreignKey, ref) {
72
71
  return factory.createQualifiedName(factory.createIdentifier(foreignKey), factory.createIdentifier(ref));
73
72
  }
74
73
  function pushStatementIntoActionAst(moduleName, node, sourceFile) {
75
- var _a;
76
74
  // let actionNames;
77
- var actionDefName;
75
+ let actionDefName;
78
76
  /* if (ts.isTypeAliasDeclaration(node) && node.name.text === 'ParticularAction') {
79
77
  const { type } = node;
80
78
  if (ts.isUnionTypeNode(type)) {
@@ -95,10 +93,10 @@ function pushStatementIntoActionAst(moduleName, node, sourceFile) {
95
93
  }
96
94
  } */
97
95
  if (ts.isVariableStatement(node)) {
98
- var declarations = node.declarationList.declarations;
99
- declarations.forEach(function (declaration) {
96
+ const { declarationList: { declarations } } = node;
97
+ declarations.forEach((declaration) => {
100
98
  if (ts.isIdentifier(declaration.name) && declaration.name.text.endsWith('ActionDef')) {
101
- var text = declaration.name.text;
99
+ const { text } = declaration.name;
102
100
  actionDefName = (0, string_1.firstLetterLowerCase)(text.slice(0, text.length - 9));
103
101
  }
104
102
  });
@@ -113,29 +111,28 @@ function pushStatementIntoActionAst(moduleName, node, sourceFile) {
113
111
  }
114
112
  }
115
113
  else {
116
- (0, lodash_1.assign)(ActionAsts, (_a = {},
117
- _a[moduleName] = {
118
- statements: tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(ActionImportStatements()), false), [node], false),
119
- sourceFile: sourceFile,
114
+ (0, lodash_1.assign)(ActionAsts, {
115
+ [moduleName]: {
116
+ statements: [...ActionImportStatements(), node],
117
+ sourceFile,
120
118
  importedFrom: {},
121
119
  // actionNames,
122
120
  actionDefNames: actionDefName ? [actionDefName] : [],
123
- },
124
- _a));
121
+ }
122
+ });
125
123
  }
126
124
  }
127
125
  function pushStatementIntoSchemaAst(moduleName, statement, sourceFile) {
128
- var _a;
129
126
  if (SchemaAsts[moduleName]) {
130
127
  SchemaAsts[moduleName].statements.push(statement);
131
128
  }
132
129
  else {
133
- (0, lodash_1.assign)(SchemaAsts, (_a = {},
134
- _a[moduleName] = {
130
+ (0, lodash_1.assign)(SchemaAsts, {
131
+ [moduleName]: {
135
132
  statements: [statement],
136
- sourceFile: sourceFile,
137
- },
138
- _a));
133
+ sourceFile,
134
+ }
135
+ });
139
136
  }
140
137
  }
141
138
  /**
@@ -144,84 +141,82 @@ function pushStatementIntoSchemaAst(moduleName, statement, sourceFile) {
144
141
  * @param actionDefNode
145
142
  */
146
143
  function checkActionDefNameConsistent(filename, actionDefNode) {
147
- var name = actionDefNode.name, type = actionDefNode.type;
144
+ const { name, type } = actionDefNode;
148
145
  (0, assert_1.default)(ts.isTypeReferenceNode(type));
149
- var typeArguments = type.typeArguments;
146
+ const { typeArguments } = type;
150
147
  (0, assert_1.default)(typeArguments.length === 2);
151
- var _a = tslib_1.__read(typeArguments, 2), actionNode = _a[0], stateNode = _a[1];
152
- (0, assert_1.default)(ts.isIdentifier(name), "\u6587\u4EF6".concat(filename, "\u4E2D\u7684ActionDef").concat(name.text, "\u4E0D\u662F\u4E00\u4E2A\u6709\u6548\u7684\u53D8\u91CF"));
153
- (0, assert_1.default)(name.text.endsWith('ActionDef'), "\u6587\u4EF6".concat(filename, "\u4E2D\u7684ActionDef").concat(name.text, "\u672A\u4EE5ActionDef\u7ED3\u5C3E"));
154
- (0, assert_1.default)(ts.isTypeReferenceNode(actionNode) && ts.isTypeReferenceNode(stateNode), "\u6587\u4EF6".concat(filename, "\u4E2D\u7684ActionDef").concat(name.text, "\u7C7B\u578B\u58F0\u660E\u4E2D\u7684action\u548Cstate\u975E\u6CD5"));
148
+ const [actionNode, stateNode] = typeArguments;
149
+ (0, assert_1.default)(ts.isIdentifier(name), `文件${filename}中的ActionDef${name.text}不是一个有效的变量`);
150
+ (0, assert_1.default)(name.text.endsWith('ActionDef'), `文件${filename}中的ActionDef${name.text}未以ActionDef结尾`);
151
+ (0, assert_1.default)(ts.isTypeReferenceNode(actionNode) && ts.isTypeReferenceNode(stateNode), `文件${filename}中的ActionDef${name.text}类型声明中的action和state非法`);
155
152
  (0, assert_1.default)(ts.isIdentifier(actionNode.typeName) && ts.isIdentifier(stateNode.typeName));
156
- (0, assert_1.default)(actionNode.typeName.text.endsWith('Action'), "\u6587\u4EF6".concat(filename, "\u4E2D\u7684ActionDef").concat(name.text, "\u6240\u5F15\u7528\u7684Action").concat(actionNode.typeName, "\u672A\u4EE5Action\u7ED3\u5C3E"));
157
- (0, assert_1.default)(stateNode.typeName.text.endsWith('State'), "\u6587\u4EF6".concat(filename, "\u4E2D\u7684ActionDef").concat(name.text, "\u6240\u5F15\u7528\u7684Action").concat(stateNode.typeName, "\u672A\u4EE5Action\u7ED3\u5C3E"));
158
- var adfName = name.text.slice(0, name.text.length - 9);
159
- var aName = actionNode.typeName.text.slice(0, actionNode.typeName.text.length - 6);
160
- var sName = stateNode.typeName.text.slice(0, stateNode.typeName.text.length - 5);
161
- (0, assert_1.default)(adfName === aName && aName === sName, "\u6587\u4EF6".concat(filename, "\u4E2D\u7684ActionDef").concat(name.text, "\u4E2DActionDef, Action\u548CState\u7684\u547D\u540D\u89C4\u5219\u4E0D\u4E00\u81F4"));
153
+ (0, assert_1.default)(actionNode.typeName.text.endsWith('Action'), `文件${filename}中的ActionDef${name.text}所引用的Action${actionNode.typeName}未以Action结尾`);
154
+ (0, assert_1.default)(stateNode.typeName.text.endsWith('State'), `文件${filename}中的ActionDef${name.text}所引用的Action${stateNode.typeName}未以Action结尾`);
155
+ const adfName = name.text.slice(0, name.text.length - 9);
156
+ const aName = actionNode.typeName.text.slice(0, actionNode.typeName.text.length - 6);
157
+ const sName = stateNode.typeName.text.slice(0, stateNode.typeName.text.length - 5);
158
+ (0, assert_1.default)(adfName === aName && aName === sName, `文件${filename}中的ActionDef${name.text}中ActionDef, Action和State的命名规则不一致`);
162
159
  }
163
160
  function checkStringLiteralLegal(filename, obj, text, ele) {
164
- (0, assert_1.default)(ts.isLiteralTypeNode(ele) && ts.isStringLiteral(ele.literal), "".concat(filename, "\u4E2D\u5F15\u7528\u7684").concat(obj, " ").concat(text, "\u4E2D\u5B58\u5728\u4E0D\u662Fstringliteral\u7684\u7C7B\u578B"));
165
- (0, assert_1.default)(!ele.literal.text.includes('$'), "".concat(filename, "\u4E2D\u5F15\u7528\u7684action").concat(text, "\u4E2D\u7684").concat(obj, "\u300C").concat(ele.literal.text, "\u300D\u5305\u542B\u975E\u6CD5\u5B57\u7B26$"));
166
- (0, assert_1.default)(ele.literal.text.length > 0, "".concat(filename, "\u4E2D\u5F15\u7528\u7684action").concat(text, "\u4E2D\u7684").concat(obj, "\u300C").concat(ele.literal.text, "\u300D\u957F\u5EA6\u975E\u6CD5"));
167
- (0, assert_1.default)(ele.literal.text.length < env_1.STRING_LITERAL_MAX_LENGTH, "".concat(filename, "\u4E2D\u5F15\u7528\u7684").concat(obj, " ").concat(text, "\u4E2D\u7684\u300C").concat(ele.literal.text, "\u300D\u957F\u5EA6\u8FC7\u957F"));
161
+ (0, assert_1.default)(ts.isLiteralTypeNode(ele) && ts.isStringLiteral(ele.literal), `${filename}中引用的${obj} ${text}中存在不是stringliteral的类型`);
162
+ (0, assert_1.default)(!ele.literal.text.includes('$'), `${filename}中引用的action${text}中的${obj}「${ele.literal.text}」包含非法字符$`);
163
+ (0, assert_1.default)(ele.literal.text.length > 0, `${filename}中引用的action${text}中的${obj}「${ele.literal.text}」长度非法`);
164
+ (0, assert_1.default)(ele.literal.text.length < env_1.STRING_LITERAL_MAX_LENGTH, `${filename}中引用的${obj} ${text}中的「${ele.literal.text}」长度过长`);
168
165
  return ele.literal.text;
169
166
  }
170
167
  function addActionSource(moduleName, name, node) {
171
- var _a;
172
- var ast = ActionAsts[moduleName];
173
- var moduleSpecifier = node.moduleSpecifier;
168
+ const ast = ActionAsts[moduleName];
169
+ const { moduleSpecifier } = node;
174
170
  // todo 目前应该只会引用oak-domain/src/actions/action里的公共action,未来如果有交叉引用这里代码要修正(如果domain中也有引用action_constants这里应该也会错)
175
171
  (0, assert_1.default)(ts.isStringLiteral(moduleSpecifier) && moduleSpecifier.text === (0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)());
176
- (0, lodash_1.assign)(ast.importedFrom, (_a = {},
177
- _a[name.text] = node,
178
- _a));
172
+ (0, lodash_1.assign)(ast.importedFrom, {
173
+ [name.text]: node,
174
+ });
179
175
  }
180
176
  function getStringTextFromUnionStringLiterals(moduleName, filename, node, program) {
181
- var _a;
182
- var checker = program.getTypeChecker();
183
- var symbol = checker.getSymbolAtLocation(node.typeName);
184
- var declaration = symbol === null || symbol === void 0 ? void 0 : symbol.getDeclarations()[0];
185
- var isImport = false;
177
+ const checker = program.getTypeChecker();
178
+ const symbol = checker.getSymbolAtLocation(node.typeName);
179
+ let declaration = symbol?.getDeclarations()[0];
180
+ let isImport = false;
186
181
  /* const typee = checker.getDeclaredTypeOfSymbol(symbol!);
187
182
 
188
183
  const declaration = typee.aliasSymbol!.getDeclarations()![0]; */
189
184
  if (ts.isImportSpecifier(declaration)) {
190
185
  isImport = true;
191
- var typee = checker.getDeclaredTypeOfSymbol(symbol);
186
+ const typee = checker.getDeclaredTypeOfSymbol(symbol);
192
187
  declaration = typee.aliasSymbol.getDeclarations()[0];
193
188
  }
194
189
  (0, assert_1.default)(ts.isTypeAliasDeclaration(declaration));
195
- var type = declaration.type, name = declaration.name;
190
+ const { type, name } = declaration;
196
191
  // assert(ts.isUnionTypeNode(type!) || ts.isLiteralTypeNode(type!), `${filename}中引用的action「${(<ts.Identifier>name).text}」的定义不是union和stringLiteral类型`);
197
192
  // 如果这个action是从外部导入的,在这里要记下来此entity和这个导入之间的关系
198
193
  if (isImport) {
199
- var importDeclartion = symbol.getDeclarations()[0].parent.parent.parent;
194
+ const importDeclartion = symbol.getDeclarations()[0].parent.parent.parent;
200
195
  (0, assert_1.default)(ts.isImportDeclaration(importDeclartion));
201
196
  addActionSource(moduleName, name, importDeclartion);
202
197
  }
203
198
  else {
204
- var ast = ActionAsts[moduleName];
205
- (0, lodash_1.assign)(ast.importedFrom, (_a = {},
206
- _a[name.text] = 'local',
207
- _a));
199
+ const ast = ActionAsts[moduleName];
200
+ (0, lodash_1.assign)(ast.importedFrom, {
201
+ [name.text]: 'local',
202
+ });
208
203
  }
209
204
  if (ts.isUnionTypeNode(type)) {
210
- var actions = type.types.map(function (ele) { return checkStringLiteralLegal(filename, 'action', name.text, ele); });
205
+ const actions = type.types.map(ele => checkStringLiteralLegal(filename, 'action', name.text, ele));
211
206
  return actions;
212
207
  }
213
208
  else {
214
- (0, assert_1.default)(ts.isLiteralTypeNode(type), "".concat(filename, "\u4E2D\u5F15\u7528\u7684action\u300C").concat(name.text, "\u300D\u7684\u5B9A\u4E49\u4E0D\u662Funion\u548CstringLiteral\u7C7B\u578B"));
215
- var action = checkStringLiteralLegal(filename, 'action', name.text, type);
209
+ (0, assert_1.default)(ts.isLiteralTypeNode(type), `${filename}中引用的action「${name.text}」的定义不是union和stringLiteral类型`);
210
+ const action = checkStringLiteralLegal(filename, 'action', name.text, type);
216
211
  return [action];
217
212
  }
218
213
  }
219
- var RESERVED_ACTION_NAMES = ['GenericAction', 'ParticularAction', 'ExcludeRemoveAction', 'ExcludeUpdateAction', 'ReadOnlyAction', 'AppendOnlyAction', 'RelationAction'];
220
- var action_1 = require("../actions/action");
221
- var DataType_1 = require("../types/DataType");
222
- var Entity_1 = require("../types/Entity");
223
- var uuid_1 = require("../utils/uuid");
224
- var OriginActionDict = {
214
+ const RESERVED_ACTION_NAMES = ['GenericAction', 'ParticularAction', 'ExcludeRemoveAction', 'ExcludeUpdateAction', 'ReadOnlyAction', 'AppendOnlyAction', 'RelationAction'];
215
+ const action_1 = require("../actions/action");
216
+ const DataType_1 = require("../types/DataType");
217
+ const Entity_1 = require("../types/Entity");
218
+ const uuid_1 = require("../utils/uuid");
219
+ const OriginActionDict = {
225
220
  'crud': 'GenericAction',
226
221
  'excludeUpdate': 'ExcludeUpdateAction',
227
222
  'excludeRemove': 'ExcludeRemoveAction',
@@ -229,53 +224,52 @@ var OriginActionDict = {
229
224
  'readOnly': 'ReadOnlyAction',
230
225
  };
231
226
  function dealWithActions(moduleName, filename, node, program, sourceFile) {
232
- var actionTexts = action_1.genericActions.map(function (ele) { return ele; });
227
+ const actionTexts = action_1.genericActions.map(ele => ele);
233
228
  if (moduleName === 'User') {
234
- actionTexts.push.apply(actionTexts, tslib_1.__spreadArray([], tslib_1.__read(action_1.relationActions), false));
229
+ actionTexts.push(...action_1.relationActions);
235
230
  }
236
231
  if (ts.isUnionTypeNode(node)) {
237
- var actionNames = node.types.map(function (ele) {
232
+ const actionNames = node.types.map(ele => {
238
233
  if (ts.isTypeReferenceNode(ele) && ts.isIdentifier(ele.typeName)) {
239
234
  return ele.typeName.text;
240
235
  }
241
- }).filter(function (ele) { return !!ele; });
242
- (0, assert_1.default)((0, lodash_1.intersection)(actionNames, RESERVED_ACTION_NAMES).length === 0, "".concat(filename, "\u4E2D\u7684Action\u547D\u540D\u4E0D\u80FD\u662F\u300C").concat(RESERVED_ACTION_NAMES.join(','), "\u300D\u4E4B\u4E00"));
243
- node.types.forEach(function (ele) {
236
+ }).filter(ele => !!ele);
237
+ (0, assert_1.default)((0, lodash_1.intersection)(actionNames, RESERVED_ACTION_NAMES).length === 0, `${filename}中的Action命名不能是「${RESERVED_ACTION_NAMES.join(',')}」之一`);
238
+ node.types.forEach(ele => {
244
239
  if (ts.isTypeReferenceNode(ele)) {
245
- actionTexts.push.apply(actionTexts, tslib_1.__spreadArray([], tslib_1.__read(getStringTextFromUnionStringLiterals(moduleName, filename, ele, program)), false));
240
+ actionTexts.push(...getStringTextFromUnionStringLiterals(moduleName, filename, ele, program));
246
241
  }
247
242
  else {
248
- (0, assert_1.default)(ts.isLiteralTypeNode(ele) && ts.isStringLiteral(ele.literal), "\u3010".concat(moduleName, "\u3011action\u7684\u5B9A\u4E49\u65E2\u975EType\u4E5F\u4E0D\u662Fstring"));
243
+ (0, assert_1.default)(ts.isLiteralTypeNode(ele) && ts.isStringLiteral(ele.literal), `【${moduleName}】action的定义既非Type也不是string`);
249
244
  actionTexts.push(ele.literal.text);
250
245
  }
251
246
  });
252
247
  }
253
248
  else if (ts.isTypeReferenceNode(node)) {
254
249
  if (ts.isIdentifier(node.typeName)) {
255
- (0, assert_1.default)(!RESERVED_ACTION_NAMES.includes(node.typeName.text), "".concat(filename, "\u4E2D\u7684Action\u547D\u540D\u4E0D\u80FD\u662F\u300C").concat(RESERVED_ACTION_NAMES.join(','), "\u300D\u4E4B\u4E00"));
250
+ (0, assert_1.default)(!RESERVED_ACTION_NAMES.includes(node.typeName.text), `${filename}中的Action命名不能是「${RESERVED_ACTION_NAMES.join(',')}」之一`);
256
251
  }
257
- actionTexts.push.apply(actionTexts, tslib_1.__spreadArray([], tslib_1.__read(getStringTextFromUnionStringLiterals(moduleName, filename, node, program)), false));
252
+ actionTexts.push(...getStringTextFromUnionStringLiterals(moduleName, filename, node, program));
258
253
  }
259
254
  else {
260
- (0, assert_1.default)(ts.isLiteralTypeNode(node) && ts.isStringLiteral(node.literal), "\u3010".concat(moduleName, "\u3011action\u7684\u5B9A\u4E49\u65E2\u975EType\u4E5F\u4E0D\u662Fstring"));
255
+ (0, assert_1.default)(ts.isLiteralTypeNode(node) && ts.isStringLiteral(node.literal), `【${moduleName}】action的定义既非Type也不是string`);
261
256
  actionTexts.push(node.literal.text);
262
257
  }
263
258
  // 所有的action定义不能有重名
264
- var ActionDict = {};
265
- actionTexts.forEach(function (action) {
266
- var _a;
267
- (0, assert_1.default)(action.length <= env_1.STRING_LITERAL_MAX_LENGTH, "".concat(filename, "\u4E2D\u7684Action\u300C").concat(action, "\u300D\u547D\u540D\u957F\u5EA6\u5927\u4E8E").concat(env_1.STRING_LITERAL_MAX_LENGTH));
268
- (0, assert_1.default)(/^[a-z][a-z|A-Z]+$/.test(action), "".concat(filename, "\u4E2D\u7684Action\u300C").concat(action, "\u300D\u547D\u540D\u4E0D\u5408\u6CD5\uFF0C\u5FC5\u987B\u4EE5\u5C0F\u5B57\u5B57\u6BCD\u5F00\u5934\u4E14\u53EA\u80FD\u5305\u542B\u5B57\u6BCD"));
259
+ const ActionDict = {};
260
+ actionTexts.forEach((action) => {
261
+ (0, assert_1.default)(action.length <= env_1.STRING_LITERAL_MAX_LENGTH, `${filename}中的Action「${action}」命名长度大于${env_1.STRING_LITERAL_MAX_LENGTH}`);
262
+ (0, assert_1.default)(/^[a-z][a-z|A-Z]+$/.test(action), `${filename}中的Action「${action}」命名不合法,必须以小字字母开头且只能包含字母`);
269
263
  if (ActionDict.hasOwnProperty(action)) {
270
- throw new Error("\u6587\u4EF6".concat(filename, "\u4E2D\uFF0CAction\u5B9A\u4E49\u4E0A\u7684\u3010").concat(action, "\u3011\u52A8\u4F5C\u5B58\u5728\u540C\u540D"));
264
+ throw new Error(`文件${filename}中,Action定义上的【${action}】动作存在同名`);
271
265
  }
272
266
  else {
273
- (0, lodash_1.assign)(ActionDict, (_a = {},
274
- _a[action] = 1,
275
- _a));
267
+ (0, lodash_1.assign)(ActionDict, {
268
+ [action]: 1,
269
+ });
276
270
  }
277
271
  });
278
- pushStatementIntoActionAst(moduleName, factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("actions"), undefined, undefined, factory.createArrayLiteralExpression(actionTexts.map(function (ele) { return factory.createStringLiteral(ele); }), false))], ts.NodeFlags.Const)), sourceFile);
272
+ pushStatementIntoActionAst(moduleName, factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("actions"), undefined, undefined, factory.createArrayLiteralExpression(actionTexts.map(ele => factory.createStringLiteral(ele)), false))], ts.NodeFlags.Const)), sourceFile);
279
273
  }
280
274
  /**
281
275
  * entity的引用一定要以 import { Schema as XXX } from '..../XXX'这种形式
@@ -284,124 +278,121 @@ function dealWithActions(moduleName, filename, node, program, sourceFile) {
284
278
  * @returns
285
279
  */
286
280
  function getEntityImported(declaration) {
287
- var moduleSpecifier = declaration.moduleSpecifier, importClause = declaration.importClause;
288
- var entityImported;
281
+ const { moduleSpecifier, importClause } = declaration;
282
+ let entityImported;
289
283
  if (ts.isStringLiteral(moduleSpecifier)) {
290
- var importedFileName_1 = path_1.default.parse(moduleSpecifier.text).name;
291
- var namedBindings = importClause.namedBindings;
284
+ const { name: importedFileName } = path_1.default.parse(moduleSpecifier.text);
285
+ const { namedBindings } = importClause;
292
286
  if (namedBindings && ts.isNamedImports(namedBindings)) {
293
- var elements = namedBindings.elements;
294
- if (elements.find(function (ele) { var _a; return ts.isImportSpecifier(ele) && ele.name.text === importedFileName_1 && ((_a = ele.propertyName) === null || _a === void 0 ? void 0 : _a.text) === 'Schema'; })) {
295
- entityImported = importedFileName_1;
287
+ const { elements } = namedBindings;
288
+ if (elements.find(ele => ts.isImportSpecifier(ele) && ele.name.text === importedFileName && ele.propertyName?.text === 'Schema')) {
289
+ entityImported = importedFileName;
296
290
  }
297
291
  }
298
292
  }
299
293
  return entityImported;
300
294
  }
301
295
  function checkLocaleEnumAttrs(node, attrs, filename) {
302
- var members = node.members;
303
- var memberKeys = members.map(function (ele) {
296
+ const { members } = node;
297
+ const memberKeys = members.map((ele) => {
304
298
  (0, assert_1.default)(ts.isPropertySignature(ele) && ts.isIdentifier(ele.name));
305
299
  return ele.name.text;
306
300
  });
307
- var lack = (0, lodash_1.difference)(attrs, memberKeys);
301
+ const lack = (0, lodash_1.difference)(attrs, memberKeys);
308
302
  if (lack.length > 0) {
309
- throw new Error("".concat(filename, "\u4E2D\u7F3A\u5C11\u4E86\u5BF9").concat(lack.join(','), "\u5C5E\u6027\u7684locale\u5B9A\u4E49"));
303
+ throw new Error(`${filename}中缺少了对${lack.join(',')}属性的locale定义`);
310
304
  }
311
305
  }
312
306
  function checkLocaleExpressionPropertyExists(root, attr, exists, filename) {
313
- var properties = root.properties;
314
- properties.forEach(function (ele) {
307
+ const { properties } = root;
308
+ properties.forEach((ele) => {
315
309
  (0, assert_1.default)(ts.isPropertyAssignment(ele) && (ts.isIdentifier(ele.name) || ts.isStringLiteral(ele.name)) && ts.isObjectLiteralExpression(ele.initializer));
316
- var p2 = ele.initializer.properties;
317
- var pp = p2.find(function (ele2) {
310
+ const { properties: p2 } = ele.initializer;
311
+ const pp = p2.find((ele2) => {
318
312
  (0, assert_1.default)(ts.isPropertyAssignment(ele2) && ts.isIdentifier(ele2.name));
319
313
  return ele2.name.text === attr;
320
314
  });
321
315
  if (exists && !pp) {
322
- throw new Error("".concat(filename, "\u4E2D\u7684locale\u5B9A\u4E49\u4E2D\u7684").concat(ele.name.text, "\u4E2D\u7F3A\u5C11\u4E86").concat(attr, "\u7684\u5B9A\u4E49"));
316
+ throw new Error(`${filename}中的locale定义中的${ele.name.text}中缺少了${attr}的定义`);
323
317
  }
324
318
  else if (!exists && pp) {
325
- throw new Error("".concat(filename, "\u4E2D\u7684locale\u5B9A\u4E49\u4E2D\u7684").concat(ele.name.text, "\u4E2D\u6709\u591A\u4F59\u7684").concat(attr, "\u5B9A\u4E49"));
319
+ throw new Error(`${filename}中的locale定义中的${ele.name.text}中有多余的${attr}定义`);
326
320
  }
327
321
  });
328
322
  }
329
323
  function getStringEnumValues(filename, program, obj, node) {
330
- var _a;
331
- var checker = program.getTypeChecker();
332
- var symbol = checker.getSymbolAtLocation(node.typeName);
333
- var declaration = symbol === null || symbol === void 0 ? void 0 : symbol.getDeclarations()[0];
324
+ const checker = program.getTypeChecker();
325
+ const symbol = checker.getSymbolAtLocation(node.typeName);
326
+ let declaration = symbol?.getDeclarations()[0];
334
327
  if (ts.isImportSpecifier(declaration)) {
335
- var typee = checker.getDeclaredTypeOfSymbol(symbol);
336
- declaration = (_a = typee.aliasSymbol) === null || _a === void 0 ? void 0 : _a.getDeclarations()[0];
328
+ const typee = checker.getDeclaredTypeOfSymbol(symbol);
329
+ declaration = typee.aliasSymbol?.getDeclarations()[0];
337
330
  }
338
331
  if (declaration && ts.isTypeAliasDeclaration(declaration)) {
339
332
  if (ts.isUnionTypeNode(declaration.type) && ts.isLiteralTypeNode(declaration.type.types[0])) {
340
- return declaration.type.types.map(function (ele) { return checkStringLiteralLegal(filename, obj, declaration.name.text, ele); });
333
+ return declaration.type.types.map(ele => checkStringLiteralLegal(filename, obj, declaration.name.text, ele));
341
334
  }
342
335
  if (ts.isLiteralTypeNode(declaration.type)) {
343
- var value = checkStringLiteralLegal(filename, obj, declaration.name.text, declaration.type);
336
+ const value = checkStringLiteralLegal(filename, obj, declaration.name.text, declaration.type);
344
337
  return [value];
345
338
  }
346
339
  }
347
340
  }
348
341
  function checkNameLegal(filename, attrName, upperCase) {
349
- (0, assert_1.default)(attrName.length <= env_1.ENTITY_NAME_MAX_LENGTH, "\u6587\u4EF6\u300C".concat(filename, "\u300D\uFF1A\u300C").concat(attrName, "\u300D\u7684\u540D\u79F0\u5B9A\u4E49\u8FC7\u957F\uFF0C\u4E0D\u80FD\u8D85\u8FC7\u300C").concat(env_1.ENTITY_NAME_MAX_LENGTH, "\u300D\u957F\u5EA6"));
342
+ (0, assert_1.default)(attrName.length <= env_1.ENTITY_NAME_MAX_LENGTH, `文件「${filename}」:「${attrName}」的名称定义过长,不能超过「${env_1.ENTITY_NAME_MAX_LENGTH}」长度`);
350
343
  if (upperCase) {
351
- (0, assert_1.default)(/[A-Z][a-z|A-Z|0-9]+/i.test(attrName), "\u6587\u4EF6\u300C".concat(filename, "\u300D\uFF1A\u300C").concat(attrName, "\u300D\u7684\u540D\u79F0\u5FC5\u987B\u4EE5\u5927\u5199\u5B57\u6BCD\u5F00\u59CB\uFF0C\u4E14\u53EA\u80FD\u5305\u542B\u5B57\u6BCD\u548C\u6570\u5B57"));
344
+ (0, assert_1.default)(/[A-Z][a-z|A-Z|0-9]+/i.test(attrName), `文件「${filename}」:「${attrName}」的名称必须以大写字母开始,且只能包含字母和数字`);
352
345
  }
353
346
  else if (upperCase === false) {
354
- (0, assert_1.default)(/[a-z][a-z|A-Z|0-9]+/i.test(attrName), "\u6587\u4EF6\u300C".concat(filename, "\u300D\uFF1A\u300C").concat(attrName, "\u300D\u7684\u540D\u79F0\u5FC5\u987B\u4EE5\u5C0F\u5199\u5B57\u6BCD\u5F00\u59CB\uFF0C\u4E14\u53EA\u80FD\u5305\u542B\u5B57\u6BCD\u548C\u6570\u5B57"));
347
+ (0, assert_1.default)(/[a-z][a-z|A-Z|0-9]+/i.test(attrName), `文件「${filename}」:「${attrName}」的名称必须以小写字母开始,且只能包含字母和数字`);
355
348
  }
356
349
  else {
357
- (0, assert_1.default)(/[a-z|A-Z][a-z|A-Z|0-9]+/i.test(attrName), "\u6587\u4EF6\u300C".concat(filename, "\u300D\uFF1A\u300C").concat(attrName, "\u300D\u7684\u540D\u79F0\u5FC5\u987B\u4EE5\u5B57\u6BCD\u5F00\u59CB\uFF0C\u4E14\u53EA\u80FD\u5305\u542B\u5B57\u6BCD\u548C\u6570\u5B57"));
350
+ (0, assert_1.default)(/[a-z|A-Z][a-z|A-Z|0-9]+/i.test(attrName), `文件「${filename}」:「${attrName}」的名称必须以字母开始,且只能包含字母和数字`);
358
351
  }
359
352
  }
360
353
  function analyzeEntity(filename, path, program, relativePath) {
361
- var _a;
362
- var fullPath = "".concat(path, "/").concat(filename);
363
- var sourceFile = program.getSourceFile(fullPath);
364
- var moduleName = filename.split('.')[0];
354
+ const fullPath = `${path}/${filename}`;
355
+ const sourceFile = program.getSourceFile(fullPath);
356
+ const moduleName = filename.split('.')[0];
365
357
  if (Schema.hasOwnProperty(moduleName)) {
366
358
  delete ActionAsts[moduleName];
367
359
  delete SchemaAsts[moduleName];
368
360
  // removeFromRelationShip(moduleName);
369
- console.warn("\u51FA\u73B0\u4E86\u540C\u540D\u7684Entity\u5B9A\u4E49\u300C".concat(moduleName, "\u300D\uFF0C\u5C06\u4F7F\u7528").concat(fullPath, "\u53D6\u4EE3\u6389\u9ED8\u8BA4\u5BF9\u8C61\uFF0C\u8BF7\u68C0\u67E5\u65B0\u7684\u5BF9\u8C61\u7ED3\u6784\u53CA\u76F8\u5173\u5E38\u91CF\u5B9A\u4E49\u4E0E\u539F\u6709\u7684\u517C\u5BB9\uFF0C\u5426\u5219\u539F\u6709\u5BF9\u8C61\u7684\u76F8\u5173\u903B\u8F91\u4F1A\u51FA\u73B0\u4E0D\u53EF\u77E5\u5F02\u5E38"));
361
+ console.warn(`出现了同名的Entity定义「${moduleName}」,将使用${fullPath}取代掉默认对象,请检查新的对象结构及相关常量定义与原有的兼容,否则原有对象的相关逻辑会出现不可知异常`);
370
362
  }
371
363
  checkNameLegal(filename, moduleName, true);
372
- var referencedSchemas = [];
373
- var schemaAttrs = [];
374
- var hasFulltextIndex = false;
375
- var indexes;
376
- var beforeSchema = true;
377
- var hasActionDef = false;
378
- var hasRelationDef = false;
379
- var hasActionOrStateDef = false;
380
- var toModi = false;
381
- var actionType = 'crud';
382
- var _static = false;
383
- var enumAttributes = {};
384
- var additionalImports = [];
385
- var localeDef = undefined;
364
+ const referencedSchemas = [];
365
+ const schemaAttrs = [];
366
+ let hasFulltextIndex = false;
367
+ let indexes;
368
+ let beforeSchema = true;
369
+ let hasActionDef = false;
370
+ let hasRelationDef = false;
371
+ let hasActionOrStateDef = false;
372
+ let toModi = false;
373
+ let actionType = 'crud';
374
+ let _static = false;
375
+ const enumAttributes = {};
376
+ const additionalImports = [];
377
+ let localeDef = undefined;
386
378
  // let relationHierarchy: ts.ObjectLiteralExpression | undefined = undefined;
387
379
  // let reverseCascadeRelationHierarchy: ts.ObjectLiteralExpression | undefined = undefined;
388
- ts.forEachChild(sourceFile, function (node) {
389
- var _a, _b, _c, _d, _e, _f;
380
+ ts.forEachChild(sourceFile, (node) => {
390
381
  if (ts.isImportDeclaration(node)) {
391
- var entityImported = getEntityImported(node);
382
+ const entityImported = getEntityImported(node);
392
383
  if (entityImported) {
393
384
  referencedSchemas.push(entityImported);
394
385
  }
395
386
  else {
396
- var moduleSpecifier = node.moduleSpecifier, importClause = node.importClause;
387
+ const { moduleSpecifier, importClause } = node;
397
388
  if (ts.isStringLiteral(moduleSpecifier)) {
398
- var text = moduleSpecifier.text;
389
+ const { text } = moduleSpecifier;
399
390
  // 和数据类型相关的会自动引入,这里忽略(见initialStatements)
400
391
  // 如果是相对路径,编译后的路径默认要深一层
401
- var moduleSpecifier2Text = text.startsWith('.') ? (relativePath
392
+ const moduleSpecifier2Text = text.startsWith('.') ? (relativePath
402
393
  ? path_1.default.join(relativePath, text).replace(/\\/g, '/')
403
394
  : path_1.default.join('..', text).replace(/\\/g, '/')) : text;
404
- additionalImports.push(factory.updateImportDeclaration(node, undefined, undefined, importClause, factory.createStringLiteral(moduleSpecifier2Text), undefined));
395
+ additionalImports.push(factory.updateImportDeclaration(node, undefined, importClause, factory.createStringLiteral(moduleSpecifier2Text), undefined));
405
396
  }
406
397
  else {
407
398
  (0, assert_1.default)(false, '未处理的import方式');
@@ -411,15 +402,14 @@ function analyzeEntity(filename, path, program, relativePath) {
411
402
  if (ts.isInterfaceDeclaration(node)) {
412
403
  // schema 定义
413
404
  if (node.name.text === 'Schema') {
414
- (0, assert_1.default)(!localeDef, "\u3010".concat(filename, "\u3011locale\u5B9A\u4E49\u987B\u5728Schema\u4E4B\u540E"));
415
- var hasEntityAttr_1 = false;
416
- var hasEntityIdAttr_1 = false;
417
- var members = node.members, heritageClauses = node.heritageClauses;
405
+ (0, assert_1.default)(!localeDef, `【${filename}】locale定义须在Schema之后`);
406
+ let hasEntityAttr = false;
407
+ let hasEntityIdAttr = false;
408
+ const { members, heritageClauses } = node;
418
409
  (0, assert_1.default)(['EntityShape'].includes(heritageClauses[0].types[0].expression.text), moduleName);
419
- members.forEach(function (attrNode) {
420
- var _a, _b;
421
- var _c = attrNode, type = _c.type, name = _c.name, questionToken = _c.questionToken;
422
- var attrName = name.text;
410
+ members.forEach((attrNode) => {
411
+ const { type, name, questionToken } = attrNode;
412
+ const attrName = name.text;
423
413
  checkNameLegal(filename, attrName, false);
424
414
  if (ts.isTypeReferenceNode(type)
425
415
  && ts.isIdentifier(type.typeName)) {
@@ -429,21 +419,21 @@ function analyzeEntity(filename, path, program, relativePath) {
429
419
  }
430
420
  else if (type.typeName.text === 'Array') {
431
421
  // 这是一对多的反向指针的引用,需要特殊处理
432
- var typeArguments = type.typeArguments;
422
+ const { typeArguments } = type;
433
423
  (0, assert_1.default)(typeArguments.length === 1
434
424
  && ts.isTypeReferenceNode(typeArguments[0])
435
425
  && ts.isIdentifier(typeArguments[0].typeName)
436
- && referencedSchemas.includes(typeArguments[0].typeName.text), "\u300C".concat(filename, "\u300D\u975E\u6CD5\u7684\u5C5E\u6027\u5B9A\u4E49\u300C").concat(attrName, "\u300D"));
437
- var reverseEntity = typeArguments[0].typeName.text;
426
+ && referencedSchemas.includes(typeArguments[0].typeName.text), `「${filename}」非法的属性定义「${attrName}」`);
427
+ const reverseEntity = typeArguments[0].typeName.text;
438
428
  if (ReversePointerRelations[reverseEntity]) {
439
429
  if (!ReversePointerRelations[reverseEntity].includes(moduleName)) {
440
430
  ReversePointerRelations[reverseEntity].push(moduleName);
441
431
  }
442
432
  }
443
433
  else {
444
- (0, lodash_1.assign)(ReversePointerRelations, (_a = {},
445
- _a[reverseEntity] = [moduleName],
446
- _a));
434
+ (0, lodash_1.assign)(ReversePointerRelations, {
435
+ [reverseEntity]: [moduleName],
436
+ });
447
437
  }
448
438
  if (reverseEntity === 'Modi') {
449
439
  toModi = true;
@@ -451,88 +441,88 @@ function analyzeEntity(filename, path, program, relativePath) {
451
441
  }
452
442
  else {
453
443
  schemaAttrs.push(attrNode);
454
- var enumStringValues = getStringEnumValues(filename, program, '属性', type);
444
+ const enumStringValues = getStringEnumValues(filename, program, '属性', type);
455
445
  if (enumStringValues) {
456
446
  enumAttributes[attrName] = enumStringValues;
457
447
  }
458
448
  }
459
449
  }
460
450
  else if (ts.isArrayTypeNode(type) && ts.isTypeReferenceNode(type.elementType) && ts.isIdentifier(type.elementType.typeName)) {
461
- var typeName = type.elementType.typeName;
451
+ const { typeName } = type.elementType;
462
452
  if (referencedSchemas.includes(typeName.text)) {
463
453
  // 这也是一对多的反指定义
464
- var reverseEntity = typeName.text;
454
+ const reverseEntity = typeName.text;
465
455
  if (ReversePointerRelations[reverseEntity]) {
466
456
  ReversePointerRelations[reverseEntity].push(moduleName);
467
457
  }
468
458
  else {
469
- (0, lodash_1.assign)(ReversePointerRelations, (_b = {},
470
- _b[reverseEntity] = [moduleName],
471
- _b));
459
+ (0, lodash_1.assign)(ReversePointerRelations, {
460
+ [reverseEntity]: [moduleName],
461
+ });
472
462
  }
473
463
  if (reverseEntity === 'Modi') {
474
464
  toModi = true;
475
465
  }
476
466
  }
477
467
  else {
478
- throw new Error("\u5BF9\u8C61".concat(moduleName, "\u4E2D\u5B9A\u4E49\u7684\u5C5E\u6027").concat(attrName, "\u662F\u4E0D\u53EF\u8BC6\u522B\u7684\u6570\u7EC4\u7C7B\u522B"));
468
+ throw new Error(`对象${moduleName}中定义的属性${attrName}是不可识别的数组类别`);
479
469
  }
480
470
  }
481
471
  else {
482
472
  schemaAttrs.push(attrNode);
483
473
  if (ts.isUnionTypeNode(type) && ts.isLiteralTypeNode(type.types[0]) && ts.isStringLiteral(type.types[0].literal)) {
484
474
  (0, assert_1.default)(ts.isIdentifier(name));
485
- var types = type.types;
486
- var enumValues = types.map(function (ele) { return checkStringLiteralLegal(filename, '属性', name.text, ele); });
475
+ const { types } = type;
476
+ const enumValues = types.map((ele) => checkStringLiteralLegal(filename, '属性', name.text, ele));
487
477
  enumAttributes[name.text] = enumValues;
488
478
  }
489
479
  else if (ts.isLiteralTypeNode(type) && ts.isStringLiteral(type.literal)) {
490
480
  // 单个字符串的情形,目前应该没有,没测试过,先写着 by Xc 20230221
491
481
  (0, assert_1.default)(ts.isIdentifier(name));
492
- var enumValues = [
482
+ const enumValues = [
493
483
  checkStringLiteralLegal(filename, '属性', name.text, type)
494
484
  ];
495
485
  enumAttributes[name.text] = enumValues;
496
486
  }
497
487
  }
498
488
  if (attrName === 'entity') {
499
- (0, assert_1.default)(ts.isTypeReferenceNode(type) && ts.isIdentifier(type.typeName), "\u300C".concat(moduleName, "\u300D\u4E2Dentity\u5C5E\u6027\u7684\u5B9A\u4E49\u4E0D\u662FString<32>\u7C7B\u578B\uFF0Centity\u662F\u7CFB\u7EDF\u7528\u4E8E\u8868\u793A\u53CD\u6307\u6307\u9488\u7684\u4FDD\u7559\u5C5E\u6027\uFF0C\u8BF7\u52FF\u4ED6\u7528"));
500
- var typeArguments = type.typeArguments;
489
+ (0, assert_1.default)(ts.isTypeReferenceNode(type) && ts.isIdentifier(type.typeName), `「${moduleName}」中entity属性的定义不是String<32>类型,entity是系统用于表示反指指针的保留属性,请勿他用`);
490
+ const { typeArguments } = type;
501
491
  (0, assert_1.default)(type.typeName.text === 'String'
502
492
  && typeArguments
503
- && typeArguments.length === 1, "\u300C".concat(moduleName, "\u300D\u4E2Dentity\u5C5E\u6027\u7684\u5B9A\u4E49\u4E0D\u662FString<32>\u7C7B\u578B\uFF0Centity\u662F\u7CFB\u7EDF\u7528\u4E8E\u8868\u793A\u53CD\u6307\u6307\u9488\u7684\u4FDD\u7559\u5C5E\u6027\uFF0C\u8BF7\u52FF\u4ED6\u7528"));
504
- var _d = tslib_1.__read(typeArguments, 1), node_1 = _d[0];
505
- if (ts.isLiteralTypeNode(node_1) && ts.isNumericLiteral(node_1.literal)) {
506
- if (parseInt(node_1.literal.text) > 32) {
507
- (0, assert_1.default)(false, "\u300C".concat(moduleName, "\u300D\u4E2Dentity\u5C5E\u6027\u7684\u5B9A\u4E49\u4E0D\u662FString<32>\u7C7B\u578B\uFF0Centity\u662F\u7CFB\u7EDF\u7528\u4E8E\u8868\u793A\u53CD\u6307\u6307\u9488\u7684\u4FDD\u7559\u5C5E\u6027\uFF0C\u8BF7\u52FF\u4ED6\u7528"));
493
+ && typeArguments.length === 1, `「${moduleName}」中entity属性的定义不是String<32>类型,entity是系统用于表示反指指针的保留属性,请勿他用`);
494
+ const [node] = typeArguments;
495
+ if (ts.isLiteralTypeNode(node) && ts.isNumericLiteral(node.literal)) {
496
+ if (parseInt(node.literal.text) > 32) {
497
+ (0, assert_1.default)(false, `「${moduleName}」中entity属性的定义不是String<32>类型,entity是系统用于表示反指指针的保留属性,请勿他用`);
508
498
  }
509
499
  else {
510
- hasEntityAttr_1 = true;
500
+ hasEntityAttr = true;
511
501
  }
512
502
  }
513
503
  }
514
504
  if (attrName === 'entityId') {
515
- (0, assert_1.default)(ts.isTypeReferenceNode(type) && ts.isIdentifier(type.typeName), "\u300C".concat(moduleName, "\u300D\u4E2DentityId\u5C5E\u6027\u7684\u5B9A\u4E49\u4E0D\u662FString<64>\u7C7B\u578B\uFF0CentityId\u662F\u7CFB\u7EDF\u7528\u4E8E\u8868\u793A\u53CD\u6307\u6307\u9488\u7684\u4FDD\u7559\u5C5E\u6027\uFF0C\u8BF7\u52FF\u4ED6\u7528"));
516
- var typeArguments = type.typeArguments;
517
- (0, assert_1.default)(type.typeName.text === 'String' && typeArguments && typeArguments.length === 1, "\u300C".concat(moduleName, "\u300D\u4E2DentityId\u5C5E\u6027\u7684\u5B9A\u4E49\u4E0D\u662FString<64>\u7C7B\u578B\uFF0CentityId\u662F\u7CFB\u7EDF\u7528\u4E8E\u8868\u793A\u53CD\u6307\u6307\u9488\u7684\u4FDD\u7559\u5C5E\u6027\uFF0C\u8BF7\u52FF\u4ED6\u7528"));
518
- var _e = tslib_1.__read(typeArguments, 1), node_2 = _e[0];
519
- if (ts.isLiteralTypeNode(node_2) && ts.isNumericLiteral(node_2.literal)) {
520
- if (parseInt(node_2.literal.text) !== 64) {
521
- (0, assert_1.default)(false, "\u300C".concat(moduleName, "\u300D\u4E2DentityId\u5C5E\u6027\u7684\u5B9A\u4E49\u4E0D\u662FString<64>\u7C7B\u578B\uFF0CentityId\u662F\u7CFB\u7EDF\u7528\u4E8E\u8868\u793A\u53CD\u6307\u6307\u9488\u7684\u4FDD\u7559\u5C5E\u6027\uFF0C\u8BF7\u52FF\u4ED6\u7528"));
505
+ (0, assert_1.default)(ts.isTypeReferenceNode(type) && ts.isIdentifier(type.typeName), `「${moduleName}」中entityId属性的定义不是String<64>类型,entityId是系统用于表示反指指针的保留属性,请勿他用`);
506
+ const { typeArguments } = type;
507
+ (0, assert_1.default)(type.typeName.text === 'String' && typeArguments && typeArguments.length === 1, `「${moduleName}」中entityId属性的定义不是String<64>类型,entityId是系统用于表示反指指针的保留属性,请勿他用`);
508
+ const [node] = typeArguments;
509
+ if (ts.isLiteralTypeNode(node) && ts.isNumericLiteral(node.literal)) {
510
+ if (parseInt(node.literal.text) !== 64) {
511
+ (0, assert_1.default)(false, `「${moduleName}」中entityId属性的定义不是String<64>类型,entityId是系统用于表示反指指针的保留属性,请勿他用`);
522
512
  }
523
513
  else {
524
- hasEntityIdAttr_1 = true;
514
+ hasEntityIdAttr = true;
525
515
  }
526
516
  }
527
517
  }
528
518
  });
529
- if (hasEntityAttr_1 && hasEntityIdAttr_1) {
530
- (0, lodash_1.assign)(ReversePointerEntities, (_a = {},
531
- _a[moduleName] = 1,
532
- _a));
519
+ if (hasEntityAttr && hasEntityIdAttr) {
520
+ (0, lodash_1.assign)(ReversePointerEntities, {
521
+ [moduleName]: 1,
522
+ });
533
523
  }
534
- else if (hasEntityAttr_1 || hasEntityIdAttr_1) {
535
- throw new Error("\u6587\u4EF6\u300C".concat(filename, "\u300D\uFF1A\u5C5E\u6027 \u5B9A\u4E49\u4E2D\u53EA\u5305\u542B").concat(hasEntityAttr_1 ? 'entity' : 'entityId', "\uFF0C\u4E0D\u7B26\u5408\u5B9A\u4E49\u89C4\u8303\u3002entity/entityId\u5FC5\u987B\u8054\u5408\u51FA\u73B0\uFF0C\u4EE3\u8868\u4E0D\u5B9A\u5BF9\u8C61\u7684\u53CD\u5411\u6307\u9488"));
524
+ else if (hasEntityAttr || hasEntityIdAttr) {
525
+ throw new Error(`文件「${filename}」:属性 定义中只包含${hasEntityAttr ? 'entity' : 'entityId'},不符合定义规范。entity/entityId必须联合出现,代表不定对象的反向指针`);
536
526
  }
537
527
  beforeSchema = false;
538
528
  // 对于不是Modi和Oper的对象,全部建立和ModiEntity的反指关系
@@ -541,17 +531,17 @@ function analyzeEntity(filename, path, program, relativePath) {
541
531
  ReversePointerRelations['ModiEntity'].push(moduleName);
542
532
  }
543
533
  else {
544
- (0, lodash_1.assign)(ReversePointerRelations, (_b = {},
545
- _b['ModiEntity'] = [moduleName],
546
- _b));
534
+ (0, lodash_1.assign)(ReversePointerRelations, {
535
+ ['ModiEntity']: [moduleName],
536
+ });
547
537
  }
548
538
  if (ReversePointerRelations['OperEntity'] && !ReversePointerRelations['OperEntity'].includes(moduleName)) {
549
539
  ReversePointerRelations['OperEntity'].push(moduleName);
550
540
  }
551
541
  else {
552
- (0, lodash_1.assign)(ReversePointerRelations, (_c = {},
553
- _c['OperEntity'] = [moduleName],
554
- _c));
542
+ (0, lodash_1.assign)(ReversePointerRelations, {
543
+ ['OperEntity']: [moduleName],
544
+ });
555
545
  }
556
546
  }
557
547
  }
@@ -563,39 +553,40 @@ function analyzeEntity(filename, path, program, relativePath) {
563
553
  if (ts.isTypeAliasDeclaration(node)) {
564
554
  // action 定义
565
555
  if (node.name.text === 'Action') {
566
- (0, assert_1.default)(!localeDef, "\u3010".concat(filename, "\u3011locale\u5B9A\u4E49\u987B\u5728Action\u4E4B\u540E"));
556
+ (0, assert_1.default)(!localeDef, `【${filename}】locale定义须在Action之后`);
567
557
  hasActionDef = true;
568
- var modifiers = [factory.createModifier(ts.SyntaxKind.ExportKeyword)];
569
- pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node, node.decorators, modifiers, factory.createIdentifier('ParticularAction'), node.typeParameters, node.type), sourceFile);
558
+ const modifiers = [factory.createModifier(ts.SyntaxKind.ExportKeyword)];
559
+ pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node, modifiers, factory.createIdentifier('ParticularAction'), node.typeParameters, node.type), sourceFile);
570
560
  dealWithActions(moduleName, filename, node.type, program, sourceFile);
571
561
  }
572
562
  else if (node.name.text === 'Relation') {
573
- (0, assert_1.default)(!localeDef, "\u3010".concat(filename, "\u3011locale\u5B9A\u4E49\u987B\u5728Relation\u4E4B\u540E"));
574
- var relationValues = [];
563
+ (0, assert_1.default)(!localeDef, `【${filename}】locale定义须在Relation之后`);
564
+ const relationValues = [];
575
565
  if (ts.isLiteralTypeNode(node.type)) {
576
566
  (0, assert_1.default)(ts.isStringLiteral(node.type.literal));
577
- (0, assert_1.default)(node.type.literal.text.length < env_1.STRING_LITERAL_MAX_LENGTH, "Relation\u5B9A\u4E49\u7684\u5B57\u7B26\u4E32\u957F\u5EA6\u4E0D\u957F\u4E8E".concat(env_1.STRING_LITERAL_MAX_LENGTH, "\uFF08").concat(filename, "\uFF0C").concat(node.type.literal.text, "\uFF09"));
567
+ (0, assert_1.default)(node.type.literal.text.length < env_1.STRING_LITERAL_MAX_LENGTH, `Relation定义的字符串长度不长于${env_1.STRING_LITERAL_MAX_LENGTH}(${filename},${node.type.literal.text})`);
578
568
  relationValues.push(node.type.literal.text);
579
569
  }
580
570
  else {
581
- (0, assert_1.default)(ts.isUnionTypeNode(node.type), "Relation\u7684\u5B9A\u4E49\u53EA\u80FD\u662Fstring\u7C7B\u578B\uFF08".concat(filename, "\uFF09"));
582
- relationValues.push.apply(relationValues, tslib_1.__spreadArray([], tslib_1.__read(node.type.types.map(function (ele) {
583
- (0, assert_1.default)(ts.isLiteralTypeNode(ele) && ts.isStringLiteral(ele.literal), "Relation\u7684\u5B9A\u4E49\u53EA\u80FD\u662Fstring\u7C7B\u578B\uFF08".concat(filename, "\uFF09"));
584
- (0, assert_1.default)(ele.literal.text.length < env_1.STRING_LITERAL_MAX_LENGTH, "Relation\u5B9A\u4E49\u7684\u5B57\u7B26\u4E32\u957F\u5EA6\u4E0D\u957F\u4E8E".concat(env_1.STRING_LITERAL_MAX_LENGTH, "\uFF08").concat(filename, "\uFF0C").concat(ele.literal.text, "\uFF09"));
571
+ (0, assert_1.default)(ts.isUnionTypeNode(node.type), `Relation的定义只能是string类型(${filename})`);
572
+ relationValues.push(...node.type.types.map((ele) => {
573
+ (0, assert_1.default)(ts.isLiteralTypeNode(ele) && ts.isStringLiteral(ele.literal), `Relation的定义只能是string类型(${filename})`);
574
+ (0, assert_1.default)(ele.literal.text.length < env_1.STRING_LITERAL_MAX_LENGTH, `Relation定义的字符串长度不长于${env_1.STRING_LITERAL_MAX_LENGTH}(${filename},${ele.literal.text})`);
585
575
  return ele.literal.text;
586
- })), false));
576
+ }));
587
577
  }
588
578
  // 对UserEntityGrant对象,建立相应的反指关系
589
- if (ReversePointerRelations['UserEntityGrant']) {
579
+ // UserEntityGrant结构改变,不再建立,by Xc 20231101
580
+ /* if (ReversePointerRelations['UserEntityGrant']) {
590
581
  if (!ReversePointerRelations['UserEntityGrant'].includes(moduleName)) {
591
582
  ReversePointerRelations['UserEntityGrant'].push(moduleName);
592
583
  }
593
584
  }
594
585
  else {
595
- (0, lodash_1.assign)(ReversePointerRelations, (_d = {},
596
- _d['UserEntityGrant'] = [moduleName],
597
- _d));
598
- }
586
+ assign(ReversePointerRelations, {
587
+ ['UserEntityGrant']: [moduleName],
588
+ });
589
+ } */
599
590
  // 对Relation对象建立相应的反指关系
600
591
  if (ReversePointerRelations['Relation']) {
601
592
  if (!ReversePointerRelations['Relation'].includes(moduleName)) {
@@ -603,9 +594,9 @@ function analyzeEntity(filename, path, program, relativePath) {
603
594
  }
604
595
  }
605
596
  else {
606
- (0, lodash_1.assign)(ReversePointerRelations, (_e = {},
607
- _e['Relation'] = [moduleName],
608
- _e));
597
+ (0, lodash_1.assign)(ReversePointerRelations, {
598
+ ['Relation']: [moduleName],
599
+ });
609
600
  }
610
601
  // 对UserRelation对象建立相应的反指关系
611
602
  if (ReversePointerRelations['UserRelation']) {
@@ -614,24 +605,25 @@ function analyzeEntity(filename, path, program, relativePath) {
614
605
  }
615
606
  }
616
607
  else {
617
- (0, lodash_1.assign)(ReversePointerRelations, (_f = {},
618
- _f['UserRelation'] = [moduleName],
619
- _f));
608
+ (0, lodash_1.assign)(ReversePointerRelations, {
609
+ ['UserRelation']: [moduleName],
610
+ });
620
611
  }
621
612
  hasRelationDef = node;
622
613
  }
623
614
  else if (node.name.text.endsWith('Action') || node.name.text.endsWith('State')) {
624
- (0, assert_1.default)(!localeDef, "\u3010".concat(filename, "\u3011locale\u5B9A\u4E49\u987B\u5728Action/State\u4E4B\u540E"));
615
+ (0, assert_1.default)(!localeDef, `【${filename}】locale定义须在Action/State之后`);
625
616
  hasActionOrStateDef = true;
626
- var type = node.type;
617
+ const { type } = node;
627
618
  if (ts.isUnionTypeNode(type)) {
628
- pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node, node.decorators, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], node.name, node.typeParameters, process.env.COMPLING_AS_LIB ? factory.createUnionTypeNode(tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(type.types), false), [
619
+ pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], node.name, node.typeParameters, process.env.COMPLING_AS_LIB ? factory.createUnionTypeNode([
620
+ ...type.types,
629
621
  factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
630
- ], false)) : type), sourceFile);
622
+ ]) : type), sourceFile);
631
623
  }
632
624
  else {
633
- (0, assert_1.default)(ts.isLiteralTypeNode(type) || ts.isTypeReferenceNode(type), "".concat(moduleName, " - ").concat(node.name));
634
- pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node, node.decorators, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], node.name, node.typeParameters, process.env.COMPLING_AS_LIB ? factory.createUnionTypeNode([
625
+ (0, assert_1.default)(ts.isLiteralTypeNode(type) || ts.isTypeReferenceNode(type), `${moduleName} - ${node.name}`);
626
+ pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], node.name, node.typeParameters, process.env.COMPLING_AS_LIB ? factory.createUnionTypeNode([
635
627
  type,
636
628
  factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
637
629
  ]) : type), sourceFile);
@@ -643,115 +635,111 @@ function analyzeEntity(filename, path, program, relativePath) {
643
635
  }
644
636
  }
645
637
  if (ts.isVariableStatement(node)) {
646
- var declarations = node.declarationList.declarations;
647
- var dealWithActionDef_1 = function (declaration) {
638
+ const { declarationList: { declarations } } = node;
639
+ const dealWithActionDef = (declaration) => {
648
640
  checkActionDefNameConsistent(filename, declaration);
649
- var typeArguments = declaration.type.typeArguments;
641
+ const { typeArguments } = declaration.type;
650
642
  (0, assert_1.default)(typeArguments.length === 2);
651
- var _a = tslib_1.__read(typeArguments, 2), actionNode = _a[0], stateNode = _a[1];
643
+ const [actionNode, stateNode] = typeArguments;
652
644
  (0, assert_1.default)(ts.isTypeReferenceNode(actionNode));
653
645
  (0, assert_1.default)(ts.isTypeReferenceNode(stateNode));
654
- (0, assert_1.default)(getStringEnumValues(filename, program, 'action', actionNode), "\u6587\u4EF6".concat(filename, "\u4E2D\u7684action").concat(actionNode.typeName.text, "\u5B9A\u4E49\u4E0D\u662F\u5B57\u7B26\u4E32\u7C7B\u578B"));
655
- var enumStateValues = getStringEnumValues(filename, program, 'state', stateNode);
656
- (0, assert_1.default)(enumStateValues, "\u6587\u4EF6".concat(filename, "\u4E2D\u7684state").concat(stateNode.typeName.text, "\u5B9A\u4E49\u4E0D\u662F\u5B57\u7B26\u4E32\u7C7B\u578B"));
646
+ (0, assert_1.default)(getStringEnumValues(filename, program, 'action', actionNode), `文件${filename}中的action${actionNode.typeName.text}定义不是字符串类型`);
647
+ const enumStateValues = getStringEnumValues(filename, program, 'state', stateNode);
648
+ (0, assert_1.default)(enumStateValues, `文件${filename}中的state${stateNode.typeName.text}定义不是字符串类型`);
657
649
  pushStatementIntoActionAst(moduleName, node, sourceFile);
658
650
  (0, assert_1.default)(ts.isIdentifier(declaration.name));
659
- var adName = declaration.name.text.slice(0, declaration.name.text.length - 9);
660
- var attr = adName.concat('State');
651
+ const adName = declaration.name.text.slice(0, declaration.name.text.length - 9);
652
+ const attr = adName.concat('State');
661
653
  schemaAttrs.push(factory.createPropertySignature(undefined, (0, string_1.firstLetterLowerCase)(attr), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(attr)));
662
654
  enumAttributes[(0, string_1.firstLetterLowerCase)(attr)] = enumStateValues;
663
655
  };
664
- var dealWithIndexes_1 = function (declaration) {
665
- var indexNameDict = {};
656
+ const dealWithIndexes = (declaration) => {
657
+ const indexNameDict = {};
666
658
  // 检查索引的属性是否合法
667
- var elements = declaration.elements;
668
- elements.forEach(function (ele) {
669
- var _a;
670
- var isFulltextIndex = false;
659
+ const { elements } = declaration;
660
+ elements.forEach((ele) => {
661
+ let isFulltextIndex = false;
671
662
  (0, assert_1.default)(ts.isObjectLiteralExpression(ele));
672
- var properties = ele.properties;
673
- var attrProperty = properties.find(function (ele2) {
663
+ const { properties } = ele;
664
+ const attrProperty = properties.find((ele2) => {
674
665
  (0, assert_1.default)(ts.isPropertyAssignment(ele2));
675
666
  return ele2.name.getText() === 'attributes';
676
667
  });
677
668
  (0, assert_1.default)(ts.isArrayLiteralExpression(attrProperty.initializer));
678
- var nameProperty = properties.find(function (ele2) {
669
+ const nameProperty = properties.find((ele2) => {
679
670
  (0, assert_1.default)(ts.isPropertyAssignment(ele2));
680
671
  return ele2.name.getText() === 'name';
681
672
  });
682
673
  (0, assert_1.default)(ts.isStringLiteral(nameProperty.initializer));
683
- var nameText = nameProperty.initializer.text;
674
+ const nameText = nameProperty.initializer.text;
684
675
  if (indexNameDict[nameText]) {
685
- throw new Error("\u300C".concat(filename, "\u300D\u7D22\u5F15\u5B9A\u4E49\u91CD\u540D\u300C").concat(nameText, "\u300D"));
676
+ throw new Error(`「${filename}」索引定义重名「${nameText}」`);
686
677
  }
687
- (0, lodash_1.assign)(indexNameDict, (_a = {},
688
- _a[nameText] = true,
689
- _a));
690
- var configProperty = properties.find(function (ele2) {
678
+ (0, lodash_1.assign)(indexNameDict, {
679
+ [nameText]: true,
680
+ });
681
+ const configProperty = properties.find((ele2) => {
691
682
  (0, assert_1.default)(ts.isPropertyAssignment(ele2));
692
683
  return ele2.name.getText() === 'config';
693
684
  });
694
685
  if (configProperty) {
695
686
  (0, assert_1.default)(ts.isObjectLiteralExpression(configProperty.initializer));
696
- var properties2 = configProperty.initializer.properties;
697
- var typeProperty = properties2.find(function (ele2) {
687
+ const { properties: properties2 } = configProperty.initializer;
688
+ const typeProperty = properties2.find((ele2) => {
698
689
  (0, assert_1.default)(ts.isPropertyAssignment(ele2));
699
690
  return ele2.name.getText() === 'type';
700
691
  });
701
692
  if (typeProperty && typeProperty.initializer.text === 'fulltext') {
702
693
  // 定义了全文索引
703
694
  if (hasFulltextIndex) {
704
- throw new Error("\u300C".concat(filename, "\u300D\u53EA\u80FD\u5B9A\u4E49\u4E00\u4E2A\u5168\u6587\u7D22\u5F15"));
695
+ throw new Error(`「${filename}」只能定义一个全文索引`);
705
696
  }
706
697
  hasFulltextIndex = true;
707
698
  isFulltextIndex = true;
708
699
  }
709
700
  }
710
- var elements = attrProperty.initializer.elements;
701
+ const { elements } = attrProperty.initializer;
711
702
  // 每个属性都应该在schema中有值,且对象类型是可索引值
712
- elements.forEach(function (ele2) {
703
+ elements.forEach((ele2) => {
713
704
  (0, assert_1.default)(ts.isObjectLiteralExpression(ele2));
714
- var properties2 = ele2.properties;
715
- var nameProperty = properties2.find(function (ele3) {
705
+ const { properties: properties2 } = ele2;
706
+ const nameProperty = properties2.find((ele3) => {
716
707
  (0, assert_1.default)(ts.isPropertyAssignment(ele3));
717
708
  return ele3.name.getText() === 'name';
718
709
  });
719
- var indexAttrName = nameProperty.initializer.text;
710
+ const indexAttrName = nameProperty.initializer.text;
720
711
  if (!Entity_1.initinctiveAttributes.includes(indexAttrName)) {
721
- var schemaNode = schemaAttrs.find(function (ele3) {
712
+ const schemaNode = schemaAttrs.find((ele3) => {
722
713
  (0, assert_1.default)(ts.isPropertySignature(ele3));
723
714
  return ele3.name.text === indexAttrName;
724
715
  });
725
716
  if (!schemaNode) {
726
- throw new Error("\u300C".concat(filename, "\u300D\u4E2D\u7D22\u5F15\u300C").concat(nameText, "\u300D\u7684\u5C5E\u6027\u300C").concat(indexAttrName, "\u300D\u5B9A\u4E49\u975E\u6CD5"));
717
+ throw new Error(`「${filename}」中索引「${nameText}」的属性「${indexAttrName}」定义非法`);
727
718
  }
728
- var type = schemaNode.type, name_1 = schemaNode.name;
729
- var entity = moduleName;
730
- var _a = ManyToOne, _b = entity, manyToOneSet = _a[_b];
719
+ const { type, name } = schemaNode;
720
+ const entity = moduleName;
721
+ const { [entity]: manyToOneSet } = ManyToOne;
731
722
  if (ts.isTypeReferenceNode(type)) {
732
- var typeName = type.typeName;
723
+ const { typeName } = type;
733
724
  if (ts.isIdentifier(typeName)) {
734
- var text = typeName.text;
735
- var text2_1 = text === 'Schema' ? entity : text;
736
- var manyToOneItem = manyToOneSet && manyToOneSet.find(function (_a) {
737
- var _b = tslib_1.__read(_a, 2), refEntity = _b[0], attrName = _b[1];
738
- return refEntity === text2_1 && attrName === name_1.text;
739
- });
725
+ const { text } = typeName;
726
+ const text2 = text === 'Schema' ? entity : text;
727
+ const manyToOneItem = manyToOneSet && manyToOneSet.find(([refEntity, attrName]) => refEntity === text2 && attrName === name.text);
740
728
  if (!manyToOneItem) {
741
729
  // 如果不是外键,则不能是Text, File
742
730
  if (isFulltextIndex) {
743
- (0, assert_1.default)(['Text', 'String'].includes(text2_1), "\u300C".concat(filename, "\u300D\u4E2D\u5168\u6587\u7D22\u5F15\u300C").concat(nameText, "\u300D\u5B9A\u4E49\u7684\u5C5E\u6027\u300C").concat(indexAttrName, "\u300D\u7C7B\u578B\u975E\u6CD5\uFF0C\u53EA\u80FD\u662FText/String"));
731
+ (0, assert_1.default)(['Text', 'String'].includes(text2), `「${filename}」中全文索引「${nameText}」定义的属性「${indexAttrName}」类型非法,只能是Text/String`);
744
732
  }
745
733
  else {
746
- (0, assert_1.default)(!DataType_1.unIndexedTypes.includes(text2_1), "\u300C".concat(filename, "\u300D\u4E2D\u7D22\u5F15\u300C").concat(nameText, "\u300D\u7684\u5C5E\u6027\u300C").concat(indexAttrName, "\u300D\u7684\u7C7B\u578B\u4E3A\u300C").concat(text2_1, "\u300D\uFF0C\u4E0D\u53EF\u7D22\u5F15"));
734
+ (0, assert_1.default)(!DataType_1.unIndexedTypes.includes(text2), `「${filename}」中索引「${nameText}」的属性「${indexAttrName}」的类型为「${text2}」,不可索引`);
747
735
  }
748
736
  }
749
737
  else {
750
- (0, assert_1.default)(!isFulltextIndex, "\u300C".concat(filename, "\u300D\u4E2D\u5168\u6587\u7D22\u5F15\u300C").concat(nameText, "\u300D\u7684\u5C5E\u6027\u300C").concat(indexAttrName, "\u300D\u7C7B\u578B\u975E\u6CD5\uFF0C\u53EA\u80FD\u4E3AText/String"));
738
+ (0, assert_1.default)(!isFulltextIndex, `「${filename}」中全文索引「${nameText}」的属性「${indexAttrName}」类型非法,只能为Text/String`);
751
739
  // 在这里把外键加上Id,这样storageSchema才能正常通过
752
740
  // 这里的写法不太好,未来TS版本高了可能会有问题。by Xc 20230131
753
741
  Object.assign(nameProperty, {
754
- initializer: factory.createStringLiteral("".concat(indexAttrName, "Id")),
742
+ initializer: factory.createStringLiteral(`${indexAttrName}Id`),
755
743
  });
756
744
  }
757
745
  }
@@ -760,15 +748,15 @@ function analyzeEntity(filename, path, program, relativePath) {
760
748
  }
761
749
  }
762
750
  else {
763
- (0, assert_1.default)(!isFulltextIndex, "\u300C".concat(filename, "\u300D\u4E2D\u5168\u6587\u7D22\u5F15\u300C").concat(nameText, "\u300D\u7684\u5C5E\u6027\u300C").concat(indexAttrName, "\u300D\u7C7B\u578B\u53EA\u80FD\u4E3AText/String"));
764
- (0, assert_1.default)(ts.isUnionTypeNode(type) || ts.isLiteralTypeNode(type), "".concat(entity, "\u4E2D\u7D22\u5F15\u300C").concat(nameText, "\u300D\u7684\u5C5E\u6027").concat(name_1.text, "\u6709\u5B9A\u4E49\u975E\u6CD5"));
751
+ (0, assert_1.default)(!isFulltextIndex, `「${filename}」中全文索引「${nameText}」的属性「${indexAttrName}」类型只能为Text/String`);
752
+ (0, assert_1.default)(ts.isUnionTypeNode(type) || ts.isLiteralTypeNode(type), `${entity}中索引「${nameText}」的属性${name.text}有定义非法`);
765
753
  }
766
754
  }
767
755
  });
768
756
  });
769
757
  indexes = declaration;
770
758
  };
771
- var dealWithLocales_1 = function (declaration) {
759
+ const dealWithLocales = (declaration) => {
772
760
  if (hasActionDef) {
773
761
  // 检查每种locale定义中都应该有'action'域
774
762
  checkLocaleExpressionPropertyExists(declaration, 'action', true, filename);
@@ -783,7 +771,7 @@ function analyzeEntity(filename, path, program, relativePath) {
783
771
  else {
784
772
  checkLocaleExpressionPropertyExists(declaration, 'r', false, filename);
785
773
  }
786
- var allEnumStringAttrs = Object.keys(enumAttributes);
774
+ const allEnumStringAttrs = Object.keys(enumAttributes);
787
775
  if (allEnumStringAttrs.length > 0) {
788
776
  // 检查每种locale定义中都应该有'v'域
789
777
  checkLocaleExpressionPropertyExists(declaration, 'v', true, filename);
@@ -794,11 +782,11 @@ function analyzeEntity(filename, path, program, relativePath) {
794
782
  }
795
783
  localeDef = declaration;
796
784
  };
797
- var dealWithConfiguration_1 = function (declaration) {
785
+ const dealWithConfiguration = (declaration) => {
798
786
  // assert(!hasActionDef, `${moduleName}中的Configuration定义在Action之后`);
799
- var properties = declaration.properties;
800
- var atProperty = properties.find(function (ele) { return ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'actionType'; });
801
- var staticProperty = properties.find(function (ele) { return ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'static'; });
787
+ const { properties } = declaration;
788
+ const atProperty = properties.find(ele => ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'actionType');
789
+ const staticProperty = properties.find(ele => ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'static');
802
790
  if (atProperty) {
803
791
  actionType = atProperty.initializer.text;
804
792
  }
@@ -806,9 +794,9 @@ function analyzeEntity(filename, path, program, relativePath) {
806
794
  _static = true; // static如果有值只能为true
807
795
  }
808
796
  };
809
- declarations.forEach(function (declaration) {
797
+ declarations.forEach((declaration) => {
810
798
  if (declaration.type && ts.isTypeReferenceNode(declaration.type) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'ActionDef') {
811
- dealWithActionDef_1(declaration);
799
+ dealWithActionDef(declaration);
812
800
  }
813
801
  else if (declaration.type && (ts.isArrayTypeNode(declaration.type)
814
802
  && ts.isTypeReferenceNode(declaration.type.elementType)
@@ -821,80 +809,80 @@ function analyzeEntity(filename, path, program, relativePath) {
821
809
  && ts.isIdentifier(declaration.type.typeArguments[0].typeName)
822
810
  && declaration.type.typeArguments[0].typeName.text === 'Index')) {
823
811
  // 对索引Index的定义
824
- console.log("\u300C".concat(filename, "\u300D\u76F4\u63A5\u5B9A\u4E49indexes\u7684\u5199\u6CD5\u5DF2\u7ECF\u8FC7\u65F6\uFF0C\u8BF7\u5B9A\u4E49\u5728entityDesc\u4E2D"));
812
+ console.log(`「${filename}」直接定义indexes的写法已经过时,请定义在entityDesc中`);
825
813
  (0, assert_1.default)(ts.isArrayLiteralExpression(declaration.initializer));
826
- dealWithIndexes_1(declaration.initializer);
814
+ dealWithIndexes(declaration.initializer);
827
815
  }
828
816
  else if (declaration.type && ts.isTypeReferenceNode(declaration.type) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'LocaleDef') {
829
817
  // locale定义
830
- console.log("\u300C".concat(filename, "\u300D\u76F4\u63A5\u5B9A\u4E49locales\u7684\u5199\u6CD5\u5DF2\u7ECF\u8FC7\u65F6\uFF0C\u8BF7\u5B9A\u4E49\u5728entityDesc\u4E2D"));
831
- var type = declaration.type, initializer = declaration.initializer;
818
+ console.log(`「${filename}」直接定义locales的写法已经过时,请定义在entityDesc中`);
819
+ const { type, initializer } = declaration;
832
820
  (0, assert_1.default)(ts.isObjectLiteralExpression(initializer));
833
- var properties = initializer.properties;
834
- (0, assert_1.default)(properties.length > 0, "".concat(filename, "\u81F3\u5C11\u9700\u8981\u6709\u4E00\u79CDlocale\u5B9A\u4E49"));
835
- var allEnumStringAttrs = Object.keys(enumAttributes);
836
- var typeArguments = type.typeArguments;
821
+ const { properties } = initializer;
822
+ (0, assert_1.default)(properties.length > 0, `${filename}至少需要有一种locale定义`);
823
+ const allEnumStringAttrs = Object.keys(enumAttributes);
824
+ const { typeArguments } = type;
837
825
  (0, assert_1.default)(typeArguments &&
838
826
  ts.isTypeReferenceNode(typeArguments[0])
839
- && ts.isIdentifier(typeArguments[0].typeName) && typeArguments[0].typeName.text === 'Schema', "".concat(filename, "\u4E2D\u7F3A\u5C11locale\u5B9A\u4E49\uFF0C\u6216\u8005locale\u7C7B\u578B\u5B9A\u4E49\u7684\u7B2C\u4E00\u4E2A\u53C2\u6570\u4E0D\u662FSchema"));
827
+ && ts.isIdentifier(typeArguments[0].typeName) && typeArguments[0].typeName.text === 'Schema', `${filename}中缺少locale定义,或者locale类型定义的第一个参数不是Schema`);
840
828
  if (hasActionDef) {
841
829
  (0, assert_1.default)(ts.isTypeReferenceNode(typeArguments[1])
842
- && ts.isIdentifier(typeArguments[1].typeName) && typeArguments[1].typeName.text === 'Action', "".concat(filename, "\u4E2Dlocale\u7C7B\u578B\u5B9A\u4E49\u7684\u7B2C\u4E8C\u4E2A\u53C2\u6570\u4E0D\u662FAction"));
830
+ && ts.isIdentifier(typeArguments[1].typeName) && typeArguments[1].typeName.text === 'Action', `${filename}中locale类型定义的第二个参数不是Action`);
843
831
  }
844
832
  else {
845
833
  (0, assert_1.default)(ts.isLiteralTypeNode(typeArguments[1])
846
- && ts.isStringLiteral(typeArguments[1].literal), "".concat(filename, "\u4E2Dlocale\u7C7B\u578B\u5B9A\u4E49\u7684\u7B2C\u4E8C\u4E2A\u53C2\u6570\u4E0D\u662F\u5B57\u7B26\u4E32"));
834
+ && ts.isStringLiteral(typeArguments[1].literal), `${filename}中locale类型定义的第二个参数不是字符串`);
847
835
  }
848
836
  if (hasRelationDef) {
849
837
  (0, assert_1.default)(ts.isTypeReferenceNode(typeArguments[2])
850
838
  && ts.isIdentifier(typeArguments[2].typeName)
851
- && typeArguments[2].typeName.text === 'Relation', "".concat(filename, "\u4E2D\u7684locale\u7C7B\u578B\u5B9A\u4E49\u7684\u7B2C\u4E09\u4E2A\u53C2\u6570\u4E0D\u662FRelation"));
839
+ && typeArguments[2].typeName.text === 'Relation', `${filename}中的locale类型定义的第三个参数不是Relation`);
852
840
  }
853
841
  else {
854
842
  (0, assert_1.default)(ts.isLiteralTypeNode(typeArguments[2])
855
- && ts.isStringLiteral(typeArguments[2].literal), "".concat(filename, "\u4E2Dlocale\u7C7B\u578B\u5B9A\u4E49\u7684\u7B2C\u4E09\u4E2A\u53C2\u6570\u4E0D\u662F\u7A7A\u5B57\u7B26\u4E32"));
843
+ && ts.isStringLiteral(typeArguments[2].literal), `${filename}中locale类型定义的第三个参数不是空字符串`);
856
844
  }
857
845
  if (allEnumStringAttrs.length > 0) {
858
- (0, assert_1.default)(ts.isTypeLiteralNode(typeArguments[3]), "".concat(filename, "\u4E2D\u7684locale\u7C7B\u578B\u5B9A\u4E49\u7684\u7B2C\u56DB\u4E2A\u53C2\u6570\u4E0D\u662F{}"));
846
+ (0, assert_1.default)(ts.isTypeLiteralNode(typeArguments[3]), `${filename}中的locale类型定义的第四个参数不是{}`);
859
847
  checkLocaleEnumAttrs(typeArguments[3], allEnumStringAttrs, filename);
860
848
  }
861
849
  else {
862
- (0, assert_1.default)(ts.isTypeLiteralNode(typeArguments[3]), "".concat(filename, "\u4E2D\u7684locale\u7C7B\u578B\u5B9A\u4E49\u7684\u7B2C\u56DB\u4E2A\u53C2\u6570\u4E0D\u662F{}"));
863
- (0, assert_1.default)(typeArguments[3].members.length == 0, "".concat(filename, "\u4E2Dlocale\u7C7B\u578B\u5B9A\u4E49\u7684\u7B2C\u56DB\u4E2A\u53C2\u6570\u4E0D\u5E94\u5B58\u5728\u76F8\u5E94\u7684v\u5B9A\u4E49"));
850
+ (0, assert_1.default)(ts.isTypeLiteralNode(typeArguments[3]), `${filename}中的locale类型定义的第四个参数不是{}`);
851
+ (0, assert_1.default)(typeArguments[3].members.length == 0, `${filename}中locale类型定义的第四个参数不应存在相应的v定义`);
864
852
  }
865
- dealWithLocales_1(initializer);
853
+ dealWithLocales(initializer);
866
854
  }
867
855
  else if (declaration.type && ts.isTypeReferenceNode(declaration.type) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'Configuration') {
868
- console.log("\u300C".concat(filename, "\u300D\u76F4\u63A5\u5B9A\u4E49configuration\u7684\u5199\u6CD5\u5DF2\u7ECF\u8FC7\u65F6\uFF0C\u8BF7\u5B9A\u4E49\u5728entityDesc\u4E2D"));
856
+ console.log(`「${filename}」直接定义configuration的写法已经过时,请定义在entityDesc中`);
869
857
  (0, assert_1.default)(ts.isObjectLiteralExpression(declaration.initializer));
870
- dealWithConfiguration_1(declaration.initializer);
858
+ dealWithConfiguration(declaration.initializer);
871
859
  }
872
860
  else if (declaration.type && ts.isTypeReferenceNode(declaration.type) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'EntityDesc') {
873
861
  (0, assert_1.default)(ts.isObjectLiteralExpression(declaration.initializer));
874
- var properties = declaration.initializer.properties;
875
- var localesProperty = properties.find(function (ele) { return ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'locales'; });
862
+ const { properties } = declaration.initializer;
863
+ const localesProperty = properties.find(ele => ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'locales');
876
864
  (0, assert_1.default)(ts.isPropertyAssignment(localesProperty));
877
- dealWithLocales_1(localesProperty.initializer);
878
- var indexesProperty = properties.find(function (ele) { return ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'indexes'; });
865
+ dealWithLocales(localesProperty.initializer);
866
+ const indexesProperty = properties.find(ele => ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'indexes');
879
867
  if (indexesProperty) {
880
868
  (0, assert_1.default)(ts.isPropertyAssignment(indexesProperty));
881
- dealWithIndexes_1(indexesProperty.initializer);
869
+ dealWithIndexes(indexesProperty.initializer);
882
870
  }
883
- var configurationProperty = properties.find(function (ele) { return ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'configuration'; });
871
+ const configurationProperty = properties.find(ele => ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'configuration');
884
872
  if (configurationProperty) {
885
873
  (0, assert_1.default)(ts.isPropertyAssignment(configurationProperty));
886
- dealWithConfiguration_1(configurationProperty.initializer);
874
+ dealWithConfiguration(configurationProperty.initializer);
887
875
  }
888
876
  }
889
877
  else {
890
- throw new Error("".concat(moduleName, "\uFF1A\u4E0D\u80FD\u7406\u89E3\u7684\u5B9A\u4E49\u5185\u5BB9").concat(declaration.name.text));
878
+ throw new Error(`${moduleName}:不能理解的定义内容${declaration.name.text}`);
891
879
  }
892
880
  });
893
881
  }
894
882
  });
895
883
  // 要等configuration确定了actionType后再处理
896
884
  if (hasActionDef) {
897
- var actionDefNodes = [
885
+ const actionDefNodes = [
898
886
  factory.createTypeReferenceNode(OriginActionDict[actionType], undefined),
899
887
  factory.createTypeReferenceNode('ParticularAction', undefined)
900
888
  ];
@@ -904,24 +892,24 @@ function analyzeEntity(filename, path, program, relativePath) {
904
892
  if (process.env.COMPLING_AS_LIB) {
905
893
  actionDefNodes.push(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
906
894
  }
907
- pushStatementIntoActionAst(moduleName, factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Action"), undefined, factory.createUnionTypeNode(actionDefNodes)), sourceFile);
895
+ pushStatementIntoActionAst(moduleName, factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Action"), undefined, factory.createUnionTypeNode(actionDefNodes)), sourceFile);
908
896
  }
909
897
  if (!hasActionDef && hasActionOrStateDef) {
910
- throw new Error("".concat(filename, "\u4E2D\u6709Action\u6216State\u5B9A\u4E49\uFF0C\u4F46\u6CA1\u6709\u5B9A\u4E49\u5B8C\u6574\u7684Action\u7C7B\u578B"));
898
+ throw new Error(`${filename}中有Action或State定义,但没有定义完整的Action类型`);
911
899
  }
912
900
  if (hasActionDef && actionType !== 'crud') {
913
- throw new Error("".concat(filename, "\u4E2D\u6709Action\u5B9A\u4E49\uFF0C\u4F46\u5374\u5B9A\u4E49\u4E86actionType\u4E0D\u662Fcrud"));
914
- }
915
- (0, assert_1.default)(schemaAttrs.length > 0, "\u5BF9\u8C61".concat(moduleName, "\u6CA1\u6709\u4EFB\u4F55\u5C5E\u6027\u5B9A\u4E49"));
916
- var schema = {
917
- schemaAttrs: schemaAttrs,
918
- sourceFile: sourceFile,
919
- toModi: toModi,
920
- actionType: actionType,
901
+ throw new Error(`${filename}中有Action定义,但却定义了actionType不是crud`);
902
+ }
903
+ (0, assert_1.default)(schemaAttrs.length > 0, `对象${moduleName}没有任何属性定义`);
904
+ const schema = {
905
+ schemaAttrs,
906
+ sourceFile,
907
+ toModi,
908
+ actionType,
921
909
  static: _static,
922
- hasRelationDef: hasRelationDef,
923
- enumAttributes: enumAttributes,
924
- additionalImports: additionalImports,
910
+ hasRelationDef,
911
+ enumAttributes,
912
+ additionalImports,
925
913
  };
926
914
  if (hasFulltextIndex) {
927
915
  (0, lodash_1.assign)(schema, {
@@ -930,11 +918,11 @@ function analyzeEntity(filename, path, program, relativePath) {
930
918
  }
931
919
  if (indexes) {
932
920
  (0, lodash_1.assign)(schema, {
933
- indexes: indexes,
921
+ indexes,
934
922
  });
935
923
  }
936
924
  if (!localeDef) {
937
- throw new Error("".concat(filename, "\u4E2D\u7F3A\u5C11\u4E86locale\u5B9A\u4E49"));
925
+ throw new Error(`${filename}中缺少了locale定义`);
938
926
  }
939
927
  else {
940
928
  (0, lodash_1.assign)(schema, {
@@ -960,9 +948,9 @@ function analyzeEntity(filename, path, program, relativePath) {
960
948
  assert(!relationHierarchy, `${filename}中具有relationHierarchy定义但没有Relation定义`);
961
949
  assert(!reverseCascadeRelationHierarchy, `${filename}中具有reverseCascadeRelationHierarchy定义但没有Relation定义`)
962
950
  } */
963
- (0, lodash_1.assign)(Schema, (_a = {},
964
- _a[moduleName] = schema,
965
- _a));
951
+ (0, lodash_1.assign)(Schema, {
952
+ [moduleName]: schema,
953
+ });
966
954
  }
967
955
  /**
968
956
  * 生成Schema
@@ -971,57 +959,53 @@ function analyzeEntity(filename, path, program, relativePath) {
971
959
  * @param entity
972
960
  */
973
961
  function constructSchema(statements, entity) {
974
- var e_1, _a, e_2, _b;
975
- var schemaAttrs = Schema[entity].schemaAttrs;
976
- var members = [];
977
- var members2 = [];
978
- var _c = ManyToOne, _d = entity, manyToOneSet = _c[_d];
979
- var _e = OneToMany, _f = entity, oneToManySet = _e[_f];
980
- var referenceEntities = [];
981
- var _loop_1 = function (attr) {
982
- var type = attr.type, name_2 = attr.name, questionToken = attr.questionToken;
983
- var attrName = name_2.text;
962
+ const { schemaAttrs } = Schema[entity];
963
+ const members = [];
964
+ const members2 = [];
965
+ const { [entity]: manyToOneSet } = ManyToOne;
966
+ const { [entity]: oneToManySet } = OneToMany;
967
+ const referenceEntities = [];
968
+ for (const attr of schemaAttrs) {
969
+ const { type, name, questionToken } = attr;
970
+ const attrName = name.text;
984
971
  if (ts.isTypeReferenceNode(type)) {
985
- var typeName = type.typeName;
972
+ const { typeName } = type;
986
973
  if (ts.isIdentifier(typeName)) {
987
- var text = typeName.text;
988
- var text2_2 = text === 'Schema' ? entity : text;
989
- var manyToOneItem = manyToOneSet && manyToOneSet.find(function (_a) {
990
- var _b = tslib_1.__read(_a, 2), refEntity = _b[0], attrName = _b[1];
991
- return refEntity === text2_2 && attrName === attrName;
992
- });
974
+ const { text } = typeName;
975
+ const text2 = text === 'Schema' ? entity : text;
976
+ const manyToOneItem = manyToOneSet && manyToOneSet.find(([refEntity, attrName]) => refEntity === text2 && attrName === attrName);
993
977
  if (manyToOneItem) {
994
- referenceEntities.push(text2_2);
995
- members2.push(factory.createPropertySignature(undefined, name_2, questionToken, questionToken ? factory.createUnionTypeNode([
996
- factory.createTypeReferenceNode(createForeignRef(entity, text2_2, 'Schema')),
978
+ referenceEntities.push(text2);
979
+ members2.push(factory.createPropertySignature(undefined, name, questionToken, questionToken ? factory.createUnionTypeNode([
980
+ factory.createTypeReferenceNode(createForeignRef(entity, text2, 'Schema')),
997
981
  factory.createLiteralTypeNode(factory.createNull())
998
- ]) : factory.createTypeReferenceNode(createForeignRef(entity, text2_2, 'Schema'))));
999
- var foreignKey = "".concat(attrName, "Id");
982
+ ]) : factory.createTypeReferenceNode(createForeignRef(entity, text2, 'Schema'))));
983
+ const foreignKey = `${attrName}Id`;
1000
984
  members.push(factory.createPropertySignature(undefined, factory.createIdentifier(foreignKey), questionToken, questionToken ? factory.createUnionTypeNode([
1001
985
  factory.createTypeReferenceNode(factory.createIdentifier('ForeignKey'), [
1002
- factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(text2_2)))
986
+ factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(text2)))
1003
987
  ]),
1004
988
  factory.createLiteralTypeNode(factory.createNull())
1005
989
  ]) : factory.createTypeReferenceNode(factory.createIdentifier('ForeignKey'), [
1006
- factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(text2_2)))
990
+ factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(text2)))
1007
991
  ])));
1008
992
  }
1009
993
  else {
1010
994
  // assert(types.includes(text), `${entity}中的属性${name.toString()}有非法的属性类型定义`);
1011
995
  // 处理entity这种特殊情况
1012
996
  if (ReversePointerRelations[entity] && attrName === 'entity') {
1013
- var entityUnionTypeNode = ReversePointerRelations[entity].map(function (ele) { return factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(ele))); });
997
+ const entityUnionTypeNode = ReversePointerRelations[entity].map(ele => factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(ele))));
1014
998
  if (process.env.COMPLING_AS_LIB) {
1015
999
  // 如果是建立 base-domain,还要容纳可能的其它对象引用
1016
1000
  entityUnionTypeNode.push(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
1017
1001
  }
1018
- members.push(factory.createPropertySignature(undefined, name_2, questionToken, questionToken ? factory.createUnionTypeNode([
1002
+ members.push(factory.createPropertySignature(undefined, name, questionToken, questionToken ? factory.createUnionTypeNode([
1019
1003
  factory.createUnionTypeNode(entityUnionTypeNode),
1020
1004
  factory.createLiteralTypeNode(factory.createNull())
1021
1005
  ]) : factory.createUnionTypeNode(entityUnionTypeNode)));
1022
1006
  }
1023
1007
  else {
1024
- members.push(factory.createPropertySignature(undefined, name_2, questionToken, questionToken ? factory.createUnionTypeNode([
1008
+ members.push(factory.createPropertySignature(undefined, name, questionToken, questionToken ? factory.createUnionTypeNode([
1025
1009
  type,
1026
1010
  factory.createLiteralTypeNode(factory.createNull())
1027
1011
  ]) : type));
@@ -1034,87 +1018,61 @@ function constructSchema(statements, entity) {
1034
1018
  }
1035
1019
  }
1036
1020
  else {
1037
- (0, assert_1.default)(ts.isUnionTypeNode(type) || ts.isLiteralTypeNode(type), "".concat(entity, "\u6709\u975E\u6CD5\u7684\u5C5E\u6027\u7C7B\u578B\u5B9A\u4E49").concat(name_2.text));
1038
- members.push(factory.createPropertySignature(undefined, name_2, questionToken, questionToken ? factory.createUnionTypeNode([
1021
+ (0, assert_1.default)(ts.isUnionTypeNode(type) || ts.isLiteralTypeNode(type), `${entity}有非法的属性类型定义${name.text}`);
1022
+ members.push(factory.createPropertySignature(undefined, name, questionToken, questionToken ? factory.createUnionTypeNode([
1039
1023
  type,
1040
1024
  factory.createLiteralTypeNode(factory.createNull())
1041
1025
  ]) : type));
1042
1026
  }
1043
- };
1044
- try {
1045
- for (var schemaAttrs_1 = tslib_1.__values(schemaAttrs), schemaAttrs_1_1 = schemaAttrs_1.next(); !schemaAttrs_1_1.done; schemaAttrs_1_1 = schemaAttrs_1.next()) {
1046
- var attr = schemaAttrs_1_1.value;
1047
- _loop_1(attr);
1048
- }
1049
- }
1050
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1051
- finally {
1052
- try {
1053
- if (schemaAttrs_1_1 && !schemaAttrs_1_1.done && (_a = schemaAttrs_1.return)) _a.call(schemaAttrs_1);
1054
- }
1055
- finally { if (e_1) throw e_1.error; }
1056
1027
  }
1057
1028
  // 处理reverserPointer
1058
- var reverseOnes = ReversePointerRelations[entity];
1029
+ const reverseOnes = ReversePointerRelations[entity];
1059
1030
  if (reverseOnes) {
1060
- reverseOnes.forEach(function (one) {
1031
+ reverseOnes.forEach((one) => {
1061
1032
  referenceEntities.push(one);
1062
1033
  members2.push(factory.createPropertySignature(undefined, (0, string_1.firstLetterLowerCase)(one), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one, 'Schema'))));
1063
1034
  });
1064
1035
  }
1065
- var foreignKeySet = {};
1036
+ const foreignKeySet = {};
1066
1037
  if (oneToManySet) {
1067
- try {
1068
- for (var oneToManySet_1 = tslib_1.__values(oneToManySet), oneToManySet_1_1 = oneToManySet_1.next(); !oneToManySet_1_1.done; oneToManySet_1_1 = oneToManySet_1.next()) {
1069
- var oneToManyItem = oneToManySet_1_1.value;
1070
- var _g = tslib_1.__read(oneToManyItem, 2), entityName = _g[0], foreignKey = _g[1];
1071
- if (referenceEntities.indexOf(entityName) === -1) {
1072
- referenceEntities.push(entityName);
1073
- }
1074
- if (foreignKeySet.hasOwnProperty(entityName)) {
1075
- foreignKeySet[entityName].push(foreignKey);
1076
- }
1077
- else {
1078
- foreignKeySet[entityName] = [foreignKey];
1079
- }
1038
+ for (const oneToManyItem of oneToManySet) {
1039
+ const [entityName, foreignKey] = oneToManyItem;
1040
+ if (referenceEntities.indexOf(entityName) === -1) {
1041
+ referenceEntities.push(entityName);
1080
1042
  }
1081
- }
1082
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1083
- finally {
1084
- try {
1085
- if (oneToManySet_1_1 && !oneToManySet_1_1.done && (_b = oneToManySet_1.return)) _b.call(oneToManySet_1);
1043
+ if (foreignKeySet.hasOwnProperty(entityName)) {
1044
+ foreignKeySet[entityName].push(foreignKey);
1045
+ }
1046
+ else {
1047
+ foreignKeySet[entityName] = [foreignKey];
1086
1048
  }
1087
- finally { if (e_2) throw e_2.error; }
1088
1049
  }
1089
- var _loop_2 = function (entityName) {
1090
- var entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
1091
- foreignKeySet[entityName].forEach(function (foreignKey) {
1092
- var identifier = "".concat(entityNameLc, "$").concat(foreignKey);
1050
+ for (const entityName in foreignKeySet) {
1051
+ const entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
1052
+ foreignKeySet[entityName].forEach((foreignKey) => {
1053
+ const identifier = `${entityNameLc}$${foreignKey}`;
1093
1054
  members2.push(factory.createPropertySignature(undefined, identifier, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(factory.createIdentifier("Array"), [factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'Schema'), undefined)])));
1094
- var aggrIdentifier = "".concat(entityNameLc, "$").concat(foreignKey, "$$aggr");
1055
+ const aggrIdentifier = `${entityNameLc}$${foreignKey}$$aggr`;
1095
1056
  members2.push(factory.createPropertySignature(undefined, aggrIdentifier, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(factory.createIdentifier("AggregationResult"), [factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'Schema'), undefined)])));
1096
1057
  });
1097
- };
1098
- for (var entityName in foreignKeySet) {
1099
- _loop_2(entityName);
1100
1058
  }
1101
1059
  }
1102
- (0, lodash_1.uniq)(referenceEntities).forEach(function (ele) {
1060
+ (0, lodash_1.uniq)(referenceEntities).forEach((ele) => {
1103
1061
  if (ele !== entity) {
1104
- statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamespaceImport(factory.createIdentifier(ele))), factory.createStringLiteral("../".concat(ele, "/Schema"))));
1062
+ statements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamespaceImport(factory.createIdentifier(ele))), factory.createStringLiteral(`../${ele}/Schema`)));
1105
1063
  }
1106
1064
  });
1107
1065
  // 在这里把需要直接拷贝过来的语句写入
1108
1066
  if (SchemaAsts[entity]) {
1109
- statements.push.apply(statements, tslib_1.__spreadArray([], tslib_1.__read(SchemaAsts[entity].statements), false));
1067
+ statements.push(...SchemaAsts[entity].statements);
1110
1068
  }
1111
- statements.push(factory.createTypeAliasDeclaration(undefined, [
1069
+ statements.push(factory.createTypeAliasDeclaration([
1112
1070
  factory.createModifier(ts.SyntaxKind.ExportKeyword)
1113
1071
  ], factory.createIdentifier('OpSchema'), undefined, factory.createIntersectionTypeNode([
1114
1072
  factory.createTypeReferenceNode('EntityShape'),
1115
1073
  factory.createTypeLiteralNode(members)
1116
- ])), factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("OpAttr"), undefined, factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeReferenceNode(factory.createIdentifier("OpSchema"), undefined))));
1117
- statements.push(factory.createTypeAliasDeclaration(undefined, [
1074
+ ])), factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("OpAttr"), undefined, factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeReferenceNode(factory.createIdentifier("OpSchema"), undefined))));
1075
+ statements.push(factory.createTypeAliasDeclaration([
1118
1076
  factory.createModifier(ts.SyntaxKind.ExportKeyword)
1119
1077
  ], factory.createIdentifier('Schema'), undefined, factory.createIntersectionTypeNode([
1120
1078
  factory.createTypeReferenceNode('EntityShape'),
@@ -1129,9 +1087,8 @@ function constructSchema(statements, entity) {
1129
1087
  * @param entity
1130
1088
  */
1131
1089
  function constructFilter(statements, entity) {
1132
- var e_3, _a, e_4, _b;
1133
- var _c = Schema[entity], schemaAttrs = _c.schemaAttrs, fulltextIndex = _c.fulltextIndex, enumAttributes = _c.enumAttributes;
1134
- var members = [
1090
+ const { schemaAttrs, fulltextIndex, enumAttributes } = Schema[entity];
1091
+ const members = [
1135
1092
  // id: Q_StringValue
1136
1093
  factory.createPropertySignature(undefined, factory.createIdentifier('id'), undefined, factory.createUnionTypeNode([
1137
1094
  factory.createTypeReferenceNode(factory.createIdentifier('Q_StringValue')),
@@ -1149,19 +1106,19 @@ function constructFilter(statements, entity) {
1149
1106
  // $$updateAt$$: Q_DateValue
1150
1107
  factory.createPropertySignature(undefined, factory.createIdentifier('$$updateAt$$'), undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_DateValue')))
1151
1108
  ];
1152
- var _d = ManyToOne, _e = entity, manyToOneSet = _d[_e];
1153
- var entityUnionTypeNodes = ReversePointerRelations[entity] && ReversePointerRelations[entity].map(function (ele) { return factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(ele))); });
1109
+ const { [entity]: manyToOneSet } = ManyToOne;
1110
+ const entityUnionTypeNodes = ReversePointerRelations[entity] && ReversePointerRelations[entity].map(ele => factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(ele))));
1154
1111
  if (process.env.COMPLING_AS_LIB) {
1155
1112
  entityUnionTypeNodes && entityUnionTypeNodes.push(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
1156
1113
  }
1157
- var _loop_3 = function (attr) {
1158
- var _j = attr, type = _j.type, name_3 = _j.name;
1159
- var attrName = name_3.text;
1114
+ for (const attr of schemaAttrs) {
1115
+ const { type, name } = attr;
1116
+ const attrName = name.text;
1160
1117
  if (ts.isTypeReferenceNode(type)) {
1161
- var typeName = type.typeName;
1118
+ const { typeName } = type;
1162
1119
  if (ts.isIdentifier(typeName)) {
1163
- var text = typeName.text;
1164
- var type2 = void 0;
1120
+ const { text } = typeName;
1121
+ let type2;
1165
1122
  switch (text) {
1166
1123
  case 'String':
1167
1124
  case 'Text':
@@ -1181,7 +1138,8 @@ function constructFilter(statements, entity) {
1181
1138
  case 'Uint':
1182
1139
  case 'Float':
1183
1140
  case 'Double':
1184
- case 'Price': {
1141
+ case 'Price':
1142
+ case 'Decimal': {
1185
1143
  type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_NumberValue'));
1186
1144
  break;
1187
1145
  }
@@ -1203,15 +1161,12 @@ function constructFilter(statements, entity) {
1203
1161
  break;
1204
1162
  }
1205
1163
  default: {
1206
- var text2_3 = text === 'Schema' ? entity : text;
1207
- var manyToOneItem = manyToOneSet && manyToOneSet.find(function (_a) {
1208
- var _b = tslib_1.__read(_a, 1), refEntity = _b[0];
1209
- return refEntity === text2_3;
1210
- });
1164
+ const text2 = text === 'Schema' ? entity : text;
1165
+ const manyToOneItem = manyToOneSet && manyToOneSet.find(([refEntity]) => refEntity === text2);
1211
1166
  if (manyToOneItem) {
1212
1167
  // 外键可能落到相应的子查询中
1213
- members.push(factory.createPropertySignature(undefined, "".concat(name_3.text, "Id"), undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_StringValue'))));
1214
- type2 = factory.createTypeReferenceNode(createForeignRef(entity, text2_3, 'Filter'));
1168
+ members.push(factory.createPropertySignature(undefined, `${name.text}Id`, undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_StringValue'))));
1169
+ type2 = factory.createTypeReferenceNode(createForeignRef(entity, text2, 'Filter'));
1215
1170
  }
1216
1171
  else if (enumAttributes && enumAttributes[attrName] || ts.isUnionTypeNode(type)) {
1217
1172
  // 这里应该都是引用某个UnionType类型的定义了,如何判断?
@@ -1229,81 +1184,53 @@ function constructFilter(statements, entity) {
1229
1184
  }
1230
1185
  }
1231
1186
  if (type2) {
1232
- members.push(factory.createPropertySignature(undefined, name_3, undefined, type2));
1187
+ members.push(factory.createPropertySignature(undefined, name, undefined, type2));
1233
1188
  }
1234
1189
  }
1235
1190
  }
1236
1191
  else if (ts.isUnionTypeNode(type) && ts.isLiteralTypeNode(type.types[0]) || ts.isLiteralTypeNode(type)) {
1237
- members.push(factory.createPropertySignature(undefined, name_3, undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_EnumValue'), [
1192
+ members.push(factory.createPropertySignature(undefined, name, undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_EnumValue'), [
1238
1193
  type
1239
1194
  ])));
1240
1195
  }
1241
1196
  else {
1242
1197
  // 此时应当是引用本地定义的shape
1243
1198
  (0, assert_1.default)(type);
1244
- members.push(factory.createPropertySignature(undefined, name_3, undefined, factory.createTypeReferenceNode(factory.createIdentifier('JsonFilter'), [
1199
+ members.push(factory.createPropertySignature(undefined, name, undefined, factory.createTypeReferenceNode(factory.createIdentifier('JsonFilter'), [
1245
1200
  type
1246
1201
  ])));
1247
1202
  }
1248
- };
1249
- try {
1250
- for (var schemaAttrs_2 = tslib_1.__values(schemaAttrs), schemaAttrs_2_1 = schemaAttrs_2.next(); !schemaAttrs_2_1.done; schemaAttrs_2_1 = schemaAttrs_2.next()) {
1251
- var attr = schemaAttrs_2_1.value;
1252
- _loop_3(attr);
1253
- }
1254
- }
1255
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1256
- finally {
1257
- try {
1258
- if (schemaAttrs_2_1 && !schemaAttrs_2_1.done && (_a = schemaAttrs_2.return)) _a.call(schemaAttrs_2);
1259
- }
1260
- finally { if (e_3) throw e_3.error; }
1261
1203
  }
1262
1204
  // type AttrFilter = {};
1263
1205
  if (ReversePointerRelations[entity]) {
1264
1206
  // 有反向指针,将反向指针关联的对象的Filter也注入
1265
- ReversePointerRelations[entity].forEach(function (ele) {
1266
- return members.push(factory.createPropertySignature(undefined, (0, string_1.firstLetterLowerCase)(ele), undefined, factory.createTypeReferenceNode(createForeignRef(entity, ele, 'Filter'))));
1267
- });
1207
+ ReversePointerRelations[entity].forEach(ele => members.push(factory.createPropertySignature(undefined, (0, string_1.firstLetterLowerCase)(ele), undefined, factory.createTypeReferenceNode(createForeignRef(entity, ele, 'Filter')))));
1268
1208
  }
1269
1209
  // 一对多的生成子查询
1270
- var _f = OneToMany, _g = entity, oneToManySet = _f[_g];
1210
+ const { [entity]: oneToManySet } = OneToMany;
1271
1211
  if (oneToManySet) {
1272
- var foreignKeySet = {};
1273
- try {
1274
- for (var oneToManySet_2 = tslib_1.__values(oneToManySet), oneToManySet_2_1 = oneToManySet_2.next(); !oneToManySet_2_1.done; oneToManySet_2_1 = oneToManySet_2.next()) {
1275
- var oneToManyItem = oneToManySet_2_1.value;
1276
- var _h = tslib_1.__read(oneToManyItem, 2), entityName = _h[0], foreignKey = _h[1];
1277
- if (foreignKeySet.hasOwnProperty(entityName)) {
1278
- foreignKeySet[entityName].push(foreignKey);
1279
- }
1280
- else {
1281
- foreignKeySet[entityName] = [foreignKey];
1282
- }
1212
+ const foreignKeySet = {};
1213
+ for (const oneToManyItem of oneToManySet) {
1214
+ const [entityName, foreignKey] = oneToManyItem;
1215
+ if (foreignKeySet.hasOwnProperty(entityName)) {
1216
+ foreignKeySet[entityName].push(foreignKey);
1283
1217
  }
1284
- }
1285
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1286
- finally {
1287
- try {
1288
- if (oneToManySet_2_1 && !oneToManySet_2_1.done && (_b = oneToManySet_2.return)) _b.call(oneToManySet_2);
1218
+ else {
1219
+ foreignKeySet[entityName] = [foreignKey];
1289
1220
  }
1290
- finally { if (e_4) throw e_4.error; }
1291
1221
  }
1292
- var _loop_4 = function (entityName) {
1293
- var entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
1294
- foreignKeySet[entityName].forEach(function (foreignKey) {
1295
- var identifier = "".concat(entityNameLc, "$").concat(foreignKey);
1222
+ for (const entityName in foreignKeySet) {
1223
+ const entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
1224
+ foreignKeySet[entityName].forEach((foreignKey) => {
1225
+ const identifier = `${entityNameLc}$${foreignKey}`;
1296
1226
  members.push(factory.createPropertySignature(undefined, identifier, undefined, factory.createIntersectionTypeNode([
1297
1227
  factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'Filter'), undefined),
1298
1228
  factory.createTypeReferenceNode('SubQueryPredicateMetadata')
1299
1229
  ])));
1300
1230
  });
1301
- };
1302
- for (var entityName in foreignKeySet) {
1303
- _loop_4(entityName);
1304
1231
  }
1305
1232
  }
1306
- statements.push(factory.createTypeAliasDeclaration(undefined, undefined, factory.createIdentifier('AttrFilter'), undefined, factory.createTypeLiteralNode(members)));
1233
+ statements.push(factory.createTypeAliasDeclaration(undefined, factory.createIdentifier('AttrFilter'), undefined, factory.createTypeLiteralNode(members)));
1307
1234
  /**
1308
1235
  *
1309
1236
  export type Filter = AttrFilter | Partial<ExprOp<OpSchema> | {
@@ -1313,7 +1240,7 @@ function constructFilter(statements, entity) {
1313
1240
  }>;
1314
1241
 
1315
1242
  */
1316
- var types = [
1243
+ const types = [
1317
1244
  factory.createTypeReferenceNode(factory.createIdentifier("AttrFilter")),
1318
1245
  factory.createTypeReferenceNode(factory.createIdentifier("ExprOp"), [
1319
1246
  process.env.COMPLING_AS_LIB ?
@@ -1328,7 +1255,7 @@ function constructFilter(statements, entity) {
1328
1255
  if (fulltextIndex) {
1329
1256
  types.push(factory.createTypeReferenceNode('FulltextFilter'));
1330
1257
  }
1331
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Filter"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("MakeFilter"), [factory.createIntersectionTypeNode(types)])));
1258
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Filter"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("MakeFilter"), [factory.createIntersectionTypeNode(types)])));
1332
1259
  }
1333
1260
  /**
1334
1261
  * 构造Projection和OneAttrProjection
@@ -1336,26 +1263,24 @@ function constructFilter(statements, entity) {
1336
1263
  * @param entity
1337
1264
  */
1338
1265
  function constructProjection(statements, entity) {
1339
- var _a, e_5, _b, e_6, _c;
1340
- var _d = Schema[entity], schemaAttrs = _d.schemaAttrs, enumAttributes = _d.enumAttributes;
1341
- var properties = [
1266
+ const { schemaAttrs, enumAttributes } = Schema[entity];
1267
+ const properties = [
1342
1268
  ['id', false],
1343
1269
  ['$$createAt$$', false],
1344
1270
  ['$$updateAt$$', false],
1345
1271
  ['$$seq$$', false],
1346
1272
  ];
1347
- var foreignKeyProperties = (_a = {},
1348
- _a[entity] = [''],
1349
- _a);
1350
- var _e = ManyToOne, _f = entity, manyToOneSet = _e[_f];
1351
- var _loop_5 = function (attr) {
1352
- var _k;
1353
- var _l = attr, type = _l.type, name_4 = _l.name;
1354
- var attrName = name_4.text;
1273
+ const foreignKeyProperties = {
1274
+ [entity]: [''],
1275
+ };
1276
+ const { [entity]: manyToOneSet } = ManyToOne;
1277
+ for (const attr of schemaAttrs) {
1278
+ const { type, name } = attr;
1279
+ const attrName = name.text;
1355
1280
  if (ts.isTypeReferenceNode(type)) {
1356
- var typeName = type.typeName;
1281
+ const { typeName } = type;
1357
1282
  if (ts.isIdentifier(typeName)) {
1358
- var text = typeName.text;
1283
+ const { text } = typeName;
1359
1284
  switch (text) {
1360
1285
  case 'String':
1361
1286
  case 'Text':
@@ -1369,49 +1294,47 @@ function constructProjection(statements, entity) {
1369
1294
  case 'File':
1370
1295
  case 'SingleGeo':
1371
1296
  case 'Geo':
1372
- case 'Price': {
1373
- properties.push([name_4, false]);
1297
+ case 'Price':
1298
+ case 'Decimal': {
1299
+ properties.push([name, false]);
1374
1300
  break;
1375
1301
  }
1376
1302
  case 'Object': {
1377
- properties.push([name_4, false, factory.createUnionTypeNode([
1303
+ properties.push([name, false, factory.createUnionTypeNode([
1378
1304
  factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
1379
1305
  factory.createTypeReferenceNode(factory.createIdentifier("Object"), undefined)
1380
1306
  ])]);
1381
1307
  break;
1382
1308
  }
1383
1309
  default: {
1384
- var text2_4 = text === 'Schema' ? entity : text;
1385
- var manyToOneItem = manyToOneSet && manyToOneSet.find(function (_a) {
1386
- var _b = tslib_1.__read(_a, 1), refEntity = _b[0];
1387
- return refEntity === text2_4;
1388
- });
1310
+ const text2 = text === 'Schema' ? entity : text;
1311
+ const manyToOneItem = manyToOneSet && manyToOneSet.find(([refEntity]) => refEntity === text2);
1389
1312
  if (manyToOneItem) {
1390
1313
  // 外键投影
1391
- properties.push(["".concat(attrName, "Id"), false, undefined], [name_4, false, factory.createTypeReferenceNode(createForeignRef(entity, text2_4, 'Projection')) /* , factory.createTypeReferenceNode(
1314
+ properties.push([`${attrName}Id`, false, undefined], [name, false, factory.createTypeReferenceNode(createForeignRef(entity, text2, 'Projection')) /* , factory.createTypeReferenceNode(
1392
1315
  createForeignRef(entity, text2, 'ExportProjection')
1393
1316
  ) */
1394
1317
  ]);
1395
- if (foreignKeyProperties.hasOwnProperty(text2_4)) {
1396
- foreignKeyProperties[text2_4].push(attrName);
1318
+ if (foreignKeyProperties.hasOwnProperty(text2)) {
1319
+ foreignKeyProperties[text2].push(attrName);
1397
1320
  }
1398
1321
  else {
1399
- (0, lodash_1.assign)(foreignKeyProperties, (_k = {},
1400
- _k[text2_4] = [attrName],
1401
- _k));
1322
+ (0, lodash_1.assign)(foreignKeyProperties, {
1323
+ [text2]: [attrName],
1324
+ });
1402
1325
  }
1403
1326
  }
1404
1327
  else {
1405
1328
  if (!enumAttributes || !enumAttributes[attrName]) {
1406
1329
  // 引用的非enum类型shape
1407
- properties.push([name_4, false, factory.createUnionTypeNode([
1330
+ properties.push([name, false, factory.createUnionTypeNode([
1408
1331
  factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
1409
1332
  factory.createTypeReferenceNode(factory.createIdentifier("JsonProjection"), [type])
1410
1333
  ])]);
1411
1334
  }
1412
1335
  else {
1413
1336
  // 引用的enum类型shape
1414
- properties.push([name_4, false, undefined]);
1337
+ properties.push([name, false, undefined]);
1415
1338
  }
1416
1339
  }
1417
1340
  }
@@ -1425,34 +1348,20 @@ function constructProjection(statements, entity) {
1425
1348
  // 增加了本身object的shape定义
1426
1349
  // assert(ts.isUnionTypeNode(type!) && ts.isLiteralTypeNode(type.types[0]) || ts.isLiteralTypeNode(type!));
1427
1350
  if (enumAttributes && enumAttributes[attrName] || ts.isUnionTypeNode(type) && ts.isLiteralTypeNode(type.types[0])) {
1428
- properties.push([name_4, false, undefined]);
1351
+ properties.push([name, false, undefined]);
1429
1352
  }
1430
1353
  else {
1431
1354
  // 如果是非枚举类型的其它对象的union定义,加上JsonProjection
1432
- properties.push([name_4, false, factory.createUnionTypeNode([
1355
+ properties.push([name, false, factory.createUnionTypeNode([
1433
1356
  factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
1434
1357
  factory.createTypeReferenceNode(factory.createIdentifier("JsonProjection"), [type])
1435
1358
  ])]);
1436
1359
  }
1437
1360
  }
1438
- };
1439
- try {
1440
- for (var schemaAttrs_3 = tslib_1.__values(schemaAttrs), schemaAttrs_3_1 = schemaAttrs_3.next(); !schemaAttrs_3_1.done; schemaAttrs_3_1 = schemaAttrs_3.next()) {
1441
- var attr = schemaAttrs_3_1.value;
1442
- _loop_5(attr);
1443
- }
1444
- }
1445
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
1446
- finally {
1447
- try {
1448
- if (schemaAttrs_3_1 && !schemaAttrs_3_1.done && (_b = schemaAttrs_3.return)) _b.call(schemaAttrs_3);
1449
- }
1450
- finally { if (e_5) throw e_5.error; }
1451
1361
  }
1452
1362
  if (ReversePointerRelations[entity]) {
1453
- ReversePointerRelations[entity].forEach(function (one) {
1454
- var _a;
1455
- var text2 = one === 'Schema' ? entity : one;
1363
+ ReversePointerRelations[entity].forEach((one) => {
1364
+ const text2 = one === 'Schema' ? entity : one;
1456
1365
  properties.push([(0, string_1.firstLetterLowerCase)(one), false, factory.createTypeReferenceNode(createForeignRef(entity, one, 'Projection')) /* , factory.createTypeReferenceNode(
1457
1366
  createForeignRef(entity, one, 'ExportProjection')
1458
1367
  ) */
@@ -1461,40 +1370,30 @@ function constructProjection(statements, entity) {
1461
1370
  foreignKeyProperties[text2].push('entity');
1462
1371
  }
1463
1372
  else {
1464
- (0, lodash_1.assign)(foreignKeyProperties, (_a = {},
1465
- _a[text2] = ['entity'],
1466
- _a));
1373
+ (0, lodash_1.assign)(foreignKeyProperties, {
1374
+ [text2]: ['entity'],
1375
+ });
1467
1376
  }
1468
1377
  });
1469
1378
  }
1470
1379
  // 一对多的projection
1471
- var _g = OneToMany, _h = entity, oneToManySet = _g[_h];
1380
+ const { [entity]: oneToManySet } = OneToMany;
1472
1381
  if (oneToManySet) {
1473
- var foreignKeySet = {};
1474
- try {
1475
- for (var oneToManySet_3 = tslib_1.__values(oneToManySet), oneToManySet_3_1 = oneToManySet_3.next(); !oneToManySet_3_1.done; oneToManySet_3_1 = oneToManySet_3.next()) {
1476
- var oneToManyItem = oneToManySet_3_1.value;
1477
- var _j = tslib_1.__read(oneToManyItem, 2), entityName = _j[0], foreignKey = _j[1];
1478
- if (foreignKeySet.hasOwnProperty(entityName)) {
1479
- foreignKeySet[entityName].push(foreignKey);
1480
- }
1481
- else {
1482
- foreignKeySet[entityName] = [foreignKey];
1483
- }
1382
+ const foreignKeySet = {};
1383
+ for (const oneToManyItem of oneToManySet) {
1384
+ const [entityName, foreignKey] = oneToManyItem;
1385
+ if (foreignKeySet.hasOwnProperty(entityName)) {
1386
+ foreignKeySet[entityName].push(foreignKey);
1484
1387
  }
1485
- }
1486
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
1487
- finally {
1488
- try {
1489
- if (oneToManySet_3_1 && !oneToManySet_3_1.done && (_c = oneToManySet_3.return)) _c.call(oneToManySet_3);
1388
+ else {
1389
+ foreignKeySet[entityName] = [foreignKey];
1490
1390
  }
1491
- finally { if (e_6) throw e_6.error; }
1492
1391
  }
1493
- var _loop_6 = function (entityName) {
1494
- var entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
1495
- foreignKeySet[entityName].forEach(function (foreignKey) {
1496
- var identifier = "".concat(entityNameLc, "$").concat(foreignKey);
1497
- var aggrIdentifier = "".concat(entityNameLc, "$").concat(foreignKey, "$$aggr");
1392
+ for (const entityName in foreignKeySet) {
1393
+ const entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
1394
+ foreignKeySet[entityName].forEach((foreignKey) => {
1395
+ const identifier = `${entityNameLc}$${foreignKey}`;
1396
+ const aggrIdentifier = `${entityNameLc}$${foreignKey}$$aggr`;
1498
1397
  properties.push([identifier, false,
1499
1398
  factory.createIntersectionTypeNode([
1500
1399
  factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'Selection'), undefined),
@@ -1525,12 +1424,9 @@ function constructProjection(statements, entity) {
1525
1424
  ])
1526
1425
  ]);
1527
1426
  });
1528
- };
1529
- for (var entityName in foreignKeySet) {
1530
- _loop_6(entityName);
1531
1427
  }
1532
1428
  }
1533
- var exprNode = factory.createTypeReferenceNode(factory.createIdentifier("Partial"), [
1429
+ const exprNode = factory.createTypeReferenceNode(factory.createIdentifier("Partial"), [
1534
1430
  factory.createTypeReferenceNode(factory.createIdentifier("ExprOp"), [
1535
1431
  process.env.COMPLING_AS_LIB ?
1536
1432
  factory.createUnionTypeNode([
@@ -1540,16 +1436,15 @@ function constructProjection(statements, entity) {
1540
1436
  factory.createTypeReferenceNode(factory.createIdentifier('OpAttr'))
1541
1437
  ])
1542
1438
  ]);
1543
- var MetaPropertySignatures = [
1439
+ const MetaPropertySignatures = [
1544
1440
  factory.createPropertySignature(undefined, factory.createStringLiteral("#id"), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode('NodeId'))
1545
1441
  ];
1546
1442
  if (process.env.COMPLING_AS_LIB) {
1547
- MetaPropertySignatures.push(factory.createIndexSignature(undefined, undefined, [factory.createParameterDeclaration(undefined, undefined, undefined, factory.createIdentifier("k"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)));
1443
+ MetaPropertySignatures.push(factory.createIndexSignature(undefined, [factory.createParameterDeclaration(undefined, undefined, factory.createIdentifier("k"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)));
1548
1444
  }
1549
1445
  // Projection,正常查询的投影
1550
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Projection"), undefined, factory.createIntersectionTypeNode([
1551
- factory.createTypeLiteralNode(MetaPropertySignatures.concat(properties.map(function (_a) {
1552
- var _b = tslib_1.__read(_a, 3), n = _b[0], q = _b[1], v = _b[2];
1446
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Projection"), undefined, factory.createIntersectionTypeNode([
1447
+ factory.createTypeLiteralNode(MetaPropertySignatures.concat(properties.map(([n, q, v]) => {
1553
1448
  return factory.createPropertySignature(undefined, n, q ? undefined : factory.createToken(ts.SyntaxKind.QuestionToken), v || factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword));
1554
1449
  }))),
1555
1450
  exprNode,
@@ -1582,10 +1477,10 @@ function constructProjection(statements, entity) {
1582
1477
  )
1583
1478
  ); */
1584
1479
  // ${Entity}Projection,外键查询的专用投影
1585
- for (var foreignKey in foreignKeyProperties) {
1586
- var identifier = "".concat(foreignKey, "IdProjection");
1587
- statements.push(factory.createTypeAliasDeclaration(undefined, undefined, factory.createIdentifier(identifier), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OneOf"), [
1588
- factory.createTypeLiteralNode(foreignKeyProperties[foreignKey].map(function (attr) { return factory.createPropertySignature(undefined, attr ? factory.createIdentifier("".concat(attr, "Id")) : 'id', undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword)); }))
1480
+ for (const foreignKey in foreignKeyProperties) {
1481
+ const identifier = `${foreignKey}IdProjection`;
1482
+ statements.push(factory.createTypeAliasDeclaration(undefined, factory.createIdentifier(identifier), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OneOf"), [
1483
+ factory.createTypeLiteralNode(foreignKeyProperties[foreignKey].map((attr) => factory.createPropertySignature(undefined, attr ? factory.createIdentifier(`${attr}Id`) : 'id', undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword))))
1589
1484
  ])));
1590
1485
  }
1591
1486
  }
@@ -1595,7 +1490,7 @@ function constructProjection(statements, entity) {
1595
1490
  * @param entity
1596
1491
  */
1597
1492
  function constructQuery(statements, entity) {
1598
- var entityLc = (0, string_1.firstLetterLowerCase)(entity);
1493
+ const entityLc = (0, string_1.firstLetterLowerCase)(entity);
1599
1494
  /* statements.push(
1600
1495
  factory.createTypeAliasDeclaration(
1601
1496
  undefined,
@@ -1697,15 +1592,11 @@ function constructQuery(statements, entity) {
1697
1592
  )
1698
1593
  ); */
1699
1594
  // 对每个可能的外键的子查询,建立相应的${Entity}IdSubQuery
1700
- var _a = ManyToOne, _b = entity, manyToOneSet = _a[_b];
1701
- var manyToSelf = false;
1595
+ const { [entity]: manyToOneSet } = ManyToOne;
1596
+ let manyToSelf = false;
1702
1597
  if (manyToOneSet) {
1703
- (0, lodash_1.uniqBy)(manyToOneSet, function (_a) {
1704
- var _b = tslib_1.__read(_a, 1), a = _b[0];
1705
- return a;
1706
- }).forEach(function (_a) {
1707
- var _b = tslib_1.__read(_a, 2), oneEntity = _b[0], foreignKey = _b[1];
1708
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("".concat(oneEntity, "IdSubQuery")), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Selection"), [factory.createTypeReferenceNode(factory.createIdentifier("".concat(oneEntity, "IdProjection")), undefined)])));
1598
+ (0, lodash_1.uniqBy)(manyToOneSet, ([a]) => a).forEach(([oneEntity, foreignKey]) => {
1599
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier(`${oneEntity}IdSubQuery`), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Selection"), [factory.createTypeReferenceNode(factory.createIdentifier(`${oneEntity}IdProjection`), undefined)])));
1709
1600
  if (oneEntity === entity) {
1710
1601
  manyToSelf = true;
1711
1602
  }
@@ -1713,7 +1604,7 @@ function constructQuery(statements, entity) {
1713
1604
  }
1714
1605
  // 主键可能产生的子查询
1715
1606
  if (!manyToSelf) {
1716
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("".concat(entity, "IdSubQuery")), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Selection"), [factory.createTypeReferenceNode(factory.createIdentifier("".concat(entity, "IdProjection")), undefined)])));
1607
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier(`${entity}IdSubQuery`), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Selection"), [factory.createTypeReferenceNode(factory.createIdentifier(`${entity}IdProjection`), undefined)])));
1717
1608
  }
1718
1609
  }
1719
1610
  /**
@@ -1722,9 +1613,8 @@ function constructQuery(statements, entity) {
1722
1613
  * @param entity
1723
1614
  */
1724
1615
  function constructSorter(statements, entity) {
1725
- var e_7, _a;
1726
- var schemaAttrs = Schema[entity].schemaAttrs;
1727
- var members = [
1616
+ const { schemaAttrs } = Schema[entity];
1617
+ const members = [
1728
1618
  // id: 1
1729
1619
  factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier("id"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword))]),
1730
1620
  // $$createAt$$: 1
@@ -1734,14 +1624,14 @@ function constructSorter(statements, entity) {
1734
1624
  // $$updateAt$$: 1
1735
1625
  factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier("$$updateAt$$"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword))]),
1736
1626
  ];
1737
- var _b = ManyToOne, _c = entity, manyToOneSet = _b[_c];
1738
- var _loop_7 = function (attr) {
1739
- var _d = attr, type = _d.type, name_5 = _d.name, questionToken = _d.questionToken;
1627
+ const { [entity]: manyToOneSet } = ManyToOne;
1628
+ for (const attr of schemaAttrs) {
1629
+ const { type, name, questionToken } = attr;
1740
1630
  if (ts.isTypeReferenceNode(type)) {
1741
- var typeName = type.typeName;
1631
+ const { typeName } = type;
1742
1632
  if (ts.isIdentifier(typeName)) {
1743
- var text = typeName.text;
1744
- var type2 = void 0;
1633
+ const { text } = typeName;
1634
+ let type2;
1745
1635
  switch (text) {
1746
1636
  case 'String':
1747
1637
  case 'Text':
@@ -1757,14 +1647,11 @@ function constructSorter(statements, entity) {
1757
1647
  break;
1758
1648
  }
1759
1649
  default: {
1760
- var text2_5 = text === 'Schema' ? entity : text;
1761
- var manyToOneItem = manyToOneSet && manyToOneSet.find(function (_a) {
1762
- var _b = tslib_1.__read(_a, 1), refEntity = _b[0];
1763
- return refEntity === text2_5;
1764
- });
1650
+ const text2 = text === 'Schema' ? entity : text;
1651
+ const manyToOneItem = manyToOneSet && manyToOneSet.find(([refEntity]) => refEntity === text2);
1765
1652
  if (manyToOneItem) {
1766
- type2 = factory.createTypeReferenceNode(createForeignRef(entity, text2_5, 'SortAttr'));
1767
- members.push(factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier("".concat(name_5.text, "Id")), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword))]));
1653
+ type2 = factory.createTypeReferenceNode(createForeignRef(entity, text2, 'SortAttr'));
1654
+ members.push(factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier(`${name.text}Id`), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword))]));
1768
1655
  }
1769
1656
  else if (!['Object'].includes(text)) {
1770
1657
  // todo 对State的专门处理
@@ -1773,37 +1660,24 @@ function constructSorter(statements, entity) {
1773
1660
  }
1774
1661
  }
1775
1662
  if (type2) {
1776
- members.push(factory.createTypeLiteralNode([factory.createPropertySignature(undefined, name_5, undefined, type2)]));
1663
+ members.push(factory.createTypeLiteralNode([factory.createPropertySignature(undefined, name, undefined, type2)]));
1777
1664
  }
1778
1665
  }
1779
1666
  }
1780
1667
  else if (ts.isUnionTypeNode(type) && ts.isLiteralTypeNode(type.types[0]) || ts.isLiteralTypeNode(type)) {
1781
- members.push(factory.createTypeLiteralNode([factory.createPropertySignature(undefined, name_5, undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword))]));
1668
+ members.push(factory.createTypeLiteralNode([factory.createPropertySignature(undefined, name, undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword))]));
1782
1669
  }
1783
1670
  else {
1784
1671
  // 本地规定的shape,非结构化属性不参与排序
1785
1672
  }
1786
- };
1787
- try {
1788
- for (var schemaAttrs_4 = tslib_1.__values(schemaAttrs), schemaAttrs_4_1 = schemaAttrs_4.next(); !schemaAttrs_4_1.done; schemaAttrs_4_1 = schemaAttrs_4.next()) {
1789
- var attr = schemaAttrs_4_1.value;
1790
- _loop_7(attr);
1791
- }
1792
- }
1793
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
1794
- finally {
1795
- try {
1796
- if (schemaAttrs_4_1 && !schemaAttrs_4_1.done && (_a = schemaAttrs_4.return)) _a.call(schemaAttrs_4);
1797
- }
1798
- finally { if (e_7) throw e_7.error; }
1799
1673
  }
1800
1674
  if (ReversePointerRelations[entity]) {
1801
- ReversePointerRelations[entity].forEach(function (one) {
1675
+ ReversePointerRelations[entity].forEach((one) => {
1802
1676
  members.push(factory.createTypeLiteralNode([factory.createPropertySignature(undefined, (0, string_1.firstLetterLowerCase)(one), undefined, factory.createTypeReferenceNode(createForeignRef(entity, one, 'SortAttr')))]));
1803
1677
  });
1804
1678
  }
1805
1679
  if (process.env.COMPLING_AS_LIB) {
1806
- members.push(factory.createTypeLiteralNode([factory.createIndexSignature(undefined, undefined, [factory.createParameterDeclaration(undefined, undefined, undefined, factory.createIdentifier("k"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword))]));
1680
+ members.push(factory.createTypeLiteralNode([factory.createIndexSignature(undefined, [factory.createParameterDeclaration(undefined, undefined, factory.createIdentifier("k"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword))]));
1807
1681
  }
1808
1682
  members.push(factory.createTypeReferenceNode(factory.createIdentifier("OneOf"), [factory.createTypeReferenceNode(factory.createIdentifier("ExprOp"), [
1809
1683
  process.env.COMPLING_AS_LIB ?
@@ -1829,14 +1703,14 @@ function constructSorter(statements, entity) {
1829
1703
  [k: string]: any;
1830
1704
  } | OneOf<ExprOp<OpAttr>>
1831
1705
  */
1832
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("SortAttr"), undefined, factory.createUnionTypeNode(members)));
1706
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("SortAttr"), undefined, factory.createUnionTypeNode(members)));
1833
1707
  /**
1834
1708
  * export type SortNode = {
1835
1709
  $attr: SortAttr;
1836
1710
  $direction?: 'asc' | 'desc';
1837
1711
  };
1838
1712
  */
1839
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("SortNode"), undefined, factory.createTypeLiteralNode([
1713
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("SortNode"), undefined, factory.createTypeLiteralNode([
1840
1714
  factory.createPropertySignature(undefined, factory.createIdentifier("$attr"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("SortAttr"), undefined)),
1841
1715
  factory.createPropertySignature(undefined, factory.createIdentifier("$direction"), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
1842
1716
  factory.createLiteralTypeNode(factory.createStringLiteral("asc")),
@@ -1846,70 +1720,50 @@ function constructSorter(statements, entity) {
1846
1720
  /**
1847
1721
  * export type Sorter = SortNode[];
1848
1722
  */
1849
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Sorter"), undefined, factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier("SortNode"), undefined))));
1723
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Sorter"), undefined, factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier("SortNode"), undefined))));
1850
1724
  }
1851
1725
  function constructFullAttrs(statements, entity) {
1852
- var e_8, _a, e_9, _b;
1853
- var _c = ManyToOne, _d = entity, manyToOneSet = _c[_d];
1854
- var _e = OneToMany, _f = entity, oneToManySet = _e[_f];
1726
+ const { [entity]: manyToOneSet } = ManyToOne;
1727
+ const { [entity]: oneToManySet } = OneToMany;
1855
1728
  if (manyToOneSet && manyToOneSet.length) {
1856
- var mtoAttrs = [];
1857
- try {
1858
- for (var manyToOneSet_1 = tslib_1.__values(manyToOneSet), manyToOneSet_1_1 = manyToOneSet_1.next(); !manyToOneSet_1_1.done; manyToOneSet_1_1 = manyToOneSet_1.next()) {
1859
- var item = manyToOneSet_1_1.value;
1860
- var _g = tslib_1.__read(item, 2), one = _g[0], key = _g[1];
1861
- if (one === entity) {
1862
- // 递归引用自身,因为typescript本身不支持递归,因此这里做一个显式的三层递归应该够用了
1863
- mtoAttrs.push(factory.createTemplateLiteralType(factory.createTemplateHead("".concat(key, "."), "".concat(key, ".")), [factory.createTemplateLiteralTypeSpan(factory.createTypeReferenceNode(factory.createIdentifier("OpAttr"), undefined), factory.createTemplateTail("", ""))]), factory.createTemplateLiteralType(factory.createTemplateHead("".concat(key, ".").concat(key, "."), "".concat(key, ".").concat(key, ".")), [factory.createTemplateLiteralTypeSpan(factory.createTypeReferenceNode(factory.createIdentifier("OpAttr"), undefined), factory.createTemplateTail("", ""))]), factory.createTemplateLiteralType(factory.createTemplateHead("".concat(key, ".").concat(key, ".").concat(key, "."), "".concat(key, ".").concat(key, ".").concat(key, ".")), [factory.createTemplateLiteralTypeSpan(factory.createTypeReferenceNode(factory.createIdentifier("OpAttr"), undefined), factory.createTemplateTail("", ""))]));
1864
- }
1865
- else {
1866
- mtoAttrs.push(factory.createTemplateLiteralType(factory.createTemplateHead("".concat(key, "."), "".concat(key, ".")), [factory.createTemplateLiteralTypeSpan(factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(one), factory.createIdentifier("NativeAttr")), undefined), factory.createTemplateTail("", ""))
1867
- ]));
1868
- }
1729
+ const mtoAttrs = [];
1730
+ for (const item of manyToOneSet) {
1731
+ const [one, key] = item;
1732
+ if (one === entity) {
1733
+ // 递归引用自身,因为typescript本身不支持递归,因此这里做一个显式的三层递归应该够用了
1734
+ mtoAttrs.push(factory.createTemplateLiteralType(factory.createTemplateHead(`${key}.`, `${key}.`), [factory.createTemplateLiteralTypeSpan(factory.createTypeReferenceNode(factory.createIdentifier("OpAttr"), undefined), factory.createTemplateTail("", ""))]), factory.createTemplateLiteralType(factory.createTemplateHead(`${key}.${key}.`, `${key}.${key}.`), [factory.createTemplateLiteralTypeSpan(factory.createTypeReferenceNode(factory.createIdentifier("OpAttr"), undefined), factory.createTemplateTail("", ""))]), factory.createTemplateLiteralType(factory.createTemplateHead(`${key}.${key}.${key}.`, `${key}.${key}.${key}.`), [factory.createTemplateLiteralTypeSpan(factory.createTypeReferenceNode(factory.createIdentifier("OpAttr"), undefined), factory.createTemplateTail("", ""))]));
1869
1735
  }
1870
- }
1871
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
1872
- finally {
1873
- try {
1874
- if (manyToOneSet_1_1 && !manyToOneSet_1_1.done && (_a = manyToOneSet_1.return)) _a.call(manyToOneSet_1);
1736
+ else {
1737
+ mtoAttrs.push(factory.createTemplateLiteralType(factory.createTemplateHead(`${key}.`, `${key}.`), [factory.createTemplateLiteralTypeSpan(factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(one), factory.createIdentifier("NativeAttr")), undefined), factory.createTemplateTail("", ""))
1738
+ ]));
1875
1739
  }
1876
- finally { if (e_8) throw e_8.error; }
1877
1740
  }
1878
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("NativeAttr"), undefined, factory.createUnionTypeNode(tslib_1.__spreadArray([
1879
- factory.createTypeReferenceNode(factory.createIdentifier("OpAttr"), undefined)
1880
- ], tslib_1.__read(mtoAttrs), false))));
1741
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("NativeAttr"), undefined, factory.createUnionTypeNode([
1742
+ factory.createTypeReferenceNode(factory.createIdentifier("OpAttr"), undefined),
1743
+ ...mtoAttrs
1744
+ ])));
1881
1745
  }
1882
1746
  else {
1883
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("NativeAttr"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OpAttr"), undefined)));
1747
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("NativeAttr"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OpAttr"), undefined)));
1884
1748
  }
1885
- var foreignKeySet = {};
1749
+ const foreignKeySet = {};
1886
1750
  if (oneToManySet && oneToManySet.length > 0) {
1887
- try {
1888
- for (var oneToManySet_4 = tslib_1.__values(oneToManySet), oneToManySet_4_1 = oneToManySet_4.next(); !oneToManySet_4_1.done; oneToManySet_4_1 = oneToManySet_4.next()) {
1889
- var oneToManyItem = oneToManySet_4_1.value;
1890
- var _h = tslib_1.__read(oneToManyItem, 2), entityName = _h[0], foreignKey = _h[1];
1891
- if (foreignKeySet.hasOwnProperty(entityName)) {
1892
- foreignKeySet[entityName].push(foreignKey);
1893
- }
1894
- else {
1895
- foreignKeySet[entityName] = [foreignKey];
1896
- }
1751
+ for (const oneToManyItem of oneToManySet) {
1752
+ const [entityName, foreignKey] = oneToManyItem;
1753
+ if (foreignKeySet.hasOwnProperty(entityName)) {
1754
+ foreignKeySet[entityName].push(foreignKey);
1897
1755
  }
1898
- }
1899
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
1900
- finally {
1901
- try {
1902
- if (oneToManySet_4_1 && !oneToManySet_4_1.done && (_b = oneToManySet_4.return)) _b.call(oneToManySet_4);
1756
+ else {
1757
+ foreignKeySet[entityName] = [foreignKey];
1903
1758
  }
1904
- finally { if (e_9) throw e_9.error; }
1905
1759
  }
1906
- var otmAttrs_1 = [];
1907
- var _loop_8 = function (entityName) {
1908
- var entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
1760
+ const otmAttrs = [];
1761
+ for (const entityName in foreignKeySet) {
1762
+ const entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
1909
1763
  if (foreignKeySet[entityName].length > 1) {
1910
- foreignKeySet[entityName].forEach(function (foreignKey) {
1911
- var head = "".concat(entityNameLc, "s$").concat(foreignKey);
1912
- otmAttrs_1.push(factory.createTemplateLiteralType(factory.createTemplateHead("".concat(head, "$"), "".concat(head, "$")), [
1764
+ foreignKeySet[entityName].forEach((foreignKey) => {
1765
+ const head = `${entityNameLc}s$${foreignKey}`;
1766
+ otmAttrs.push(factory.createTemplateLiteralType(factory.createTemplateHead(`${head}$`, `${head}$`), [
1913
1767
  factory.createTemplateLiteralTypeSpan(factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword), factory.createTemplateMiddle(".", ".")),
1914
1768
  factory.createTemplateLiteralTypeSpan(factory.createTypeReferenceNode(entityName === entity
1915
1769
  ? factory.createIdentifier("NativeAttr")
@@ -1918,40 +1772,37 @@ function constructFullAttrs(statements, entity) {
1918
1772
  });
1919
1773
  }
1920
1774
  else {
1921
- otmAttrs_1.push(factory.createTemplateLiteralType(factory.createTemplateHead("".concat(entityNameLc, "s$"), "".concat(entityNameLc, "s$")), [
1775
+ otmAttrs.push(factory.createTemplateLiteralType(factory.createTemplateHead(`${entityNameLc}s$`, `${entityNameLc}s$`), [
1922
1776
  factory.createTemplateLiteralTypeSpan(factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword), factory.createTemplateMiddle(".", ".")),
1923
1777
  factory.createTemplateLiteralTypeSpan(factory.createTypeReferenceNode(entityName === entity
1924
1778
  ? factory.createIdentifier("NativeAttr")
1925
1779
  : factory.createQualifiedName(factory.createIdentifier(entityName), factory.createIdentifier("NativeAttr")), undefined), factory.createTemplateTail("", ""))
1926
1780
  ]));
1927
1781
  }
1928
- };
1929
- for (var entityName in foreignKeySet) {
1930
- _loop_8(entityName);
1931
1782
  }
1932
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("FullAttr"), undefined, factory.createUnionTypeNode(tslib_1.__spreadArray([
1933
- factory.createTypeReferenceNode(factory.createIdentifier("NativeAttr"), undefined)
1934
- ], tslib_1.__read(otmAttrs_1), false))));
1783
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("FullAttr"), undefined, factory.createUnionTypeNode([
1784
+ factory.createTypeReferenceNode(factory.createIdentifier("NativeAttr"), undefined),
1785
+ ...otmAttrs
1786
+ ])));
1935
1787
  }
1936
1788
  else {
1937
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("FullAttr"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("NativeAttr"), undefined)));
1789
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("FullAttr"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("NativeAttr"), undefined)));
1938
1790
  }
1939
1791
  }
1940
1792
  function constructOperations(statements, entity) {
1941
- var e_10, _a, e_11, _b, e_12, _c, e_13, _d, e_14, _e, e_15, _f, e_16, _g, e_17, _h, e_18, _j;
1942
1793
  // Selection
1943
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("SelectOperation"), [
1794
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("SelectOperation"), [
1944
1795
  factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("P"), factory.createTypeReferenceNode(factory.createIdentifier("Object"), undefined), factory.createTypeReferenceNode(factory.createIdentifier("Projection"), undefined))
1945
1796
  ], factory.createTypeReferenceNode(factory.createIdentifier("OakSelection"), [
1946
1797
  factory.createLiteralTypeNode(factory.createStringLiteral("select")),
1947
1798
  factory.createTypeReferenceNode(factory.createIdentifier("P"), undefined),
1948
1799
  factory.createTypeReferenceNode(factory.createIdentifier("Filter"), undefined),
1949
1800
  factory.createTypeReferenceNode(factory.createIdentifier("Sorter"), undefined)
1950
- ])), factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Selection"), [
1801
+ ])), factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Selection"), [
1951
1802
  factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("P"), factory.createTypeReferenceNode(factory.createIdentifier("Object"), undefined), factory.createTypeReferenceNode(factory.createIdentifier("Projection"), undefined))
1952
1803
  ], factory.createTypeReferenceNode(factory.createIdentifier("SelectOperation"), [
1953
1804
  factory.createTypeReferenceNode(factory.createIdentifier("P"), undefined)
1954
- ])), factory.createTypeAliasDeclaration(undefined, [factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Aggregation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("DeduceAggregation"), [
1805
+ ])), factory.createTypeAliasDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Aggregation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("DeduceAggregation"), [
1955
1806
  factory.createTypeReferenceNode(factory.createIdentifier("Projection"), undefined),
1956
1807
  factory.createTypeReferenceNode(factory.createIdentifier("Filter"), undefined),
1957
1808
  factory.createTypeReferenceNode(factory.createIdentifier("Sorter"), undefined)
@@ -1984,58 +1835,38 @@ function constructOperations(statements, entity) {
1984
1835
  )
1985
1836
  )
1986
1837
  ); */
1987
- var _k = ManyToOne, _l = entity, manyToOneSet = _k[_l];
1988
- var _m = OneToMany, _o = entity, oneToManySet = _m[_o];
1989
- var foreignKeySet = {};
1838
+ const { [entity]: manyToOneSet } = ManyToOne;
1839
+ const { [entity]: oneToManySet } = OneToMany;
1840
+ const foreignKeySet = {};
1990
1841
  if (oneToManySet) {
1991
- try {
1992
- for (var oneToManySet_5 = tslib_1.__values(oneToManySet), oneToManySet_5_1 = oneToManySet_5.next(); !oneToManySet_5_1.done; oneToManySet_5_1 = oneToManySet_5.next()) {
1993
- var oneToManyItem = oneToManySet_5_1.value;
1994
- var _p = tslib_1.__read(oneToManyItem, 2), entityName = _p[0], foreignKey = _p[1];
1995
- if (foreignKeySet.hasOwnProperty(entityName)) {
1996
- foreignKeySet[entityName].push(foreignKey);
1997
- }
1998
- else {
1999
- foreignKeySet[entityName] = [foreignKey];
2000
- }
1842
+ for (const oneToManyItem of oneToManySet) {
1843
+ const [entityName, foreignKey] = oneToManyItem;
1844
+ if (foreignKeySet.hasOwnProperty(entityName)) {
1845
+ foreignKeySet[entityName].push(foreignKey);
2001
1846
  }
2002
- }
2003
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
2004
- finally {
2005
- try {
2006
- if (oneToManySet_5_1 && !oneToManySet_5_1.done && (_a = oneToManySet_5.return)) _a.call(oneToManySet_5);
1847
+ else {
1848
+ foreignKeySet[entityName] = [foreignKey];
2007
1849
  }
2008
- finally { if (e_10) throw e_10.error; }
2009
1850
  }
2010
1851
  }
2011
1852
  // CreateOperationData
2012
- var foreignKeyAttr = [];
1853
+ let foreignKeyAttr = [];
2013
1854
  if (ReversePointerEntities[entity]) {
2014
1855
  foreignKeyAttr.push('entity', 'entityId');
2015
1856
  }
2016
1857
  if (manyToOneSet) {
2017
- try {
2018
- for (var manyToOneSet_2 = tslib_1.__values(manyToOneSet), manyToOneSet_2_1 = manyToOneSet_2.next(); !manyToOneSet_2_1.done; manyToOneSet_2_1 = manyToOneSet_2.next()) {
2019
- var one = manyToOneSet_2_1.value;
2020
- if (!ReversePointerRelations[entity] || !ReversePointerRelations[entity].includes(one[1])) {
2021
- foreignKeyAttr.push("".concat(one[1], "Id"));
2022
- }
2023
- }
2024
- }
2025
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
2026
- finally {
2027
- try {
2028
- if (manyToOneSet_2_1 && !manyToOneSet_2_1.done && (_b = manyToOneSet_2.return)) _b.call(manyToOneSet_2);
1858
+ for (const one of manyToOneSet) {
1859
+ if (!ReversePointerRelations[entity] || !ReversePointerRelations[entity].includes(one[1])) {
1860
+ foreignKeyAttr.push(`${one[1]}Id`);
2029
1861
  }
2030
- finally { if (e_11) throw e_11.error; }
2031
1862
  }
2032
1863
  }
2033
- var adNodes = [
1864
+ let adNodes = [
2034
1865
  factory.createTypeReferenceNode(factory.createIdentifier("FormCreateData"), [
2035
1866
  foreignKeyAttr.length > 0
2036
1867
  ? factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
2037
1868
  factory.createTypeReferenceNode(factory.createIdentifier("OpSchema"), undefined),
2038
- factory.createUnionTypeNode((0, lodash_1.uniq)(foreignKeyAttr).map(function (ele) { return factory.createLiteralTypeNode(factory.createStringLiteral(ele)); }))
1869
+ factory.createUnionTypeNode((0, lodash_1.uniq)(foreignKeyAttr).map(ele => factory.createLiteralTypeNode(factory.createStringLiteral(ele))))
2039
1870
  ])
2040
1871
  : factory.createTypeReferenceNode(factory.createIdentifier("OpSchema"), undefined)
2041
1872
  ])
@@ -2047,133 +1878,112 @@ function constructOperations(statements, entity) {
2047
1878
  * 如果关联对象是update,则关联对象的filter由对象决定其主键
2048
1879
  * 见cascadeStore
2049
1880
  */
2050
- var upsertOneNodes = [];
2051
- try {
2052
- for (var manyToOneSet_3 = tslib_1.__values(manyToOneSet), manyToOneSet_3_1 = manyToOneSet_3.next(); !manyToOneSet_3_1.done; manyToOneSet_3_1 = manyToOneSet_3.next()) {
2053
- var one = manyToOneSet_3_1.value;
2054
- if (!ReversePointerRelations[entity] || !ReversePointerRelations[entity].includes(one[0])) {
2055
- var oneEntity = one[0];
2056
- var cascadeCreateNode = factory.createTypeLiteralNode([
2057
- factory.createPropertySignature(undefined, factory.createIdentifier("".concat(one[1], "Id")), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
2058
- factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), one[2] ? factory.createToken(ts.SyntaxKind.QuestionToken) : undefined, factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'CreateSingleOperation')))
2059
- ]);
2060
- var cascadeUpdateNode = factory.createTypeLiteralNode([
2061
- factory.createPropertySignature(undefined, factory.createIdentifier("".concat(one[1], "Id")), undefined, factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one[1]))])),
2062
- factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'UpdateOperation')))
2063
- ]);
2064
- var noCascadeNode = factory.createTypeLiteralNode([
2065
- factory.createPropertySignature(undefined, factory.createIdentifier("".concat(one[1], "Id")), one[2] ? factory.createToken(ts.SyntaxKind.QuestionToken) : undefined, factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one[1]))]))
2066
- ]);
2067
- if (Schema[oneEntity].static) {
2068
- upsertOneNodes.push(noCascadeNode);
2069
- }
2070
- else {
2071
- switch (Schema[oneEntity].actionType) {
2072
- case 'crud':
2073
- case 'excludeRemove': {
2074
- upsertOneNodes.push(factory.createUnionTypeNode([cascadeCreateNode, cascadeUpdateNode, noCascadeNode]));
2075
- break;
2076
- }
2077
- case 'excludeUpdate':
2078
- case 'appendOnly': {
2079
- upsertOneNodes.push(factory.createUnionTypeNode([cascadeCreateNode, noCascadeNode]));
2080
- break;
2081
- }
2082
- case 'readOnly': {
2083
- upsertOneNodes.push(noCascadeNode);
2084
- break;
2085
- }
2086
- default: {
2087
- (0, assert_1.default)(false);
2088
- }
1881
+ const upsertOneNodes = [];
1882
+ for (const one of manyToOneSet) {
1883
+ if (!ReversePointerRelations[entity] || !ReversePointerRelations[entity].includes(one[0])) {
1884
+ const oneEntity = one[0];
1885
+ const cascadeCreateNode = factory.createTypeLiteralNode([
1886
+ factory.createPropertySignature(undefined, factory.createIdentifier(`${one[1]}Id`), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
1887
+ factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), one[2] ? factory.createToken(ts.SyntaxKind.QuestionToken) : undefined, factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'CreateSingleOperation')))
1888
+ ]);
1889
+ const cascadeUpdateNode = factory.createTypeLiteralNode([
1890
+ factory.createPropertySignature(undefined, factory.createIdentifier(`${one[1]}Id`), undefined, factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one[1]))])),
1891
+ factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'UpdateOperation')))
1892
+ ]);
1893
+ const noCascadeNode = factory.createTypeLiteralNode([
1894
+ factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
1895
+ factory.createPropertySignature(undefined, factory.createIdentifier(`${one[1]}Id`), one[2] ? factory.createToken(ts.SyntaxKind.QuestionToken) : undefined, factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one[1]))]))
1896
+ ]);
1897
+ if (Schema[oneEntity].static) {
1898
+ upsertOneNodes.push(noCascadeNode);
1899
+ }
1900
+ else {
1901
+ switch (Schema[oneEntity].actionType) {
1902
+ case 'crud':
1903
+ case 'excludeRemove': {
1904
+ upsertOneNodes.push(factory.createUnionTypeNode([cascadeCreateNode, cascadeUpdateNode, noCascadeNode]));
1905
+ break;
1906
+ }
1907
+ case 'excludeUpdate':
1908
+ case 'appendOnly': {
1909
+ upsertOneNodes.push(factory.createUnionTypeNode([cascadeCreateNode, noCascadeNode]));
1910
+ break;
1911
+ }
1912
+ case 'readOnly': {
1913
+ upsertOneNodes.push(noCascadeNode);
1914
+ break;
1915
+ }
1916
+ default: {
1917
+ (0, assert_1.default)(false);
2089
1918
  }
2090
1919
  }
2091
1920
  }
2092
1921
  }
2093
1922
  }
2094
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
2095
- finally {
2096
- try {
2097
- if (manyToOneSet_3_1 && !manyToOneSet_3_1.done && (_c = manyToOneSet_3.return)) _c.call(manyToOneSet_3);
2098
- }
2099
- finally { if (e_12) throw e_12.error; }
2100
- }
2101
1923
  if (upsertOneNodes.length > 0) {
2102
1924
  adNodes.push(factory.createIntersectionTypeNode(upsertOneNodes));
2103
1925
  }
2104
1926
  }
2105
- var reverseOneNodes = [];
1927
+ const reverseOneNodes = [];
2106
1928
  if (ReversePointerEntities[entity]) {
2107
1929
  if (ReversePointerRelations[entity]) {
2108
- var schemaAttrs = Schema[entity].schemaAttrs;
2109
- var entityQuestionToken = schemaAttrs.find(function (ele) {
2110
- var name = ele.name;
1930
+ const { schemaAttrs } = Schema[entity];
1931
+ const { questionToken: entityQuestionToken } = schemaAttrs.find(ele => {
1932
+ const { name } = ele;
2111
1933
  return name.text === 'entity';
2112
- }).questionToken;
2113
- var entityIdQuestionToken = schemaAttrs.find(function (ele) {
2114
- var name = ele.name;
1934
+ });
1935
+ const { questionToken: entityIdQuestionToken } = schemaAttrs.find(ele => {
1936
+ const { name } = ele;
2115
1937
  return name.text === 'entityId';
2116
- }).questionToken;
2117
- try {
2118
- for (var _q = tslib_1.__values(ReversePointerRelations[entity]), _r = _q.next(); !_r.done; _r = _q.next()) {
2119
- var one = _r.value;
2120
- var cascadeCreateNode = factory.createTypeLiteralNode([
2121
- factory.createPropertySignature(undefined, factory.createIdentifier('entity'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
2122
- factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
2123
- factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), undefined, // 反向指针好像不能为空,以后或许会有特例 by Xc
2124
- factory.createTypeReferenceNode(createForeignRef(entity, one, 'CreateSingleOperation')))
2125
- ]);
2126
- var cascadeUpdateNode = factory.createTypeLiteralNode([
2127
- factory.createPropertySignature(undefined, factory.createIdentifier('entity'), undefined, // 反向指针好像不能为空,以后或许会有特例 by Xc
2128
- factory.createLiteralTypeNode(factory.createStringLiteral("".concat((0, string_1.firstLetterLowerCase)(one))))),
2129
- factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), undefined, // 反向指针好像不能为空,以后或许会有特例 by Xc
2130
- factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one))])),
2131
- factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), undefined, factory.createTypeReferenceNode(createForeignRef(entity, one, 'UpdateOperation')))
2132
- ]);
2133
- var noCascadeNode = factory.createTypeLiteralNode([
2134
- factory.createPropertySignature(undefined, factory.createIdentifier('entity'), entityQuestionToken, factory.createLiteralTypeNode(factory.createStringLiteral("".concat((0, string_1.firstLetterLowerCase)(one))))),
2135
- factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), entityIdQuestionToken, factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one))]))
2136
- ]);
2137
- if (Schema[one].static) {
2138
- reverseOneNodes.push(noCascadeNode);
2139
- }
2140
- else {
2141
- switch (Schema[one].actionType) {
2142
- case 'crud':
2143
- case 'excludeRemove': {
2144
- reverseOneNodes.push(cascadeCreateNode, cascadeUpdateNode, noCascadeNode);
2145
- break;
2146
- }
2147
- case 'appendOnly':
2148
- case 'excludeUpdate': {
2149
- reverseOneNodes.push(cascadeCreateNode, noCascadeNode);
2150
- break;
2151
- }
2152
- case 'readOnly': {
2153
- reverseOneNodes.push(noCascadeNode);
2154
- break;
2155
- }
2156
- default: {
2157
- (0, assert_1.default)(false);
2158
- }
1938
+ });
1939
+ for (const one of ReversePointerRelations[entity]) {
1940
+ const cascadeCreateNode = factory.createTypeLiteralNode([
1941
+ factory.createPropertySignature(undefined, factory.createIdentifier('entity'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
1942
+ factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
1943
+ factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), entityQuestionToken || entityIdQuestionToken, factory.createTypeReferenceNode(createForeignRef(entity, one, 'CreateSingleOperation')))
1944
+ ]);
1945
+ const cascadeUpdateNode = factory.createTypeLiteralNode([
1946
+ factory.createPropertySignature(undefined, factory.createIdentifier('entity'), entityQuestionToken, factory.createLiteralTypeNode(factory.createStringLiteral(`${(0, string_1.firstLetterLowerCase)(one)}`))),
1947
+ factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), entityIdQuestionToken, factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one))])),
1948
+ factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one, 'UpdateOperation')))
1949
+ ]);
1950
+ const noCascadeNode = factory.createTypeLiteralNode([
1951
+ factory.createPropertySignature(undefined, factory.createIdentifier('entity'), entityQuestionToken, factory.createLiteralTypeNode(factory.createStringLiteral(`${(0, string_1.firstLetterLowerCase)(one)}`))),
1952
+ factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), entityIdQuestionToken, factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one))])),
1953
+ factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword))
1954
+ ]);
1955
+ if (Schema[one].static) {
1956
+ reverseOneNodes.push(noCascadeNode);
1957
+ }
1958
+ else {
1959
+ switch (Schema[one].actionType) {
1960
+ case 'crud':
1961
+ case 'excludeRemove': {
1962
+ reverseOneNodes.push(cascadeCreateNode, cascadeUpdateNode, noCascadeNode);
1963
+ break;
1964
+ }
1965
+ case 'appendOnly':
1966
+ case 'excludeUpdate': {
1967
+ reverseOneNodes.push(cascadeCreateNode, noCascadeNode);
1968
+ break;
1969
+ }
1970
+ case 'readOnly': {
1971
+ reverseOneNodes.push(noCascadeNode);
1972
+ break;
1973
+ }
1974
+ default: {
1975
+ (0, assert_1.default)(false);
2159
1976
  }
2160
1977
  }
2161
1978
  }
2162
1979
  }
2163
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
2164
- finally {
2165
- try {
2166
- if (_r && !_r.done && (_d = _q.return)) _d.call(_q);
2167
- }
2168
- finally { if (e_13) throw e_13.error; }
2169
- }
2170
1980
  }
2171
1981
  if (process.env.COMPLING_AS_LIB) {
2172
1982
  // 如果是base,要包容更多可能的反指
2173
1983
  reverseOneNodes.push(factory.createTypeLiteralNode([
2174
1984
  factory.createPropertySignature(undefined, factory.createIdentifier('entity'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)),
2175
1985
  factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)),
2176
- factory.createIndexSignature(undefined, undefined, [factory.createParameterDeclaration(undefined, undefined, undefined, factory.createIdentifier("K"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword))
1986
+ factory.createIndexSignature(undefined, [factory.createParameterDeclaration(undefined, undefined, factory.createIdentifier("K"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword))
2177
1987
  ]));
2178
1988
  }
2179
1989
  if (reverseOneNodes.length > 0) {
@@ -2181,31 +1991,31 @@ function constructOperations(statements, entity) {
2181
1991
  }
2182
1992
  }
2183
1993
  // 一对多
2184
- var propertySignatures = [];
1994
+ const propertySignatures = [];
2185
1995
  if (oneToManySet) {
2186
- var _loop_9 = function (entityName) {
2187
- var entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
2188
- foreignKeySet[entityName].forEach(function (foreignKey) {
2189
- var identifier = "".concat(entityNameLc, "$").concat(foreignKey);
2190
- var otmCreateOperationDataNode = factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
1996
+ for (const entityName in foreignKeySet) {
1997
+ const entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
1998
+ foreignKeySet[entityName].forEach((foreignKey) => {
1999
+ const identifier = `${entityNameLc}$${foreignKey}`;
2000
+ const otmCreateOperationDataNode = factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
2191
2001
  factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'CreateOperationData'), undefined),
2192
2002
  factory.createUnionTypeNode(foreignKey === 'entity' ? [
2193
2003
  factory.createLiteralTypeNode(factory.createStringLiteral("entity")),
2194
2004
  factory.createLiteralTypeNode(factory.createStringLiteral("entityId"))
2195
2005
  ] : [
2196
2006
  factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey)),
2197
- factory.createLiteralTypeNode(factory.createStringLiteral("".concat(foreignKey, "Id")))
2007
+ factory.createLiteralTypeNode(factory.createStringLiteral(`${foreignKey}Id`))
2198
2008
  ])
2199
2009
  ]);
2200
- var otmCreateSingleOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2010
+ const otmCreateSingleOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2201
2011
  factory.createLiteralTypeNode(factory.createStringLiteral("create")),
2202
2012
  otmCreateOperationDataNode
2203
2013
  ]);
2204
- var otmCreateMultipleOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2014
+ const otmCreateMultipleOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2205
2015
  factory.createLiteralTypeNode(factory.createStringLiteral("create")),
2206
2016
  factory.createArrayTypeNode(otmCreateOperationDataNode)
2207
2017
  ]);
2208
- var otmUpdateOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2018
+ const otmUpdateOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2209
2019
  factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'UpdateOperation'), undefined), factory.createLiteralTypeNode(factory.createStringLiteral("action"))),
2210
2020
  factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
2211
2021
  factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'UpdateOperationData'), undefined),
@@ -2214,7 +2024,7 @@ function constructOperations(statements, entity) {
2214
2024
  factory.createLiteralTypeNode(factory.createStringLiteral("entityId"))
2215
2025
  ] : [
2216
2026
  factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey)),
2217
- factory.createLiteralTypeNode(factory.createStringLiteral("".concat(foreignKey, "Id")))
2027
+ factory.createLiteralTypeNode(factory.createStringLiteral(`${foreignKey}Id`))
2218
2028
  ])
2219
2029
  ]),
2220
2030
  factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
@@ -2224,7 +2034,7 @@ function constructOperations(statements, entity) {
2224
2034
  factory.createLiteralTypeNode(factory.createStringLiteral("entityId"))
2225
2035
  ] : [
2226
2036
  factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey)),
2227
- factory.createLiteralTypeNode(factory.createStringLiteral("".concat(foreignKey, "Id")))
2037
+ factory.createLiteralTypeNode(factory.createStringLiteral(`${foreignKey}Id`))
2228
2038
  ])
2229
2039
  ])
2230
2040
  ]);
@@ -2258,23 +2068,20 @@ function constructOperations(statements, entity) {
2258
2068
  }
2259
2069
  }
2260
2070
  });
2261
- };
2262
- for (var entityName in foreignKeySet) {
2263
- _loop_9(entityName);
2264
2071
  }
2265
2072
  }
2266
2073
  if (propertySignatures.length > 0) {
2267
2074
  adNodes.push(factory.createTypeLiteralNode(propertySignatures));
2268
2075
  }
2269
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("CreateOperationData"), undefined, factory.createIntersectionTypeNode(adNodes)));
2076
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("CreateOperationData"), undefined, factory.createIntersectionTypeNode(adNodes)));
2270
2077
  // CreateOperation
2271
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("CreateSingleOperation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2078
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("CreateSingleOperation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2272
2079
  factory.createLiteralTypeNode(factory.createStringLiteral("create")),
2273
2080
  factory.createTypeReferenceNode(factory.createIdentifier("CreateOperationData"))
2274
- ])), factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("CreateMultipleOperation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2081
+ ])), factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("CreateMultipleOperation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2275
2082
  factory.createLiteralTypeNode(factory.createStringLiteral("create")),
2276
2083
  factory.createTypeReferenceNode(factory.createIdentifier("Array"), [factory.createTypeReferenceNode(factory.createIdentifier("CreateOperationData"))])
2277
- ])), factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("CreateOperation"), undefined, factory.createUnionTypeNode([
2084
+ ])), factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("CreateOperation"), undefined, factory.createUnionTypeNode([
2278
2085
  factory.createTypeReferenceNode(factory.createIdentifier("CreateSingleOperation")),
2279
2086
  factory.createTypeReferenceNode(factory.createIdentifier("CreateMultipleOperation"))
2280
2087
  ])));
@@ -2284,27 +2091,17 @@ function constructOperations(statements, entity) {
2284
2091
  foreignKeyAttr.push('entity', 'entityId');
2285
2092
  }
2286
2093
  if (manyToOneSet) {
2287
- try {
2288
- for (var manyToOneSet_4 = tslib_1.__values(manyToOneSet), manyToOneSet_4_1 = manyToOneSet_4.next(); !manyToOneSet_4_1.done; manyToOneSet_4_1 = manyToOneSet_4.next()) {
2289
- var one = manyToOneSet_4_1.value;
2290
- if (!ReversePointerRelations[entity] || !ReversePointerRelations[entity].includes(one[1])) {
2291
- foreignKeyAttr.push("".concat(one[1], "Id"));
2292
- }
2094
+ for (const one of manyToOneSet) {
2095
+ if (!ReversePointerRelations[entity] || !ReversePointerRelations[entity].includes(one[1])) {
2096
+ foreignKeyAttr.push(`${one[1]}Id`);
2293
2097
  }
2294
2098
  }
2295
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
2296
- finally {
2297
- try {
2298
- if (manyToOneSet_4_1 && !manyToOneSet_4_1.done && (_e = manyToOneSet_4.return)) _e.call(manyToOneSet_4);
2299
- }
2300
- finally { if (e_14) throw e_14.error; }
2301
- }
2302
2099
  }
2303
2100
  adNodes = [
2304
2101
  factory.createTypeReferenceNode(factory.createIdentifier("FormUpdateData"), [
2305
2102
  foreignKeyAttr.length > 0 ? factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
2306
2103
  factory.createTypeReferenceNode(factory.createIdentifier("OpSchema"), undefined),
2307
- factory.createUnionTypeNode((0, lodash_1.uniq)(foreignKeyAttr).map(function (ele) { return factory.createLiteralTypeNode(factory.createStringLiteral(ele)); }))
2104
+ factory.createUnionTypeNode((0, lodash_1.uniq)(foreignKeyAttr).map(ele => factory.createLiteralTypeNode(factory.createStringLiteral(ele))))
2308
2105
  ]) : factory.createTypeReferenceNode(factory.createIdentifier("OpSchema"), undefined)
2309
2106
  ])
2310
2107
  ];
@@ -2315,170 +2112,156 @@ function constructOperations(statements, entity) {
2315
2112
  * 如果关联对象是update或者remove,则关联对象的filter由对象(的原行!注意这里的外键是不能变的!)决定其主键
2316
2113
  * 见cascadeStore
2317
2114
  */
2318
- var upsertOneNodes = [];
2319
- try {
2320
- for (var manyToOneSet_5 = tslib_1.__values(manyToOneSet), manyToOneSet_5_1 = manyToOneSet_5.next(); !manyToOneSet_5_1.done; manyToOneSet_5_1 = manyToOneSet_5.next()) {
2321
- var one = manyToOneSet_5_1.value;
2322
- if (!ReversePointerRelations[entity] || !ReversePointerRelations[entity].includes(one[0])) {
2323
- var cascadeCreateNode = factory.createTypeLiteralNode([
2324
- factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), undefined, factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'CreateSingleOperation'))),
2325
- factory.createPropertySignature(undefined, factory.createIdentifier("".concat(one[1], "Id")), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
2326
- ]);
2327
- var cascadeUpdateNode = factory.createTypeLiteralNode([
2328
- factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), undefined, factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'UpdateOperation'))),
2329
- factory.createPropertySignature(undefined, factory.createIdentifier("".concat(one[1], "Id")), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
2330
- ]);
2331
- var cascadeRemoveNode = factory.createTypeLiteralNode([
2332
- factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), undefined, factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'RemoveOperation'))),
2333
- factory.createPropertySignature(undefined, factory.createIdentifier("".concat(one[1], "Id")), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
2334
- ]);
2335
- var noCascadeNode = factory.createTypeLiteralNode([
2336
- factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
2337
- factory.createPropertySignature(undefined, factory.createIdentifier("".concat(one[1], "Id")), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
2338
- factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one[1]))]),
2339
- factory.createLiteralTypeNode(factory.createNull())
2340
- ])),
2341
- ]);
2342
- if (Schema[one[0]].static) {
2343
- upsertOneNodes.push(noCascadeNode);
2344
- }
2345
- else {
2346
- switch (Schema[one[0]].actionType) {
2347
- case 'crud': {
2348
- upsertOneNodes.push(factory.createUnionTypeNode([cascadeCreateNode, cascadeUpdateNode, cascadeRemoveNode, noCascadeNode]));
2349
- break;
2350
- }
2351
- case 'excludeUpdate': {
2352
- upsertOneNodes.push(factory.createUnionTypeNode([cascadeCreateNode, cascadeRemoveNode, noCascadeNode]));
2353
- break;
2354
- }
2355
- case 'appendOnly': {
2356
- upsertOneNodes.push(factory.createUnionTypeNode([cascadeCreateNode, noCascadeNode]));
2357
- break;
2358
- }
2359
- case 'readOnly': {
2360
- upsertOneNodes.push(noCascadeNode);
2361
- break;
2362
- }
2363
- case 'excludeRemove': {
2364
- upsertOneNodes.push(factory.createUnionTypeNode([cascadeCreateNode, cascadeUpdateNode, noCascadeNode]));
2365
- break;
2366
- }
2367
- default: {
2368
- (0, assert_1.default)(false);
2369
- }
2115
+ const upsertOneNodes = [];
2116
+ for (const one of manyToOneSet) {
2117
+ if (!ReversePointerRelations[entity] || !ReversePointerRelations[entity].includes(one[0])) {
2118
+ const cascadeCreateNode = factory.createTypeLiteralNode([
2119
+ factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'CreateSingleOperation'))),
2120
+ factory.createPropertySignature(undefined, factory.createIdentifier(`${one[1]}Id`), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
2121
+ ]);
2122
+ const cascadeUpdateNode = factory.createTypeLiteralNode([
2123
+ factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'UpdateOperation'))),
2124
+ factory.createPropertySignature(undefined, factory.createIdentifier(`${one[1]}Id`), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
2125
+ ]);
2126
+ const cascadeRemoveNode = factory.createTypeLiteralNode([
2127
+ factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'RemoveOperation'))),
2128
+ factory.createPropertySignature(undefined, factory.createIdentifier(`${one[1]}Id`), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
2129
+ ]);
2130
+ const noCascadeNode = factory.createTypeLiteralNode([
2131
+ factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
2132
+ factory.createPropertySignature(undefined, factory.createIdentifier(`${one[1]}Id`), factory.createToken(ts.SyntaxKind.QuestionToken), one[2] ? factory.createUnionTypeNode([
2133
+ factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one[1]))]),
2134
+ factory.createLiteralTypeNode(factory.createNull())
2135
+ ]) : factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one[1]))])),
2136
+ ]);
2137
+ if (Schema[one[0]].static) {
2138
+ upsertOneNodes.push(noCascadeNode);
2139
+ }
2140
+ else {
2141
+ switch (Schema[one[0]].actionType) {
2142
+ case 'crud': {
2143
+ upsertOneNodes.push(factory.createUnionTypeNode([cascadeCreateNode, cascadeUpdateNode, cascadeRemoveNode, noCascadeNode]));
2144
+ break;
2145
+ }
2146
+ case 'excludeUpdate': {
2147
+ upsertOneNodes.push(factory.createUnionTypeNode([cascadeCreateNode, cascadeRemoveNode, noCascadeNode]));
2148
+ break;
2149
+ }
2150
+ case 'appendOnly': {
2151
+ upsertOneNodes.push(factory.createUnionTypeNode([cascadeCreateNode, noCascadeNode]));
2152
+ break;
2153
+ }
2154
+ case 'readOnly': {
2155
+ upsertOneNodes.push(noCascadeNode);
2156
+ break;
2157
+ }
2158
+ case 'excludeRemove': {
2159
+ upsertOneNodes.push(factory.createUnionTypeNode([cascadeCreateNode, cascadeUpdateNode, noCascadeNode]));
2160
+ break;
2161
+ }
2162
+ default: {
2163
+ (0, assert_1.default)(false);
2370
2164
  }
2371
2165
  }
2372
2166
  }
2373
2167
  }
2374
2168
  }
2375
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
2376
- finally {
2377
- try {
2378
- if (manyToOneSet_5_1 && !manyToOneSet_5_1.done && (_f = manyToOneSet_5.return)) _f.call(manyToOneSet_5);
2379
- }
2380
- finally { if (e_15) throw e_15.error; }
2381
- }
2382
2169
  if (upsertOneNodes.length > 0) {
2383
2170
  adNodes.push(factory.createIntersectionTypeNode(upsertOneNodes));
2384
2171
  }
2385
- var reverseOneNodes_1 = [];
2172
+ const reverseOneNodes = [];
2386
2173
  if (ReversePointerRelations[entity]) {
2387
- var refEntityLitrals = [];
2388
- try {
2389
- for (var _s = tslib_1.__values(ReversePointerRelations[entity]), _t = _s.next(); !_t.done; _t = _s.next()) {
2390
- var one = _t.value;
2391
- refEntityLitrals.push(factory.createLiteralTypeNode(factory.createStringLiteral("".concat((0, string_1.firstLetterLowerCase)(one)))));
2392
- var actionNodes = [];
2393
- if (!Schema[one].static) {
2394
- switch (Schema[one].actionType) {
2395
- case 'crud': {
2396
- actionNodes.push(factory.createTypeReferenceNode(createForeignRef(entity, one, 'CreateSingleOperation')), factory.createTypeReferenceNode(createForeignRef(entity, one, 'UpdateOperation')), factory.createTypeReferenceNode(createForeignRef(entity, one, 'RemoveOperation')));
2397
- break;
2398
- }
2399
- case 'excludeUpdate': {
2400
- actionNodes.push(factory.createTypeReferenceNode(createForeignRef(entity, one, 'CreateSingleOperation')), factory.createTypeReferenceNode(createForeignRef(entity, one, 'RemoveOperation')));
2401
- break;
2402
- }
2403
- case 'excludeRemove': {
2404
- actionNodes.push(factory.createTypeReferenceNode(createForeignRef(entity, one, 'CreateSingleOperation')), factory.createTypeReferenceNode(createForeignRef(entity, one, 'UpdateOperation')));
2405
- break;
2406
- }
2407
- case 'appendOnly': {
2408
- actionNodes.push(factory.createTypeReferenceNode(createForeignRef(entity, one, 'CreateSingleOperation')));
2409
- break;
2410
- }
2411
- case 'readOnly': {
2412
- break;
2413
- }
2414
- default: {
2415
- (0, assert_1.default)(false);
2416
- }
2174
+ const refEntityLitrals = [];
2175
+ for (const one of ReversePointerRelations[entity]) {
2176
+ refEntityLitrals.push(factory.createLiteralTypeNode(factory.createStringLiteral(`${(0, string_1.firstLetterLowerCase)(one)}`)));
2177
+ const actionNodes = [];
2178
+ if (!Schema[one].static) {
2179
+ switch (Schema[one].actionType) {
2180
+ case 'crud': {
2181
+ actionNodes.push(factory.createTypeReferenceNode(createForeignRef(entity, one, 'CreateSingleOperation')), factory.createTypeReferenceNode(createForeignRef(entity, one, 'UpdateOperation')), factory.createTypeReferenceNode(createForeignRef(entity, one, 'RemoveOperation')));
2182
+ break;
2183
+ }
2184
+ case 'excludeUpdate': {
2185
+ actionNodes.push(factory.createTypeReferenceNode(createForeignRef(entity, one, 'CreateSingleOperation')), factory.createTypeReferenceNode(createForeignRef(entity, one, 'RemoveOperation')));
2186
+ break;
2187
+ }
2188
+ case 'excludeRemove': {
2189
+ actionNodes.push(factory.createTypeReferenceNode(createForeignRef(entity, one, 'CreateSingleOperation')), factory.createTypeReferenceNode(createForeignRef(entity, one, 'UpdateOperation')));
2190
+ break;
2191
+ }
2192
+ case 'appendOnly': {
2193
+ actionNodes.push(factory.createTypeReferenceNode(createForeignRef(entity, one, 'CreateSingleOperation')));
2194
+ break;
2195
+ }
2196
+ case 'readOnly': {
2197
+ break;
2198
+ }
2199
+ default: {
2200
+ (0, assert_1.default)(false);
2417
2201
  }
2418
- }
2419
- if (actionNodes.length > 0) {
2420
- reverseOneNodes_1.push(factory.createTypeLiteralNode([
2421
- factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode(actionNodes)),
2422
- factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
2423
- factory.createPropertySignature(undefined, factory.createIdentifier('entity'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword))
2424
- ]));
2425
2202
  }
2426
2203
  }
2427
- }
2428
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
2429
- finally {
2430
- try {
2431
- if (_t && !_t.done && (_g = _s.return)) _g.call(_s);
2204
+ if (actionNodes.length > 0) {
2205
+ reverseOneNodes.push(factory.createTypeLiteralNode([
2206
+ factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode(actionNodes)),
2207
+ factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
2208
+ factory.createPropertySignature(undefined, factory.createIdentifier('entity'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword))
2209
+ ]));
2432
2210
  }
2433
- finally { if (e_16) throw e_16.error; }
2434
- }
2435
- if (process.env.COMPLING_AS_LIB) {
2436
- // 如果是base,要包容更多可能的反指
2437
- refEntityLitrals.push(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
2438
2211
  }
2439
- reverseOneNodes_1.push(factory.createTypeLiteralNode([
2440
- factory.createPropertySignature(undefined, factory.createIdentifier('entity'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
2441
- factory.createUnionTypeNode(refEntityLitrals),
2212
+ const { schemaAttrs } = Schema[entity];
2213
+ const { questionToken: entityQuestionToken } = schemaAttrs.find(ele => {
2214
+ const { name } = ele;
2215
+ return name.text === 'entity';
2216
+ });
2217
+ const { questionToken: entityIdQuestionToken } = schemaAttrs.find(ele => {
2218
+ const { name } = ele;
2219
+ return name.text === 'entityId';
2220
+ });
2221
+ reverseOneNodes.push(factory.createTypeLiteralNode([
2222
+ factory.createPropertySignature(undefined, factory.createIdentifier('entity'), factory.createToken(ts.SyntaxKind.QuestionToken), !entityQuestionToken ? factory.createUnionTypeNode([
2223
+ // 如果是作为lib,要包容更多可能的反指
2224
+ factory.createUnionTypeNode(process.env.COMPLING_AS_LIB ? refEntityLitrals.concat(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)) : refEntityLitrals),
2442
2225
  factory.createLiteralTypeNode(factory.createNull())
2443
- ])),
2444
- factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
2445
- factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createUnionTypeNode(ReversePointerRelations[entity].map(function (ele) { return factory.createLiteralTypeNode(factory.createStringLiteral(ele)); }))]),
2226
+ ]) : factory.createUnionTypeNode(process.env.COMPLING_AS_LIB ? refEntityLitrals.concat(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)) : refEntityLitrals)),
2227
+ factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), factory.createToken(ts.SyntaxKind.QuestionToken), !entityIdQuestionToken ? factory.createUnionTypeNode([
2228
+ factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createUnionTypeNode(ReversePointerRelations[entity].map(ele => factory.createLiteralTypeNode(factory.createStringLiteral(ele))))]),
2446
2229
  factory.createLiteralTypeNode(factory.createNull())
2447
- ]))
2448
- ]));
2230
+ ]) : factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createUnionTypeNode(ReversePointerRelations[entity].map(ele => factory.createLiteralTypeNode(factory.createStringLiteral(ele))))]))
2231
+ ].concat(ReversePointerRelations[entity].map((one) => factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword))))));
2449
2232
  }
2450
- if (reverseOneNodes_1.length > 0) {
2451
- adNodes.push(factory.createUnionTypeNode(reverseOneNodes_1));
2233
+ if (reverseOneNodes.length > 0) {
2234
+ adNodes.push(factory.createUnionTypeNode(reverseOneNodes));
2452
2235
  }
2453
2236
  }
2454
- var propertySignatures2 = [];
2237
+ const propertySignatures2 = [];
2455
2238
  if (process.env.COMPLING_AS_LIB) {
2456
- propertySignatures2.push(factory.createIndexSignature(undefined, undefined, [factory.createParameterDeclaration(undefined, undefined, undefined, factory.createIdentifier("k"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)));
2239
+ propertySignatures2.push(factory.createIndexSignature(undefined, [factory.createParameterDeclaration(undefined, undefined, factory.createIdentifier("k"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)));
2457
2240
  }
2458
2241
  if (oneToManySet) {
2459
- var _loop_10 = function (entityName) {
2460
- var entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
2461
- foreignKeySet[entityName].forEach(function (foreignKey) {
2462
- var identifier = "".concat(entityNameLc, "$").concat(foreignKey);
2463
- var otmCreateOperationDataNode = factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
2242
+ for (const entityName in foreignKeySet) {
2243
+ const entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
2244
+ foreignKeySet[entityName].forEach((foreignKey) => {
2245
+ const identifier = `${entityNameLc}$${foreignKey}`;
2246
+ const otmCreateOperationDataNode = factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
2464
2247
  factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'CreateOperationData'), undefined),
2465
2248
  factory.createUnionTypeNode(foreignKey === 'entity' ? [
2466
2249
  factory.createLiteralTypeNode(factory.createStringLiteral("entity")),
2467
2250
  factory.createLiteralTypeNode(factory.createStringLiteral("entityId"))
2468
2251
  ] : [
2469
2252
  factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey)),
2470
- factory.createLiteralTypeNode(factory.createStringLiteral("".concat(foreignKey, "Id")))
2253
+ factory.createLiteralTypeNode(factory.createStringLiteral(`${foreignKey}Id`))
2471
2254
  ])
2472
2255
  ]);
2473
- var otmCreateSingleOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2256
+ const otmCreateSingleOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2474
2257
  factory.createLiteralTypeNode(factory.createStringLiteral("create")),
2475
2258
  otmCreateOperationDataNode
2476
2259
  ]);
2477
- var otmCreateMultipleOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2260
+ const otmCreateMultipleOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2478
2261
  factory.createLiteralTypeNode(factory.createStringLiteral("create")),
2479
2262
  factory.createArrayTypeNode(otmCreateOperationDataNode)
2480
2263
  ]);
2481
- var otmUpdateOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2264
+ const otmUpdateOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2482
2265
  factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'UpdateOperation'), undefined), factory.createLiteralTypeNode(factory.createStringLiteral("action"))),
2483
2266
  factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
2484
2267
  factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'UpdateOperationData'), undefined),
@@ -2487,7 +2270,7 @@ function constructOperations(statements, entity) {
2487
2270
  factory.createLiteralTypeNode(factory.createStringLiteral("entityId"))
2488
2271
  ] : [
2489
2272
  factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey)),
2490
- factory.createLiteralTypeNode(factory.createStringLiteral("".concat(foreignKey, "Id")))
2273
+ factory.createLiteralTypeNode(factory.createStringLiteral(`${foreignKey}Id`))
2491
2274
  ])
2492
2275
  ]),
2493
2276
  factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
@@ -2497,11 +2280,11 @@ function constructOperations(statements, entity) {
2497
2280
  factory.createLiteralTypeNode(factory.createStringLiteral("entityId"))
2498
2281
  ] : [
2499
2282
  factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey)),
2500
- factory.createLiteralTypeNode(factory.createStringLiteral("".concat(foreignKey, "Id")))
2283
+ factory.createLiteralTypeNode(factory.createStringLiteral(`${foreignKey}Id`))
2501
2284
  ])
2502
2285
  ])
2503
2286
  ]);
2504
- var otmRemoveOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2287
+ const otmRemoveOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2505
2288
  factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'RemoveOperation'), undefined), factory.createLiteralTypeNode(factory.createStringLiteral("action"))),
2506
2289
  factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
2507
2290
  factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'RemoveOperationData'), undefined),
@@ -2510,7 +2293,7 @@ function constructOperations(statements, entity) {
2510
2293
  factory.createLiteralTypeNode(factory.createStringLiteral("entityId"))
2511
2294
  ] : [
2512
2295
  factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey)),
2513
- factory.createLiteralTypeNode(factory.createStringLiteral("".concat(foreignKey, "Id")))
2296
+ factory.createLiteralTypeNode(factory.createStringLiteral(`${foreignKey}Id`))
2514
2297
  ])
2515
2298
  ]),
2516
2299
  factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
@@ -2520,7 +2303,7 @@ function constructOperations(statements, entity) {
2520
2303
  factory.createLiteralTypeNode(factory.createStringLiteral("entityId"))
2521
2304
  ] : [
2522
2305
  factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey)),
2523
- factory.createLiteralTypeNode(factory.createStringLiteral("".concat(foreignKey, "Id")))
2306
+ factory.createLiteralTypeNode(factory.createStringLiteral(`${foreignKey}Id`))
2524
2307
  ])
2525
2308
  ])
2526
2309
  ]);
@@ -2579,17 +2362,14 @@ function constructOperations(statements, entity) {
2579
2362
  }
2580
2363
  }
2581
2364
  });
2582
- };
2583
- for (var entityName in foreignKeySet) {
2584
- _loop_10(entityName);
2585
2365
  }
2586
2366
  }
2587
2367
  if (propertySignatures2.length > 0) {
2588
2368
  adNodes.push(factory.createTypeLiteralNode(propertySignatures2));
2589
2369
  }
2590
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("UpdateOperationData"), undefined, factory.createIntersectionTypeNode(adNodes)));
2370
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("UpdateOperationData"), undefined, factory.createIntersectionTypeNode(adNodes)));
2591
2371
  // UpdateOperation
2592
- var actionTypeNodes = [factory.createLiteralTypeNode(factory.createStringLiteral("update"))];
2372
+ const actionTypeNodes = [factory.createLiteralTypeNode(factory.createStringLiteral("update"))];
2593
2373
  if (ActionAsts[entity]) {
2594
2374
  actionTypeNodes.push(factory.createTypeReferenceNode('ParticularAction'));
2595
2375
  }
@@ -2599,7 +2379,7 @@ function constructOperations(statements, entity) {
2599
2379
  if (process.env.COMPLING_AS_LIB) {
2600
2380
  actionTypeNodes.push(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
2601
2381
  }
2602
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("UpdateOperation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2382
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("UpdateOperation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2603
2383
  factory.createUnionTypeNode(actionTypeNodes),
2604
2384
  factory.createTypeReferenceNode(factory.createIdentifier("UpdateOperationData")),
2605
2385
  factory.createTypeReferenceNode(factory.createIdentifier("Filter"), undefined),
@@ -2615,118 +2395,98 @@ function constructOperations(statements, entity) {
2615
2395
  * 如果关联对象动作是update或者remove,则关联对象的filter由对象(的原行!注意这里的外键是不能变的!)决定其主键
2616
2396
  * 见cascadeStore
2617
2397
  */
2618
- var upsertOneNodes = [];
2619
- try {
2620
- for (var manyToOneSet_6 = tslib_1.__values(manyToOneSet), manyToOneSet_6_1 = manyToOneSet_6.next(); !manyToOneSet_6_1.done; manyToOneSet_6_1 = manyToOneSet_6.next()) {
2621
- var one = manyToOneSet_6_1.value;
2622
- if (!ReversePointerRelations[entity] || !ReversePointerRelations[entity].includes(one[0])) {
2623
- if (!Schema[one[0]].static) {
2624
- switch (Schema[one[0]].actionType) {
2625
- case 'crud': {
2626
- upsertOneNodes.push(factory.createUnionTypeNode([
2627
- factory.createTypeLiteralNode([
2628
- factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
2629
- factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'UpdateOperation')),
2630
- factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'RemoveOperation'))
2631
- ]))
2632
- ])
2633
- ]));
2634
- break;
2635
- }
2636
- case 'excludeUpdate': {
2637
- upsertOneNodes.push(factory.createUnionTypeNode([
2638
- factory.createTypeLiteralNode([
2639
- factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'RemoveOperation')))
2640
- ])
2641
- ]));
2642
- break;
2643
- }
2644
- case 'excludeRemove': {
2645
- upsertOneNodes.push(factory.createUnionTypeNode([
2646
- factory.createTypeLiteralNode([
2647
- factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'UpdateOperation')))
2648
- ])
2649
- ]));
2650
- break;
2651
- }
2652
- case 'appendOnly':
2653
- case 'readOnly': {
2654
- break;
2655
- }
2656
- default: {
2657
- (0, assert_1.default)(false);
2658
- }
2398
+ const upsertOneNodes = [];
2399
+ for (const one of manyToOneSet) {
2400
+ if (!ReversePointerRelations[entity] || !ReversePointerRelations[entity].includes(one[0])) {
2401
+ if (!Schema[one[0]].static) {
2402
+ switch (Schema[one[0]].actionType) {
2403
+ case 'crud': {
2404
+ upsertOneNodes.push(factory.createUnionTypeNode([
2405
+ factory.createTypeLiteralNode([
2406
+ factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
2407
+ factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'UpdateOperation')),
2408
+ factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'RemoveOperation'))
2409
+ ]))
2410
+ ])
2411
+ ]));
2412
+ break;
2413
+ }
2414
+ case 'excludeUpdate': {
2415
+ upsertOneNodes.push(factory.createUnionTypeNode([
2416
+ factory.createTypeLiteralNode([
2417
+ factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'RemoveOperation')))
2418
+ ])
2419
+ ]));
2420
+ break;
2421
+ }
2422
+ case 'excludeRemove': {
2423
+ upsertOneNodes.push(factory.createUnionTypeNode([
2424
+ factory.createTypeLiteralNode([
2425
+ factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'UpdateOperation')))
2426
+ ])
2427
+ ]));
2428
+ break;
2429
+ }
2430
+ case 'appendOnly':
2431
+ case 'readOnly': {
2432
+ break;
2433
+ }
2434
+ default: {
2435
+ (0, assert_1.default)(false);
2659
2436
  }
2660
2437
  }
2661
2438
  }
2662
2439
  }
2663
2440
  }
2664
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
2665
- finally {
2666
- try {
2667
- if (manyToOneSet_6_1 && !manyToOneSet_6_1.done && (_h = manyToOneSet_6.return)) _h.call(manyToOneSet_6);
2668
- }
2669
- finally { if (e_17) throw e_17.error; }
2670
- }
2671
- var reverseOneNodes_2 = [];
2441
+ const reverseOneNodes = [];
2672
2442
  if (ReversePointerRelations[entity]) {
2673
- var refEntityLitrals = [];
2674
- try {
2675
- for (var _u = tslib_1.__values(ReversePointerRelations[entity]), _v = _u.next(); !_v.done; _v = _u.next()) {
2676
- var one = _v.value;
2677
- refEntityLitrals.push(factory.createLiteralTypeNode(factory.createStringLiteral("".concat((0, string_1.firstLetterLowerCase)(one)))));
2678
- if (!Schema[one].static) {
2679
- switch (Schema[one].actionType) {
2680
- case 'crud': {
2681
- reverseOneNodes_2.push(factory.createTypeLiteralNode([
2682
- factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
2683
- factory.createTypeReferenceNode(createForeignRef(entity, one, 'UpdateOperation')),
2684
- factory.createTypeReferenceNode(createForeignRef(entity, one, 'RemoveOperation'))
2685
- ]))
2686
- ]));
2687
- break;
2688
- }
2689
- case 'excludeUpdate': {
2690
- reverseOneNodes_2.push(factory.createTypeLiteralNode([
2691
- factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one, 'RemoveOperation')))
2692
- ]));
2693
- break;
2694
- }
2695
- case 'excludeRemove': {
2696
- reverseOneNodes_2.push(factory.createTypeLiteralNode([
2697
- factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one, 'UpdateOperation')))
2698
- ]));
2699
- break;
2700
- }
2701
- case 'appendOnly':
2702
- case 'readOnly': {
2703
- break;
2704
- }
2705
- default: {
2706
- (0, assert_1.default)(false);
2707
- }
2443
+ const refEntityLitrals = [];
2444
+ for (const one of ReversePointerRelations[entity]) {
2445
+ refEntityLitrals.push(factory.createLiteralTypeNode(factory.createStringLiteral(`${(0, string_1.firstLetterLowerCase)(one)}`)));
2446
+ if (!Schema[one].static) {
2447
+ switch (Schema[one].actionType) {
2448
+ case 'crud': {
2449
+ reverseOneNodes.push(factory.createTypeLiteralNode([
2450
+ factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
2451
+ factory.createTypeReferenceNode(createForeignRef(entity, one, 'UpdateOperation')),
2452
+ factory.createTypeReferenceNode(createForeignRef(entity, one, 'RemoveOperation'))
2453
+ ]))
2454
+ ]));
2455
+ break;
2456
+ }
2457
+ case 'excludeUpdate': {
2458
+ reverseOneNodes.push(factory.createTypeLiteralNode([
2459
+ factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one, 'RemoveOperation')))
2460
+ ]));
2461
+ break;
2462
+ }
2463
+ case 'excludeRemove': {
2464
+ reverseOneNodes.push(factory.createTypeLiteralNode([
2465
+ factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one, 'UpdateOperation')))
2466
+ ]));
2467
+ break;
2468
+ }
2469
+ case 'appendOnly':
2470
+ case 'readOnly': {
2471
+ break;
2472
+ }
2473
+ default: {
2474
+ (0, assert_1.default)(false);
2708
2475
  }
2709
2476
  }
2710
2477
  }
2711
2478
  }
2712
- catch (e_18_1) { e_18 = { error: e_18_1 }; }
2713
- finally {
2714
- try {
2715
- if (_v && !_v.done && (_j = _u.return)) _j.call(_u);
2716
- }
2717
- finally { if (e_18) throw e_18.error; }
2718
- }
2719
2479
  if (process.env.COMPLING_AS_LIB) {
2720
- reverseOneNodes_2.push(factory.createTypeLiteralNode([
2721
- factory.createIndexSignature(undefined, undefined, [factory.createParameterDeclaration(undefined, undefined, undefined, factory.createIdentifier("k"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword))
2480
+ reverseOneNodes.push(factory.createTypeLiteralNode([
2481
+ factory.createIndexSignature(undefined, [factory.createParameterDeclaration(undefined, undefined, factory.createIdentifier("k"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword))
2722
2482
  ]));
2723
2483
  }
2724
2484
  }
2725
2485
  if (upsertOneNodes.length > 0) {
2726
2486
  adNodes.push(factory.createIntersectionTypeNode(upsertOneNodes));
2727
2487
  }
2728
- if (reverseOneNodes_2.length > 0) {
2729
- adNodes.push(factory.createUnionTypeNode(reverseOneNodes_2));
2488
+ if (reverseOneNodes.length > 0) {
2489
+ adNodes.push(factory.createUnionTypeNode(reverseOneNodes));
2730
2490
  }
2731
2491
  }
2732
2492
  /**
@@ -2799,33 +2559,33 @@ function constructOperations(statements, entity) {
2799
2559
  )
2800
2560
  );
2801
2561
  } */
2802
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("RemoveOperationData"), undefined, factory.createIntersectionTypeNode(adNodes)));
2562
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("RemoveOperationData"), undefined, factory.createIntersectionTypeNode(adNodes)));
2803
2563
  // RemoveOperation
2804
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("RemoveOperation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2564
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("RemoveOperation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
2805
2565
  factory.createLiteralTypeNode(factory.createStringLiteral("remove")),
2806
2566
  factory.createTypeReferenceNode(factory.createIdentifier("RemoveOperationData"), undefined),
2807
2567
  factory.createTypeReferenceNode(factory.createIdentifier("Filter"), undefined),
2808
2568
  factory.createTypeReferenceNode(factory.createIdentifier("Sorter"), undefined)
2809
2569
  ])));
2810
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Operation"), undefined, factory.createUnionTypeNode([
2570
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Operation"), undefined, factory.createUnionTypeNode([
2811
2571
  factory.createTypeReferenceNode(factory.createIdentifier("CreateOperation"), undefined),
2812
2572
  factory.createTypeReferenceNode(factory.createIdentifier("UpdateOperation"), undefined),
2813
2573
  factory.createTypeReferenceNode(factory.createIdentifier("RemoveOperation"), undefined)
2814
2574
  ])));
2815
2575
  }
2816
- var initialStatements = function () { return [
2576
+ const initialStatements = () => [
2817
2577
  // import { String, Text, Int, SpecificKey } from 'oak-domain/types/DataType';
2818
- factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
2578
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
2819
2579
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('PrimaryKey')),
2820
2580
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('ForeignKey')),
2821
2581
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('JsonProjection'))
2822
- ])), factory.createStringLiteral("".concat((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(), "DataType"))),
2582
+ ])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)()}DataType`)),
2823
2583
  /* import {
2824
2584
  Q_DateValue, Q_LogicKey, Q_NumberValue, FnCallKey, FnCallValue,
2825
2585
  Q_StringValue, Q_FullTextKey, Q_FullTextValue, FnCallValueAs,
2826
2586
  Q_BooleanValue,
2827
2587
  } from 'oak-domain/types/Demand'; */
2828
- factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
2588
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
2829
2589
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_DateValue')),
2830
2590
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_BooleanValue')),
2831
2591
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_NumberValue')),
@@ -2838,11 +2598,11 @@ var initialStatements = function () { return [
2838
2598
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('ExpressionKey')),
2839
2599
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('JsonFilter')),
2840
2600
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('SubQueryPredicateMetadata')),
2841
- ])), factory.createStringLiteral("".concat((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(), "Demand"))),
2842
- factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
2601
+ ])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)()}Demand`)),
2602
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
2843
2603
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("OneOf")),
2844
2604
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("ValueOf"))
2845
- ])), factory.createStringLiteral("".concat((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(), "Polyfill"))),
2605
+ ])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)()}Polyfill`)),
2846
2606
  // import * as SubQuery from '../_SubQuery';
2847
2607
  /* factory.createImportDeclaration(
2848
2608
  undefined,
@@ -2855,7 +2615,7 @@ var initialStatements = function () { return [
2855
2615
  factory.createStringLiteral("../_SubQuery")
2856
2616
  ), */
2857
2617
  // import { Filter as OakFilter } from 'oak-domain/src/types/Entity';
2858
- factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
2618
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
2859
2619
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("FormCreateData")),
2860
2620
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("FormUpdateData")),
2861
2621
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("DeduceAggregation")),
@@ -2863,83 +2623,77 @@ var initialStatements = function () { return [
2863
2623
  factory.createImportSpecifier(false, factory.createIdentifier("Selection"), factory.createIdentifier("OakSelection")),
2864
2624
  factory.createImportSpecifier(false, factory.createIdentifier("MakeAction"), factory.createIdentifier("OakMakeAction")),
2865
2625
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("AggregationResult")),
2866
- ])), factory.createStringLiteral("".concat((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(), "Entity")), undefined)
2867
- ]; };
2626
+ ])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)()}Entity`), undefined)
2627
+ ];
2868
2628
  function outputSubQuery(outputDir, printer) {
2869
- var statements = [];
2629
+ const statements = [];
2870
2630
  if (process.env.COMPLING_AS_LIB) {
2871
2631
  }
2872
- for (var entity in Schema) {
2632
+ for (const entity in Schema) {
2873
2633
  // import * as User from '../User/Schema';
2874
- statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamespaceImport(factory.createIdentifier(entity))), factory.createStringLiteral("./".concat(entity, "/Schema"))));
2634
+ statements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamespaceImport(factory.createIdentifier(entity))), factory.createStringLiteral(`./${entity}/Schema`)));
2875
2635
  }
2876
- var entities = (0, lodash_1.keys)(Schema);
2877
- var _loop_11 = function (one) {
2878
- var identifier = "".concat(one, "IdSubQuery");
2879
- var fromEntites = OneToMany[one] ? (0, lodash_1.uniq)(OneToMany[one]
2636
+ const entities = (0, lodash_1.keys)(Schema);
2637
+ // 每个有manyToOne的Entity都会输出${One}IdSubQuery
2638
+ for (const one in Schema) {
2639
+ const identifier = `${one}IdSubQuery`;
2640
+ const fromEntites = OneToMany[one] ? (0, lodash_1.uniq)(OneToMany[one]
2880
2641
  /* .filter(
2881
2642
  ([e, f]) => f !== 'entity'
2882
- ) */ .map(function (_a) {
2883
- var _b = tslib_1.__read(_a, 1), e = _b[0];
2884
- return e;
2885
- })) : [];
2643
+ ) */ .map(([e]) => e)) : [];
2886
2644
  fromEntites.push(one);
2887
- var inUnionTypeNode = fromEntites.map(function (ele) { return factory.createIntersectionTypeNode([
2645
+ const inUnionTypeNode = fromEntites.map(ele => factory.createIntersectionTypeNode([
2888
2646
  factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(ele), factory.createIdentifier(identifier)), undefined),
2889
2647
  factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier("entity"), undefined, factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(ele))))])
2890
- ]); });
2648
+ ]));
2891
2649
  if (process.env.COMPLING_AS_LIB) {
2892
2650
  // 如果是建立 base,这里要加上额外可能的对象信息
2893
2651
  inUnionTypeNode.push(factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword));
2894
2652
  }
2895
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier(identifier), undefined, factory.createMappedTypeNode(undefined, factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("K"), factory.createUnionTypeNode([
2653
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier(identifier), undefined, factory.createMappedTypeNode(undefined, factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("K"), factory.createUnionTypeNode([
2896
2654
  factory.createLiteralTypeNode(factory.createStringLiteral("$in")),
2897
2655
  factory.createLiteralTypeNode(factory.createStringLiteral("$nin"))
2898
2656
  ]), undefined), undefined, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode(inUnionTypeNode), undefined)));
2899
- };
2900
- // 每个有manyToOne的Entity都会输出${One}IdSubQuery
2901
- for (var one in Schema) {
2902
- _loop_11(one);
2903
2657
  }
2904
- var resultFile = ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS);
2905
- var result = printer.printNode(ts.EmitHint.Unspecified, factory.createSourceFile(statements, factory.createToken(ts.SyntaxKind.EndOfFileToken), ts.NodeFlags.None), resultFile);
2906
- var fileName = path_1.default.join(outputDir, '_SubQuery.ts');
2658
+ const resultFile = ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS);
2659
+ const result = printer.printNode(ts.EmitHint.Unspecified, factory.createSourceFile(statements, factory.createToken(ts.SyntaxKind.EndOfFileToken), ts.NodeFlags.None), resultFile);
2660
+ const fileName = path_1.default.join(outputDir, '_SubQuery.ts');
2907
2661
  (0, fs_1.writeFileSync)(fileName, result, { flag: 'w' });
2908
2662
  }
2909
2663
  function outputEntityDict(outputDir, printer) {
2910
- var statements = [];
2911
- var propertySignatures = [];
2912
- for (var entity in Schema) {
2664
+ const statements = [];
2665
+ const propertySignatures = [];
2666
+ for (const entity in Schema) {
2913
2667
  // import * as User from '../User/Schema';
2914
- statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("EntityDef"), factory.createIdentifier(entity))])), factory.createStringLiteral("./".concat(entity, "/Schema"))));
2915
- var entityLc = (0, string_1.firstLetterLowerCase)(entity);
2668
+ statements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("EntityDef"), factory.createIdentifier(entity))])), factory.createStringLiteral(`./${entity}/Schema`)));
2669
+ const entityLc = (0, string_1.firstLetterLowerCase)(entity);
2916
2670
  propertySignatures.push(factory.createPropertySignature(undefined, factory.createIdentifier(entityLc), undefined, factory.createTypeReferenceNode(entity)));
2917
2671
  }
2918
2672
  if ( /* process.env.COMPLING_AS_LIB */false) {
2919
- statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("EntityDef"))])), factory.createStringLiteral("../types/Entity"), undefined), factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDict"), undefined, factory.createIntersectionTypeNode([
2673
+ statements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("EntityDef"))])), factory.createStringLiteral("../types/Entity"), undefined), factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDict"), undefined, factory.createIntersectionTypeNode([
2920
2674
  factory.createTypeLiteralNode(propertySignatures),
2921
2675
  factory.createTypeLiteralNode([
2922
- factory.createIndexSignature(undefined, undefined, [factory.createParameterDeclaration(undefined, undefined, undefined, factory.createIdentifier("E"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createTypeReferenceNode(factory.createIdentifier("EntityDef"), undefined))
2676
+ factory.createIndexSignature(undefined, [factory.createParameterDeclaration(undefined, undefined, factory.createIdentifier("E"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createTypeReferenceNode(factory.createIdentifier("EntityDef"), undefined))
2923
2677
  ])
2924
2678
  ])));
2925
2679
  }
2926
2680
  else {
2927
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDict"), undefined, factory.createTypeLiteralNode(propertySignatures)));
2681
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDict"), undefined, factory.createTypeLiteralNode(propertySignatures)));
2928
2682
  }
2929
- var resultFile = ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS);
2930
- var result = printer.printNode(ts.EmitHint.Unspecified, factory.createSourceFile(statements, factory.createToken(ts.SyntaxKind.EndOfFileToken), ts.NodeFlags.None), resultFile);
2931
- var fileName = path_1.default.join(outputDir, 'EntityDict.ts');
2683
+ const resultFile = ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS);
2684
+ const result = printer.printNode(ts.EmitHint.Unspecified, factory.createSourceFile(statements, factory.createToken(ts.SyntaxKind.EndOfFileToken), ts.NodeFlags.None), resultFile);
2685
+ const fileName = path_1.default.join(outputDir, 'EntityDict.ts');
2932
2686
  (0, fs_1.writeFileSync)(fileName, result, { flag: 'w' });
2933
2687
  }
2934
2688
  function outputSchema(outputDir, printer) {
2935
- for (var entity in Schema) {
2936
- var statements = initialStatements();
2689
+ for (const entity in Schema) {
2690
+ const statements = initialStatements();
2937
2691
  if (ActionAsts[entity]) {
2938
- var _a = ActionAsts[entity], importedFrom = _a.importedFrom, actionDefNames = _a.actionDefNames;
2939
- var localActions = ['Action', 'ParticularAction'];
2940
- for (var a in importedFrom) {
2692
+ const { importedFrom, actionDefNames } = ActionAsts[entity];
2693
+ const localActions = ['Action', 'ParticularAction'];
2694
+ for (const a in importedFrom) {
2941
2695
  (0, assert_1.default)(a.endsWith('Action'));
2942
- var s = a.slice(0, a.length - 6).concat('State');
2696
+ const s = a.slice(0, a.length - 6).concat('State');
2943
2697
  if (importedFrom[a] === 'local' && actionDefNames.includes((0, string_1.firstLetterLowerCase)(a.slice(0, a.length - 6)))) {
2944
2698
  localActions.push(s);
2945
2699
  }
@@ -2969,12 +2723,12 @@ function outputSchema(outputDir, printer) {
2969
2723
  // );
2970
2724
  }
2971
2725
  }
2972
- 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([
2726
+ statements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports(localActions.map(ele => factory.createImportSpecifier(false, undefined, factory.createIdentifier(ele))))), factory.createStringLiteral('./Action'), undefined), factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
2973
2727
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("RelationAction")),
2974
2728
  ])), factory.createStringLiteral((0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)()), undefined));
2975
2729
  }
2976
2730
  else {
2977
- statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
2731
+ statements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
2978
2732
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("GenericAction")),
2979
2733
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("AppendOnlyAction")),
2980
2734
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("ReadOnlyAction")),
@@ -2983,9 +2737,9 @@ function outputSchema(outputDir, printer) {
2983
2737
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("RelationAction")),
2984
2738
  ])), factory.createStringLiteral((0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)()), undefined));
2985
2739
  }
2986
- var additionalImports = Schema[entity].additionalImports;
2987
- if ((additionalImports === null || additionalImports === void 0 ? void 0 : additionalImports.length) > 0) {
2988
- statements.push.apply(statements, tslib_1.__spreadArray([], tslib_1.__read(additionalImports), false));
2740
+ const { additionalImports } = Schema[entity];
2741
+ if (additionalImports?.length > 0) {
2742
+ statements.push(...additionalImports);
2989
2743
  }
2990
2744
  // Relation定义加入
2991
2745
  /* if (typeof Schema[entity].hasRelationDef === 'object' && ts.isTypeAliasDeclaration(Schema[entity].hasRelationDef as ts.Node)) {
@@ -3009,7 +2763,7 @@ function outputSchema(outputDir, printer) {
3009
2763
  constructQuery(statements, entity);
3010
2764
  // 现在FullAttrs和NativeAttrs似乎没什么用,还会引起递归
3011
2765
  // constructFullAttrs(statements, entity);
3012
- var makeActionArguments = [];
2766
+ const makeActionArguments = [];
3013
2767
  if (ActionAsts[entity]) {
3014
2768
  makeActionArguments.push(factory.createTypeReferenceNode('Action'));
3015
2769
  }
@@ -3019,8 +2773,8 @@ function outputSchema(outputDir, printer) {
3019
2773
  if (Schema[entity].hasRelationDef || entity === 'User') {
3020
2774
  makeActionArguments.push(factory.createTypeReferenceNode('RelationAction'));
3021
2775
  }
3022
- var actionTypeNode = factory.createTypeReferenceNode(factory.createIdentifier('OakMakeAction'), makeActionArguments.length === 1 ? makeActionArguments : [factory.createUnionTypeNode(makeActionArguments)]);
3023
- var EntityDefAttrs = [
2776
+ const actionTypeNode = factory.createTypeReferenceNode(factory.createIdentifier('OakMakeAction'), makeActionArguments.length === 1 ? makeActionArguments : [factory.createUnionTypeNode(makeActionArguments)]);
2777
+ const EntityDefAttrs = [
3024
2778
  factory.createPropertySignature(undefined, factory.createIdentifier("Schema"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Schema"), undefined)),
3025
2779
  factory.createPropertySignature(undefined, factory.createIdentifier("OpSchema"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OpSchema"), undefined)),
3026
2780
  factory.createPropertySignature(undefined, factory.createIdentifier("Action"), undefined, process.env.COMPLING_AS_LIB ?
@@ -3053,19 +2807,19 @@ function outputSchema(outputDir, printer) {
3053
2807
  )
3054
2808
  );
3055
2809
  } */
3056
- statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDef"), undefined, factory.createTypeLiteralNode(EntityDefAttrs)));
3057
- var result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements), Schema[entity].sourceFile);
3058
- var fileName = path_1.default.join(outputDir, entity, 'Schema.ts');
2810
+ statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDef"), undefined, factory.createTypeLiteralNode(EntityDefAttrs)));
2811
+ const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements), Schema[entity].sourceFile);
2812
+ const fileName = path_1.default.join(outputDir, entity, 'Schema.ts');
3059
2813
  (0, fs_1.writeFileSync)(fileName, result, { flag: 'w' });
3060
2814
  }
3061
2815
  }
3062
2816
  function outputAction(outputDir, printer) {
3063
- var actionDictStatements = [];
3064
- var propertyAssignments = [];
3065
- for (var entity in ActionAsts) {
3066
- var _a = ActionAsts[entity], sourceFile = _a.sourceFile, statements = _a.statements, importedFrom = _a.importedFrom, actionDefNames = _a.actionDefNames;
3067
- var importStatements = [];
3068
- for (var k in importedFrom) {
2817
+ const actionDictStatements = [];
2818
+ const propertyAssignments = [];
2819
+ for (const entity in ActionAsts) {
2820
+ const { sourceFile, statements, importedFrom, actionDefNames } = ActionAsts[entity];
2821
+ const importStatements = [];
2822
+ for (const k in importedFrom) {
3069
2823
  (0, assert_1.default)(k.endsWith('Action'));
3070
2824
  if (importedFrom[k] !== 'local') {
3071
2825
  importStatements.push(importedFrom[k]);
@@ -3075,7 +2829,7 @@ function outputAction(outputDir, printer) {
3075
2829
  if (actionDiff.length > 0) {
3076
2830
  throw new Error(`action not conform to actionDef: ${actionDiff.join(',')}, entity: ${entity}`);
3077
2831
  } */
3078
- statements.push(factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("ActionDefDict"), undefined, undefined, factory.createObjectLiteralExpression(actionDefNames.map(function (ele) { return factory.createPropertyAssignment(factory.createIdentifier("".concat(ele, "State")), factory.createIdentifier("".concat((0, string_1.firstLetterUpperCase)(ele), "ActionDef"))); }), true))], ts.NodeFlags.Const)));
2832
+ statements.push(factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("ActionDefDict"), undefined, undefined, factory.createObjectLiteralExpression(actionDefNames.map(ele => factory.createPropertyAssignment(factory.createIdentifier(`${ele}State`), factory.createIdentifier(`${(0, string_1.firstLetterUpperCase)(ele)}ActionDef`))), true))], ts.NodeFlags.Const)));
3079
2833
  /* const result = printer.printNode(
3080
2834
  ts.EmitHint.Unspecified,
3081
2835
  factory.createSourceFile(statements,
@@ -3084,33 +2838,33 @@ function outputAction(outputDir, printer) {
3084
2838
  sourceFile
3085
2839
  ); */
3086
2840
  // 这里如果用printNode,stringLiteral的输出始终有个bug不知道如何处理
3087
- var result_1 = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(importStatements.concat(statements)), sourceFile);
3088
- var filename = path_1.default.join(outputDir, entity, 'Action.ts');
3089
- (0, fs_1.writeFileSync)(filename, result_1, { flag: 'w' });
3090
- actionDictStatements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("ActionDefDict"), factory.createIdentifier(entity))])), factory.createStringLiteral("./".concat(entity, "/Action"))));
2841
+ const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(importStatements.concat(statements)), sourceFile);
2842
+ const filename = path_1.default.join(outputDir, entity, 'Action.ts');
2843
+ (0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
2844
+ actionDictStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("ActionDefDict"), factory.createIdentifier(entity))])), factory.createStringLiteral(`./${entity}/Action`)));
3091
2845
  propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier((0, string_1.firstLetterLowerCase)(entity)), factory.createIdentifier(entity)));
3092
2846
  }
3093
2847
  actionDictStatements.push(factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("ActionDefDict"), undefined, undefined, factory.createObjectLiteralExpression(propertyAssignments, true))], ts.NodeFlags.Const)));
3094
- var resultFile = ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS);
3095
- var result = printer.printNode(ts.EmitHint.Unspecified, factory.createSourceFile(actionDictStatements, factory.createToken(ts.SyntaxKind.EndOfFileToken), ts.NodeFlags.None), resultFile);
3096
- var fileName = path_1.default.join(outputDir, 'ActionDefDict.ts');
2848
+ const resultFile = ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS);
2849
+ const result = printer.printNode(ts.EmitHint.Unspecified, factory.createSourceFile(actionDictStatements, factory.createToken(ts.SyntaxKind.EndOfFileToken), ts.NodeFlags.None), resultFile);
2850
+ const fileName = path_1.default.join(outputDir, 'ActionDefDict.ts');
3097
2851
  (0, fs_1.writeFileSync)(fileName, result, { flag: 'w' });
3098
2852
  }
3099
2853
  function constructAttributes(entity) {
3100
- var _a = Schema[entity], schemaAttrs = _a.schemaAttrs, enumAttributes = _a.enumAttributes;
3101
- var _b = ManyToOne, _c = entity, manyToOneSet = _b[_c];
3102
- var result = [];
3103
- schemaAttrs.forEach(function (attr) {
3104
- var attrAssignments = [];
3105
- var name = attr.name, type = attr.type, allowNull = attr.questionToken;
2854
+ const { schemaAttrs, enumAttributes } = Schema[entity];
2855
+ const { [entity]: manyToOneSet } = ManyToOne;
2856
+ const result = [];
2857
+ schemaAttrs.forEach((attr) => {
2858
+ const attrAssignments = [];
2859
+ const { name, type, questionToken: allowNull } = attr;
3106
2860
  if (!allowNull) {
3107
2861
  attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("notNull"), factory.createTrue()));
3108
2862
  }
3109
- var name2 = name;
2863
+ let name2 = name;
3110
2864
  if (ts.isTypeReferenceNode(type)) {
3111
- var typeName = type.typeName, typeArguments = type.typeArguments;
2865
+ const { typeName, typeArguments } = type;
3112
2866
  if (ts.isIdentifier(typeName)) {
3113
- var text = typeName.text;
2867
+ const { text } = typeName;
3114
2868
  switch (text) {
3115
2869
  case 'String': {
3116
2870
  attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("varchar")), factory.createPropertyAssignment(factory.createIdentifier("params"), factory.createObjectLiteralExpression([
@@ -3118,10 +2872,10 @@ function constructAttributes(entity) {
3118
2872
  ], true)));
3119
2873
  // 如果是entity,在这里处理一下ref
3120
2874
  if (ts.isIdentifier(name) && name.text === 'entity') {
3121
- var mtoRelations = ReversePointerRelations[entity];
2875
+ const mtoRelations = ReversePointerRelations[entity];
3122
2876
  if (mtoRelations) {
3123
- var mtoEntities = mtoRelations.map(function (ele) { return (0, string_1.firstLetterLowerCase)(ele); });
3124
- attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("ref"), factory.createArrayLiteralExpression(mtoEntities.map(function (ele) { return factory.createStringLiteral(ele); }), false)));
2877
+ const mtoEntities = mtoRelations.map(ele => (0, string_1.firstLetterLowerCase)(ele));
2878
+ attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("ref"), factory.createArrayLiteralExpression(mtoEntities.map(ele => factory.createStringLiteral(ele)), false)));
3125
2879
  }
3126
2880
  }
3127
2881
  break;
@@ -3144,7 +2898,7 @@ function constructAttributes(entity) {
3144
2898
  case 'Float':
3145
2899
  case 'Decimal': {
3146
2900
  if (['Double', 'Float'].includes(text)) {
3147
- console.warn("".concat(entity, "\u5BF9\u8C61\u4E2D\u8FD8\u6709").concat(text, "\u7C7B\u578B\u5B9A\u4E49\uFF0C\u73B0\u5728\u7EDF\u4E00\u7528Decimal\u8FDB\u884C\u5B58\u50A8"));
2901
+ console.warn(`${entity}对象中还有${text}类型定义,现在统一用Decimal进行存储`);
3148
2902
  }
3149
2903
  attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("decimal")), factory.createPropertyAssignment(factory.createIdentifier("params"), factory.createObjectLiteralExpression([
3150
2904
  factory.createPropertyAssignment(factory.createIdentifier("precision"), factory.createNumericLiteral(typeArguments[0].literal.text)),
@@ -3176,19 +2930,16 @@ function constructAttributes(entity) {
3176
2930
  break;
3177
2931
  }
3178
2932
  default: {
3179
- var text2_6 = text === 'Schema' ? entity : text;
3180
- var manyToOneItem = manyToOneSet && manyToOneSet.find(function (_a) {
3181
- var _b = tslib_1.__read(_a, 2), refEntity = _b[0], attrName = _b[1];
3182
- return refEntity === text2_6 && attrName === attrName;
3183
- });
2933
+ const text2 = text === 'Schema' ? entity : text;
2934
+ const manyToOneItem = manyToOneSet && manyToOneSet.find(([refEntity, attrName]) => refEntity === text2 && attrName === attrName);
3184
2935
  if (manyToOneItem) {
3185
2936
  // 外键
3186
- name2 = factory.createIdentifier("".concat(name.text, "Id"));
3187
- attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("ref")), factory.createPropertyAssignment(factory.createIdentifier("ref"), factory.createStringLiteral((0, string_1.firstLetterLowerCase)(text2_6))));
2937
+ name2 = factory.createIdentifier(`${name.text}Id`);
2938
+ attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("ref")), factory.createPropertyAssignment(factory.createIdentifier("ref"), factory.createStringLiteral((0, string_1.firstLetterLowerCase)(text2))));
3188
2939
  }
3189
2940
  else {
3190
2941
  if (enumAttributes && enumAttributes[name.text]) {
3191
- attrAssignments.push(factory.createPropertyAssignment('type', factory.createStringLiteral("enum")), factory.createPropertyAssignment('enumeration', factory.createArrayLiteralExpression(enumAttributes[name.text].map(function (ele) { return factory.createStringLiteral(ele); }))));
2942
+ attrAssignments.push(factory.createPropertyAssignment('type', factory.createStringLiteral("enum")), factory.createPropertyAssignment('enumeration', factory.createArrayLiteralExpression(enumAttributes[name.text].map(ele => factory.createStringLiteral(ele)))));
3192
2943
  }
3193
2944
  else {
3194
2945
  // todo 引用的非string定义,目前没有处理int类型的引用,等遇到了再处理
@@ -3207,7 +2958,7 @@ function constructAttributes(entity) {
3207
2958
  if (ts.isLiteralTypeNode(type.types[0])) {
3208
2959
  if (ts.isStringLiteral(type.types[0].literal)) {
3209
2960
  (0, assert_1.default)(enumAttributes && enumAttributes[name.text]);
3210
- attrAssignments.push(factory.createPropertyAssignment('type', factory.createStringLiteral("enum")), factory.createPropertyAssignment('enumeration', factory.createArrayLiteralExpression(enumAttributes[name.text].map(function (ele) { return factory.createStringLiteral(ele); }))));
2961
+ attrAssignments.push(factory.createPropertyAssignment('type', factory.createStringLiteral("enum")), factory.createPropertyAssignment('enumeration', factory.createArrayLiteralExpression(enumAttributes[name.text].map(ele => factory.createStringLiteral(ele)))));
3211
2962
  }
3212
2963
  else {
3213
2964
  (0, assert_1.default)(ts.isNumericLiteral(type.types[0].literal));
@@ -3245,20 +2996,20 @@ function constructAttributes(entity) {
3245
2996
  return result;
3246
2997
  }
3247
2998
  function outputLocale(outputDir, printer) {
3248
- var locales = {};
3249
- var entities = [];
3250
- var _loop_12 = function (entity) {
3251
- var _a = Schema[entity], locale = _a.locale, sourceFile = _a.sourceFile;
2999
+ const locales = {};
3000
+ const entities = [];
3001
+ for (const entity in Schema) {
3002
+ const { locale, sourceFile } = Schema[entity];
3252
3003
  if (locale) {
3253
- var properties = locale.properties;
3254
- properties.forEach(function (ele) {
3004
+ const { properties } = locale;
3005
+ properties.forEach((ele) => {
3255
3006
  (0, assert_1.default)(ts.isPropertyAssignment(ele) && (ts.isIdentifier(ele.name) || ts.isStringLiteral(ele.name)) && ts.isObjectLiteralExpression(ele.initializer));
3256
- var lng = ele.name.text;
3257
- var result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray([
3007
+ const lng = ele.name.text;
3008
+ const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray([
3258
3009
  factory.createReturnStatement(ele.initializer)
3259
3010
  ]), sourceFile);
3260
- var data = Function(result)();
3261
- var filename = path_1.default.join(outputDir, entity, 'locales', "".concat(lng, ".json"));
3011
+ const data = Function(result)();
3012
+ const filename = path_1.default.join(outputDir, entity, 'locales', `${lng}.json`);
3262
3013
  (0, fs_1.writeFileSync)(filename, JSON.stringify(data), { flag: 'w' });
3263
3014
  if (locales[lng]) {
3264
3015
  locales[lng].push(entity);
@@ -3269,14 +3020,11 @@ function outputLocale(outputDir, printer) {
3269
3020
  });
3270
3021
  entities.push(entity);
3271
3022
  }
3272
- };
3273
- for (var entity in Schema) {
3274
- _loop_12(entity);
3275
3023
  }
3276
- for (var lng in locales) {
3024
+ for (const lng in locales) {
3277
3025
  if (locales[lng].length < entities.length) {
3278
- var lack = (0, lodash_1.difference)(entities, locales[lng]);
3279
- throw new Error("".concat(lng, "\u8BED\u8A00\u5B9A\u4E49\u4E2D\u7F3A\u5C11\u4E86\u5BF9\u8C61").concat(lack.join(','), "\u7684\u5B9A\u4E49\uFF0C\u8BF7\u68C0\u67E5\u76F8\u5E94\u7684\u5B9A\u4E49\u6587\u4EF6"));
3026
+ const lack = (0, lodash_1.difference)(entities, locales[lng]);
3027
+ throw new Error(`${lng}语言定义中缺少了对象${lack.join(',')}的定义,请检查相应的定义文件`);
3280
3028
  }
3281
3029
  /* const statements: ts.Statement[] = locales[lng].map(
3282
3030
  (entity) => factory.createImportDeclaration(
@@ -3318,15 +3066,15 @@ function outputLocale(outputDir, printer) {
3318
3066
  }
3319
3067
  }
3320
3068
  function outputStorage(outputDir, printer) {
3321
- var importStatements = [
3322
- factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("StorageSchema"))])), factory.createStringLiteral("".concat((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(1), "Storage")), undefined),
3323
- factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("EntityDict"))])), factory.createStringLiteral("./EntityDict"), undefined)
3069
+ const importStatements = [
3070
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("StorageSchema"))])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(1)}Storage`), undefined),
3071
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("EntityDict"))])), factory.createStringLiteral("./EntityDict"), undefined)
3324
3072
  ];
3325
- var entityAssignments = [];
3326
- for (var entity in Schema) {
3327
- var indexExpressions = [];
3328
- var _a = Schema[entity], sourceFile = _a.sourceFile, inModi = _a.inModi, indexes = _a.indexes, toModi = _a.toModi, actionType = _a.actionType, _static = _a.static, hasRelationDef = _a.hasRelationDef;
3329
- var fromSchemaSpecifiers = [
3073
+ const entityAssignments = [];
3074
+ for (const entity in Schema) {
3075
+ const indexExpressions = [];
3076
+ const { sourceFile, inModi, indexes, toModi, actionType, static: _static, hasRelationDef } = Schema[entity];
3077
+ const fromSchemaSpecifiers = [
3330
3078
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("OpSchema"))
3331
3079
  ];
3332
3080
  /* if (relationHierarchy || reverseCascadeRelationHierarchy) {
@@ -3338,11 +3086,11 @@ function outputStorage(outputDir, printer) {
3338
3086
  )
3339
3087
  );
3340
3088
  } */
3341
- var statements = [
3342
- 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),
3343
- factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports(fromSchemaSpecifiers)), factory.createStringLiteral("./Schema"), undefined)
3089
+ const statements = [
3090
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("StorageDesc"))])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)()}Storage`), undefined),
3091
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports(fromSchemaSpecifiers)), factory.createStringLiteral("./Schema"), undefined)
3344
3092
  ];
3345
- var needImportActions = [];
3093
+ const needImportActions = [];
3346
3094
  switch (actionType) {
3347
3095
  case 'readOnly': {
3348
3096
  needImportActions.push(factory.createImportSpecifier(false, factory.createIdentifier("readOnlyActions"), factory.createIdentifier("actions")));
@@ -3358,7 +3106,7 @@ function outputStorage(outputDir, printer) {
3358
3106
  }
3359
3107
  default: {
3360
3108
  if (ActionAsts[entity]) {
3361
- statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("actions"))])), factory.createStringLiteral("./Action"), undefined));
3109
+ statements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("actions"))])), factory.createStringLiteral("./Action"), undefined));
3362
3110
  }
3363
3111
  else {
3364
3112
  needImportActions.push(factory.createImportSpecifier(false, factory.createIdentifier("genericActions"), factory.createIdentifier("actions")));
@@ -3369,13 +3117,13 @@ function outputStorage(outputDir, printer) {
3369
3117
  needImportActions.push(factory.createImportSpecifier(false, undefined, factory.createIdentifier("relationActions")));
3370
3118
  }
3371
3119
  if (needImportActions.length > 0) {
3372
- statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports(needImportActions)), factory.createStringLiteral((0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)()), undefined));
3120
+ statements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports(needImportActions)), factory.createStringLiteral((0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)()), undefined));
3373
3121
  }
3374
- var propertyAssignments = [];
3375
- var attributes = constructAttributes(entity);
3122
+ const propertyAssignments = [];
3123
+ const attributes = constructAttributes(entity);
3376
3124
  propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("attributes"), factory.createObjectLiteralExpression(attributes, true)));
3377
3125
  if (indexes) {
3378
- indexExpressions.push.apply(indexExpressions, tslib_1.__spreadArray([], tslib_1.__read(indexes.elements), false));
3126
+ indexExpressions.push(...indexes.elements);
3379
3127
  }
3380
3128
  if (toModi) {
3381
3129
  propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("toModi"), factory.createTrue()));
@@ -3408,14 +3156,14 @@ function outputStorage(outputDir, printer) {
3408
3156
  );
3409
3157
  } */
3410
3158
  if (hasRelationDef) {
3411
- var type = hasRelationDef.type;
3159
+ const { type } = hasRelationDef;
3412
3160
  if (ts.isUnionTypeNode(type)) {
3413
- var types = type.types;
3414
- var relationTexts = types.map(function (ele) {
3161
+ const { types } = type;
3162
+ const relationTexts = types.map(ele => {
3415
3163
  (0, assert_1.default)(ts.isLiteralTypeNode(ele) && ts.isStringLiteral(ele.literal));
3416
3164
  return ele.literal.text;
3417
3165
  });
3418
- propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("relation"), factory.createArrayLiteralExpression(relationTexts.map(function (ele) { return factory.createStringLiteral(ele); }))));
3166
+ propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("relation"), factory.createArrayLiteralExpression(relationTexts.map(ele => factory.createStringLiteral(ele)))));
3419
3167
  }
3420
3168
  else {
3421
3169
  (0, assert_1.default)(ts.isLiteralTypeNode(type));
@@ -3425,124 +3173,130 @@ function outputStorage(outputDir, printer) {
3425
3173
  ])));
3426
3174
  }
3427
3175
  }
3428
- var sdTypeArguments = [
3176
+ const sdTypeArguments = [
3429
3177
  factory.createTypeReferenceNode(factory.createIdentifier("OpSchema"), undefined)
3430
3178
  ];
3431
3179
  statements.push(factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("desc"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("StorageDesc"), sdTypeArguments), factory.createObjectLiteralExpression(propertyAssignments, true))], ts.NodeFlags.Const)));
3432
- var result_2 = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements), sourceFile);
3433
- var filename_1 = path_1.default.join(outputDir, entity, 'Storage.ts');
3434
- (0, fs_1.writeFileSync)(filename_1, result_2, { flag: 'w' });
3435
- importStatements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
3436
- factory.createImportSpecifier(false, factory.createIdentifier("desc"), factory.createIdentifier("".concat((0, string_1.firstLetterLowerCase)(entity), "Desc")))
3437
- ])), factory.createStringLiteral("./".concat(entity, "/Storage")), undefined));
3438
- entityAssignments.push(factory.createPropertyAssignment((0, string_1.firstLetterLowerCase)(entity), factory.createIdentifier("".concat((0, string_1.firstLetterLowerCase)(entity), "Desc"))));
3180
+ const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements), sourceFile);
3181
+ const filename = path_1.default.join(outputDir, entity, 'Storage.ts');
3182
+ (0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
3183
+ importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
3184
+ factory.createImportSpecifier(false, factory.createIdentifier("desc"), factory.createIdentifier(`${(0, string_1.firstLetterLowerCase)(entity)}Desc`))
3185
+ ])), factory.createStringLiteral(`./${entity}/Storage`), undefined));
3186
+ entityAssignments.push(factory.createPropertyAssignment((0, string_1.firstLetterLowerCase)(entity), factory.createIdentifier(`${(0, string_1.firstLetterLowerCase)(entity)}Desc`)));
3439
3187
  }
3440
3188
  importStatements.push(factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("storageSchema"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("StorageSchema"), [
3441
3189
  factory.createTypeReferenceNode('EntityDict')
3442
3190
  ]), factory.createObjectLiteralExpression(entityAssignments, true))], ts.NodeFlags.Const)));
3443
- var result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(importStatements), ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS));
3444
- var filename = path_1.default.join(outputDir, 'Storage.ts');
3191
+ const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(importStatements), ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS));
3192
+ const filename = path_1.default.join(outputDir, 'Storage.ts');
3445
3193
  (0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
3446
3194
  }
3447
3195
  function resetOutputDir(outputDir) {
3448
3196
  (0, fs_extra_1.emptydirSync)(outputDir);
3449
- for (var moduleName in Schema) {
3197
+ for (const moduleName in Schema) {
3450
3198
  (0, fs_1.mkdirSync)(path_1.default.join(outputDir, moduleName));
3451
3199
  (0, fs_1.mkdirSync)(path_1.default.join(outputDir, moduleName, 'locales'));
3452
3200
  }
3453
3201
  (0, fs_1.mkdirSync)(path_1.default.join(outputDir, '_locales'));
3454
3202
  }
3455
3203
  function addReverseRelationship() {
3456
- var e_19, _a;
3457
- for (var reverseEntity in ReversePointerRelations) {
3204
+ for (const reverseEntity in ReversePointerRelations) {
3458
3205
  if (!ReversePointerEntities.hasOwnProperty(reverseEntity)) {
3459
- throw new Error("\u300C".concat(reverseEntity, "\u300D\u88AB\u5F15\u7528\u4E3A\u4E00\u4E2A\u53CD\u6307\u5BF9\u8C61\uFF0C\u4F46\u5176\u5B9A\u4E49\u4E2D\u7684entity\u548CentityId\u4E0D\u7B26\u5408\u8981\u6C42"));
3206
+ throw new Error(`「${reverseEntity}」被引用为一个反指对象,但其定义中的entity和entityId不符合要求`);
3460
3207
  }
3461
- try {
3462
- for (var _b = (e_19 = void 0, tslib_1.__values(ReversePointerRelations[reverseEntity])), _c = _b.next(); !_c.done; _c = _b.next()) {
3463
- var one = _c.value;
3464
- addRelationship(reverseEntity, one, 'entity', false);
3465
- }
3466
- }
3467
- catch (e_19_1) { e_19 = { error: e_19_1 }; }
3468
- finally {
3469
- try {
3470
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3471
- }
3472
- finally { if (e_19) throw e_19.error; }
3208
+ for (const one of ReversePointerRelations[reverseEntity]) {
3209
+ addRelationship(reverseEntity, one, 'entity', false);
3473
3210
  }
3474
3211
  }
3475
3212
  }
3476
3213
  function outputIndexTs(outputDir) {
3477
- var indexTs = "export * from './EntityDict';\n export * from './Storage';\n export * from './ActionDefDict';\n export * from './Relation';\n ";
3478
- var filename = path_1.default.join(outputDir, 'index.ts');
3214
+ const indexTs = `export * from './EntityDict';
3215
+ export * from './Storage';
3216
+ export * from './ActionDefDict';
3217
+ export * from './Relation';
3218
+ `;
3219
+ const filename = path_1.default.join(outputDir, 'index.ts');
3479
3220
  (0, fs_1.writeFileSync)(filename, indexTs, { flag: 'w' });
3480
3221
  }
3481
3222
  function outputPackageJson(outputDir) {
3482
- var pj = {
3223
+ const pj = {
3483
3224
  "name": process.env.COMPLING_AS_LIB ? "general-app-domain" : "oak-app-domain",
3484
3225
  "main": "index.ts"
3485
3226
  };
3486
- var filename = path_1.default.join(outputDir, 'package.json');
3227
+ const filename = path_1.default.join(outputDir, 'package.json');
3487
3228
  (0, fs_1.writeFileSync)(filename, JSON.stringify(pj), { flag: 'w' });
3488
3229
  }
3489
3230
  /**
3490
3231
  * (从toModi的对象开始)分析可能被modi指向的对象
3491
3232
  */
3492
3233
  function analyzeInModi() {
3493
- var getRelateEntities = function (entity) {
3494
- var result = [];
3234
+ const getRelateEntities = (entity) => {
3235
+ let result = [];
3495
3236
  if (ManyToOne[entity]) {
3496
3237
  // 用反指指针指向的对象可以忽略,因为前端不可能设计出这样的更新页面
3497
- result = ManyToOne[entity].filter(function (ele) { return ele[1] !== 'entity'; }).map(function (ele) { return ele[0]; });
3238
+ result = ManyToOne[entity].filter(ele => ele[1] !== 'entity').map(ele => ele[0]);
3498
3239
  }
3499
3240
  if (OneToMany[entity]) {
3500
- result.push.apply(result, tslib_1.__spreadArray([], tslib_1.__read(OneToMany[entity].map(function (ele) { return ele[0]; })), false));
3241
+ result.push(...OneToMany[entity].map(ele => ele[0]));
3501
3242
  }
3502
3243
  return (0, lodash_1.uniq)(result);
3503
3244
  };
3504
- var setInModi = function (entity) {
3245
+ const setInModi = (entity) => {
3505
3246
  if (['Modi', 'ModiEntity', 'Oper', 'OperEntity', 'User'].includes(entity)) {
3506
3247
  return;
3507
3248
  }
3508
- var schema = Schema[entity];
3249
+ const schema = Schema[entity];
3509
3250
  if (schema.toModi || schema.inModi || schema.actionType === 'readOnly' || schema.static) {
3510
3251
  return;
3511
3252
  }
3512
3253
  schema.inModi = true;
3513
- var related = getRelateEntities(entity);
3514
- related.forEach(function (ele) { return setInModi(ele); });
3254
+ const related = getRelateEntities(entity);
3255
+ related.forEach(ele => setInModi(ele));
3515
3256
  };
3516
- for (var entity in Schema) {
3257
+ for (const entity in Schema) {
3517
3258
  if (Schema[entity].toModi) {
3518
- var related = getRelateEntities(entity);
3519
- related.forEach(function (ele) { return setInModi(ele); });
3259
+ const related = getRelateEntities(entity);
3260
+ related.forEach(ele => setInModi(ele));
3520
3261
  }
3521
3262
  }
3522
3263
  }
3523
- var IGNORED_FOREIGN_KEY_MAP = {};
3524
- var IGNORED_RELATION_PATH_MAP = {};
3525
- var DEDUCED_RELATION_MAP = {};
3526
- var SELECT_FREE_ENTITIES = [];
3527
- var CREATE_FREE_ENTITIES = [];
3528
- var UPDATE_FREE_ENTITIES = [];
3529
- var FIXED_DESTINATION_PATH_MAP = {};
3530
- var FIXED_FOR_ALL_DESTINATION_PATH_ENTITIES = [];
3264
+ /**
3265
+ * 此部分功能不再使用
3266
+ * @param map
3267
+ */
3268
+ let IGNORED_FOREIGN_KEY_MAP = {};
3269
+ let IGNORED_RELATION_PATH_MAP = {};
3270
+ let DEDUCED_RELATION_MAP = {};
3271
+ let SELECT_FREE_ENTITIES = [];
3272
+ let CREATE_FREE_ENTITIES = [];
3273
+ let UPDATE_FREE_ENTITIES = [];
3274
+ let FIXED_DESTINATION_PATH_MAP = {};
3275
+ let FIXED_FOR_ALL_DESTINATION_PATH_ENTITIES = [];
3276
+ /**
3277
+ * 此函数不再使用
3278
+ * @param map
3279
+ */
3531
3280
  function registerIgnoredForeignKeyMap(map) {
3532
3281
  IGNORED_FOREIGN_KEY_MAP = map;
3533
3282
  }
3534
3283
  exports.registerIgnoredForeignKeyMap = registerIgnoredForeignKeyMap;
3535
- function registerFreeEntities(selectFreeEntities, createFreeEntities, updateFreeEntities) {
3536
- if (selectFreeEntities === void 0) { selectFreeEntities = []; }
3537
- if (createFreeEntities === void 0) { createFreeEntities = []; }
3538
- if (updateFreeEntities === void 0) { updateFreeEntities = []; }
3284
+ /**
3285
+ * 此函数不再使用
3286
+ * @param map
3287
+ */
3288
+ function registerFreeEntities(selectFreeEntities = [], createFreeEntities = [], updateFreeEntities = []) {
3539
3289
  SELECT_FREE_ENTITIES = selectFreeEntities;
3540
3290
  CREATE_FREE_ENTITIES = createFreeEntities;
3541
3291
  UPDATE_FREE_ENTITIES = updateFreeEntities;
3542
3292
  }
3543
3293
  exports.registerFreeEntities = registerFreeEntities;
3294
+ /**
3295
+ * 此函数不再使用
3296
+ * @param map
3297
+ */
3544
3298
  function registerIgnoredRelationPathMap(map) {
3545
- for (var k in map) {
3299
+ for (const k in map) {
3546
3300
  IGNORED_RELATION_PATH_MAP[(0, string_1.firstLetterUpperCase)(k)] = map[k];
3547
3301
  }
3548
3302
  }
@@ -3552,13 +3306,12 @@ exports.registerIgnoredRelationPathMap = registerIgnoredRelationPathMap;
3552
3306
  * @param map
3553
3307
  */
3554
3308
  function registerFixedDestinationPathMap(map) {
3555
- var _a;
3556
- for (var k in map) {
3309
+ for (const k in map) {
3557
3310
  if (k === '.') {
3558
- FIXED_FOR_ALL_DESTINATION_PATH_ENTITIES.push.apply(FIXED_FOR_ALL_DESTINATION_PATH_ENTITIES, tslib_1.__spreadArray([], tslib_1.__read(map[k]), false));
3311
+ FIXED_FOR_ALL_DESTINATION_PATH_ENTITIES.push(...map[k]);
3559
3312
  }
3560
3313
  else if (FIXED_DESTINATION_PATH_MAP[k]) {
3561
- (_a = FIXED_DESTINATION_PATH_MAP[k]).push.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(map[k]), false));
3314
+ FIXED_DESTINATION_PATH_MAP[k].push(...map[k]);
3562
3315
  }
3563
3316
  else {
3564
3317
  FIXED_DESTINATION_PATH_MAP[k] = map[k];
@@ -3566,37 +3319,38 @@ function registerFixedDestinationPathMap(map) {
3566
3319
  }
3567
3320
  }
3568
3321
  exports.registerFixedDestinationPathMap = registerFixedDestinationPathMap;
3322
+ /**
3323
+ * 此函数不再使用
3324
+ * @param map
3325
+ */
3569
3326
  function registerDeducedRelationMap(map) {
3570
- var _loop_13 = function (k) {
3571
- var entity = (0, string_1.firstLetterUpperCase)(k);
3572
- (0, assert_1.default)(Schema.hasOwnProperty(entity), "config/relation.ts\u4E2D\u914D\u7F6E\u7684DeducedRelationMap\u5305\u542B\u4E0D\u5408\u6CD5\u7684\u5BF9\u8C61\u540D\u79F0\u300C".concat(k, "\u300D"));
3327
+ for (const k in map) {
3328
+ const entity = (0, string_1.firstLetterUpperCase)(k);
3329
+ (0, assert_1.default)(Schema.hasOwnProperty(entity), `config/relation.ts中配置的DeducedRelationMap包含不合法的对象名称「${k}」`);
3573
3330
  // 定义的deduce的属性一定是多对一的外键,此时ReversePointerEntities还未处理
3574
3331
  if (ReversePointerEntities[entity] && map[k] === 'entity') {
3575
3332
  }
3576
3333
  else {
3577
- var mto = ManyToOne[entity].find(function (ele) { return ele[1] === map[k]; });
3578
- (0, assert_1.default)(mto, "config/relation.ts\u4E2D\u914D\u7F6E\u7684DeducedRelationMap\u6240\u5B9A\u4E49\u7684\u300C".concat(k, "\u300D\u7684deduce\u5C5E\u6027\u300C").concat(map[k], "\u300D\u4E0D\u662F\u4E00\u4E2A\u6709\u6548\u7684\u5916\u952E\u6307\u9488"));
3334
+ const mto = ManyToOne[entity].find(ele => ele[1] === map[k]);
3335
+ (0, assert_1.default)(mto, `config/relation.ts中配置的DeducedRelationMap所定义的「${k}」的deduce属性「${map[k]}」不是一个有效的外键指针`);
3579
3336
  }
3580
3337
  DEDUCED_RELATION_MAP[entity] = map[k];
3581
- };
3582
- for (var k in map) {
3583
- _loop_13(k);
3584
3338
  }
3585
3339
  }
3586
3340
  exports.registerDeducedRelationMap = registerDeducedRelationMap;
3587
3341
  /**
3588
3342
  * 输出所有和User相关的对象的后继
3343
+ * 此函数不再使用
3589
3344
  */
3590
3345
  function outputRelation(outputDir, printer) {
3591
- var ExcludedEntities = ['Oper', 'User', 'OperEntity', 'Modi', 'ModiEntity', 'UserRelation', 'Relation', 'RelationAuth', 'ActionAuth'];
3592
- var actionPath = [];
3593
- var relationPath = [];
3594
- var outputRecursively = function (root, entity, path, paths, isRelation) {
3595
- var _a;
3346
+ const ExcludedEntities = ['Oper', 'User', 'OperEntity', 'Modi', 'ModiEntity', 'UserRelation', 'Relation', 'RelationAuth', 'ActionAuth'];
3347
+ const actionPath = [];
3348
+ const relationPath = [];
3349
+ const outputRecursively = (root, entity, path, paths, isRelation) => {
3596
3350
  if (ExcludedEntities.includes(entity)) {
3597
3351
  return;
3598
3352
  }
3599
- if ((_a = IGNORED_RELATION_PATH_MAP[entity]) === null || _a === void 0 ? void 0 : _a.find(function (ele) { return path.includes(ele); })) {
3353
+ if (IGNORED_RELATION_PATH_MAP[entity]?.find((ele) => path.includes(ele))) {
3600
3354
  return;
3601
3355
  }
3602
3356
  if (paths.length > 12) {
@@ -3607,12 +3361,10 @@ function outputRelation(outputDir, printer) {
3607
3361
  // assert(!DEDUCED_RELATION_MAP[entity], `${entity}对象定义了deducedRelationMap,但它有relation`);
3608
3362
  relationPath.push([(0, string_1.firstLetterLowerCase)(entity), path, root, isRelation]);
3609
3363
  }
3610
- var _b = OneToMany, _c = entity, parent = _b[_c];
3364
+ const { [entity]: parent } = OneToMany;
3611
3365
  if (parent) {
3612
- parent.forEach(function (_a) {
3613
- var _b;
3614
- var _c = tslib_1.__read(_a, 2), child = _c[0], foreignKey = _c[1];
3615
- var child2 = (0, string_1.firstLetterLowerCase)(child);
3366
+ parent.forEach(([child, foreignKey]) => {
3367
+ const child2 = (0, string_1.firstLetterLowerCase)(child);
3616
3368
  if (child === entity) {
3617
3369
  // 如果有层级关系对象,最多找3层。同时这里只找本身存在relation关系的对象,因为如果对象上没有relation,则其上的公共路径应当可以维护住层级关系
3618
3370
  // 例如在jichuang项目中,house上没有relation,通过其park外键所维护的路径不需要遍历其父亲。而parkCluster因为有relation,所以必须构造以之为根的所有的可能路径
@@ -3620,7 +3372,7 @@ function outputRelation(outputDir, printer) {
3620
3372
  if (!Schema[entity].hasRelationDef) {
3621
3373
  return;
3622
3374
  }
3623
- if (paths.find(function (ele) { return ele !== child2; }) || paths.length > 2) {
3375
+ if (paths.find(ele => ele !== child2) || paths.length > 2) {
3624
3376
  return;
3625
3377
  }
3626
3378
  }
@@ -3628,7 +3380,7 @@ function outputRelation(outputDir, printer) {
3628
3380
  // 除了层级之外的递归直接忽略
3629
3381
  return;
3630
3382
  }
3631
- if ((_b = IGNORED_FOREIGN_KEY_MAP[child2]) === null || _b === void 0 ? void 0 : _b.includes(foreignKey)) {
3383
+ if (IGNORED_FOREIGN_KEY_MAP[child2]?.includes(foreignKey)) {
3632
3384
  // 忽略的路径放弃
3633
3385
  return;
3634
3386
  }
@@ -3636,28 +3388,26 @@ function outputRelation(outputDir, printer) {
3636
3388
  // 如果子对象本身由父对象推定,也放弃
3637
3389
  return;
3638
3390
  }
3639
- var fk = foreignKey === 'entity' ? (0, string_1.firstLetterLowerCase)(entity) : foreignKey;
3640
- var path2 = path ? "".concat(fk, ".").concat(path) : fk;
3391
+ const fk = foreignKey === 'entity' ? (0, string_1.firstLetterLowerCase)(entity) : foreignKey;
3392
+ const path2 = path ? `${fk}.${path}` : fk;
3641
3393
  outputRecursively(root, child, path2, paths.concat([(0, string_1.firstLetterLowerCase)(entity)]), isRelation);
3642
3394
  });
3643
3395
  }
3644
3396
  };
3645
3397
  // 所有属性中有指向user的对象
3646
- var User = OneToMany.User;
3647
- User.forEach(function (_a) {
3648
- var _b;
3649
- var _c = tslib_1.__read(_a, 2), entity3 = _c[0], foreignKey = _c[1];
3650
- var fk = foreignKey === 'entity' ? 'user' : foreignKey;
3651
- if (!((_b = IGNORED_FOREIGN_KEY_MAP[(0, string_1.firstLetterLowerCase)(entity3)]) === null || _b === void 0 ? void 0 : _b.includes(foreignKey))) {
3398
+ const { User } = OneToMany;
3399
+ User.forEach(([entity3, foreignKey]) => {
3400
+ const fk = foreignKey === 'entity' ? 'user' : foreignKey;
3401
+ if (!IGNORED_FOREIGN_KEY_MAP[(0, string_1.firstLetterLowerCase)(entity3)]?.includes(foreignKey)) {
3652
3402
  outputRecursively((0, string_1.firstLetterLowerCase)(entity3), entity3, fk, [fk], false);
3653
3403
  }
3654
3404
  });
3655
3405
  // 所有带relation的对象
3656
- var hasRelationEntities = Object.keys(Schema).filter(function (entity) { return Schema[entity].hasRelationDef; });
3657
- hasRelationEntities.forEach(function (entity3) {
3406
+ const hasRelationEntities = Object.keys(Schema).filter((entity) => Schema[entity].hasRelationDef);
3407
+ hasRelationEntities.forEach((entity3) => {
3658
3408
  outputRecursively((0, string_1.firstLetterLowerCase)(entity3), entity3, '', [], true);
3659
3409
  });
3660
- actionPath.sort(function (ele1, ele2) {
3410
+ actionPath.sort((ele1, ele2) => {
3661
3411
  // 先按sourceEntity来排序
3662
3412
  if (ele1[0] > ele2[0]) {
3663
3413
  return 1;
@@ -3679,14 +3429,14 @@ function outputRelation(outputDir, printer) {
3679
3429
  }
3680
3430
  }
3681
3431
  });
3682
- var entityRelations = [];
3683
- for (var entity in Schema) {
3684
- var hasRelationDef = Schema[entity].hasRelationDef;
3432
+ const entityRelations = [];
3433
+ for (const entity in Schema) {
3434
+ const { hasRelationDef } = Schema[entity];
3685
3435
  if (hasRelationDef) {
3686
- var type = hasRelationDef.type;
3436
+ const { type } = hasRelationDef;
3687
3437
  if (ts.isUnionTypeNode(type)) {
3688
- var types = type.types;
3689
- var relations = types.map(function (ele) {
3438
+ const { types } = type;
3439
+ const relations = types.map(ele => {
3690
3440
  (0, assert_1.default)(ts.isLiteralTypeNode(ele) && ts.isStringLiteral(ele.literal));
3691
3441
  return ele.literal.text;
3692
3442
  });
@@ -3695,72 +3445,104 @@ function outputRelation(outputDir, printer) {
3695
3445
  else {
3696
3446
  (0, assert_1.default)(ts.isLiteralTypeNode(type));
3697
3447
  (0, assert_1.default)(ts.isStringLiteral(type.literal));
3698
- var relations = [type.literal.text];
3448
+ const relations = [type.literal.text];
3699
3449
  entityRelations.push([(0, string_1.firstLetterLowerCase)(entity), relations]);
3700
3450
  }
3701
3451
  }
3702
3452
  }
3703
- var stmts = [
3704
- factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
3453
+ const stmts = [
3454
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
3705
3455
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("AuthCascadePath")),
3706
3456
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("AuthDeduceRelationMap"))
3707
- ])), factory.createStringLiteral("".concat((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(1), "Entity")), undefined),
3708
- factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("EntityDict"))])), factory.createStringLiteral("./EntityDict"), undefined),
3709
- factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("CreateOperationData"), factory.createIdentifier("Relation"))])), factory.createStringLiteral("./Relation/Schema"), undefined),
3710
- factory.createVariableStatement([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("ActionCascadePathGraph"), undefined, factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier("AuthCascadePath"), [factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)])), factory.createArrayLiteralExpression(actionPath.map(function (_a) {
3711
- var _b = tslib_1.__read(_a, 4), entity = _b[0], path = _b[1], root = _b[2], isRelation = _b[3];
3712
- return factory.createArrayLiteralExpression([
3713
- factory.createStringLiteral(entity),
3714
- factory.createStringLiteral(path),
3715
- factory.createStringLiteral(root),
3716
- isRelation ? factory.createTrue() : factory.createFalse()
3717
- ], false);
3718
- }), true))], ts.NodeFlags.Const)),
3719
- factory.createVariableStatement([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("RelationCascadePathGraph"), undefined, factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier("AuthCascadePath"), [factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)])), factory.createArrayLiteralExpression(relationPath.map(function (_a) {
3720
- var _b = tslib_1.__read(_a, 4), entity = _b[0], path = _b[1], root = _b[2], isRelation = _b[3];
3721
- return factory.createArrayLiteralExpression([
3722
- factory.createStringLiteral(entity),
3723
- factory.createStringLiteral(path),
3724
- factory.createStringLiteral(root),
3725
- isRelation ? factory.createTrue() : factory.createFalse()
3726
- ], false);
3727
- }), true))], ts.NodeFlags.Const)),
3728
- factory.createVariableStatement([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("relations"), undefined, factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier("Relation"), undefined)), factory.createArrayLiteralExpression((0, lodash_1.flatten)(entityRelations.map(function (_a) {
3729
- var _b = tslib_1.__read(_a, 2), entity = _b[0], relations = _b[1];
3730
- return relations.map(function (relation) { return factory.createObjectLiteralExpression([
3731
- factory.createPropertyAssignment(factory.createIdentifier("id"), factory.createStringLiteral((0, uuid_1.formUuid)(entity, relation))),
3732
- factory.createPropertyAssignment(factory.createIdentifier("entity"), factory.createStringLiteral(entity)),
3733
- factory.createPropertyAssignment(factory.createIdentifier("name"), factory.createStringLiteral(relation))
3734
- ], true); });
3735
- })), true))], ts.NodeFlags.Const))
3457
+ ])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(1)}Entity`), undefined),
3458
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("EntityDict"))])), factory.createStringLiteral("./EntityDict"), undefined),
3459
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("CreateOperationData"), factory.createIdentifier("Relation"))])), factory.createStringLiteral("./Relation/Schema"), undefined),
3460
+ factory.createVariableStatement([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("ActionCascadePathGraph"), undefined, factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier("AuthCascadePath"), [factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)])), factory.createArrayLiteralExpression(actionPath.map(([entity, path, root, isRelation]) => factory.createArrayLiteralExpression([
3461
+ factory.createStringLiteral(entity),
3462
+ factory.createStringLiteral(path),
3463
+ factory.createStringLiteral(root),
3464
+ isRelation ? factory.createTrue() : factory.createFalse()
3465
+ ], false)), true))], ts.NodeFlags.Const)),
3466
+ factory.createVariableStatement([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("RelationCascadePathGraph"), undefined, factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier("AuthCascadePath"), [factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)])), factory.createArrayLiteralExpression(relationPath.map(([entity, path, root, isRelation]) => factory.createArrayLiteralExpression([
3467
+ factory.createStringLiteral(entity),
3468
+ factory.createStringLiteral(path),
3469
+ factory.createStringLiteral(root),
3470
+ isRelation ? factory.createTrue() : factory.createFalse()
3471
+ ], false)), true))], ts.NodeFlags.Const)),
3472
+ factory.createVariableStatement([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("relations"), undefined, factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier("Relation"), undefined)), factory.createArrayLiteralExpression((0, lodash_1.flatten)(entityRelations.map(([entity, relations]) => relations.map((relation) => factory.createObjectLiteralExpression([
3473
+ factory.createPropertyAssignment(factory.createIdentifier("id"), factory.createStringLiteral((0, uuid_1.formUuid)(entity, relation))),
3474
+ factory.createPropertyAssignment(factory.createIdentifier("entity"), factory.createStringLiteral(entity)),
3475
+ factory.createPropertyAssignment(factory.createIdentifier("name"), factory.createStringLiteral(relation))
3476
+ ], true)))), true))], ts.NodeFlags.Const))
3736
3477
  ];
3737
3478
  stmts.push(factory.createVariableStatement([
3738
3479
  factory.createToken(ts.SyntaxKind.ExportKeyword)
3739
3480
  ], factory.createVariableDeclarationList([
3740
- factory.createVariableDeclaration(factory.createIdentifier("deducedRelationMap"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("AuthDeduceRelationMap"), [factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)]), factory.createObjectLiteralExpression(Object.keys(DEDUCED_RELATION_MAP).map(function (ele) { return factory.createPropertyAssignment(factory.createIdentifier((0, string_1.firstLetterLowerCase)(ele)), factory.createStringLiteral(DEDUCED_RELATION_MAP[ele])); }), true))
3481
+ factory.createVariableDeclaration(factory.createIdentifier("deducedRelationMap"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("AuthDeduceRelationMap"), [factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)]), factory.createObjectLiteralExpression(Object.keys(DEDUCED_RELATION_MAP).map(ele => factory.createPropertyAssignment(factory.createIdentifier((0, string_1.firstLetterLowerCase)(ele)), factory.createStringLiteral(DEDUCED_RELATION_MAP[ele]))), true))
3741
3482
  ], ts.NodeFlags.Const)));
3742
3483
  stmts.push(factory.createVariableStatement([
3743
3484
  factory.createToken(ts.SyntaxKind.ExportKeyword)
3744
- ], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("selectFreeEntities"), undefined, factory.createArrayTypeNode(factory.createParenthesizedType(factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)))), factory.createArrayLiteralExpression(SELECT_FREE_ENTITIES.map(function (ele) { return factory.createStringLiteral(ele); }), false))], ts.NodeFlags.Const)), factory.createVariableStatement([
3485
+ ], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("selectFreeEntities"), undefined, factory.createArrayTypeNode(factory.createParenthesizedType(factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)))), factory.createArrayLiteralExpression(SELECT_FREE_ENTITIES.map(ele => factory.createStringLiteral(ele)), false))], ts.NodeFlags.Const)), factory.createVariableStatement([
3745
3486
  factory.createToken(ts.SyntaxKind.ExportKeyword)
3746
- ], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("updateFreeEntities"), undefined, factory.createArrayTypeNode(factory.createParenthesizedType(factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)))), factory.createArrayLiteralExpression(UPDATE_FREE_ENTITIES.map(function (ele) { return factory.createStringLiteral(ele); }), false))], ts.NodeFlags.Const)), factory.createVariableStatement([
3487
+ ], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("updateFreeEntities"), undefined, factory.createArrayTypeNode(factory.createParenthesizedType(factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)))), factory.createArrayLiteralExpression(UPDATE_FREE_ENTITIES.map(ele => factory.createStringLiteral(ele)), false))], ts.NodeFlags.Const)), factory.createVariableStatement([
3747
3488
  factory.createToken(ts.SyntaxKind.ExportKeyword)
3748
- ], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("createFreeEntities"), undefined, factory.createArrayTypeNode(factory.createParenthesizedType(factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)))), factory.createArrayLiteralExpression(CREATE_FREE_ENTITIES.map(function (ele) { return factory.createStringLiteral(ele); }), false))], ts.NodeFlags.Const)));
3749
- var result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(stmts), ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS));
3750
- var filename = path_1.default.join(outputDir, 'Relation.ts');
3489
+ ], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("createFreeEntities"), undefined, factory.createArrayTypeNode(factory.createParenthesizedType(factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)))), factory.createArrayLiteralExpression(CREATE_FREE_ENTITIES.map(ele => factory.createStringLiteral(ele)), false))], ts.NodeFlags.Const)));
3490
+ const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(stmts), ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS));
3491
+ const filename = path_1.default.join(outputDir, 'Relation.ts');
3492
+ (0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
3493
+ }
3494
+ /**
3495
+ * 输出oak-app-domain中的Relation.ts文件
3496
+ * 不再输出actionAuthGraph和relationAuthGraph两个复杂的对象
3497
+ * @param outputDir
3498
+ * @param printer
3499
+ */
3500
+ function outputRelation2(outputDir, printer) {
3501
+ const entityRelations = [];
3502
+ for (const entity in Schema) {
3503
+ const { hasRelationDef } = Schema[entity];
3504
+ if (hasRelationDef) {
3505
+ const { type } = hasRelationDef;
3506
+ if (ts.isUnionTypeNode(type)) {
3507
+ const { types } = type;
3508
+ const relations = types.map(ele => {
3509
+ (0, assert_1.default)(ts.isLiteralTypeNode(ele) && ts.isStringLiteral(ele.literal));
3510
+ return ele.literal.text;
3511
+ });
3512
+ entityRelations.push([(0, string_1.firstLetterLowerCase)(entity), relations]);
3513
+ }
3514
+ else {
3515
+ (0, assert_1.default)(ts.isLiteralTypeNode(type));
3516
+ (0, assert_1.default)(ts.isStringLiteral(type.literal));
3517
+ const relations = [type.literal.text];
3518
+ entityRelations.push([(0, string_1.firstLetterLowerCase)(entity), relations]);
3519
+ }
3520
+ }
3521
+ }
3522
+ const stmts = [
3523
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("EntityDict"))])), factory.createStringLiteral("./EntityDict"), undefined),
3524
+ factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("CreateOperationData"), factory.createIdentifier("Relation"))])), factory.createStringLiteral("./Relation/Schema"), undefined),
3525
+ factory.createVariableStatement([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("relations"), undefined, factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier("Relation"), undefined)), factory.createArrayLiteralExpression((0, lodash_1.flatten)(entityRelations.map(([entity, relations]) => relations.map((relation) => factory.createObjectLiteralExpression([
3526
+ factory.createPropertyAssignment(factory.createIdentifier("id"), factory.createStringLiteral((0, uuid_1.formUuid)(entity, relation))),
3527
+ factory.createPropertyAssignment(factory.createIdentifier("entity"), factory.createStringLiteral(entity)),
3528
+ factory.createPropertyAssignment(factory.createIdentifier("name"), factory.createStringLiteral(relation))
3529
+ ], true)))), true))], ts.NodeFlags.Const))
3530
+ ];
3531
+ const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(stmts), ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS));
3532
+ const filename = path_1.default.join(outputDir, 'Relation.ts');
3751
3533
  (0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
3752
3534
  }
3753
3535
  function analyzeEntities(inputDir, relativePath) {
3754
- var files = (0, fs_1.readdirSync)(inputDir);
3755
- var fullFilenames = files.map(function (ele) {
3756
- var entity = ele.slice(0, ele.indexOf('.'));
3757
- if (env_1.RESERVED_ENTITY_NAMES.includes(entity) || env_1.RESERVED_ENTITY_NAMES.find(function (ele2) { return entity.startsWith(ele2); })) {
3758
- throw new Error("".concat(ele, "\u662F\u7CFB\u7EDF\u4FDD\u7559\u5B57\uFF0C\u8BF7\u52FF\u4F7F\u7528\u5176\u5F53\u5BF9\u8C61\u540D\u6216\u5BF9\u8C61\u540D\u524D\u7F00"));
3536
+ const files = (0, fs_1.readdirSync)(inputDir);
3537
+ const fullFilenames = files.map(ele => {
3538
+ const entity = ele.slice(0, ele.indexOf('.'));
3539
+ if (env_1.RESERVED_ENTITY_NAMES.includes(entity) || env_1.RESERVED_ENTITY_NAMES.find(ele2 => entity.startsWith(ele2))) {
3540
+ throw new Error(`${ele}是系统保留字,请勿使用其当对象名或对象名前缀`);
3759
3541
  }
3760
- return "".concat(inputDir, "/").concat(ele);
3542
+ return `${inputDir}/${ele}`;
3761
3543
  });
3762
- var program = ts.createProgram(fullFilenames, { allowJs: true });
3763
- files.forEach(function (filename) {
3544
+ const program = ts.createProgram(fullFilenames, { allowJs: true });
3545
+ files.forEach((filename) => {
3764
3546
  analyzeEntity(filename, inputDir, program, relativePath);
3765
3547
  });
3766
3548
  analyzeInModi();
@@ -3770,7 +3552,7 @@ exports.analyzeEntities = analyzeEntities;
3770
3552
  function buildSchema(outputDir) {
3771
3553
  addReverseRelationship();
3772
3554
  // setRelationEntities();
3773
- var printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
3555
+ const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
3774
3556
  resetOutputDir(outputDir);
3775
3557
  outputSchema(outputDir, printer);
3776
3558
  outputLocale(outputDir, printer);
@@ -3778,7 +3560,7 @@ function buildSchema(outputDir) {
3778
3560
  outputAction(outputDir, printer);
3779
3561
  outputEntityDict(outputDir, printer);
3780
3562
  outputStorage(outputDir, printer);
3781
- outputRelation(outputDir, printer);
3563
+ outputRelation2(outputDir, printer);
3782
3564
  outputIndexTs(outputDir);
3783
3565
  if (!process.env.COMPLING_AS_LIB) {
3784
3566
  outputPackageJson(outputDir);