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.
- package/lib/actions/action.d.ts +8 -8
- package/lib/actions/action.js +2 -2
- package/lib/actions/relation.d.ts +1 -1
- package/lib/actions/relation.js +9 -22
- package/lib/base-app-domain/ActionAuth/Schema.d.ts +68 -42
- package/lib/base-app-domain/ActionAuth/Storage.js +12 -15
- package/lib/base-app-domain/ActionDefDict.d.ts +2 -3
- package/lib/base-app-domain/ActionDefDict.js +3 -5
- package/lib/base-app-domain/EntityDict.d.ts +5 -1
- package/lib/base-app-domain/I18n/Schema.d.ts +24 -24
- package/lib/base-app-domain/I18n/Storage.js +5 -5
- package/lib/base-app-domain/Modi/Action.d.ts +4 -4
- package/lib/base-app-domain/Modi/Action.js +3 -3
- package/lib/base-app-domain/Modi/Schema.d.ts +24 -24
- package/lib/base-app-domain/Modi/Storage.js +3 -3
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +128 -55
- package/lib/base-app-domain/ModiEntity/Storage.js +2 -2
- package/lib/base-app-domain/Oper/Schema.d.ts +30 -29
- package/lib/base-app-domain/Oper/Storage.js +1 -1
- package/lib/base-app-domain/OperEntity/Schema.d.ts +126 -53
- package/lib/base-app-domain/OperEntity/Storage.js +2 -2
- package/lib/base-app-domain/Path/Schema.d.ts +149 -0
- package/lib/base-app-domain/Path/Schema.js +2 -0
- package/lib/base-app-domain/Path/Storage.d.ts +3 -0
- package/lib/base-app-domain/Path/Storage.js +54 -0
- package/lib/base-app-domain/Relation/Schema.d.ts +34 -34
- package/lib/base-app-domain/Relation/Storage.js +6 -6
- package/lib/base-app-domain/Relation.d.ts +0 -8
- package/lib/base-app-domain/Relation.js +1 -7
- package/lib/base-app-domain/RelationAuth/Schema.d.ts +74 -40
- package/lib/base-app-domain/RelationAuth/Storage.js +9 -11
- package/lib/base-app-domain/Storage.js +20 -16
- package/lib/base-app-domain/User/Action.d.ts +4 -4
- package/lib/base-app-domain/User/Action.js +3 -3
- package/lib/base-app-domain/User/Schema.d.ts +40 -27
- package/lib/base-app-domain/User/Storage.js +1 -1
- package/lib/base-app-domain/UserEntityClaim/Schema.d.ts +264 -0
- package/lib/base-app-domain/UserEntityClaim/Schema.js +2 -0
- package/lib/base-app-domain/UserEntityClaim/Storage.d.ts +3 -0
- package/lib/base-app-domain/UserEntityClaim/Storage.js +37 -0
- package/lib/base-app-domain/UserEntityGrant/Action.d.ts +2 -2
- package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +55 -81
- package/lib/base-app-domain/UserEntityGrant/Storage.js +7 -11
- package/lib/base-app-domain/UserRelation/Schema.d.ts +50 -36
- package/lib/base-app-domain/UserRelation/Storage.js +7 -7
- package/lib/base-app-domain/_SubQuery.d.ts +45 -15
- package/lib/base-app-domain/index.js +1 -1
- package/lib/checkers/index.js +6 -7
- package/lib/compiler/env.js +16 -18
- package/lib/compiler/localeBuilder.js +83 -79
- package/lib/compiler/schemalBuilder.d.ts +16 -0
- package/lib/compiler/schemalBuilder.js +1160 -1378
- package/lib/entities/ActionAuth.d.ts +3 -5
- package/lib/entities/ActionAuth.js +9 -7
- package/lib/entities/I18n.js +1 -1
- package/lib/entities/Modi.js +2 -2
- package/lib/entities/ModiEntity.js +1 -1
- package/lib/entities/Oper.js +1 -1
- package/lib/entities/OperEntity.js +1 -1
- package/lib/entities/Path.d.ts +8 -0
- package/lib/entities/Path.js +35 -0
- package/lib/entities/Relation.js +1 -1
- package/lib/entities/RelationAuth.d.ts +2 -2
- package/lib/entities/RelationAuth.js +1 -1
- package/lib/entities/User.js +2 -2
- package/lib/entities/UserEntityClaim.d.ts +13 -0
- package/lib/entities/UserEntityClaim.js +17 -0
- package/lib/entities/UserEntityGrant.d.ts +5 -4
- package/lib/entities/UserEntityGrant.js +4 -7
- package/lib/entities/UserRelation.js +1 -1
- package/lib/index.d.ts +23 -0
- package/lib/index.js +37 -0
- package/lib/store/AsyncRowStore.d.ts +2 -1
- package/lib/store/AsyncRowStore.js +75 -149
- package/lib/store/CascadeStore.js +968 -1341
- package/lib/store/RelationAuth.d.ts +9 -16
- package/lib/store/RelationAuth.js +752 -910
- package/lib/store/SyncRowStore.d.ts +1 -1
- package/lib/store/SyncRowStore.js +27 -26
- package/lib/store/TriggerExecutor.d.ts +17 -10
- package/lib/store/TriggerExecutor.js +350 -423
- package/lib/store/actionAuth.js +13 -28
- package/lib/store/actionDef.js +142 -215
- package/lib/store/checker.js +225 -361
- package/lib/store/filter.d.ts +2 -3
- package/lib/store/filter.js +451 -589
- package/lib/store/modi.js +116 -177
- package/lib/store/relation.js +17 -17
- package/lib/timers/oper.d.ts +1 -1
- package/lib/timers/oper.js +44 -47
- package/lib/timers/vaccum.d.ts +2 -2
- package/lib/timers/vaccum.js +100 -165
- package/lib/triggers/index.js +1 -1
- package/lib/types/Action.d.ts +7 -7
- package/lib/types/AppLoader.d.ts +8 -2
- package/lib/types/AppLoader.js +4 -4
- package/lib/types/Auth.d.ts +15 -19
- package/lib/types/Connector.d.ts +19 -14
- package/lib/types/Connector.js +0 -7
- package/lib/types/DataType.d.ts +19 -18
- package/lib/types/DataType.js +1 -1
- package/lib/types/Demand.d.ts +25 -25
- package/lib/types/Endpoint.d.ts +1 -1
- package/lib/types/Entity.d.ts +62 -53
- package/lib/types/Entity.js +4 -3
- package/lib/types/EntityDesc.d.ts +2 -1
- package/lib/types/Environment.d.ts +4 -4
- package/lib/types/Exception.d.ts +34 -2
- package/lib/types/Exception.js +214 -197
- package/lib/types/Expression.d.ts +14 -14
- package/lib/types/Expression.js +54 -87
- package/lib/types/Geo.d.ts +6 -6
- package/lib/types/Locale.d.ts +5 -5
- package/lib/types/Polyfill.d.ts +9 -9
- package/lib/types/Port.d.ts +4 -4
- package/lib/types/RowStore.d.ts +3 -3
- package/lib/types/RowStore.js +18 -19
- package/lib/types/Storage.d.ts +5 -4
- package/lib/types/Style.d.ts +2 -2
- package/lib/types/Timer.d.ts +3 -3
- package/lib/types/Trigger.d.ts +30 -14
- package/lib/types/Trigger.js +6 -2
- package/lib/types/Watcher.d.ts +2 -2
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +2 -1
- package/lib/types/schema/DataTypes.d.ts +7 -7
- package/lib/utils/SimpleConnector.d.ts +26 -10
- package/lib/utils/SimpleConnector.js +167 -141
- package/lib/utils/assert.js +2 -2
- package/lib/utils/concurrent.d.ts +1 -1
- package/lib/utils/concurrent.js +31 -57
- package/lib/utils/date.js +2 -2
- package/lib/utils/geo.js +8 -8
- package/lib/utils/lodash.d.ts +3 -1
- package/lib/utils/lodash.js +21 -34
- package/lib/utils/mask.js +12 -13
- package/lib/utils/money.d.ts +1 -1
- package/lib/utils/money.js +22 -11
- package/lib/utils/projection.d.ts +4 -0
- package/lib/utils/projection.js +15 -0
- package/lib/utils/random/random.js +11 -16
- package/lib/utils/random/random.mp.js +7 -18
- package/lib/utils/random/random.web.js +6 -12
- package/lib/utils/string.d.ts +4 -4
- package/lib/utils/string.js +19 -32
- package/lib/utils/url.js +5 -4
- package/lib/utils/uuid.d.ts +1 -1
- package/lib/utils/uuid.js +46 -85
- package/lib/utils/validator.d.ts +4 -3
- package/lib/utils/validator.js +35 -32
- package/lib/utils/version.js +6 -6
- package/package.json +7 -7
- package/src/entities/ActionAuth.ts +10 -10
- package/src/entities/Path.ts +43 -0
- package/src/entities/RelationAuth.ts +2 -1
- package/src/entities/UserEntityClaim.ts +30 -0
- 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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
factory.createImportDeclaration(undefined,
|
|
21
|
-
factory.createImportDeclaration(undefined,
|
|
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
|
-
|
|
31
|
-
|
|
29
|
+
];
|
|
30
|
+
const ActionAsts = {};
|
|
31
|
+
const SchemaAsts = {};
|
|
32
32
|
function addRelationship(many, one, key, notNull) {
|
|
33
|
-
|
|
34
|
-
|
|
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,
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
(0, lodash_1.assign)(ManyToOne, {
|
|
40
|
+
[many]: [[one2, key, notNull]],
|
|
41
|
+
});
|
|
43
42
|
}
|
|
44
|
-
|
|
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,
|
|
50
|
-
|
|
51
|
-
|
|
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 (
|
|
59
|
-
ManyToOne[entity] = (0, lodash_1.uniqBy)(ManyToOne[entity],
|
|
57
|
+
for (const entity in ManyToOne) {
|
|
58
|
+
ManyToOne[entity] = (0, lodash_1.uniqBy)(ManyToOne[entity], (ele) => `${ele[0]}-${ele[1]}`);
|
|
60
59
|
}
|
|
61
|
-
for (
|
|
62
|
-
OneToMany[entity] = (0, lodash_1.uniqBy)(OneToMany[entity],
|
|
60
|
+
for (const entity in OneToMany) {
|
|
61
|
+
OneToMany[entity] = (0, lodash_1.uniqBy)(OneToMany[entity], (ele) => `${ele[0]}-${ele[1]}`);
|
|
63
62
|
}
|
|
64
|
-
for (
|
|
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
|
-
|
|
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
|
-
|
|
99
|
-
declarations.forEach(
|
|
96
|
+
const { declarationList: { declarations } } = node;
|
|
97
|
+
declarations.forEach((declaration) => {
|
|
100
98
|
if (ts.isIdentifier(declaration.name) && declaration.name.text.endsWith('ActionDef')) {
|
|
101
|
-
|
|
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,
|
|
117
|
-
|
|
118
|
-
statements:
|
|
119
|
-
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
|
-
|
|
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,
|
|
134
|
-
|
|
130
|
+
(0, lodash_1.assign)(SchemaAsts, {
|
|
131
|
+
[moduleName]: {
|
|
135
132
|
statements: [statement],
|
|
136
|
-
sourceFile
|
|
137
|
-
}
|
|
138
|
-
|
|
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
|
-
|
|
144
|
+
const { name, type } = actionDefNode;
|
|
148
145
|
(0, assert_1.default)(ts.isTypeReferenceNode(type));
|
|
149
|
-
|
|
146
|
+
const { typeArguments } = type;
|
|
150
147
|
(0, assert_1.default)(typeArguments.length === 2);
|
|
151
|
-
|
|
152
|
-
(0, assert_1.default)(ts.isIdentifier(name),
|
|
153
|
-
(0, assert_1.default)(name.text.endsWith('ActionDef'),
|
|
154
|
-
(0, assert_1.default)(ts.isTypeReferenceNode(actionNode) && ts.isTypeReferenceNode(stateNode),
|
|
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'),
|
|
157
|
-
(0, assert_1.default)(stateNode.typeName.text.endsWith('State'),
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
(0, assert_1.default)(adfName === aName && aName === sName,
|
|
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),
|
|
165
|
-
(0, assert_1.default)(!ele.literal.text.includes('$'),
|
|
166
|
-
(0, assert_1.default)(ele.literal.text.length > 0,
|
|
167
|
-
(0, assert_1.default)(ele.literal.text.length < env_1.STRING_LITERAL_MAX_LENGTH,
|
|
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
|
-
|
|
172
|
-
|
|
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,
|
|
177
|
-
|
|
178
|
-
|
|
172
|
+
(0, lodash_1.assign)(ast.importedFrom, {
|
|
173
|
+
[name.text]: node,
|
|
174
|
+
});
|
|
179
175
|
}
|
|
180
176
|
function getStringTextFromUnionStringLiterals(moduleName, filename, node, program) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
205
|
-
(0, lodash_1.assign)(ast.importedFrom,
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
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),
|
|
215
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
|
|
227
|
+
const actionTexts = action_1.genericActions.map(ele => ele);
|
|
233
228
|
if (moduleName === 'User') {
|
|
234
|
-
actionTexts.push
|
|
229
|
+
actionTexts.push(...action_1.relationActions);
|
|
235
230
|
}
|
|
236
231
|
if (ts.isUnionTypeNode(node)) {
|
|
237
|
-
|
|
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(
|
|
242
|
-
(0, assert_1.default)((0, lodash_1.intersection)(actionNames, RESERVED_ACTION_NAMES).length === 0,
|
|
243
|
-
node.types.forEach(
|
|
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
|
|
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),
|
|
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),
|
|
250
|
+
(0, assert_1.default)(!RESERVED_ACTION_NAMES.includes(node.typeName.text), `${filename}中的Action命名不能是「${RESERVED_ACTION_NAMES.join(',')}」之一`);
|
|
256
251
|
}
|
|
257
|
-
actionTexts.push
|
|
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),
|
|
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
|
-
|
|
265
|
-
actionTexts.forEach(
|
|
266
|
-
|
|
267
|
-
(0, assert_1.default)(action
|
|
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(
|
|
264
|
+
throw new Error(`文件${filename}中,Action定义上的【${action}】动作存在同名`);
|
|
271
265
|
}
|
|
272
266
|
else {
|
|
273
|
-
(0, lodash_1.assign)(ActionDict,
|
|
274
|
-
|
|
275
|
-
|
|
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(
|
|
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
|
-
|
|
288
|
-
|
|
281
|
+
const { moduleSpecifier, importClause } = declaration;
|
|
282
|
+
let entityImported;
|
|
289
283
|
if (ts.isStringLiteral(moduleSpecifier)) {
|
|
290
|
-
|
|
291
|
-
|
|
284
|
+
const { name: importedFileName } = path_1.default.parse(moduleSpecifier.text);
|
|
285
|
+
const { namedBindings } = importClause;
|
|
292
286
|
if (namedBindings && ts.isNamedImports(namedBindings)) {
|
|
293
|
-
|
|
294
|
-
if (elements.find(
|
|
295
|
-
entityImported =
|
|
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
|
-
|
|
303
|
-
|
|
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
|
-
|
|
301
|
+
const lack = (0, lodash_1.difference)(attrs, memberKeys);
|
|
308
302
|
if (lack.length > 0) {
|
|
309
|
-
throw new Error(
|
|
303
|
+
throw new Error(`${filename}中缺少了对${lack.join(',')}属性的locale定义`);
|
|
310
304
|
}
|
|
311
305
|
}
|
|
312
306
|
function checkLocaleExpressionPropertyExists(root, attr, exists, filename) {
|
|
313
|
-
|
|
314
|
-
properties.forEach(
|
|
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
|
-
|
|
317
|
-
|
|
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(
|
|
316
|
+
throw new Error(`${filename}中的locale定义中的${ele.name.text}中缺少了${attr}的定义`);
|
|
323
317
|
}
|
|
324
318
|
else if (!exists && pp) {
|
|
325
|
-
throw new Error(
|
|
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
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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
|
-
|
|
336
|
-
declaration =
|
|
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(
|
|
333
|
+
return declaration.type.types.map(ele => checkStringLiteralLegal(filename, obj, declaration.name.text, ele));
|
|
341
334
|
}
|
|
342
335
|
if (ts.isLiteralTypeNode(declaration.type)) {
|
|
343
|
-
|
|
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,
|
|
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),
|
|
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),
|
|
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),
|
|
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
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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(
|
|
361
|
+
console.warn(`出现了同名的Entity定义「${moduleName}」,将使用${fullPath}取代掉默认对象,请检查新的对象结构及相关常量定义与原有的兼容,否则原有对象的相关逻辑会出现不可知异常`);
|
|
370
362
|
}
|
|
371
363
|
checkNameLegal(filename, moduleName, true);
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
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,
|
|
389
|
-
var _a, _b, _c, _d, _e, _f;
|
|
380
|
+
ts.forEachChild(sourceFile, (node) => {
|
|
390
381
|
if (ts.isImportDeclaration(node)) {
|
|
391
|
-
|
|
382
|
+
const entityImported = getEntityImported(node);
|
|
392
383
|
if (entityImported) {
|
|
393
384
|
referencedSchemas.push(entityImported);
|
|
394
385
|
}
|
|
395
386
|
else {
|
|
396
|
-
|
|
387
|
+
const { moduleSpecifier, importClause } = node;
|
|
397
388
|
if (ts.isStringLiteral(moduleSpecifier)) {
|
|
398
|
-
|
|
389
|
+
const { text } = moduleSpecifier;
|
|
399
390
|
// 和数据类型相关的会自动引入,这里忽略(见initialStatements)
|
|
400
391
|
// 如果是相对路径,编译后的路径默认要深一层
|
|
401
|
-
|
|
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,
|
|
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,
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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(
|
|
420
|
-
|
|
421
|
-
|
|
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
|
-
|
|
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),
|
|
437
|
-
|
|
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,
|
|
445
|
-
|
|
446
|
-
|
|
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
|
-
|
|
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
|
-
|
|
451
|
+
const { typeName } = type.elementType;
|
|
462
452
|
if (referencedSchemas.includes(typeName.text)) {
|
|
463
453
|
// 这也是一对多的反指定义
|
|
464
|
-
|
|
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,
|
|
470
|
-
|
|
471
|
-
|
|
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(
|
|
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
|
-
|
|
486
|
-
|
|
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
|
-
|
|
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),
|
|
500
|
-
|
|
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,
|
|
504
|
-
|
|
505
|
-
if (ts.isLiteralTypeNode(
|
|
506
|
-
if (parseInt(
|
|
507
|
-
(0, assert_1.default)(false,
|
|
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
|
-
|
|
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),
|
|
516
|
-
|
|
517
|
-
(0, assert_1.default)(type.typeName.text === 'String' && typeArguments && typeArguments.length === 1,
|
|
518
|
-
|
|
519
|
-
if (ts.isLiteralTypeNode(
|
|
520
|
-
if (parseInt(
|
|
521
|
-
(0, assert_1.default)(false,
|
|
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
|
-
|
|
514
|
+
hasEntityIdAttr = true;
|
|
525
515
|
}
|
|
526
516
|
}
|
|
527
517
|
}
|
|
528
518
|
});
|
|
529
|
-
if (
|
|
530
|
-
(0, lodash_1.assign)(ReversePointerEntities,
|
|
531
|
-
|
|
532
|
-
|
|
519
|
+
if (hasEntityAttr && hasEntityIdAttr) {
|
|
520
|
+
(0, lodash_1.assign)(ReversePointerEntities, {
|
|
521
|
+
[moduleName]: 1,
|
|
522
|
+
});
|
|
533
523
|
}
|
|
534
|
-
else if (
|
|
535
|
-
throw new Error(
|
|
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,
|
|
545
|
-
|
|
546
|
-
|
|
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,
|
|
553
|
-
|
|
554
|
-
|
|
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,
|
|
556
|
+
(0, assert_1.default)(!localeDef, `【${filename}】locale定义须在Action之后`);
|
|
567
557
|
hasActionDef = true;
|
|
568
|
-
|
|
569
|
-
pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node,
|
|
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,
|
|
574
|
-
|
|
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,
|
|
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),
|
|
582
|
-
relationValues.push
|
|
583
|
-
(0, assert_1.default)(ts.isLiteralTypeNode(ele) && ts.isStringLiteral(ele.literal),
|
|
584
|
-
(0, assert_1.default)(ele.literal.text.length < env_1.STRING_LITERAL_MAX_LENGTH,
|
|
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
|
-
}))
|
|
576
|
+
}));
|
|
587
577
|
}
|
|
588
578
|
// 对UserEntityGrant对象,建立相应的反指关系
|
|
589
|
-
|
|
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
|
-
|
|
596
|
-
|
|
597
|
-
|
|
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,
|
|
607
|
-
|
|
608
|
-
|
|
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,
|
|
618
|
-
|
|
619
|
-
|
|
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,
|
|
615
|
+
(0, assert_1.default)(!localeDef, `【${filename}】locale定义须在Action/State之后`);
|
|
625
616
|
hasActionOrStateDef = true;
|
|
626
|
-
|
|
617
|
+
const { type } = node;
|
|
627
618
|
if (ts.isUnionTypeNode(type)) {
|
|
628
|
-
pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node,
|
|
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
|
-
]
|
|
622
|
+
]) : type), sourceFile);
|
|
631
623
|
}
|
|
632
624
|
else {
|
|
633
|
-
(0, assert_1.default)(ts.isLiteralTypeNode(type) || ts.isTypeReferenceNode(type),
|
|
634
|
-
pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node,
|
|
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
|
-
|
|
647
|
-
|
|
638
|
+
const { declarationList: { declarations } } = node;
|
|
639
|
+
const dealWithActionDef = (declaration) => {
|
|
648
640
|
checkActionDefNameConsistent(filename, declaration);
|
|
649
|
-
|
|
641
|
+
const { typeArguments } = declaration.type;
|
|
650
642
|
(0, assert_1.default)(typeArguments.length === 2);
|
|
651
|
-
|
|
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),
|
|
655
|
-
|
|
656
|
-
(0, assert_1.default)(enumStateValues,
|
|
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
|
-
|
|
660
|
-
|
|
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
|
-
|
|
665
|
-
|
|
656
|
+
const dealWithIndexes = (declaration) => {
|
|
657
|
+
const indexNameDict = {};
|
|
666
658
|
// 检查索引的属性是否合法
|
|
667
|
-
|
|
668
|
-
elements.forEach(
|
|
669
|
-
|
|
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
|
-
|
|
673
|
-
|
|
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
|
-
|
|
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
|
-
|
|
674
|
+
const nameText = nameProperty.initializer.text;
|
|
684
675
|
if (indexNameDict[nameText]) {
|
|
685
|
-
throw new Error(
|
|
676
|
+
throw new Error(`「${filename}」索引定义重名「${nameText}」`);
|
|
686
677
|
}
|
|
687
|
-
(0, lodash_1.assign)(indexNameDict,
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
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
|
-
|
|
697
|
-
|
|
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(
|
|
695
|
+
throw new Error(`「${filename}」只能定义一个全文索引`);
|
|
705
696
|
}
|
|
706
697
|
hasFulltextIndex = true;
|
|
707
698
|
isFulltextIndex = true;
|
|
708
699
|
}
|
|
709
700
|
}
|
|
710
|
-
|
|
701
|
+
const { elements } = attrProperty.initializer;
|
|
711
702
|
// 每个属性都应该在schema中有值,且对象类型是可索引值
|
|
712
|
-
elements.forEach(
|
|
703
|
+
elements.forEach((ele2) => {
|
|
713
704
|
(0, assert_1.default)(ts.isObjectLiteralExpression(ele2));
|
|
714
|
-
|
|
715
|
-
|
|
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
|
-
|
|
710
|
+
const indexAttrName = nameProperty.initializer.text;
|
|
720
711
|
if (!Entity_1.initinctiveAttributes.includes(indexAttrName)) {
|
|
721
|
-
|
|
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(
|
|
717
|
+
throw new Error(`「${filename}」中索引「${nameText}」的属性「${indexAttrName}」定义非法`);
|
|
727
718
|
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
719
|
+
const { type, name } = schemaNode;
|
|
720
|
+
const entity = moduleName;
|
|
721
|
+
const { [entity]: manyToOneSet } = ManyToOne;
|
|
731
722
|
if (ts.isTypeReferenceNode(type)) {
|
|
732
|
-
|
|
723
|
+
const { typeName } = type;
|
|
733
724
|
if (ts.isIdentifier(typeName)) {
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
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(
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
764
|
-
(0, assert_1.default)(ts.isUnionTypeNode(type) || ts.isLiteralTypeNode(type),
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
785
|
+
const dealWithConfiguration = (declaration) => {
|
|
798
786
|
// assert(!hasActionDef, `${moduleName}中的Configuration定义在Action之后`);
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
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(
|
|
797
|
+
declarations.forEach((declaration) => {
|
|
810
798
|
if (declaration.type && ts.isTypeReferenceNode(declaration.type) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'ActionDef') {
|
|
811
|
-
|
|
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(
|
|
812
|
+
console.log(`「${filename}」直接定义indexes的写法已经过时,请定义在entityDesc中`);
|
|
825
813
|
(0, assert_1.default)(ts.isArrayLiteralExpression(declaration.initializer));
|
|
826
|
-
|
|
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(
|
|
831
|
-
|
|
818
|
+
console.log(`「${filename}」直接定义locales的写法已经过时,请定义在entityDesc中`);
|
|
819
|
+
const { type, initializer } = declaration;
|
|
832
820
|
(0, assert_1.default)(ts.isObjectLiteralExpression(initializer));
|
|
833
|
-
|
|
834
|
-
(0, assert_1.default)(properties.length > 0,
|
|
835
|
-
|
|
836
|
-
|
|
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',
|
|
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',
|
|
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),
|
|
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',
|
|
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),
|
|
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]),
|
|
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]),
|
|
863
|
-
(0, assert_1.default)(typeArguments[3].members.length == 0,
|
|
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
|
-
|
|
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(
|
|
856
|
+
console.log(`「${filename}」直接定义configuration的写法已经过时,请定义在entityDesc中`);
|
|
869
857
|
(0, assert_1.default)(ts.isObjectLiteralExpression(declaration.initializer));
|
|
870
|
-
|
|
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
|
-
|
|
875
|
-
|
|
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
|
-
|
|
878
|
-
|
|
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
|
-
|
|
869
|
+
dealWithIndexes(indexesProperty.initializer);
|
|
882
870
|
}
|
|
883
|
-
|
|
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
|
-
|
|
874
|
+
dealWithConfiguration(configurationProperty.initializer);
|
|
887
875
|
}
|
|
888
876
|
}
|
|
889
877
|
else {
|
|
890
|
-
throw new Error(
|
|
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
|
-
|
|
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(
|
|
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(
|
|
898
|
+
throw new Error(`${filename}中有Action或State定义,但没有定义完整的Action类型`);
|
|
911
899
|
}
|
|
912
900
|
if (hasActionDef && actionType !== 'crud') {
|
|
913
|
-
throw new Error(
|
|
914
|
-
}
|
|
915
|
-
(0, assert_1.default)(schemaAttrs.length > 0,
|
|
916
|
-
|
|
917
|
-
schemaAttrs
|
|
918
|
-
sourceFile
|
|
919
|
-
toModi
|
|
920
|
-
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
|
|
923
|
-
enumAttributes
|
|
924
|
-
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
|
|
921
|
+
indexes,
|
|
934
922
|
});
|
|
935
923
|
}
|
|
936
924
|
if (!localeDef) {
|
|
937
|
-
throw new Error(
|
|
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,
|
|
964
|
-
|
|
965
|
-
|
|
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
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
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
|
-
|
|
972
|
+
const { typeName } = type;
|
|
986
973
|
if (ts.isIdentifier(typeName)) {
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
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(
|
|
995
|
-
members2.push(factory.createPropertySignature(undefined,
|
|
996
|
-
factory.createTypeReferenceNode(createForeignRef(entity,
|
|
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,
|
|
999
|
-
|
|
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)(
|
|
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)(
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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),
|
|
1038
|
-
members.push(factory.createPropertySignature(undefined,
|
|
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
|
-
|
|
1029
|
+
const reverseOnes = ReversePointerRelations[entity];
|
|
1059
1030
|
if (reverseOnes) {
|
|
1060
|
-
reverseOnes.forEach(
|
|
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
|
-
|
|
1036
|
+
const foreignKeySet = {};
|
|
1066
1037
|
if (oneToManySet) {
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
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
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
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
|
-
|
|
1090
|
-
|
|
1091
|
-
foreignKeySet[entityName].forEach(
|
|
1092
|
-
|
|
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
|
-
|
|
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(
|
|
1060
|
+
(0, lodash_1.uniq)(referenceEntities).forEach((ele) => {
|
|
1103
1061
|
if (ele !== entity) {
|
|
1104
|
-
statements.push(factory.createImportDeclaration(undefined,
|
|
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
|
|
1067
|
+
statements.push(...SchemaAsts[entity].statements);
|
|
1110
1068
|
}
|
|
1111
|
-
statements.push(factory.createTypeAliasDeclaration(
|
|
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(
|
|
1117
|
-
statements.push(factory.createTypeAliasDeclaration(
|
|
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
|
-
|
|
1133
|
-
|
|
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
|
-
|
|
1153
|
-
|
|
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
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1114
|
+
for (const attr of schemaAttrs) {
|
|
1115
|
+
const { type, name } = attr;
|
|
1116
|
+
const attrName = name.text;
|
|
1160
1117
|
if (ts.isTypeReferenceNode(type)) {
|
|
1161
|
-
|
|
1118
|
+
const { typeName } = type;
|
|
1162
1119
|
if (ts.isIdentifier(typeName)) {
|
|
1163
|
-
|
|
1164
|
-
|
|
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
|
-
|
|
1207
|
-
|
|
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,
|
|
1214
|
-
type2 = factory.createTypeReferenceNode(createForeignRef(entity,
|
|
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,
|
|
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,
|
|
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,
|
|
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(
|
|
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
|
-
|
|
1210
|
+
const { [entity]: oneToManySet } = OneToMany;
|
|
1271
1211
|
if (oneToManySet) {
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1293
|
-
|
|
1294
|
-
foreignKeySet[entityName].forEach(
|
|
1295
|
-
|
|
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,
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
1340
|
-
|
|
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
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
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
|
-
|
|
1281
|
+
const { typeName } = type;
|
|
1357
1282
|
if (ts.isIdentifier(typeName)) {
|
|
1358
|
-
|
|
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
|
-
|
|
1297
|
+
case 'Price':
|
|
1298
|
+
case 'Decimal': {
|
|
1299
|
+
properties.push([name, false]);
|
|
1374
1300
|
break;
|
|
1375
1301
|
}
|
|
1376
1302
|
case 'Object': {
|
|
1377
|
-
properties.push([
|
|
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
|
-
|
|
1385
|
-
|
|
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([
|
|
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(
|
|
1396
|
-
foreignKeyProperties[
|
|
1318
|
+
if (foreignKeyProperties.hasOwnProperty(text2)) {
|
|
1319
|
+
foreignKeyProperties[text2].push(attrName);
|
|
1397
1320
|
}
|
|
1398
1321
|
else {
|
|
1399
|
-
(0, lodash_1.assign)(foreignKeyProperties,
|
|
1400
|
-
|
|
1401
|
-
|
|
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([
|
|
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([
|
|
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([
|
|
1351
|
+
properties.push([name, false, undefined]);
|
|
1429
1352
|
}
|
|
1430
1353
|
else {
|
|
1431
1354
|
// 如果是非枚举类型的其它对象的union定义,加上JsonProjection
|
|
1432
|
-
properties.push([
|
|
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(
|
|
1454
|
-
|
|
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,
|
|
1465
|
-
|
|
1466
|
-
|
|
1373
|
+
(0, lodash_1.assign)(foreignKeyProperties, {
|
|
1374
|
+
[text2]: ['entity'],
|
|
1375
|
+
});
|
|
1467
1376
|
}
|
|
1468
1377
|
});
|
|
1469
1378
|
}
|
|
1470
1379
|
// 一对多的projection
|
|
1471
|
-
|
|
1380
|
+
const { [entity]: oneToManySet } = OneToMany;
|
|
1472
1381
|
if (oneToManySet) {
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1494
|
-
|
|
1495
|
-
foreignKeySet[entityName].forEach(
|
|
1496
|
-
|
|
1497
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
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(
|
|
1551
|
-
factory.createTypeLiteralNode(MetaPropertySignatures.concat(properties.map(
|
|
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 (
|
|
1586
|
-
|
|
1587
|
-
statements.push(factory.createTypeAliasDeclaration(undefined,
|
|
1588
|
-
factory.createTypeLiteralNode(foreignKeyProperties[foreignKey].map(
|
|
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
|
-
|
|
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
|
-
|
|
1701
|
-
|
|
1595
|
+
const { [entity]: manyToOneSet } = ManyToOne;
|
|
1596
|
+
let manyToSelf = false;
|
|
1702
1597
|
if (manyToOneSet) {
|
|
1703
|
-
(0, lodash_1.uniqBy)(manyToOneSet,
|
|
1704
|
-
|
|
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(
|
|
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
|
-
|
|
1726
|
-
|
|
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
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1627
|
+
const { [entity]: manyToOneSet } = ManyToOne;
|
|
1628
|
+
for (const attr of schemaAttrs) {
|
|
1629
|
+
const { type, name, questionToken } = attr;
|
|
1740
1630
|
if (ts.isTypeReferenceNode(type)) {
|
|
1741
|
-
|
|
1631
|
+
const { typeName } = type;
|
|
1742
1632
|
if (ts.isIdentifier(typeName)) {
|
|
1743
|
-
|
|
1744
|
-
|
|
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
|
-
|
|
1761
|
-
|
|
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,
|
|
1767
|
-
members.push(factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier(
|
|
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,
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
1853
|
-
|
|
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
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
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
|
-
|
|
1872
|
-
|
|
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(
|
|
1879
|
-
factory.createTypeReferenceNode(factory.createIdentifier("OpAttr"), undefined)
|
|
1880
|
-
|
|
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(
|
|
1747
|
+
statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("NativeAttr"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OpAttr"), undefined)));
|
|
1884
1748
|
}
|
|
1885
|
-
|
|
1749
|
+
const foreignKeySet = {};
|
|
1886
1750
|
if (oneToManySet && oneToManySet.length > 0) {
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
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(
|
|
1911
|
-
|
|
1912
|
-
|
|
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
|
-
|
|
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(
|
|
1933
|
-
factory.createTypeReferenceNode(factory.createIdentifier("NativeAttr"), undefined)
|
|
1934
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1838
|
+
const { [entity]: manyToOneSet } = ManyToOne;
|
|
1839
|
+
const { [entity]: oneToManySet } = OneToMany;
|
|
1840
|
+
const foreignKeySet = {};
|
|
1990
1841
|
if (oneToManySet) {
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1853
|
+
let foreignKeyAttr = [];
|
|
2013
1854
|
if (ReversePointerEntities[entity]) {
|
|
2014
1855
|
foreignKeyAttr.push('entity', 'entityId');
|
|
2015
1856
|
}
|
|
2016
1857
|
if (manyToOneSet) {
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
])
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
])
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
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
|
-
|
|
1927
|
+
const reverseOneNodes = [];
|
|
2106
1928
|
if (ReversePointerEntities[entity]) {
|
|
2107
1929
|
if (ReversePointerRelations[entity]) {
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
1930
|
+
const { schemaAttrs } = Schema[entity];
|
|
1931
|
+
const { questionToken: entityQuestionToken } = schemaAttrs.find(ele => {
|
|
1932
|
+
const { name } = ele;
|
|
2111
1933
|
return name.text === 'entity';
|
|
2112
|
-
})
|
|
2113
|
-
|
|
2114
|
-
|
|
1934
|
+
});
|
|
1935
|
+
const { questionToken: entityIdQuestionToken } = schemaAttrs.find(ele => {
|
|
1936
|
+
const { name } = ele;
|
|
2115
1937
|
return name.text === 'entityId';
|
|
2116
|
-
})
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
])
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
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,
|
|
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
|
-
|
|
1994
|
+
const propertySignatures = [];
|
|
2185
1995
|
if (oneToManySet) {
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
foreignKeySet[entityName].forEach(
|
|
2189
|
-
|
|
2190
|
-
|
|
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(
|
|
2007
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(`${foreignKey}Id`))
|
|
2198
2008
|
])
|
|
2199
2009
|
]);
|
|
2200
|
-
|
|
2010
|
+
const otmCreateSingleOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
|
|
2201
2011
|
factory.createLiteralTypeNode(factory.createStringLiteral("create")),
|
|
2202
2012
|
otmCreateOperationDataNode
|
|
2203
2013
|
]);
|
|
2204
|
-
|
|
2014
|
+
const otmCreateMultipleOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
|
|
2205
2015
|
factory.createLiteralTypeNode(factory.createStringLiteral("create")),
|
|
2206
2016
|
factory.createArrayTypeNode(otmCreateOperationDataNode)
|
|
2207
2017
|
]);
|
|
2208
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
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(
|
|
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
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
])
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
])
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
])
|
|
2335
|
-
|
|
2336
|
-
factory.
|
|
2337
|
-
factory.
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
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
|
-
|
|
2172
|
+
const reverseOneNodes = [];
|
|
2386
2173
|
if (ReversePointerRelations[entity]) {
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
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
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
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
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
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(
|
|
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 (
|
|
2451
|
-
adNodes.push(factory.createUnionTypeNode(
|
|
2233
|
+
if (reverseOneNodes.length > 0) {
|
|
2234
|
+
adNodes.push(factory.createUnionTypeNode(reverseOneNodes));
|
|
2452
2235
|
}
|
|
2453
2236
|
}
|
|
2454
|
-
|
|
2237
|
+
const propertySignatures2 = [];
|
|
2455
2238
|
if (process.env.COMPLING_AS_LIB) {
|
|
2456
|
-
propertySignatures2.push(factory.createIndexSignature(undefined,
|
|
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
|
-
|
|
2460
|
-
|
|
2461
|
-
foreignKeySet[entityName].forEach(
|
|
2462
|
-
|
|
2463
|
-
|
|
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(
|
|
2253
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(`${foreignKey}Id`))
|
|
2471
2254
|
])
|
|
2472
2255
|
]);
|
|
2473
|
-
|
|
2256
|
+
const otmCreateSingleOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
|
|
2474
2257
|
factory.createLiteralTypeNode(factory.createStringLiteral("create")),
|
|
2475
2258
|
otmCreateOperationDataNode
|
|
2476
2259
|
]);
|
|
2477
|
-
|
|
2260
|
+
const otmCreateMultipleOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
|
|
2478
2261
|
factory.createLiteralTypeNode(factory.createStringLiteral("create")),
|
|
2479
2262
|
factory.createArrayTypeNode(otmCreateOperationDataNode)
|
|
2480
2263
|
]);
|
|
2481
|
-
|
|
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(
|
|
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(
|
|
2283
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(`${foreignKey}Id`))
|
|
2501
2284
|
])
|
|
2502
2285
|
])
|
|
2503
2286
|
]);
|
|
2504
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
2370
|
+
statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("UpdateOperationData"), undefined, factory.createIntersectionTypeNode(adNodes)));
|
|
2591
2371
|
// UpdateOperation
|
|
2592
|
-
|
|
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(
|
|
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
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
factory.
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
factory.
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
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
|
-
|
|
2721
|
-
factory.createIndexSignature(undefined,
|
|
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 (
|
|
2729
|
-
adNodes.push(factory.createUnionTypeNode(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
2576
|
+
const initialStatements = () => [
|
|
2817
2577
|
// import { String, Text, Int, SpecificKey } from 'oak-domain/types/DataType';
|
|
2818
|
-
factory.createImportDeclaration(undefined,
|
|
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(
|
|
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,
|
|
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(
|
|
2842
|
-
factory.createImportDeclaration(undefined,
|
|
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(
|
|
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,
|
|
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(
|
|
2867
|
-
];
|
|
2626
|
+
])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)()}Entity`), undefined)
|
|
2627
|
+
];
|
|
2868
2628
|
function outputSubQuery(outputDir, printer) {
|
|
2869
|
-
|
|
2629
|
+
const statements = [];
|
|
2870
2630
|
if (process.env.COMPLING_AS_LIB) {
|
|
2871
2631
|
}
|
|
2872
|
-
for (
|
|
2632
|
+
for (const entity in Schema) {
|
|
2873
2633
|
// import * as User from '../User/Schema';
|
|
2874
|
-
statements.push(factory.createImportDeclaration(undefined,
|
|
2634
|
+
statements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamespaceImport(factory.createIdentifier(entity))), factory.createStringLiteral(`./${entity}/Schema`)));
|
|
2875
2635
|
}
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
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
|
-
|
|
2911
|
-
|
|
2912
|
-
for (
|
|
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,
|
|
2915
|
-
|
|
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,
|
|
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,
|
|
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(
|
|
2681
|
+
statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDict"), undefined, factory.createTypeLiteralNode(propertySignatures)));
|
|
2928
2682
|
}
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
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 (
|
|
2936
|
-
|
|
2689
|
+
for (const entity in Schema) {
|
|
2690
|
+
const statements = initialStatements();
|
|
2937
2691
|
if (ActionAsts[entity]) {
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
for (
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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
|
-
|
|
2987
|
-
if (
|
|
2988
|
-
statements.push
|
|
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
|
-
|
|
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
|
-
|
|
3023
|
-
|
|
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(
|
|
3057
|
-
|
|
3058
|
-
|
|
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
|
-
|
|
3064
|
-
|
|
3065
|
-
for (
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
for (
|
|
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(
|
|
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
|
-
|
|
3088
|
-
|
|
3089
|
-
(0, fs_1.writeFileSync)(filename,
|
|
3090
|
-
actionDictStatements.push(factory.createImportDeclaration(undefined,
|
|
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
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
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
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
schemaAttrs.forEach(
|
|
3104
|
-
|
|
3105
|
-
|
|
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
|
-
|
|
2863
|
+
let name2 = name;
|
|
3110
2864
|
if (ts.isTypeReferenceNode(type)) {
|
|
3111
|
-
|
|
2865
|
+
const { typeName, typeArguments } = type;
|
|
3112
2866
|
if (ts.isIdentifier(typeName)) {
|
|
3113
|
-
|
|
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
|
-
|
|
2875
|
+
const mtoRelations = ReversePointerRelations[entity];
|
|
3122
2876
|
if (mtoRelations) {
|
|
3123
|
-
|
|
3124
|
-
attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("ref"), factory.createArrayLiteralExpression(mtoEntities.map(
|
|
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(
|
|
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
|
-
|
|
3180
|
-
|
|
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(
|
|
3187
|
-
attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("ref")), factory.createPropertyAssignment(factory.createIdentifier("ref"), factory.createStringLiteral((0, string_1.firstLetterLowerCase)(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
2999
|
+
const locales = {};
|
|
3000
|
+
const entities = [];
|
|
3001
|
+
for (const entity in Schema) {
|
|
3002
|
+
const { locale, sourceFile } = Schema[entity];
|
|
3252
3003
|
if (locale) {
|
|
3253
|
-
|
|
3254
|
-
properties.forEach(
|
|
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
|
-
|
|
3257
|
-
|
|
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
|
-
|
|
3261
|
-
|
|
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 (
|
|
3024
|
+
for (const lng in locales) {
|
|
3277
3025
|
if (locales[lng].length < entities.length) {
|
|
3278
|
-
|
|
3279
|
-
throw new Error(
|
|
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
|
-
|
|
3322
|
-
factory.createImportDeclaration(undefined,
|
|
3323
|
-
factory.createImportDeclaration(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
|
-
|
|
3326
|
-
for (
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
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
|
-
|
|
3342
|
-
factory.createImportDeclaration(undefined,
|
|
3343
|
-
factory.createImportDeclaration(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
|
-
|
|
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,
|
|
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,
|
|
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
|
-
|
|
3375
|
-
|
|
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
|
|
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
|
-
|
|
3159
|
+
const { type } = hasRelationDef;
|
|
3412
3160
|
if (ts.isUnionTypeNode(type)) {
|
|
3413
|
-
|
|
3414
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
3433
|
-
|
|
3434
|
-
(0, fs_1.writeFileSync)(
|
|
3435
|
-
importStatements.push(factory.createImportDeclaration(undefined,
|
|
3436
|
-
factory.createImportSpecifier(false, factory.createIdentifier("desc"), factory.createIdentifier(
|
|
3437
|
-
])), factory.createStringLiteral(
|
|
3438
|
-
entityAssignments.push(factory.createPropertyAssignment((0, string_1.firstLetterLowerCase)(entity), factory.createIdentifier(
|
|
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
|
-
|
|
3444
|
-
|
|
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 (
|
|
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
|
-
|
|
3457
|
-
for (var reverseEntity in ReversePointerRelations) {
|
|
3204
|
+
for (const reverseEntity in ReversePointerRelations) {
|
|
3458
3205
|
if (!ReversePointerEntities.hasOwnProperty(reverseEntity)) {
|
|
3459
|
-
throw new Error(
|
|
3206
|
+
throw new Error(`「${reverseEntity}」被引用为一个反指对象,但其定义中的entity和entityId不符合要求`);
|
|
3460
3207
|
}
|
|
3461
|
-
|
|
3462
|
-
|
|
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
|
-
|
|
3478
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3494
|
-
|
|
3234
|
+
const getRelateEntities = (entity) => {
|
|
3235
|
+
let result = [];
|
|
3495
3236
|
if (ManyToOne[entity]) {
|
|
3496
3237
|
// 用反指指针指向的对象可以忽略,因为前端不可能设计出这样的更新页面
|
|
3497
|
-
result = ManyToOne[entity].filter(
|
|
3238
|
+
result = ManyToOne[entity].filter(ele => ele[1] !== 'entity').map(ele => ele[0]);
|
|
3498
3239
|
}
|
|
3499
3240
|
if (OneToMany[entity]) {
|
|
3500
|
-
result.push
|
|
3241
|
+
result.push(...OneToMany[entity].map(ele => ele[0]));
|
|
3501
3242
|
}
|
|
3502
3243
|
return (0, lodash_1.uniq)(result);
|
|
3503
3244
|
};
|
|
3504
|
-
|
|
3245
|
+
const setInModi = (entity) => {
|
|
3505
3246
|
if (['Modi', 'ModiEntity', 'Oper', 'OperEntity', 'User'].includes(entity)) {
|
|
3506
3247
|
return;
|
|
3507
3248
|
}
|
|
3508
|
-
|
|
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
|
-
|
|
3514
|
-
related.forEach(
|
|
3254
|
+
const related = getRelateEntities(entity);
|
|
3255
|
+
related.forEach(ele => setInModi(ele));
|
|
3515
3256
|
};
|
|
3516
|
-
for (
|
|
3257
|
+
for (const entity in Schema) {
|
|
3517
3258
|
if (Schema[entity].toModi) {
|
|
3518
|
-
|
|
3519
|
-
related.forEach(
|
|
3259
|
+
const related = getRelateEntities(entity);
|
|
3260
|
+
related.forEach(ele => setInModi(ele));
|
|
3520
3261
|
}
|
|
3521
3262
|
}
|
|
3522
3263
|
}
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
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
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
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 (
|
|
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
|
-
|
|
3556
|
-
for (var k in map) {
|
|
3309
|
+
for (const k in map) {
|
|
3557
3310
|
if (k === '.') {
|
|
3558
|
-
FIXED_FOR_ALL_DESTINATION_PATH_ENTITIES.push
|
|
3311
|
+
FIXED_FOR_ALL_DESTINATION_PATH_ENTITIES.push(...map[k]);
|
|
3559
3312
|
}
|
|
3560
3313
|
else if (FIXED_DESTINATION_PATH_MAP[k]) {
|
|
3561
|
-
|
|
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
|
-
|
|
3571
|
-
|
|
3572
|
-
(0, assert_1.default)(Schema.hasOwnProperty(entity),
|
|
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
|
-
|
|
3578
|
-
(0, assert_1.default)(mto,
|
|
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
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
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 (
|
|
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
|
-
|
|
3364
|
+
const { [entity]: parent } = OneToMany;
|
|
3611
3365
|
if (parent) {
|
|
3612
|
-
parent.forEach(
|
|
3613
|
-
|
|
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(
|
|
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 (
|
|
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
|
-
|
|
3640
|
-
|
|
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
|
-
|
|
3647
|
-
User.forEach(
|
|
3648
|
-
|
|
3649
|
-
|
|
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
|
-
|
|
3657
|
-
hasRelationEntities.forEach(
|
|
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(
|
|
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
|
-
|
|
3683
|
-
for (
|
|
3684
|
-
|
|
3432
|
+
const entityRelations = [];
|
|
3433
|
+
for (const entity in Schema) {
|
|
3434
|
+
const { hasRelationDef } = Schema[entity];
|
|
3685
3435
|
if (hasRelationDef) {
|
|
3686
|
-
|
|
3436
|
+
const { type } = hasRelationDef;
|
|
3687
3437
|
if (ts.isUnionTypeNode(type)) {
|
|
3688
|
-
|
|
3689
|
-
|
|
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
|
-
|
|
3448
|
+
const relations = [type.literal.text];
|
|
3699
3449
|
entityRelations.push([(0, string_1.firstLetterLowerCase)(entity), relations]);
|
|
3700
3450
|
}
|
|
3701
3451
|
}
|
|
3702
3452
|
}
|
|
3703
|
-
|
|
3704
|
-
factory.createImportDeclaration(undefined,
|
|
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(
|
|
3708
|
-
factory.createImportDeclaration(undefined,
|
|
3709
|
-
factory.createImportDeclaration(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(
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
3749
|
-
|
|
3750
|
-
|
|
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
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
if (env_1.RESERVED_ENTITY_NAMES.includes(entity) || env_1.RESERVED_ENTITY_NAMES.find(
|
|
3758
|
-
throw new Error(
|
|
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
|
|
3542
|
+
return `${inputDir}/${ele}`;
|
|
3761
3543
|
});
|
|
3762
|
-
|
|
3763
|
-
files.forEach(
|
|
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
|
-
|
|
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
|
-
|
|
3563
|
+
outputRelation2(outputDir, printer);
|
|
3782
3564
|
outputIndexTs(outputDir);
|
|
3783
3565
|
if (!process.env.COMPLING_AS_LIB) {
|
|
3784
3566
|
outputPackageJson(outputDir);
|