oak-domain 2.6.10 → 3.0.0
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 +1 -1
- package/lib/actions/action.js +2 -2
- package/lib/base-app-domain/ActionAuth/Schema.d.ts +25 -21
- package/lib/base-app-domain/ActionAuth/Storage.js +6 -13
- package/lib/base-app-domain/ActionDefDict.d.ts +1 -0
- package/lib/base-app-domain/ActionDefDict.js +3 -1
- package/lib/base-app-domain/EntityDict.d.ts +2 -0
- package/lib/base-app-domain/I18n/Schema.d.ts +129 -0
- package/lib/base-app-domain/I18n/Schema.js +2 -0
- package/lib/base-app-domain/I18n/Storage.d.ts +3 -0
- package/lib/base-app-domain/I18n/Storage.js +59 -0
- package/lib/base-app-domain/Modi/Action.d.ts +1 -1
- package/lib/base-app-domain/Modi/Schema.d.ts +10 -9
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +42 -28
- package/lib/base-app-domain/ModiEntity/Storage.js +1 -1
- package/lib/base-app-domain/Oper/Schema.d.ts +15 -13
- package/lib/base-app-domain/OperEntity/Schema.d.ts +41 -27
- package/lib/base-app-domain/OperEntity/Storage.js +1 -1
- package/lib/base-app-domain/Relation/Schema.d.ts +50 -22
- package/lib/base-app-domain/Relation/Storage.js +1 -4
- package/lib/base-app-domain/Relation.d.ts +10 -0
- package/lib/base-app-domain/Relation.js +10 -0
- package/lib/base-app-domain/RelationAuth/Schema.d.ts +67 -43
- package/lib/base-app-domain/RelationAuth/Storage.js +9 -12
- package/lib/base-app-domain/Storage.js +20 -18
- package/lib/base-app-domain/User/Action.d.ts +1 -1
- package/lib/base-app-domain/User/Schema.d.ts +20 -14
- package/lib/base-app-domain/User/Storage.js +1 -2
- package/lib/base-app-domain/UserEntityGrant/Action.d.ts +5 -0
- package/lib/base-app-domain/UserEntityGrant/Action.js +5 -0
- package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +53 -17
- package/lib/base-app-domain/UserEntityGrant/Storage.js +5 -7
- package/lib/base-app-domain/UserRelation/Schema.d.ts +35 -16
- package/lib/base-app-domain/UserRelation/Storage.js +21 -1
- package/lib/base-app-domain/_SubQuery.d.ts +40 -4
- package/lib/base-app-domain/index.d.ts +1 -0
- package/lib/base-app-domain/index.js +1 -0
- package/lib/checkers/index.d.ts +2 -2
- package/lib/checkers/index.js +2 -5
- package/lib/compiler/env.d.ts +3 -1
- package/lib/compiler/env.js +12 -2
- package/lib/compiler/localeBuilder.d.ts +22 -0
- package/lib/compiler/localeBuilder.js +169 -0
- package/lib/compiler/schemalBuilder.d.ts +9 -0
- package/lib/compiler/schemalBuilder.js +774 -362
- package/lib/entities/ActionAuth.d.ts +3 -2
- package/lib/entities/ActionAuth.js +21 -22
- package/lib/entities/I18n.d.ts +9 -0
- package/lib/entities/I18n.js +37 -0
- package/lib/entities/Modi.js +35 -33
- package/lib/entities/ModiEntity.js +12 -10
- package/lib/entities/Oper.js +15 -13
- package/lib/entities/OperEntity.js +12 -10
- package/lib/entities/Relation.d.ts +3 -3
- package/lib/entities/Relation.js +27 -25
- package/lib/entities/RelationAuth.d.ts +2 -5
- package/lib/entities/RelationAuth.js +27 -23
- package/lib/entities/User.js +20 -18
- package/lib/entities/UserEntityGrant.d.ts +2 -1
- package/lib/entities/UserEntityGrant.js +12 -7
- package/lib/entities/UserRelation.d.ts +3 -0
- package/lib/entities/UserRelation.js +30 -20
- package/lib/store/AsyncRowStore.d.ts +3 -0
- package/lib/store/AsyncRowStore.js +3 -0
- package/lib/store/CascadeStore.d.ts +9 -3
- package/lib/store/CascadeStore.js +247 -113
- package/lib/store/RelationAuth.d.ts +96 -0
- package/lib/store/RelationAuth.js +1307 -0
- package/lib/store/TriggerExecutor.d.ts +1 -2
- package/lib/store/TriggerExecutor.js +22 -22
- package/lib/store/actionAuth.d.ts +4 -0
- package/lib/store/actionAuth.js +40 -0
- package/lib/store/actionDef.d.ts +4 -3
- package/lib/store/actionDef.js +14 -10
- package/lib/store/checker.d.ts +2 -9
- package/lib/store/checker.js +39 -815
- package/lib/store/filter.d.ts +31 -18
- package/lib/store/filter.js +1256 -422
- package/lib/store/modi.d.ts +1 -1
- package/lib/store/modi.js +108 -9
- package/lib/store/relation.d.ts +3 -4
- package/lib/timers/oper.js +1 -1
- package/lib/timers/vaccum.js +2 -2
- package/lib/triggers/index.d.ts +2 -3
- package/lib/triggers/index.js +2 -5
- package/lib/types/Auth.d.ts +5 -0
- package/lib/types/DataType.d.ts +3 -0
- package/lib/types/Demand.d.ts +11 -0
- package/lib/types/Demand.js +2 -1
- package/lib/types/Entity.d.ts +10 -3
- package/lib/types/EntityDesc.d.ts +8 -0
- package/lib/types/EntityDesc.js +2 -0
- package/lib/types/Environment.d.ts +57 -0
- package/lib/types/Environment.js +2 -0
- package/lib/types/Exception.d.ts +6 -0
- package/lib/types/Exception.js +25 -1
- package/lib/types/Logger.d.ts +1 -0
- package/lib/types/RowStore.d.ts +6 -4
- package/lib/types/Style.d.ts +1 -1
- package/lib/types/Trigger.d.ts +4 -5
- package/lib/types/Trigger.js +11 -6
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +2 -0
- package/lib/utils/SimpleConnector.js +1 -1
- package/lib/utils/string.d.ts +6 -0
- package/lib/utils/string.js +13 -1
- package/lib/utils/uuid.d.ts +5 -0
- package/lib/utils/uuid.js +64 -1
- package/package.json +3 -3
- package/src/entities/ActionAuth.ts +25 -33
- package/src/entities/I18n.ts +46 -0
- package/src/entities/Modi.ts +36 -36
- package/src/entities/ModiEntity.ts +14 -13
- package/src/entities/Oper.ts +17 -16
- package/src/entities/OperEntity.ts +13 -11
- package/src/entities/Relation.ts +31 -37
- package/src/entities/RelationAuth.ts +31 -37
- package/src/entities/User.ts +24 -21
- package/src/entities/UserEntityGrant.ts +16 -14
- package/src/entities/UserRelation.ts +33 -27
- package/lib/triggers/modi.d.ts +0 -5
- package/lib/triggers/modi.js +0 -72
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildSchema = exports.analyzeEntities = void 0;
|
|
3
|
+
exports.buildSchema = exports.analyzeEntities = exports.registerDeducedRelationMap = exports.registerFixedDestinationPathMap = exports.registerIgnoredRelationPathMap = exports.registerFreeEntities = exports.registerIgnoredForeignKeyMap = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var path_1 = tslib_1.__importDefault(require("path"));
|
|
6
6
|
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
@@ -220,6 +220,7 @@ var RESERVED_ACTION_NAMES = ['GenericAction', 'ParticularAction', 'ExcludeRemove
|
|
|
220
220
|
var action_1 = require("../actions/action");
|
|
221
221
|
var DataType_1 = require("../types/DataType");
|
|
222
222
|
var Entity_1 = require("../types/Entity");
|
|
223
|
+
var uuid_1 = require("../utils/uuid");
|
|
223
224
|
var OriginActionDict = {
|
|
224
225
|
'crud': 'GenericAction',
|
|
225
226
|
'excludeUpdate': 'ExcludeUpdateAction',
|
|
@@ -227,9 +228,9 @@ var OriginActionDict = {
|
|
|
227
228
|
'appendOnly': 'AppendOnlyAction',
|
|
228
229
|
'readOnly': 'ReadOnlyAction',
|
|
229
230
|
};
|
|
230
|
-
function dealWithActions(moduleName, filename, node, program, sourceFile
|
|
231
|
+
function dealWithActions(moduleName, filename, node, program, sourceFile) {
|
|
231
232
|
var actionTexts = action_1.genericActions.map(function (ele) { return ele; });
|
|
232
|
-
if (
|
|
233
|
+
if (moduleName === 'User') {
|
|
233
234
|
actionTexts.push.apply(actionTexts, tslib_1.__spreadArray([], tslib_1.__read(action_1.relationActions), false));
|
|
234
235
|
}
|
|
235
236
|
if (ts.isUnionTypeNode(node)) {
|
|
@@ -238,7 +239,7 @@ function dealWithActions(moduleName, filename, node, program, sourceFile, hasRel
|
|
|
238
239
|
return ele.typeName.text;
|
|
239
240
|
}
|
|
240
241
|
}).filter(function (ele) { return !!ele; });
|
|
241
|
-
(0, assert_1.default)((0, lodash_1.intersection)(actionNames,
|
|
242
|
+
(0, assert_1.default)((0, lodash_1.intersection)(actionNames, RESERVED_ACTION_NAMES).length === 0, "".concat(filename, "\u4E2D\u7684Action\u547D\u540D\u4E0D\u80FD\u662F\u300C").concat(RESERVED_ACTION_NAMES.join(','), "\u300D\u4E4B\u4E00"));
|
|
242
243
|
node.types.forEach(function (ele) {
|
|
243
244
|
if (ts.isTypeReferenceNode(ele)) {
|
|
244
245
|
actionTexts.push.apply(actionTexts, tslib_1.__spreadArray([], tslib_1.__read(getStringTextFromUnionStringLiterals(moduleName, filename, ele, program)), false));
|
|
@@ -385,26 +386,26 @@ function analyzeEntity(filename, path, program, relativePath) {
|
|
|
385
386
|
// let relationHierarchy: ts.ObjectLiteralExpression | undefined = undefined;
|
|
386
387
|
// let reverseCascadeRelationHierarchy: ts.ObjectLiteralExpression | undefined = undefined;
|
|
387
388
|
ts.forEachChild(sourceFile, function (node) {
|
|
388
|
-
var _a, _b, _c, _d, _e;
|
|
389
|
+
var _a, _b, _c, _d, _e, _f;
|
|
389
390
|
if (ts.isImportDeclaration(node)) {
|
|
390
391
|
var entityImported = getEntityImported(node);
|
|
391
392
|
if (entityImported) {
|
|
392
393
|
referencedSchemas.push(entityImported);
|
|
393
394
|
}
|
|
394
|
-
else
|
|
395
|
-
/**import了domain以外的其它定义类型,需要被复制到生成的Schema文件中
|
|
396
|
-
* 这里必须注意,1、假设了domain当中定义的几个entity不会引用其它文件上的定义(除了type里的那些通用类型,默认都会被输出到文件中)
|
|
397
|
-
* 2、假设了其它项目文件不会引用domain当中除了type通用类型之外的其它内容,否则不会被输出到文件中
|
|
398
|
-
* 这里主要是对import的处理比较粗略,日后有需要的时候再精修
|
|
399
|
-
*/
|
|
395
|
+
else {
|
|
400
396
|
var moduleSpecifier = node.moduleSpecifier, importClause = node.importClause;
|
|
401
|
-
if (ts.isStringLiteral(moduleSpecifier)
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
397
|
+
if (ts.isStringLiteral(moduleSpecifier)) {
|
|
398
|
+
var text = moduleSpecifier.text;
|
|
399
|
+
// 和数据类型相关的会自动引入,这里忽略(见initialStatements)
|
|
400
|
+
// 如果是相对路径,编译后的路径默认要深一层
|
|
401
|
+
var moduleSpecifier2Text = text.startsWith('.') ? (relativePath
|
|
402
|
+
? path_1.default.join(relativePath, text).replace(/\\/g, '/')
|
|
403
|
+
: path_1.default.join('..', text).replace(/\\/g, '/')) : text;
|
|
406
404
|
additionalImports.push(factory.updateImportDeclaration(node, undefined, undefined, importClause, factory.createStringLiteral(moduleSpecifier2Text), undefined));
|
|
407
405
|
}
|
|
406
|
+
else {
|
|
407
|
+
(0, assert_1.default)(false, '未处理的import方式');
|
|
408
|
+
}
|
|
408
409
|
}
|
|
409
410
|
}
|
|
410
411
|
if (ts.isInterfaceDeclaration(node)) {
|
|
@@ -566,23 +567,10 @@ function analyzeEntity(filename, path, program, relativePath) {
|
|
|
566
567
|
hasActionDef = true;
|
|
567
568
|
var modifiers = [factory.createModifier(ts.SyntaxKind.ExportKeyword)];
|
|
568
569
|
pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node, node.decorators, modifiers, factory.createIdentifier('ParticularAction'), node.typeParameters, node.type), sourceFile);
|
|
569
|
-
|
|
570
|
-
factory.createTypeReferenceNode(OriginActionDict[actionType], undefined),
|
|
571
|
-
factory.createTypeReferenceNode('ParticularAction', undefined)
|
|
572
|
-
];
|
|
573
|
-
if (hasRelationDef || moduleName === 'User') {
|
|
574
|
-
actionDefNodes.push(factory.createTypeReferenceNode('RelationAction', undefined));
|
|
575
|
-
}
|
|
576
|
-
if (process.env.COMPLING_AS_LIB) {
|
|
577
|
-
actionDefNodes.push(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
|
|
578
|
-
}
|
|
579
|
-
pushStatementIntoActionAst(moduleName, factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Action"), undefined, factory.createUnionTypeNode(actionDefNodes)), sourceFile);
|
|
580
|
-
dealWithActions(moduleName, filename, node.type, program, sourceFile, !!hasRelationDef || moduleName === 'User');
|
|
570
|
+
dealWithActions(moduleName, filename, node.type, program, sourceFile);
|
|
581
571
|
}
|
|
582
572
|
else if (node.name.text === 'Relation') {
|
|
583
|
-
(0, assert_1.default)(!hasActionDef, "\u3010".concat(filename, "\u3011action\u5B9A\u4E49\u987B\u5728Relation\u4E4B\u540E"));
|
|
584
573
|
(0, assert_1.default)(!localeDef, "\u3010".concat(filename, "\u3011locale\u5B9A\u4E49\u987B\u5728Relation\u4E4B\u540E"));
|
|
585
|
-
// 增加userXXX对象的描述
|
|
586
574
|
var relationValues = [];
|
|
587
575
|
if (ts.isLiteralTypeNode(node.type)) {
|
|
588
576
|
(0, assert_1.default)(ts.isStringLiteral(node.type.literal));
|
|
@@ -597,39 +585,39 @@ function analyzeEntity(filename, path, program, relativePath) {
|
|
|
597
585
|
return ele.literal.text;
|
|
598
586
|
})), false));
|
|
599
587
|
}
|
|
600
|
-
var entityLc = (0, string_1.firstLetterLowerCase)(moduleName);
|
|
601
|
-
var relationEntityName = "User".concat(moduleName);
|
|
602
|
-
var relationSchemaAttrs = [
|
|
603
|
-
factory.createPropertySignature(undefined, factory.createIdentifier("user"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("User"), undefined)),
|
|
604
|
-
factory.createPropertySignature(undefined, factory.createIdentifier(entityLc), undefined, factory.createTypeReferenceNode(factory.createIdentifier(moduleName), undefined)),
|
|
605
|
-
factory.createPropertySignature(undefined, factory.createIdentifier('relation'), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Relation"), undefined)),
|
|
606
|
-
];
|
|
607
|
-
(0, lodash_1.assign)(Schema, (_d = {},
|
|
608
|
-
_d[relationEntityName] = {
|
|
609
|
-
schemaAttrs: relationSchemaAttrs,
|
|
610
|
-
sourceFile: sourceFile,
|
|
611
|
-
enumAttributes: {
|
|
612
|
-
relation: relationValues,
|
|
613
|
-
},
|
|
614
|
-
actionType: 'excludeUpdate',
|
|
615
|
-
additionalImports: [
|
|
616
|
-
factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("Relation"))])), factory.createStringLiteral("../".concat(moduleName, "/Schema")), undefined)
|
|
617
|
-
],
|
|
618
|
-
},
|
|
619
|
-
_d));
|
|
620
|
-
addRelationship(relationEntityName, 'User', 'user', true);
|
|
621
|
-
addRelationship(relationEntityName, moduleName, entityLc, true);
|
|
622
588
|
// 对UserEntityGrant对象,建立相应的反指关系
|
|
623
589
|
if (ReversePointerRelations['UserEntityGrant']) {
|
|
624
590
|
if (!ReversePointerRelations['UserEntityGrant'].includes(moduleName)) {
|
|
625
591
|
ReversePointerRelations['UserEntityGrant'].push(moduleName);
|
|
626
592
|
}
|
|
627
593
|
}
|
|
594
|
+
else {
|
|
595
|
+
(0, lodash_1.assign)(ReversePointerRelations, (_d = {},
|
|
596
|
+
_d['UserEntityGrant'] = [moduleName],
|
|
597
|
+
_d));
|
|
598
|
+
}
|
|
599
|
+
// 对Relation对象建立相应的反指关系
|
|
600
|
+
if (ReversePointerRelations['Relation']) {
|
|
601
|
+
if (!ReversePointerRelations['Relation'].includes(moduleName)) {
|
|
602
|
+
ReversePointerRelations['Relation'].push(moduleName);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
628
605
|
else {
|
|
629
606
|
(0, lodash_1.assign)(ReversePointerRelations, (_e = {},
|
|
630
|
-
_e['
|
|
607
|
+
_e['Relation'] = [moduleName],
|
|
631
608
|
_e));
|
|
632
609
|
}
|
|
610
|
+
// 对UserRelation对象建立相应的反指关系
|
|
611
|
+
if (ReversePointerRelations['UserRelation']) {
|
|
612
|
+
if (!ReversePointerRelations['UserRelation'].includes(moduleName)) {
|
|
613
|
+
ReversePointerRelations['UserRelation'].push(moduleName);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
else {
|
|
617
|
+
(0, lodash_1.assign)(ReversePointerRelations, (_f = {},
|
|
618
|
+
_f['UserRelation'] = [moduleName],
|
|
619
|
+
_f));
|
|
620
|
+
}
|
|
633
621
|
hasRelationDef = node;
|
|
634
622
|
}
|
|
635
623
|
else if (node.name.text.endsWith('Action') || node.name.text.endsWith('State')) {
|
|
@@ -656,145 +644,190 @@ function analyzeEntity(filename, path, program, relativePath) {
|
|
|
656
644
|
}
|
|
657
645
|
if (ts.isVariableStatement(node)) {
|
|
658
646
|
var declarations = node.declarationList.declarations;
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
(0, assert_1.default)(ts.isArrayLiteralExpression(
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
647
|
+
var dealWithActionDef_1 = function (declaration) {
|
|
648
|
+
checkActionDefNameConsistent(filename, declaration);
|
|
649
|
+
var typeArguments = declaration.type.typeArguments;
|
|
650
|
+
(0, assert_1.default)(typeArguments.length === 2);
|
|
651
|
+
var _a = tslib_1.__read(typeArguments, 2), actionNode = _a[0], stateNode = _a[1];
|
|
652
|
+
(0, assert_1.default)(ts.isTypeReferenceNode(actionNode));
|
|
653
|
+
(0, assert_1.default)(ts.isTypeReferenceNode(stateNode));
|
|
654
|
+
(0, assert_1.default)(getStringEnumValues(filename, program, 'action', actionNode), "\u6587\u4EF6".concat(filename, "\u4E2D\u7684action").concat(actionNode.typeName.text, "\u5B9A\u4E49\u4E0D\u662F\u5B57\u7B26\u4E32\u7C7B\u578B"));
|
|
655
|
+
var enumStateValues = getStringEnumValues(filename, program, 'state', stateNode);
|
|
656
|
+
(0, assert_1.default)(enumStateValues, "\u6587\u4EF6".concat(filename, "\u4E2D\u7684state").concat(stateNode.typeName.text, "\u5B9A\u4E49\u4E0D\u662F\u5B57\u7B26\u4E32\u7C7B\u578B"));
|
|
657
|
+
pushStatementIntoActionAst(moduleName, node, sourceFile);
|
|
658
|
+
(0, assert_1.default)(ts.isIdentifier(declaration.name));
|
|
659
|
+
var adName = declaration.name.text.slice(0, declaration.name.text.length - 9);
|
|
660
|
+
var attr = adName.concat('State');
|
|
661
|
+
schemaAttrs.push(factory.createPropertySignature(undefined, (0, string_1.firstLetterLowerCase)(attr), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(attr)));
|
|
662
|
+
enumAttributes[(0, string_1.firstLetterLowerCase)(attr)] = enumStateValues;
|
|
663
|
+
};
|
|
664
|
+
var dealWithIndexes_1 = function (declaration) {
|
|
665
|
+
var indexNameDict = {};
|
|
666
|
+
// 检查索引的属性是否合法
|
|
667
|
+
var elements = declaration.elements;
|
|
668
|
+
elements.forEach(function (ele) {
|
|
669
|
+
var _a;
|
|
670
|
+
var isFulltextIndex = false;
|
|
671
|
+
(0, assert_1.default)(ts.isObjectLiteralExpression(ele));
|
|
672
|
+
var properties = ele.properties;
|
|
673
|
+
var attrProperty = properties.find(function (ele2) {
|
|
674
|
+
(0, assert_1.default)(ts.isPropertyAssignment(ele2));
|
|
675
|
+
return ele2.name.getText() === 'attributes';
|
|
676
|
+
});
|
|
677
|
+
(0, assert_1.default)(ts.isArrayLiteralExpression(attrProperty.initializer));
|
|
678
|
+
var nameProperty = properties.find(function (ele2) {
|
|
679
|
+
(0, assert_1.default)(ts.isPropertyAssignment(ele2));
|
|
680
|
+
return ele2.name.getText() === 'name';
|
|
681
|
+
});
|
|
682
|
+
(0, assert_1.default)(ts.isStringLiteral(nameProperty.initializer));
|
|
683
|
+
var nameText = nameProperty.initializer.text;
|
|
684
|
+
if (indexNameDict[nameText]) {
|
|
685
|
+
throw new Error("\u300C".concat(filename, "\u300D\u7D22\u5F15\u5B9A\u4E49\u91CD\u540D\u300C").concat(nameText, "\u300D"));
|
|
686
|
+
}
|
|
687
|
+
(0, lodash_1.assign)(indexNameDict, (_a = {},
|
|
688
|
+
_a[nameText] = true,
|
|
689
|
+
_a));
|
|
690
|
+
var configProperty = properties.find(function (ele2) {
|
|
691
|
+
(0, assert_1.default)(ts.isPropertyAssignment(ele2));
|
|
692
|
+
return ele2.name.getText() === 'config';
|
|
693
|
+
});
|
|
694
|
+
if (configProperty) {
|
|
695
|
+
(0, assert_1.default)(ts.isObjectLiteralExpression(configProperty.initializer));
|
|
696
|
+
var properties2 = configProperty.initializer.properties;
|
|
697
|
+
var typeProperty = properties2.find(function (ele2) {
|
|
704
698
|
(0, assert_1.default)(ts.isPropertyAssignment(ele2));
|
|
705
|
-
return ele2.name.getText() === '
|
|
699
|
+
return ele2.name.getText() === 'type';
|
|
706
700
|
});
|
|
707
|
-
(
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
701
|
+
if (typeProperty && typeProperty.initializer.text === 'fulltext') {
|
|
702
|
+
// 定义了全文索引
|
|
703
|
+
if (hasFulltextIndex) {
|
|
704
|
+
throw new Error("\u300C".concat(filename, "\u300D\u53EA\u80FD\u5B9A\u4E49\u4E00\u4E2A\u5168\u6587\u7D22\u5F15"));
|
|
705
|
+
}
|
|
706
|
+
hasFulltextIndex = true;
|
|
707
|
+
isFulltextIndex = true;
|
|
711
708
|
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
709
|
+
}
|
|
710
|
+
var elements = attrProperty.initializer.elements;
|
|
711
|
+
// 每个属性都应该在schema中有值,且对象类型是可索引值
|
|
712
|
+
elements.forEach(function (ele2) {
|
|
713
|
+
(0, assert_1.default)(ts.isObjectLiteralExpression(ele2));
|
|
714
|
+
var properties2 = ele2.properties;
|
|
715
|
+
var nameProperty = properties2.find(function (ele3) {
|
|
716
|
+
(0, assert_1.default)(ts.isPropertyAssignment(ele3));
|
|
717
|
+
return ele3.name.getText() === 'name';
|
|
718
718
|
});
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
var
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
return ele2.name.getText() === 'type';
|
|
719
|
+
var indexAttrName = nameProperty.initializer.text;
|
|
720
|
+
if (!Entity_1.initinctiveAttributes.includes(indexAttrName)) {
|
|
721
|
+
var schemaNode = schemaAttrs.find(function (ele3) {
|
|
722
|
+
(0, assert_1.default)(ts.isPropertySignature(ele3));
|
|
723
|
+
return ele3.name.text === indexAttrName;
|
|
725
724
|
});
|
|
726
|
-
if (
|
|
727
|
-
|
|
728
|
-
if (hasFulltextIndex) {
|
|
729
|
-
throw new Error("\u300C".concat(filename, "\u300D\u53EA\u80FD\u5B9A\u4E49\u4E00\u4E2A\u5168\u6587\u7D22\u5F15"));
|
|
730
|
-
}
|
|
731
|
-
hasFulltextIndex = true;
|
|
732
|
-
isFulltextIndex = true;
|
|
725
|
+
if (!schemaNode) {
|
|
726
|
+
throw new Error("\u300C".concat(filename, "\u300D\u4E2D\u7D22\u5F15\u300C").concat(nameText, "\u300D\u7684\u5C5E\u6027\u300C").concat(indexAttrName, "\u300D\u5B9A\u4E49\u975E\u6CD5"));
|
|
733
727
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
if (!schemaNode) {
|
|
751
|
-
throw new Error("\u300C".concat(filename, "\u300D\u4E2D\u7D22\u5F15\u300C").concat(nameText, "\u300D\u7684\u5C5E\u6027\u300C").concat(indexAttrName, "\u300D\u5B9A\u4E49\u975E\u6CD5"));
|
|
752
|
-
}
|
|
753
|
-
var type = schemaNode.type, name_1 = schemaNode.name;
|
|
754
|
-
var entity = moduleName;
|
|
755
|
-
var _a = ManyToOne, _b = entity, manyToOneSet = _a[_b];
|
|
756
|
-
if (ts.isTypeReferenceNode(type)) {
|
|
757
|
-
var typeName = type.typeName;
|
|
758
|
-
if (ts.isIdentifier(typeName)) {
|
|
759
|
-
var text = typeName.text;
|
|
760
|
-
var text2_1 = text === 'Schema' ? entity : text;
|
|
761
|
-
var manyToOneItem = manyToOneSet && manyToOneSet.find(function (_a) {
|
|
762
|
-
var _b = tslib_1.__read(_a, 2), refEntity = _b[0], attrName = _b[1];
|
|
763
|
-
return refEntity === text2_1 && attrName === name_1.text;
|
|
764
|
-
});
|
|
765
|
-
if (!manyToOneItem) {
|
|
766
|
-
// 如果不是外键,则不能是Text, File
|
|
767
|
-
if (isFulltextIndex) {
|
|
768
|
-
(0, assert_1.default)(['Text', 'String'].includes(text2_1), "\u300C".concat(filename, "\u300D\u4E2D\u5168\u6587\u7D22\u5F15\u300C").concat(nameText, "\u300D\u5B9A\u4E49\u7684\u5C5E\u6027\u300C").concat(indexAttrName, "\u300D\u7C7B\u578B\u975E\u6CD5\uFF0C\u53EA\u80FD\u662FText/String"));
|
|
769
|
-
}
|
|
770
|
-
else {
|
|
771
|
-
(0, assert_1.default)(!DataType_1.unIndexedTypes.includes(text2_1), "\u300C".concat(filename, "\u300D\u4E2D\u7D22\u5F15\u300C").concat(nameText, "\u300D\u7684\u5C5E\u6027\u300C").concat(indexAttrName, "\u300D\u7684\u7C7B\u578B\u4E3A\u300C").concat(text2_1, "\u300D\uFF0C\u4E0D\u53EF\u7D22\u5F15"));
|
|
772
|
-
}
|
|
728
|
+
var type = schemaNode.type, name_1 = schemaNode.name;
|
|
729
|
+
var entity = moduleName;
|
|
730
|
+
var _a = ManyToOne, _b = entity, manyToOneSet = _a[_b];
|
|
731
|
+
if (ts.isTypeReferenceNode(type)) {
|
|
732
|
+
var typeName = type.typeName;
|
|
733
|
+
if (ts.isIdentifier(typeName)) {
|
|
734
|
+
var text = typeName.text;
|
|
735
|
+
var text2_1 = text === 'Schema' ? entity : text;
|
|
736
|
+
var manyToOneItem = manyToOneSet && manyToOneSet.find(function (_a) {
|
|
737
|
+
var _b = tslib_1.__read(_a, 2), refEntity = _b[0], attrName = _b[1];
|
|
738
|
+
return refEntity === text2_1 && attrName === name_1.text;
|
|
739
|
+
});
|
|
740
|
+
if (!manyToOneItem) {
|
|
741
|
+
// 如果不是外键,则不能是Text, File
|
|
742
|
+
if (isFulltextIndex) {
|
|
743
|
+
(0, assert_1.default)(['Text', 'String'].includes(text2_1), "\u300C".concat(filename, "\u300D\u4E2D\u5168\u6587\u7D22\u5F15\u300C").concat(nameText, "\u300D\u5B9A\u4E49\u7684\u5C5E\u6027\u300C").concat(indexAttrName, "\u300D\u7C7B\u578B\u975E\u6CD5\uFF0C\u53EA\u80FD\u662FText/String"));
|
|
773
744
|
}
|
|
774
745
|
else {
|
|
775
|
-
(0, assert_1.default)(!
|
|
776
|
-
// 在这里把外键加上Id,这样storageSchema才能正常通过
|
|
777
|
-
// 这里的写法不太好,未来TS版本高了可能会有问题。by Xc 20230131
|
|
778
|
-
Object.assign(nameProperty, {
|
|
779
|
-
initializer: factory.createStringLiteral("".concat(indexAttrName, "Id")),
|
|
780
|
-
});
|
|
746
|
+
(0, assert_1.default)(!DataType_1.unIndexedTypes.includes(text2_1), "\u300C".concat(filename, "\u300D\u4E2D\u7D22\u5F15\u300C").concat(nameText, "\u300D\u7684\u5C5E\u6027\u300C").concat(indexAttrName, "\u300D\u7684\u7C7B\u578B\u4E3A\u300C").concat(text2_1, "\u300D\uFF0C\u4E0D\u53EF\u7D22\u5F15"));
|
|
781
747
|
}
|
|
782
748
|
}
|
|
783
749
|
else {
|
|
784
|
-
(0, assert_1.default)(
|
|
750
|
+
(0, assert_1.default)(!isFulltextIndex, "\u300C".concat(filename, "\u300D\u4E2D\u5168\u6587\u7D22\u5F15\u300C").concat(nameText, "\u300D\u7684\u5C5E\u6027\u300C").concat(indexAttrName, "\u300D\u7C7B\u578B\u975E\u6CD5\uFF0C\u53EA\u80FD\u4E3AText/String"));
|
|
751
|
+
// 在这里把外键加上Id,这样storageSchema才能正常通过
|
|
752
|
+
// 这里的写法不太好,未来TS版本高了可能会有问题。by Xc 20230131
|
|
753
|
+
Object.assign(nameProperty, {
|
|
754
|
+
initializer: factory.createStringLiteral("".concat(indexAttrName, "Id")),
|
|
755
|
+
});
|
|
785
756
|
}
|
|
786
757
|
}
|
|
787
758
|
else {
|
|
788
|
-
(0, assert_1.default)(
|
|
789
|
-
(0, assert_1.default)(ts.isUnionTypeNode(type) || ts.isLiteralTypeNode(type), "".concat(entity, "\u4E2D\u7D22\u5F15\u300C").concat(nameText, "\u300D\u7684\u5C5E\u6027").concat(name_1.text, "\u6709\u5B9A\u4E49\u975E\u6CD5"));
|
|
759
|
+
(0, assert_1.default)(false); // 这是什么case,不确定
|
|
790
760
|
}
|
|
791
761
|
}
|
|
792
|
-
|
|
762
|
+
else {
|
|
763
|
+
(0, assert_1.default)(!isFulltextIndex, "\u300C".concat(filename, "\u300D\u4E2D\u5168\u6587\u7D22\u5F15\u300C").concat(nameText, "\u300D\u7684\u5C5E\u6027\u300C").concat(indexAttrName, "\u300D\u7C7B\u578B\u53EA\u80FD\u4E3AText/String"));
|
|
764
|
+
(0, assert_1.default)(ts.isUnionTypeNode(type) || ts.isLiteralTypeNode(type), "".concat(entity, "\u4E2D\u7D22\u5F15\u300C").concat(nameText, "\u300D\u7684\u5C5E\u6027").concat(name_1.text, "\u6709\u5B9A\u4E49\u975E\u6CD5"));
|
|
765
|
+
}
|
|
766
|
+
}
|
|
793
767
|
});
|
|
794
|
-
|
|
768
|
+
});
|
|
769
|
+
indexes = declaration;
|
|
770
|
+
};
|
|
771
|
+
var dealWithLocales_1 = function (declaration) {
|
|
772
|
+
if (hasActionDef) {
|
|
773
|
+
// 检查每种locale定义中都应该有'action'域
|
|
774
|
+
checkLocaleExpressionPropertyExists(declaration, 'action', true, filename);
|
|
775
|
+
}
|
|
776
|
+
else {
|
|
777
|
+
checkLocaleExpressionPropertyExists(declaration, 'action', false, filename);
|
|
778
|
+
}
|
|
779
|
+
if (hasRelationDef) {
|
|
780
|
+
// 检查每种locale定义中都应该有'r'域
|
|
781
|
+
checkLocaleExpressionPropertyExists(declaration, 'r', true, filename);
|
|
782
|
+
}
|
|
783
|
+
else {
|
|
784
|
+
checkLocaleExpressionPropertyExists(declaration, 'r', false, filename);
|
|
785
|
+
}
|
|
786
|
+
var allEnumStringAttrs = Object.keys(enumAttributes);
|
|
787
|
+
if (allEnumStringAttrs.length > 0) {
|
|
788
|
+
// 检查每种locale定义中都应该有'v'域
|
|
789
|
+
checkLocaleExpressionPropertyExists(declaration, 'v', true, filename);
|
|
790
|
+
}
|
|
791
|
+
else {
|
|
792
|
+
// 检查每种locale定义中都应该有'v'域
|
|
793
|
+
checkLocaleExpressionPropertyExists(declaration, 'v', false, filename);
|
|
794
|
+
}
|
|
795
|
+
localeDef = declaration;
|
|
796
|
+
};
|
|
797
|
+
var dealWithConfiguration_1 = function (declaration) {
|
|
798
|
+
// assert(!hasActionDef, `${moduleName}中的Configuration定义在Action之后`);
|
|
799
|
+
var properties = declaration.properties;
|
|
800
|
+
var atProperty = properties.find(function (ele) { return ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'actionType'; });
|
|
801
|
+
var staticProperty = properties.find(function (ele) { return ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'static'; });
|
|
802
|
+
if (atProperty) {
|
|
803
|
+
actionType = atProperty.initializer.text;
|
|
804
|
+
}
|
|
805
|
+
if (staticProperty) {
|
|
806
|
+
_static = true; // static如果有值只能为true
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
declarations.forEach(function (declaration) {
|
|
810
|
+
if (declaration.type && ts.isTypeReferenceNode(declaration.type) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'ActionDef') {
|
|
811
|
+
dealWithActionDef_1(declaration);
|
|
812
|
+
}
|
|
813
|
+
else if (declaration.type && (ts.isArrayTypeNode(declaration.type)
|
|
814
|
+
&& ts.isTypeReferenceNode(declaration.type.elementType)
|
|
815
|
+
&& ts.isIdentifier(declaration.type.elementType.typeName)
|
|
816
|
+
&& declaration.type.elementType.typeName.text === 'Index'
|
|
817
|
+
|| ts.isTypeReferenceNode(declaration.type)
|
|
818
|
+
&& ts.isIdentifier(declaration.type.typeName)
|
|
819
|
+
&& declaration.type.typeName.text === 'Array'
|
|
820
|
+
&& ts.isTypeReferenceNode(declaration.type.typeArguments[0])
|
|
821
|
+
&& ts.isIdentifier(declaration.type.typeArguments[0].typeName)
|
|
822
|
+
&& declaration.type.typeArguments[0].typeName.text === 'Index')) {
|
|
823
|
+
// 对索引Index的定义
|
|
824
|
+
console.log("\u300C".concat(filename, "\u300D\u76F4\u63A5\u5B9A\u4E49indexes\u7684\u5199\u6CD5\u5DF2\u7ECF\u8FC7\u65F6\uFF0C\u8BF7\u5B9A\u4E49\u5728entityDesc\u4E2D"));
|
|
825
|
+
(0, assert_1.default)(ts.isArrayLiteralExpression(declaration.initializer));
|
|
826
|
+
dealWithIndexes_1(declaration.initializer);
|
|
795
827
|
}
|
|
796
828
|
else if (declaration.type && ts.isTypeReferenceNode(declaration.type) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'LocaleDef') {
|
|
797
829
|
// locale定义
|
|
830
|
+
console.log("\u300C".concat(filename, "\u300D\u76F4\u63A5\u5B9A\u4E49locales\u7684\u5199\u6CD5\u5DF2\u7ECF\u8FC7\u65F6\uFF0C\u8BF7\u5B9A\u4E49\u5728entityDesc\u4E2D"));
|
|
798
831
|
var type = declaration.type, initializer = declaration.initializer;
|
|
799
832
|
(0, assert_1.default)(ts.isObjectLiteralExpression(initializer));
|
|
800
833
|
var properties = initializer.properties;
|
|
@@ -807,73 +840,72 @@ function analyzeEntity(filename, path, program, relativePath) {
|
|
|
807
840
|
if (hasActionDef) {
|
|
808
841
|
(0, assert_1.default)(ts.isTypeReferenceNode(typeArguments[1])
|
|
809
842
|
&& ts.isIdentifier(typeArguments[1].typeName) && typeArguments[1].typeName.text === 'Action', "".concat(filename, "\u4E2Dlocale\u7C7B\u578B\u5B9A\u4E49\u7684\u7B2C\u4E8C\u4E2A\u53C2\u6570\u4E0D\u662FAction"));
|
|
810
|
-
// 检查每种locale定义中都应该有'action'域
|
|
811
|
-
checkLocaleExpressionPropertyExists(initializer, 'action', true, filename);
|
|
812
843
|
}
|
|
813
844
|
else {
|
|
814
845
|
(0, assert_1.default)(ts.isLiteralTypeNode(typeArguments[1])
|
|
815
846
|
&& ts.isStringLiteral(typeArguments[1].literal), "".concat(filename, "\u4E2Dlocale\u7C7B\u578B\u5B9A\u4E49\u7684\u7B2C\u4E8C\u4E2A\u53C2\u6570\u4E0D\u662F\u5B57\u7B26\u4E32"));
|
|
816
|
-
checkLocaleExpressionPropertyExists(initializer, 'action', false, filename);
|
|
817
847
|
}
|
|
818
848
|
if (hasRelationDef) {
|
|
819
849
|
(0, assert_1.default)(ts.isTypeReferenceNode(typeArguments[2])
|
|
820
850
|
&& ts.isIdentifier(typeArguments[2].typeName)
|
|
821
851
|
&& typeArguments[2].typeName.text === 'Relation', "".concat(filename, "\u4E2D\u7684locale\u7C7B\u578B\u5B9A\u4E49\u7684\u7B2C\u4E09\u4E2A\u53C2\u6570\u4E0D\u662FRelation"));
|
|
822
|
-
// 检查每种locale定义中都应该有'r'域
|
|
823
|
-
checkLocaleExpressionPropertyExists(initializer, 'r', true, filename);
|
|
824
852
|
}
|
|
825
853
|
else {
|
|
826
854
|
(0, assert_1.default)(ts.isLiteralTypeNode(typeArguments[2])
|
|
827
855
|
&& ts.isStringLiteral(typeArguments[2].literal), "".concat(filename, "\u4E2Dlocale\u7C7B\u578B\u5B9A\u4E49\u7684\u7B2C\u4E09\u4E2A\u53C2\u6570\u4E0D\u662F\u7A7A\u5B57\u7B26\u4E32"));
|
|
828
|
-
checkLocaleExpressionPropertyExists(initializer, 'r', false, filename);
|
|
829
856
|
}
|
|
830
857
|
if (allEnumStringAttrs.length > 0) {
|
|
831
858
|
(0, assert_1.default)(ts.isTypeLiteralNode(typeArguments[3]), "".concat(filename, "\u4E2D\u7684locale\u7C7B\u578B\u5B9A\u4E49\u7684\u7B2C\u56DB\u4E2A\u53C2\u6570\u4E0D\u662F{}"));
|
|
832
859
|
checkLocaleEnumAttrs(typeArguments[3], allEnumStringAttrs, filename);
|
|
833
|
-
// 检查每种locale定义中都应该有'v'域
|
|
834
|
-
checkLocaleExpressionPropertyExists(initializer, 'v', true, filename);
|
|
835
860
|
}
|
|
836
861
|
else {
|
|
837
862
|
(0, assert_1.default)(ts.isTypeLiteralNode(typeArguments[3]), "".concat(filename, "\u4E2D\u7684locale\u7C7B\u578B\u5B9A\u4E49\u7684\u7B2C\u56DB\u4E2A\u53C2\u6570\u4E0D\u662F{}"));
|
|
838
863
|
(0, assert_1.default)(typeArguments[3].members.length == 0, "".concat(filename, "\u4E2Dlocale\u7C7B\u578B\u5B9A\u4E49\u7684\u7B2C\u56DB\u4E2A\u53C2\u6570\u4E0D\u5E94\u5B58\u5728\u76F8\u5E94\u7684v\u5B9A\u4E49"));
|
|
839
|
-
// 检查每种locale定义中都应该有'v'域
|
|
840
|
-
checkLocaleExpressionPropertyExists(initializer, 'v', false, filename);
|
|
841
864
|
}
|
|
842
|
-
|
|
865
|
+
dealWithLocales_1(initializer);
|
|
843
866
|
}
|
|
844
867
|
else if (declaration.type && ts.isTypeReferenceNode(declaration.type) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'Configuration') {
|
|
845
|
-
|
|
868
|
+
console.log("\u300C".concat(filename, "\u300D\u76F4\u63A5\u5B9A\u4E49configuration\u7684\u5199\u6CD5\u5DF2\u7ECF\u8FC7\u65F6\uFF0C\u8BF7\u5B9A\u4E49\u5728entityDesc\u4E2D"));
|
|
869
|
+
(0, assert_1.default)(ts.isObjectLiteralExpression(declaration.initializer));
|
|
870
|
+
dealWithConfiguration_1(declaration.initializer);
|
|
871
|
+
}
|
|
872
|
+
else if (declaration.type && ts.isTypeReferenceNode(declaration.type) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'EntityDesc') {
|
|
846
873
|
(0, assert_1.default)(ts.isObjectLiteralExpression(declaration.initializer));
|
|
847
874
|
var properties = declaration.initializer.properties;
|
|
848
|
-
var
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
relationHierarchy = initializer;
|
|
863
|
-
}
|
|
864
|
-
else if (ts.isTypeReferenceNode(declaration.type!) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'ReverseCascadeRelationHierarchy') {
|
|
865
|
-
// ReverseCascadeRelationHierarchy
|
|
866
|
-
assert(hasRelationDef, `${moduleName}中的Relation定义在ReverseCascadeRelationHierarchy之后`);
|
|
867
|
-
const { initializer } = declaration;
|
|
868
|
-
assert(ts.isObjectLiteralExpression(initializer!), `${moduleName}中的RelationHierarchy的定义必须是初始化为ObjectLiteralExpress`);
|
|
869
|
-
reverseCascadeRelationHierarchy = initializer;
|
|
870
|
-
} */
|
|
875
|
+
var localesProperty = properties.find(function (ele) { return ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'locales'; });
|
|
876
|
+
(0, assert_1.default)(ts.isPropertyAssignment(localesProperty));
|
|
877
|
+
dealWithLocales_1(localesProperty.initializer);
|
|
878
|
+
var indexesProperty = properties.find(function (ele) { return ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'indexes'; });
|
|
879
|
+
if (indexesProperty) {
|
|
880
|
+
(0, assert_1.default)(ts.isPropertyAssignment(indexesProperty));
|
|
881
|
+
dealWithIndexes_1(indexesProperty.initializer);
|
|
882
|
+
}
|
|
883
|
+
var configurationProperty = properties.find(function (ele) { return ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'configuration'; });
|
|
884
|
+
if (configurationProperty) {
|
|
885
|
+
(0, assert_1.default)(ts.isPropertyAssignment(configurationProperty));
|
|
886
|
+
dealWithConfiguration_1(configurationProperty.initializer);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
871
889
|
else {
|
|
872
890
|
throw new Error("".concat(moduleName, "\uFF1A\u4E0D\u80FD\u7406\u89E3\u7684\u5B9A\u4E49\u5185\u5BB9").concat(declaration.name.text));
|
|
873
891
|
}
|
|
874
892
|
});
|
|
875
893
|
}
|
|
876
894
|
});
|
|
895
|
+
// 要等configuration确定了actionType后再处理
|
|
896
|
+
if (hasActionDef) {
|
|
897
|
+
var actionDefNodes = [
|
|
898
|
+
factory.createTypeReferenceNode(OriginActionDict[actionType], undefined),
|
|
899
|
+
factory.createTypeReferenceNode('ParticularAction', undefined)
|
|
900
|
+
];
|
|
901
|
+
if (moduleName === 'User') {
|
|
902
|
+
actionDefNodes.push(factory.createTypeReferenceNode('RelationAction', undefined));
|
|
903
|
+
}
|
|
904
|
+
if (process.env.COMPLING_AS_LIB) {
|
|
905
|
+
actionDefNodes.push(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
|
|
906
|
+
}
|
|
907
|
+
pushStatementIntoActionAst(moduleName, factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Action"), undefined, factory.createUnionTypeNode(actionDefNodes)), sourceFile);
|
|
908
|
+
}
|
|
877
909
|
if (!hasActionDef && hasActionOrStateDef) {
|
|
878
910
|
throw new Error("".concat(filename, "\u4E2D\u6709Action\u6216State\u5B9A\u4E49\uFF0C\u4F46\u6CA1\u6709\u5B9A\u4E49\u5B8C\u6574\u7684Action\u7C7B\u578B"));
|
|
879
911
|
}
|
|
@@ -1097,13 +1129,18 @@ function constructSchema(statements, entity) {
|
|
|
1097
1129
|
* @param entity
|
|
1098
1130
|
*/
|
|
1099
1131
|
function constructFilter(statements, entity) {
|
|
1100
|
-
var e_3, _a;
|
|
1101
|
-
var
|
|
1132
|
+
var e_3, _a, e_4, _b;
|
|
1133
|
+
var _c = Schema[entity], schemaAttrs = _c.schemaAttrs, fulltextIndex = _c.fulltextIndex, enumAttributes = _c.enumAttributes;
|
|
1102
1134
|
var members = [
|
|
1103
1135
|
// id: Q_StringValue
|
|
1104
1136
|
factory.createPropertySignature(undefined, factory.createIdentifier('id'), undefined, factory.createUnionTypeNode([
|
|
1105
1137
|
factory.createTypeReferenceNode(factory.createIdentifier('Q_StringValue')),
|
|
1106
|
-
factory.createTypeReferenceNode(
|
|
1138
|
+
/* factory.createTypeReferenceNode(
|
|
1139
|
+
factory.createQualifiedName(
|
|
1140
|
+
factory.createIdentifier("SubQuery"),
|
|
1141
|
+
factory.createIdentifier(`${entity}IdSubQuery`)
|
|
1142
|
+
)
|
|
1143
|
+
) */
|
|
1107
1144
|
])),
|
|
1108
1145
|
// $$createAt$$: Q_DateValue
|
|
1109
1146
|
factory.createPropertySignature(undefined, factory.createIdentifier('$$createAt$$'), undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_DateValue'))),
|
|
@@ -1112,9 +1149,13 @@ function constructFilter(statements, entity) {
|
|
|
1112
1149
|
// $$updateAt$$: Q_DateValue
|
|
1113
1150
|
factory.createPropertySignature(undefined, factory.createIdentifier('$$updateAt$$'), undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_DateValue')))
|
|
1114
1151
|
];
|
|
1115
|
-
var
|
|
1152
|
+
var _d = ManyToOne, _e = entity, manyToOneSet = _d[_e];
|
|
1153
|
+
var entityUnionTypeNodes = ReversePointerRelations[entity] && ReversePointerRelations[entity].map(function (ele) { return factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(ele))); });
|
|
1154
|
+
if (process.env.COMPLING_AS_LIB) {
|
|
1155
|
+
entityUnionTypeNodes && entityUnionTypeNodes.push(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
|
|
1156
|
+
}
|
|
1116
1157
|
var _loop_3 = function (attr) {
|
|
1117
|
-
var
|
|
1158
|
+
var _j = attr, type = _j.type, name_3 = _j.name;
|
|
1118
1159
|
var attrName = name_3.text;
|
|
1119
1160
|
if (ts.isTypeReferenceNode(type)) {
|
|
1120
1161
|
var typeName = type.typeName;
|
|
@@ -1127,7 +1168,9 @@ function constructFilter(statements, entity) {
|
|
|
1127
1168
|
case 'Image':
|
|
1128
1169
|
case 'File': {
|
|
1129
1170
|
if (ReversePointerRelations[entity] && attrName === 'entity') {
|
|
1130
|
-
type2 = factory.createTypeReferenceNode('
|
|
1171
|
+
type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_EnumValue'), [
|
|
1172
|
+
factory.createUnionTypeNode(entityUnionTypeNodes)
|
|
1173
|
+
]);
|
|
1131
1174
|
}
|
|
1132
1175
|
else {
|
|
1133
1176
|
type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_StringValue'));
|
|
@@ -1167,19 +1210,22 @@ function constructFilter(statements, entity) {
|
|
|
1167
1210
|
});
|
|
1168
1211
|
if (manyToOneItem) {
|
|
1169
1212
|
// 外键可能落到相应的子查询中
|
|
1170
|
-
members.push(factory.createPropertySignature(undefined, "".concat(name_3.text, "Id"), undefined, factory.
|
|
1171
|
-
factory.createTypeReferenceNode(factory.createIdentifier('Q_StringValue')),
|
|
1172
|
-
factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier("SubQuery"), factory.createIdentifier("".concat(text2_3, "IdSubQuery"))), undefined)
|
|
1173
|
-
])));
|
|
1213
|
+
members.push(factory.createPropertySignature(undefined, "".concat(name_3.text, "Id"), undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_StringValue'))));
|
|
1174
1214
|
type2 = factory.createTypeReferenceNode(createForeignRef(entity, text2_3, 'Filter'));
|
|
1175
1215
|
}
|
|
1176
|
-
else {
|
|
1216
|
+
else if (enumAttributes && enumAttributes[attrName] || ts.isUnionTypeNode(type)) {
|
|
1177
1217
|
// 这里应该都是引用某个UnionType类型的定义了,如何判断?
|
|
1178
1218
|
// const words = getStringTextFromUnionStringLiterals();
|
|
1179
1219
|
type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_EnumValue'), [
|
|
1180
1220
|
factory.createTypeReferenceNode(factory.createIdentifier(text), undefined)
|
|
1181
1221
|
]);
|
|
1182
1222
|
}
|
|
1223
|
+
else {
|
|
1224
|
+
// 非枚举类型的非结构化属性,用JSONFilter来形式化
|
|
1225
|
+
type2 = factory.createTypeReferenceNode(factory.createIdentifier('JsonFilter'), [
|
|
1226
|
+
factory.createTypeReferenceNode(factory.createIdentifier(text), undefined)
|
|
1227
|
+
]);
|
|
1228
|
+
}
|
|
1183
1229
|
}
|
|
1184
1230
|
}
|
|
1185
1231
|
if (type2) {
|
|
@@ -1194,6 +1240,10 @@ function constructFilter(statements, entity) {
|
|
|
1194
1240
|
}
|
|
1195
1241
|
else {
|
|
1196
1242
|
// 此时应当是引用本地定义的shape
|
|
1243
|
+
(0, assert_1.default)(type);
|
|
1244
|
+
members.push(factory.createPropertySignature(undefined, name_3, undefined, factory.createTypeReferenceNode(factory.createIdentifier('JsonFilter'), [
|
|
1245
|
+
type
|
|
1246
|
+
])));
|
|
1197
1247
|
}
|
|
1198
1248
|
};
|
|
1199
1249
|
try {
|
|
@@ -1216,13 +1266,44 @@ function constructFilter(statements, entity) {
|
|
|
1216
1266
|
return members.push(factory.createPropertySignature(undefined, (0, string_1.firstLetterLowerCase)(ele), undefined, factory.createTypeReferenceNode(createForeignRef(entity, ele, 'Filter'))));
|
|
1217
1267
|
});
|
|
1218
1268
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1269
|
+
// 一对多的生成子查询
|
|
1270
|
+
var _f = OneToMany, _g = entity, oneToManySet = _f[_g];
|
|
1271
|
+
if (oneToManySet) {
|
|
1272
|
+
var foreignKeySet = {};
|
|
1273
|
+
try {
|
|
1274
|
+
for (var oneToManySet_2 = tslib_1.__values(oneToManySet), oneToManySet_2_1 = oneToManySet_2.next(); !oneToManySet_2_1.done; oneToManySet_2_1 = oneToManySet_2.next()) {
|
|
1275
|
+
var oneToManyItem = oneToManySet_2_1.value;
|
|
1276
|
+
var _h = tslib_1.__read(oneToManyItem, 2), entityName = _h[0], foreignKey = _h[1];
|
|
1277
|
+
if (foreignKeySet.hasOwnProperty(entityName)) {
|
|
1278
|
+
foreignKeySet[entityName].push(foreignKey);
|
|
1279
|
+
}
|
|
1280
|
+
else {
|
|
1281
|
+
foreignKeySet[entityName] = [foreignKey];
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1286
|
+
finally {
|
|
1287
|
+
try {
|
|
1288
|
+
if (oneToManySet_2_1 && !oneToManySet_2_1.done && (_b = oneToManySet_2.return)) _b.call(oneToManySet_2);
|
|
1289
|
+
}
|
|
1290
|
+
finally { if (e_4) throw e_4.error; }
|
|
1291
|
+
}
|
|
1292
|
+
var _loop_4 = function (entityName) {
|
|
1293
|
+
var entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
|
|
1294
|
+
foreignKeySet[entityName].forEach(function (foreignKey) {
|
|
1295
|
+
var identifier = "".concat(entityNameLc, "$").concat(foreignKey);
|
|
1296
|
+
members.push(factory.createPropertySignature(undefined, identifier, undefined, factory.createIntersectionTypeNode([
|
|
1297
|
+
factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'Filter'), undefined),
|
|
1298
|
+
factory.createTypeReferenceNode('SubQueryPredicateMetadata')
|
|
1299
|
+
])));
|
|
1300
|
+
});
|
|
1301
|
+
};
|
|
1302
|
+
for (var entityName in foreignKeySet) {
|
|
1303
|
+
_loop_4(entityName);
|
|
1304
|
+
}
|
|
1222
1305
|
}
|
|
1223
|
-
statements.push(factory.createTypeAliasDeclaration(undefined, undefined, factory.createIdentifier('AttrFilter'),
|
|
1224
|
-
factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("E"), undefined)
|
|
1225
|
-
] : undefined, factory.createTypeLiteralNode(members)));
|
|
1306
|
+
statements.push(factory.createTypeAliasDeclaration(undefined, undefined, factory.createIdentifier('AttrFilter'), undefined, factory.createTypeLiteralNode(members)));
|
|
1226
1307
|
/**
|
|
1227
1308
|
*
|
|
1228
1309
|
export type Filter = AttrFilter | Partial<ExprOp<OpSchema> | {
|
|
@@ -1233,7 +1314,7 @@ function constructFilter(statements, entity) {
|
|
|
1233
1314
|
|
|
1234
1315
|
*/
|
|
1235
1316
|
var types = [
|
|
1236
|
-
factory.createTypeReferenceNode(factory.createIdentifier("AttrFilter")
|
|
1317
|
+
factory.createTypeReferenceNode(factory.createIdentifier("AttrFilter")),
|
|
1237
1318
|
factory.createTypeReferenceNode(factory.createIdentifier("ExprOp"), [
|
|
1238
1319
|
process.env.COMPLING_AS_LIB ?
|
|
1239
1320
|
factory.createUnionTypeNode([
|
|
@@ -1247,11 +1328,7 @@ function constructFilter(statements, entity) {
|
|
|
1247
1328
|
if (fulltextIndex) {
|
|
1248
1329
|
types.push(factory.createTypeReferenceNode('FulltextFilter'));
|
|
1249
1330
|
}
|
|
1250
|
-
statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Filter"),
|
|
1251
|
-
factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("E"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Q_EnumValue"), [
|
|
1252
|
-
factory.createUnionTypeNode(eumUnionTypeNode)
|
|
1253
|
-
]))
|
|
1254
|
-
] : undefined, factory.createTypeReferenceNode(factory.createIdentifier("MakeFilter"), [factory.createIntersectionTypeNode(types)])));
|
|
1331
|
+
statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Filter"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("MakeFilter"), [factory.createIntersectionTypeNode(types)])));
|
|
1255
1332
|
}
|
|
1256
1333
|
/**
|
|
1257
1334
|
* 构造Projection和OneAttrProjection
|
|
@@ -1259,8 +1336,8 @@ function constructFilter(statements, entity) {
|
|
|
1259
1336
|
* @param entity
|
|
1260
1337
|
*/
|
|
1261
1338
|
function constructProjection(statements, entity) {
|
|
1262
|
-
var _a,
|
|
1263
|
-
var
|
|
1339
|
+
var _a, e_5, _b, e_6, _c;
|
|
1340
|
+
var _d = Schema[entity], schemaAttrs = _d.schemaAttrs, enumAttributes = _d.enumAttributes;
|
|
1264
1341
|
var properties = [
|
|
1265
1342
|
['id', false],
|
|
1266
1343
|
['$$createAt$$', false],
|
|
@@ -1270,10 +1347,10 @@ function constructProjection(statements, entity) {
|
|
|
1270
1347
|
var foreignKeyProperties = (_a = {},
|
|
1271
1348
|
_a[entity] = [''],
|
|
1272
1349
|
_a);
|
|
1273
|
-
var
|
|
1274
|
-
var
|
|
1275
|
-
var
|
|
1276
|
-
var
|
|
1350
|
+
var _e = ManyToOne, _f = entity, manyToOneSet = _e[_f];
|
|
1351
|
+
var _loop_5 = function (attr) {
|
|
1352
|
+
var _k;
|
|
1353
|
+
var _l = attr, type = _l.type, name_4 = _l.name;
|
|
1277
1354
|
var attrName = name_4.text;
|
|
1278
1355
|
if (ts.isTypeReferenceNode(type)) {
|
|
1279
1356
|
var typeName = type.typeName;
|
|
@@ -1283,6 +1360,7 @@ function constructProjection(statements, entity) {
|
|
|
1283
1360
|
case 'String':
|
|
1284
1361
|
case 'Text':
|
|
1285
1362
|
case 'Int':
|
|
1363
|
+
case 'Uint':
|
|
1286
1364
|
case 'Float':
|
|
1287
1365
|
case 'Double':
|
|
1288
1366
|
case 'Boolean':
|
|
@@ -1291,11 +1369,17 @@ function constructProjection(statements, entity) {
|
|
|
1291
1369
|
case 'File':
|
|
1292
1370
|
case 'SingleGeo':
|
|
1293
1371
|
case 'Geo':
|
|
1294
|
-
case 'Object':
|
|
1295
1372
|
case 'Price': {
|
|
1296
1373
|
properties.push([name_4, false]);
|
|
1297
1374
|
break;
|
|
1298
1375
|
}
|
|
1376
|
+
case 'Object': {
|
|
1377
|
+
properties.push([name_4, false, factory.createUnionTypeNode([
|
|
1378
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
|
|
1379
|
+
factory.createTypeReferenceNode(factory.createIdentifier("Object"), undefined)
|
|
1380
|
+
])]);
|
|
1381
|
+
break;
|
|
1382
|
+
}
|
|
1299
1383
|
default: {
|
|
1300
1384
|
var text2_4 = text === 'Schema' ? entity : text;
|
|
1301
1385
|
var manyToOneItem = manyToOneSet && manyToOneSet.find(function (_a) {
|
|
@@ -1312,18 +1396,21 @@ function constructProjection(statements, entity) {
|
|
|
1312
1396
|
foreignKeyProperties[text2_4].push(attrName);
|
|
1313
1397
|
}
|
|
1314
1398
|
else {
|
|
1315
|
-
(0, lodash_1.assign)(foreignKeyProperties, (
|
|
1316
|
-
|
|
1317
|
-
|
|
1399
|
+
(0, lodash_1.assign)(foreignKeyProperties, (_k = {},
|
|
1400
|
+
_k[text2_4] = [attrName],
|
|
1401
|
+
_k));
|
|
1318
1402
|
}
|
|
1319
1403
|
}
|
|
1320
1404
|
else {
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
properties.push([name_4, false,
|
|
1405
|
+
if (!enumAttributes || !enumAttributes[attrName]) {
|
|
1406
|
+
// 引用的非enum类型shape
|
|
1407
|
+
properties.push([name_4, false, factory.createUnionTypeNode([
|
|
1408
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
|
|
1409
|
+
factory.createTypeReferenceNode(factory.createIdentifier("JsonProjection"), [type])
|
|
1410
|
+
])]);
|
|
1324
1411
|
}
|
|
1325
1412
|
else {
|
|
1326
|
-
// 引用的shape
|
|
1413
|
+
// 引用的enum类型shape
|
|
1327
1414
|
properties.push([name_4, false, undefined]);
|
|
1328
1415
|
}
|
|
1329
1416
|
}
|
|
@@ -1337,21 +1424,30 @@ function constructProjection(statements, entity) {
|
|
|
1337
1424
|
else {
|
|
1338
1425
|
// 增加了本身object的shape定义
|
|
1339
1426
|
// assert(ts.isUnionTypeNode(type!) && ts.isLiteralTypeNode(type.types[0]) || ts.isLiteralTypeNode(type!));
|
|
1340
|
-
|
|
1427
|
+
if (enumAttributes && enumAttributes[attrName] || ts.isUnionTypeNode(type) && ts.isLiteralTypeNode(type.types[0])) {
|
|
1428
|
+
properties.push([name_4, false, undefined]);
|
|
1429
|
+
}
|
|
1430
|
+
else {
|
|
1431
|
+
// 如果是非枚举类型的其它对象的union定义,加上JsonProjection
|
|
1432
|
+
properties.push([name_4, false, factory.createUnionTypeNode([
|
|
1433
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
|
|
1434
|
+
factory.createTypeReferenceNode(factory.createIdentifier("JsonProjection"), [type])
|
|
1435
|
+
])]);
|
|
1436
|
+
}
|
|
1341
1437
|
}
|
|
1342
1438
|
};
|
|
1343
1439
|
try {
|
|
1344
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()) {
|
|
1345
1441
|
var attr = schemaAttrs_3_1.value;
|
|
1346
|
-
|
|
1442
|
+
_loop_5(attr);
|
|
1347
1443
|
}
|
|
1348
1444
|
}
|
|
1349
|
-
catch (
|
|
1445
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1350
1446
|
finally {
|
|
1351
1447
|
try {
|
|
1352
1448
|
if (schemaAttrs_3_1 && !schemaAttrs_3_1.done && (_b = schemaAttrs_3.return)) _b.call(schemaAttrs_3);
|
|
1353
1449
|
}
|
|
1354
|
-
finally { if (
|
|
1450
|
+
finally { if (e_5) throw e_5.error; }
|
|
1355
1451
|
}
|
|
1356
1452
|
if (ReversePointerRelations[entity]) {
|
|
1357
1453
|
ReversePointerRelations[entity].forEach(function (one) {
|
|
@@ -1372,13 +1468,13 @@ function constructProjection(statements, entity) {
|
|
|
1372
1468
|
});
|
|
1373
1469
|
}
|
|
1374
1470
|
// 一对多的projection
|
|
1375
|
-
var
|
|
1471
|
+
var _g = OneToMany, _h = entity, oneToManySet = _g[_h];
|
|
1376
1472
|
if (oneToManySet) {
|
|
1377
1473
|
var foreignKeySet = {};
|
|
1378
1474
|
try {
|
|
1379
|
-
for (var
|
|
1380
|
-
var oneToManyItem =
|
|
1381
|
-
var
|
|
1475
|
+
for (var oneToManySet_3 = tslib_1.__values(oneToManySet), oneToManySet_3_1 = oneToManySet_3.next(); !oneToManySet_3_1.done; oneToManySet_3_1 = oneToManySet_3.next()) {
|
|
1476
|
+
var oneToManyItem = oneToManySet_3_1.value;
|
|
1477
|
+
var _j = tslib_1.__read(oneToManyItem, 2), entityName = _j[0], foreignKey = _j[1];
|
|
1382
1478
|
if (foreignKeySet.hasOwnProperty(entityName)) {
|
|
1383
1479
|
foreignKeySet[entityName].push(foreignKey);
|
|
1384
1480
|
}
|
|
@@ -1387,14 +1483,14 @@ function constructProjection(statements, entity) {
|
|
|
1387
1483
|
}
|
|
1388
1484
|
}
|
|
1389
1485
|
}
|
|
1390
|
-
catch (
|
|
1486
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1391
1487
|
finally {
|
|
1392
1488
|
try {
|
|
1393
|
-
if (
|
|
1489
|
+
if (oneToManySet_3_1 && !oneToManySet_3_1.done && (_c = oneToManySet_3.return)) _c.call(oneToManySet_3);
|
|
1394
1490
|
}
|
|
1395
|
-
finally { if (
|
|
1491
|
+
finally { if (e_6) throw e_6.error; }
|
|
1396
1492
|
}
|
|
1397
|
-
var
|
|
1493
|
+
var _loop_6 = function (entityName) {
|
|
1398
1494
|
var entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
|
|
1399
1495
|
foreignKeySet[entityName].forEach(function (foreignKey) {
|
|
1400
1496
|
var identifier = "".concat(entityNameLc, "$").concat(foreignKey);
|
|
@@ -1431,7 +1527,7 @@ function constructProjection(statements, entity) {
|
|
|
1431
1527
|
});
|
|
1432
1528
|
};
|
|
1433
1529
|
for (var entityName in foreignKeySet) {
|
|
1434
|
-
|
|
1530
|
+
_loop_6(entityName);
|
|
1435
1531
|
}
|
|
1436
1532
|
}
|
|
1437
1533
|
var exprNode = factory.createTypeReferenceNode(factory.createIdentifier("Partial"), [
|
|
@@ -1626,7 +1722,7 @@ function constructQuery(statements, entity) {
|
|
|
1626
1722
|
* @param entity
|
|
1627
1723
|
*/
|
|
1628
1724
|
function constructSorter(statements, entity) {
|
|
1629
|
-
var
|
|
1725
|
+
var e_7, _a;
|
|
1630
1726
|
var schemaAttrs = Schema[entity].schemaAttrs;
|
|
1631
1727
|
var members = [
|
|
1632
1728
|
// id: 1
|
|
@@ -1639,7 +1735,7 @@ function constructSorter(statements, entity) {
|
|
|
1639
1735
|
factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier("$$updateAt$$"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword))]),
|
|
1640
1736
|
];
|
|
1641
1737
|
var _b = ManyToOne, _c = entity, manyToOneSet = _b[_c];
|
|
1642
|
-
var
|
|
1738
|
+
var _loop_7 = function (attr) {
|
|
1643
1739
|
var _d = attr, type = _d.type, name_5 = _d.name, questionToken = _d.questionToken;
|
|
1644
1740
|
if (ts.isTypeReferenceNode(type)) {
|
|
1645
1741
|
var typeName = type.typeName;
|
|
@@ -1691,15 +1787,15 @@ function constructSorter(statements, entity) {
|
|
|
1691
1787
|
try {
|
|
1692
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()) {
|
|
1693
1789
|
var attr = schemaAttrs_4_1.value;
|
|
1694
|
-
|
|
1790
|
+
_loop_7(attr);
|
|
1695
1791
|
}
|
|
1696
1792
|
}
|
|
1697
|
-
catch (
|
|
1793
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
1698
1794
|
finally {
|
|
1699
1795
|
try {
|
|
1700
1796
|
if (schemaAttrs_4_1 && !schemaAttrs_4_1.done && (_a = schemaAttrs_4.return)) _a.call(schemaAttrs_4);
|
|
1701
1797
|
}
|
|
1702
|
-
finally { if (
|
|
1798
|
+
finally { if (e_7) throw e_7.error; }
|
|
1703
1799
|
}
|
|
1704
1800
|
if (ReversePointerRelations[entity]) {
|
|
1705
1801
|
ReversePointerRelations[entity].forEach(function (one) {
|
|
@@ -1753,7 +1849,7 @@ function constructSorter(statements, entity) {
|
|
|
1753
1849
|
statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Sorter"), undefined, factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier("SortNode"), undefined))));
|
|
1754
1850
|
}
|
|
1755
1851
|
function constructFullAttrs(statements, entity) {
|
|
1756
|
-
var
|
|
1852
|
+
var e_8, _a, e_9, _b;
|
|
1757
1853
|
var _c = ManyToOne, _d = entity, manyToOneSet = _c[_d];
|
|
1758
1854
|
var _e = OneToMany, _f = entity, oneToManySet = _e[_f];
|
|
1759
1855
|
if (manyToOneSet && manyToOneSet.length) {
|
|
@@ -1772,12 +1868,12 @@ function constructFullAttrs(statements, entity) {
|
|
|
1772
1868
|
}
|
|
1773
1869
|
}
|
|
1774
1870
|
}
|
|
1775
|
-
catch (
|
|
1871
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
1776
1872
|
finally {
|
|
1777
1873
|
try {
|
|
1778
1874
|
if (manyToOneSet_1_1 && !manyToOneSet_1_1.done && (_a = manyToOneSet_1.return)) _a.call(manyToOneSet_1);
|
|
1779
1875
|
}
|
|
1780
|
-
finally { if (
|
|
1876
|
+
finally { if (e_8) throw e_8.error; }
|
|
1781
1877
|
}
|
|
1782
1878
|
statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("NativeAttr"), undefined, factory.createUnionTypeNode(tslib_1.__spreadArray([
|
|
1783
1879
|
factory.createTypeReferenceNode(factory.createIdentifier("OpAttr"), undefined)
|
|
@@ -1789,8 +1885,8 @@ function constructFullAttrs(statements, entity) {
|
|
|
1789
1885
|
var foreignKeySet = {};
|
|
1790
1886
|
if (oneToManySet && oneToManySet.length > 0) {
|
|
1791
1887
|
try {
|
|
1792
|
-
for (var
|
|
1793
|
-
var oneToManyItem =
|
|
1888
|
+
for (var oneToManySet_4 = tslib_1.__values(oneToManySet), oneToManySet_4_1 = oneToManySet_4.next(); !oneToManySet_4_1.done; oneToManySet_4_1 = oneToManySet_4.next()) {
|
|
1889
|
+
var oneToManyItem = oneToManySet_4_1.value;
|
|
1794
1890
|
var _h = tslib_1.__read(oneToManyItem, 2), entityName = _h[0], foreignKey = _h[1];
|
|
1795
1891
|
if (foreignKeySet.hasOwnProperty(entityName)) {
|
|
1796
1892
|
foreignKeySet[entityName].push(foreignKey);
|
|
@@ -1800,15 +1896,15 @@ function constructFullAttrs(statements, entity) {
|
|
|
1800
1896
|
}
|
|
1801
1897
|
}
|
|
1802
1898
|
}
|
|
1803
|
-
catch (
|
|
1899
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
1804
1900
|
finally {
|
|
1805
1901
|
try {
|
|
1806
|
-
if (
|
|
1902
|
+
if (oneToManySet_4_1 && !oneToManySet_4_1.done && (_b = oneToManySet_4.return)) _b.call(oneToManySet_4);
|
|
1807
1903
|
}
|
|
1808
|
-
finally { if (
|
|
1904
|
+
finally { if (e_9) throw e_9.error; }
|
|
1809
1905
|
}
|
|
1810
1906
|
var otmAttrs_1 = [];
|
|
1811
|
-
var
|
|
1907
|
+
var _loop_8 = function (entityName) {
|
|
1812
1908
|
var entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
|
|
1813
1909
|
if (foreignKeySet[entityName].length > 1) {
|
|
1814
1910
|
foreignKeySet[entityName].forEach(function (foreignKey) {
|
|
@@ -1831,7 +1927,7 @@ function constructFullAttrs(statements, entity) {
|
|
|
1831
1927
|
}
|
|
1832
1928
|
};
|
|
1833
1929
|
for (var entityName in foreignKeySet) {
|
|
1834
|
-
|
|
1930
|
+
_loop_8(entityName);
|
|
1835
1931
|
}
|
|
1836
1932
|
statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("FullAttr"), undefined, factory.createUnionTypeNode(tslib_1.__spreadArray([
|
|
1837
1933
|
factory.createTypeReferenceNode(factory.createIdentifier("NativeAttr"), undefined)
|
|
@@ -1841,8 +1937,8 @@ function constructFullAttrs(statements, entity) {
|
|
|
1841
1937
|
statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("FullAttr"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("NativeAttr"), undefined)));
|
|
1842
1938
|
}
|
|
1843
1939
|
}
|
|
1844
|
-
function
|
|
1845
|
-
var
|
|
1940
|
+
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;
|
|
1846
1942
|
// Selection
|
|
1847
1943
|
statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("SelectOperation"), [
|
|
1848
1944
|
factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("P"), factory.createTypeReferenceNode(factory.createIdentifier("Object"), undefined), factory.createTypeReferenceNode(factory.createIdentifier("Projection"), undefined))
|
|
@@ -1853,11 +1949,8 @@ function constructActions(statements, entity) {
|
|
|
1853
1949
|
factory.createTypeReferenceNode(factory.createIdentifier("Sorter"), undefined)
|
|
1854
1950
|
])), factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Selection"), [
|
|
1855
1951
|
factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("P"), factory.createTypeReferenceNode(factory.createIdentifier("Object"), undefined), factory.createTypeReferenceNode(factory.createIdentifier("Projection"), undefined))
|
|
1856
|
-
], factory.createTypeReferenceNode(factory.createIdentifier("
|
|
1857
|
-
factory.createTypeReferenceNode(factory.createIdentifier("
|
|
1858
|
-
factory.createTypeReferenceNode(factory.createIdentifier("P"), undefined)
|
|
1859
|
-
]),
|
|
1860
|
-
factory.createLiteralTypeNode(factory.createStringLiteral("action"))
|
|
1952
|
+
], factory.createTypeReferenceNode(factory.createIdentifier("SelectOperation"), [
|
|
1953
|
+
factory.createTypeReferenceNode(factory.createIdentifier("P"), undefined)
|
|
1861
1954
|
])), factory.createTypeAliasDeclaration(undefined, [factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Aggregation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("DeduceAggregation"), [
|
|
1862
1955
|
factory.createTypeReferenceNode(factory.createIdentifier("Projection"), undefined),
|
|
1863
1956
|
factory.createTypeReferenceNode(factory.createIdentifier("Filter"), undefined),
|
|
@@ -1896,8 +1989,8 @@ function constructActions(statements, entity) {
|
|
|
1896
1989
|
var foreignKeySet = {};
|
|
1897
1990
|
if (oneToManySet) {
|
|
1898
1991
|
try {
|
|
1899
|
-
for (var
|
|
1900
|
-
var oneToManyItem =
|
|
1992
|
+
for (var oneToManySet_5 = tslib_1.__values(oneToManySet), oneToManySet_5_1 = oneToManySet_5.next(); !oneToManySet_5_1.done; oneToManySet_5_1 = oneToManySet_5.next()) {
|
|
1993
|
+
var oneToManyItem = oneToManySet_5_1.value;
|
|
1901
1994
|
var _p = tslib_1.__read(oneToManyItem, 2), entityName = _p[0], foreignKey = _p[1];
|
|
1902
1995
|
if (foreignKeySet.hasOwnProperty(entityName)) {
|
|
1903
1996
|
foreignKeySet[entityName].push(foreignKey);
|
|
@@ -1907,12 +2000,12 @@ function constructActions(statements, entity) {
|
|
|
1907
2000
|
}
|
|
1908
2001
|
}
|
|
1909
2002
|
}
|
|
1910
|
-
catch (
|
|
2003
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
1911
2004
|
finally {
|
|
1912
2005
|
try {
|
|
1913
|
-
if (
|
|
2006
|
+
if (oneToManySet_5_1 && !oneToManySet_5_1.done && (_a = oneToManySet_5.return)) _a.call(oneToManySet_5);
|
|
1914
2007
|
}
|
|
1915
|
-
finally { if (
|
|
2008
|
+
finally { if (e_10) throw e_10.error; }
|
|
1916
2009
|
}
|
|
1917
2010
|
}
|
|
1918
2011
|
// CreateOperationData
|
|
@@ -1929,12 +2022,12 @@ function constructActions(statements, entity) {
|
|
|
1929
2022
|
}
|
|
1930
2023
|
}
|
|
1931
2024
|
}
|
|
1932
|
-
catch (
|
|
2025
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
1933
2026
|
finally {
|
|
1934
2027
|
try {
|
|
1935
2028
|
if (manyToOneSet_2_1 && !manyToOneSet_2_1.done && (_b = manyToOneSet_2.return)) _b.call(manyToOneSet_2);
|
|
1936
2029
|
}
|
|
1937
|
-
finally { if (
|
|
2030
|
+
finally { if (e_11) throw e_11.error; }
|
|
1938
2031
|
}
|
|
1939
2032
|
}
|
|
1940
2033
|
var adNodes = [
|
|
@@ -1965,11 +2058,11 @@ function constructActions(statements, entity) {
|
|
|
1965
2058
|
factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), one[2] ? factory.createToken(ts.SyntaxKind.QuestionToken) : undefined, factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'CreateSingleOperation')))
|
|
1966
2059
|
]);
|
|
1967
2060
|
var cascadeUpdateNode = factory.createTypeLiteralNode([
|
|
1968
|
-
factory.createPropertySignature(undefined, factory.createIdentifier("".concat(one[1], "Id")), undefined, factory.createTypeReferenceNode(factory.createIdentifier("
|
|
2061
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("".concat(one[1], "Id")), undefined, factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one[1]))])),
|
|
1969
2062
|
factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(createForeignRef(entity, one[0], 'UpdateOperation')))
|
|
1970
2063
|
]);
|
|
1971
2064
|
var noCascadeNode = factory.createTypeLiteralNode([
|
|
1972
|
-
factory.createPropertySignature(undefined, factory.createIdentifier("".concat(one[1], "Id")), one[2] ? factory.createToken(ts.SyntaxKind.QuestionToken) : undefined, factory.createTypeReferenceNode(factory.createIdentifier("
|
|
2065
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("".concat(one[1], "Id")), one[2] ? factory.createToken(ts.SyntaxKind.QuestionToken) : undefined, factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one[1]))]))
|
|
1973
2066
|
]);
|
|
1974
2067
|
if (Schema[oneEntity].static) {
|
|
1975
2068
|
upsertOneNodes.push(noCascadeNode);
|
|
@@ -1998,12 +2091,12 @@ function constructActions(statements, entity) {
|
|
|
1998
2091
|
}
|
|
1999
2092
|
}
|
|
2000
2093
|
}
|
|
2001
|
-
catch (
|
|
2094
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
2002
2095
|
finally {
|
|
2003
2096
|
try {
|
|
2004
2097
|
if (manyToOneSet_3_1 && !manyToOneSet_3_1.done && (_c = manyToOneSet_3.return)) _c.call(manyToOneSet_3);
|
|
2005
2098
|
}
|
|
2006
|
-
finally { if (
|
|
2099
|
+
finally { if (e_12) throw e_12.error; }
|
|
2007
2100
|
}
|
|
2008
2101
|
if (upsertOneNodes.length > 0) {
|
|
2009
2102
|
adNodes.push(factory.createIntersectionTypeNode(upsertOneNodes));
|
|
@@ -2013,10 +2106,14 @@ function constructActions(statements, entity) {
|
|
|
2013
2106
|
if (ReversePointerEntities[entity]) {
|
|
2014
2107
|
if (ReversePointerRelations[entity]) {
|
|
2015
2108
|
var schemaAttrs = Schema[entity].schemaAttrs;
|
|
2016
|
-
var
|
|
2109
|
+
var entityQuestionToken = schemaAttrs.find(function (ele) {
|
|
2017
2110
|
var name = ele.name;
|
|
2018
2111
|
return name.text === 'entity';
|
|
2019
2112
|
}).questionToken;
|
|
2113
|
+
var entityIdQuestionToken = schemaAttrs.find(function (ele) {
|
|
2114
|
+
var name = ele.name;
|
|
2115
|
+
return name.text === 'entityId';
|
|
2116
|
+
}).questionToken;
|
|
2020
2117
|
try {
|
|
2021
2118
|
for (var _q = tslib_1.__values(ReversePointerRelations[entity]), _r = _q.next(); !_r.done; _r = _q.next()) {
|
|
2022
2119
|
var one = _r.value;
|
|
@@ -2030,12 +2127,12 @@ function constructActions(statements, entity) {
|
|
|
2030
2127
|
factory.createPropertySignature(undefined, factory.createIdentifier('entity'), undefined, // 反向指针好像不能为空,以后或许会有特例 by Xc
|
|
2031
2128
|
factory.createLiteralTypeNode(factory.createStringLiteral("".concat((0, string_1.firstLetterLowerCase)(one))))),
|
|
2032
2129
|
factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), undefined, // 反向指针好像不能为空,以后或许会有特例 by Xc
|
|
2033
|
-
factory.createTypeReferenceNode(factory.createIdentifier("
|
|
2130
|
+
factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one))])),
|
|
2034
2131
|
factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), undefined, factory.createTypeReferenceNode(createForeignRef(entity, one, 'UpdateOperation')))
|
|
2035
2132
|
]);
|
|
2036
2133
|
var noCascadeNode = factory.createTypeLiteralNode([
|
|
2037
|
-
factory.createPropertySignature(undefined, factory.createIdentifier('entity'),
|
|
2038
|
-
factory.createPropertySignature(undefined, factory.createIdentifier('entityId'),
|
|
2134
|
+
factory.createPropertySignature(undefined, factory.createIdentifier('entity'), entityQuestionToken, factory.createLiteralTypeNode(factory.createStringLiteral("".concat((0, string_1.firstLetterLowerCase)(one))))),
|
|
2135
|
+
factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), entityIdQuestionToken, factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one))]))
|
|
2039
2136
|
]);
|
|
2040
2137
|
if (Schema[one].static) {
|
|
2041
2138
|
reverseOneNodes.push(noCascadeNode);
|
|
@@ -2063,12 +2160,12 @@ function constructActions(statements, entity) {
|
|
|
2063
2160
|
}
|
|
2064
2161
|
}
|
|
2065
2162
|
}
|
|
2066
|
-
catch (
|
|
2163
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
2067
2164
|
finally {
|
|
2068
2165
|
try {
|
|
2069
2166
|
if (_r && !_r.done && (_d = _q.return)) _d.call(_q);
|
|
2070
2167
|
}
|
|
2071
|
-
finally { if (
|
|
2168
|
+
finally { if (e_13) throw e_13.error; }
|
|
2072
2169
|
}
|
|
2073
2170
|
}
|
|
2074
2171
|
if (process.env.COMPLING_AS_LIB) {
|
|
@@ -2086,7 +2183,7 @@ function constructActions(statements, entity) {
|
|
|
2086
2183
|
// 一对多
|
|
2087
2184
|
var propertySignatures = [];
|
|
2088
2185
|
if (oneToManySet) {
|
|
2089
|
-
var
|
|
2186
|
+
var _loop_9 = function (entityName) {
|
|
2090
2187
|
var entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
|
|
2091
2188
|
foreignKeySet[entityName].forEach(function (foreignKey) {
|
|
2092
2189
|
var identifier = "".concat(entityNameLc, "$").concat(foreignKey);
|
|
@@ -2120,7 +2217,16 @@ function constructActions(statements, entity) {
|
|
|
2120
2217
|
factory.createLiteralTypeNode(factory.createStringLiteral("".concat(foreignKey, "Id")))
|
|
2121
2218
|
])
|
|
2122
2219
|
]),
|
|
2123
|
-
factory.createTypeReferenceNode(
|
|
2220
|
+
factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
|
|
2221
|
+
factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'Filter'), undefined),
|
|
2222
|
+
factory.createUnionTypeNode(foreignKey === 'entity' ? [
|
|
2223
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("entity")),
|
|
2224
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("entityId"))
|
|
2225
|
+
] : [
|
|
2226
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey)),
|
|
2227
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("".concat(foreignKey, "Id")))
|
|
2228
|
+
])
|
|
2229
|
+
])
|
|
2124
2230
|
]);
|
|
2125
2231
|
if (!Schema[entityName].static) {
|
|
2126
2232
|
switch (Schema[entityName].actionType) {
|
|
@@ -2154,7 +2260,7 @@ function constructActions(statements, entity) {
|
|
|
2154
2260
|
});
|
|
2155
2261
|
};
|
|
2156
2262
|
for (var entityName in foreignKeySet) {
|
|
2157
|
-
|
|
2263
|
+
_loop_9(entityName);
|
|
2158
2264
|
}
|
|
2159
2265
|
}
|
|
2160
2266
|
if (propertySignatures.length > 0) {
|
|
@@ -2186,12 +2292,12 @@ function constructActions(statements, entity) {
|
|
|
2186
2292
|
}
|
|
2187
2293
|
}
|
|
2188
2294
|
}
|
|
2189
|
-
catch (
|
|
2295
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
2190
2296
|
finally {
|
|
2191
2297
|
try {
|
|
2192
2298
|
if (manyToOneSet_4_1 && !manyToOneSet_4_1.done && (_e = manyToOneSet_4.return)) _e.call(manyToOneSet_4);
|
|
2193
2299
|
}
|
|
2194
|
-
finally { if (
|
|
2300
|
+
finally { if (e_14) throw e_14.error; }
|
|
2195
2301
|
}
|
|
2196
2302
|
}
|
|
2197
2303
|
adNodes = [
|
|
@@ -2229,7 +2335,7 @@ function constructActions(statements, entity) {
|
|
|
2229
2335
|
var noCascadeNode = factory.createTypeLiteralNode([
|
|
2230
2336
|
factory.createPropertySignature(undefined, factory.createIdentifier(one[1]), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword)),
|
|
2231
2337
|
factory.createPropertySignature(undefined, factory.createIdentifier("".concat(one[1], "Id")), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
|
|
2232
|
-
factory.createTypeReferenceNode(factory.createIdentifier("
|
|
2338
|
+
factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createLiteralTypeNode(factory.createStringLiteral(one[1]))]),
|
|
2233
2339
|
factory.createLiteralTypeNode(factory.createNull())
|
|
2234
2340
|
])),
|
|
2235
2341
|
]);
|
|
@@ -2266,12 +2372,12 @@ function constructActions(statements, entity) {
|
|
|
2266
2372
|
}
|
|
2267
2373
|
}
|
|
2268
2374
|
}
|
|
2269
|
-
catch (
|
|
2375
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
2270
2376
|
finally {
|
|
2271
2377
|
try {
|
|
2272
2378
|
if (manyToOneSet_5_1 && !manyToOneSet_5_1.done && (_f = manyToOneSet_5.return)) _f.call(manyToOneSet_5);
|
|
2273
2379
|
}
|
|
2274
|
-
finally { if (
|
|
2380
|
+
finally { if (e_15) throw e_15.error; }
|
|
2275
2381
|
}
|
|
2276
2382
|
if (upsertOneNodes.length > 0) {
|
|
2277
2383
|
adNodes.push(factory.createIntersectionTypeNode(upsertOneNodes));
|
|
@@ -2319,12 +2425,12 @@ function constructActions(statements, entity) {
|
|
|
2319
2425
|
}
|
|
2320
2426
|
}
|
|
2321
2427
|
}
|
|
2322
|
-
catch (
|
|
2428
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
2323
2429
|
finally {
|
|
2324
2430
|
try {
|
|
2325
2431
|
if (_t && !_t.done && (_g = _s.return)) _g.call(_s);
|
|
2326
2432
|
}
|
|
2327
|
-
finally { if (
|
|
2433
|
+
finally { if (e_16) throw e_16.error; }
|
|
2328
2434
|
}
|
|
2329
2435
|
if (process.env.COMPLING_AS_LIB) {
|
|
2330
2436
|
// 如果是base,要包容更多可能的反指
|
|
@@ -2336,7 +2442,7 @@ function constructActions(statements, entity) {
|
|
|
2336
2442
|
factory.createLiteralTypeNode(factory.createNull())
|
|
2337
2443
|
])),
|
|
2338
2444
|
factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
|
|
2339
|
-
factory.createTypeReferenceNode(factory.createIdentifier("
|
|
2445
|
+
factory.createTypeReferenceNode(factory.createIdentifier("ForeignKey"), [factory.createUnionTypeNode(ReversePointerRelations[entity].map(function (ele) { return factory.createLiteralTypeNode(factory.createStringLiteral(ele)); }))]),
|
|
2340
2446
|
factory.createLiteralTypeNode(factory.createNull())
|
|
2341
2447
|
]))
|
|
2342
2448
|
]));
|
|
@@ -2350,7 +2456,7 @@ function constructActions(statements, entity) {
|
|
|
2350
2456
|
propertySignatures2.push(factory.createIndexSignature(undefined, undefined, [factory.createParameterDeclaration(undefined, undefined, undefined, factory.createIdentifier("k"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)));
|
|
2351
2457
|
}
|
|
2352
2458
|
if (oneToManySet) {
|
|
2353
|
-
var
|
|
2459
|
+
var _loop_10 = function (entityName) {
|
|
2354
2460
|
var entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
|
|
2355
2461
|
foreignKeySet[entityName].forEach(function (foreignKey) {
|
|
2356
2462
|
var identifier = "".concat(entityNameLc, "$").concat(foreignKey);
|
|
@@ -2372,8 +2478,52 @@ function constructActions(statements, entity) {
|
|
|
2372
2478
|
factory.createLiteralTypeNode(factory.createStringLiteral("create")),
|
|
2373
2479
|
factory.createArrayTypeNode(otmCreateOperationDataNode)
|
|
2374
2480
|
]);
|
|
2375
|
-
var otmUpdateOperationNode = factory.createTypeReferenceNode(
|
|
2376
|
-
|
|
2481
|
+
var otmUpdateOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
|
|
2482
|
+
factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'UpdateOperation'), undefined), factory.createLiteralTypeNode(factory.createStringLiteral("action"))),
|
|
2483
|
+
factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
|
|
2484
|
+
factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'UpdateOperationData'), undefined),
|
|
2485
|
+
factory.createUnionTypeNode(foreignKey === 'entity' ? [
|
|
2486
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("entity")),
|
|
2487
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("entityId"))
|
|
2488
|
+
] : [
|
|
2489
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey)),
|
|
2490
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("".concat(foreignKey, "Id")))
|
|
2491
|
+
])
|
|
2492
|
+
]),
|
|
2493
|
+
factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
|
|
2494
|
+
factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'Filter'), undefined),
|
|
2495
|
+
factory.createUnionTypeNode(foreignKey === 'entity' ? [
|
|
2496
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("entity")),
|
|
2497
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("entityId"))
|
|
2498
|
+
] : [
|
|
2499
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey)),
|
|
2500
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("".concat(foreignKey, "Id")))
|
|
2501
|
+
])
|
|
2502
|
+
])
|
|
2503
|
+
]);
|
|
2504
|
+
var otmRemoveOperationNode = factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
|
|
2505
|
+
factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'RemoveOperation'), undefined), factory.createLiteralTypeNode(factory.createStringLiteral("action"))),
|
|
2506
|
+
factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
|
|
2507
|
+
factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'RemoveOperationData'), undefined),
|
|
2508
|
+
factory.createUnionTypeNode(foreignKey === 'entity' ? [
|
|
2509
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("entity")),
|
|
2510
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("entityId"))
|
|
2511
|
+
] : [
|
|
2512
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey)),
|
|
2513
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("".concat(foreignKey, "Id")))
|
|
2514
|
+
])
|
|
2515
|
+
]),
|
|
2516
|
+
factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
|
|
2517
|
+
factory.createTypeReferenceNode(createForeignRef(entity, entityName, 'Filter'), undefined),
|
|
2518
|
+
factory.createUnionTypeNode(foreignKey === 'entity' ? [
|
|
2519
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("entity")),
|
|
2520
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("entityId"))
|
|
2521
|
+
] : [
|
|
2522
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey)),
|
|
2523
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("".concat(foreignKey, "Id")))
|
|
2524
|
+
])
|
|
2525
|
+
])
|
|
2526
|
+
]);
|
|
2377
2527
|
if (!Schema[entityName].static) {
|
|
2378
2528
|
switch (Schema[entityName].actionType) {
|
|
2379
2529
|
case 'crud': {
|
|
@@ -2431,7 +2581,7 @@ function constructActions(statements, entity) {
|
|
|
2431
2581
|
});
|
|
2432
2582
|
};
|
|
2433
2583
|
for (var entityName in foreignKeySet) {
|
|
2434
|
-
|
|
2584
|
+
_loop_10(entityName);
|
|
2435
2585
|
}
|
|
2436
2586
|
}
|
|
2437
2587
|
if (propertySignatures2.length > 0) {
|
|
@@ -2511,12 +2661,12 @@ function constructActions(statements, entity) {
|
|
|
2511
2661
|
}
|
|
2512
2662
|
}
|
|
2513
2663
|
}
|
|
2514
|
-
catch (
|
|
2664
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
2515
2665
|
finally {
|
|
2516
2666
|
try {
|
|
2517
2667
|
if (manyToOneSet_6_1 && !manyToOneSet_6_1.done && (_h = manyToOneSet_6.return)) _h.call(manyToOneSet_6);
|
|
2518
2668
|
}
|
|
2519
|
-
finally { if (
|
|
2669
|
+
finally { if (e_17) throw e_17.error; }
|
|
2520
2670
|
}
|
|
2521
2671
|
var reverseOneNodes_2 = [];
|
|
2522
2672
|
if (ReversePointerRelations[entity]) {
|
|
@@ -2559,12 +2709,12 @@ function constructActions(statements, entity) {
|
|
|
2559
2709
|
}
|
|
2560
2710
|
}
|
|
2561
2711
|
}
|
|
2562
|
-
catch (
|
|
2712
|
+
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
2563
2713
|
finally {
|
|
2564
2714
|
try {
|
|
2565
2715
|
if (_v && !_v.done && (_j = _u.return)) _j.call(_u);
|
|
2566
2716
|
}
|
|
2567
|
-
finally { if (
|
|
2717
|
+
finally { if (e_18) throw e_18.error; }
|
|
2568
2718
|
}
|
|
2569
2719
|
if (process.env.COMPLING_AS_LIB) {
|
|
2570
2720
|
reverseOneNodes_2.push(factory.createTypeLiteralNode([
|
|
@@ -2666,21 +2816,9 @@ function constructActions(statements, entity) {
|
|
|
2666
2816
|
var initialStatements = function () { return [
|
|
2667
2817
|
// import { String, Text, Int, SpecificKey } from 'oak-domain/types/DataType';
|
|
2668
2818
|
factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
2669
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('String')),
|
|
2670
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Int')),
|
|
2671
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Uint')),
|
|
2672
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Float')),
|
|
2673
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Double')),
|
|
2674
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Boolean')),
|
|
2675
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Text')),
|
|
2676
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Datetime')),
|
|
2677
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('File')),
|
|
2678
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Price')),
|
|
2679
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Image')),
|
|
2680
2819
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('PrimaryKey')),
|
|
2681
2820
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('ForeignKey')),
|
|
2682
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('
|
|
2683
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('SingleGeo'))
|
|
2821
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('JsonProjection'))
|
|
2684
2822
|
])), factory.createStringLiteral("".concat((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(), "DataType"))),
|
|
2685
2823
|
/* import {
|
|
2686
2824
|
Q_DateValue, Q_LogicKey, Q_NumberValue, FnCallKey, FnCallValue,
|
|
@@ -2698,13 +2836,24 @@ var initialStatements = function () { return [
|
|
|
2698
2836
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('FulltextFilter')),
|
|
2699
2837
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('ExprOp')),
|
|
2700
2838
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('ExpressionKey')),
|
|
2839
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('JsonFilter')),
|
|
2840
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('SubQueryPredicateMetadata')),
|
|
2701
2841
|
])), factory.createStringLiteral("".concat((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(), "Demand"))),
|
|
2702
2842
|
factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
2703
2843
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier("OneOf")),
|
|
2704
2844
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier("ValueOf"))
|
|
2705
2845
|
])), factory.createStringLiteral("".concat((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(), "Polyfill"))),
|
|
2706
2846
|
// import * as SubQuery from '../_SubQuery';
|
|
2707
|
-
factory.createImportDeclaration(
|
|
2847
|
+
/* factory.createImportDeclaration(
|
|
2848
|
+
undefined,
|
|
2849
|
+
undefined,
|
|
2850
|
+
factory.createImportClause(
|
|
2851
|
+
false,
|
|
2852
|
+
undefined,
|
|
2853
|
+
factory.createNamespaceImport(factory.createIdentifier("SubQuery"))
|
|
2854
|
+
),
|
|
2855
|
+
factory.createStringLiteral("../_SubQuery")
|
|
2856
|
+
), */
|
|
2708
2857
|
// import { Filter as OakFilter } from 'oak-domain/src/types/Entity';
|
|
2709
2858
|
factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
2710
2859
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier("FormCreateData")),
|
|
@@ -2713,7 +2862,6 @@ var initialStatements = function () { return [
|
|
|
2713
2862
|
factory.createImportSpecifier(false, factory.createIdentifier("Operation"), factory.createIdentifier("OakOperation")),
|
|
2714
2863
|
factory.createImportSpecifier(false, factory.createIdentifier("Selection"), factory.createIdentifier("OakSelection")),
|
|
2715
2864
|
factory.createImportSpecifier(false, factory.createIdentifier("MakeAction"), factory.createIdentifier("OakMakeAction")),
|
|
2716
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier("EntityShape")),
|
|
2717
2865
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier("AggregationResult")),
|
|
2718
2866
|
])), factory.createStringLiteral("".concat((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(), "Entity")), undefined)
|
|
2719
2867
|
]; };
|
|
@@ -2726,13 +2874,12 @@ function outputSubQuery(outputDir, printer) {
|
|
|
2726
2874
|
statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamespaceImport(factory.createIdentifier(entity))), factory.createStringLiteral("./".concat(entity, "/Schema"))));
|
|
2727
2875
|
}
|
|
2728
2876
|
var entities = (0, lodash_1.keys)(Schema);
|
|
2729
|
-
var
|
|
2877
|
+
var _loop_11 = function (one) {
|
|
2730
2878
|
var identifier = "".concat(one, "IdSubQuery");
|
|
2731
2879
|
var fromEntites = OneToMany[one] ? (0, lodash_1.uniq)(OneToMany[one]
|
|
2732
|
-
.filter(
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
}).map(function (_a) {
|
|
2880
|
+
/* .filter(
|
|
2881
|
+
([e, f]) => f !== 'entity'
|
|
2882
|
+
) */ .map(function (_a) {
|
|
2736
2883
|
var _b = tslib_1.__read(_a, 1), e = _b[0];
|
|
2737
2884
|
return e;
|
|
2738
2885
|
})) : [];
|
|
@@ -2752,7 +2899,7 @@ function outputSubQuery(outputDir, printer) {
|
|
|
2752
2899
|
};
|
|
2753
2900
|
// 每个有manyToOne的Entity都会输出${One}IdSubQuery
|
|
2754
2901
|
for (var one in Schema) {
|
|
2755
|
-
|
|
2902
|
+
_loop_11(one);
|
|
2756
2903
|
}
|
|
2757
2904
|
var resultFile = ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS);
|
|
2758
2905
|
var result = printer.printNode(ts.EmitHint.Unspecified, factory.createSourceFile(statements, factory.createToken(ts.SyntaxKind.EndOfFileToken), ts.NodeFlags.None), resultFile);
|
|
@@ -2797,10 +2944,29 @@ function outputSchema(outputDir, printer) {
|
|
|
2797
2944
|
localActions.push(s);
|
|
2798
2945
|
}
|
|
2799
2946
|
else if (actionDefNames.includes((0, string_1.firstLetterLowerCase)(a.slice(0, a.length - 6)))) {
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2947
|
+
// 现在源文件中的import语句保留下来了
|
|
2948
|
+
// const { moduleSpecifier } = importedFrom[a] as ts.ImportDeclaration;
|
|
2949
|
+
// statements.push(
|
|
2950
|
+
// factory.createImportDeclaration(
|
|
2951
|
+
// undefined,
|
|
2952
|
+
// undefined,
|
|
2953
|
+
// factory.createImportClause(
|
|
2954
|
+
// false,
|
|
2955
|
+
// undefined,
|
|
2956
|
+
// factory.createNamedImports(
|
|
2957
|
+
// [
|
|
2958
|
+
// factory.createImportSpecifier(
|
|
2959
|
+
// false,
|
|
2960
|
+
// undefined,
|
|
2961
|
+
// factory.createIdentifier(s)
|
|
2962
|
+
// )
|
|
2963
|
+
// ]
|
|
2964
|
+
// )
|
|
2965
|
+
// ),
|
|
2966
|
+
// moduleSpecifier,
|
|
2967
|
+
// undefined
|
|
2968
|
+
// )
|
|
2969
|
+
// );
|
|
2804
2970
|
}
|
|
2805
2971
|
}
|
|
2806
2972
|
statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports(localActions.map(function (ele) { return factory.createImportSpecifier(false, undefined, factory.createIdentifier(ele)); }))), factory.createStringLiteral('./Action'), undefined), factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
@@ -2822,15 +2988,24 @@ function outputSchema(outputDir, printer) {
|
|
|
2822
2988
|
statements.push.apply(statements, tslib_1.__spreadArray([], tslib_1.__read(additionalImports), false));
|
|
2823
2989
|
}
|
|
2824
2990
|
// Relation定义加入
|
|
2825
|
-
if (typeof Schema[entity].hasRelationDef === 'object' && ts.isTypeAliasDeclaration(Schema[entity].hasRelationDef)) {
|
|
2826
|
-
|
|
2827
|
-
statements.push(
|
|
2828
|
-
|
|
2991
|
+
/* if (typeof Schema[entity].hasRelationDef === 'object' && ts.isTypeAliasDeclaration(Schema[entity].hasRelationDef as ts.Node)) {
|
|
2992
|
+
const node = Schema[entity].hasRelationDef as ts.TypeAliasDeclaration;
|
|
2993
|
+
statements.push(
|
|
2994
|
+
factory.updateTypeAliasDeclaration(
|
|
2995
|
+
node,
|
|
2996
|
+
undefined,
|
|
2997
|
+
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
2998
|
+
node.name,
|
|
2999
|
+
node.typeParameters,
|
|
3000
|
+
node.type
|
|
3001
|
+
)
|
|
3002
|
+
);
|
|
3003
|
+
} */
|
|
2829
3004
|
constructSchema(statements, entity);
|
|
2830
3005
|
constructFilter(statements, entity);
|
|
2831
3006
|
constructProjection(statements, entity);
|
|
2832
3007
|
constructSorter(statements, entity);
|
|
2833
|
-
|
|
3008
|
+
constructOperations(statements, entity);
|
|
2834
3009
|
constructQuery(statements, entity);
|
|
2835
3010
|
// 现在FullAttrs和NativeAttrs似乎没什么用,还会引起递归
|
|
2836
3011
|
// constructFullAttrs(statements, entity);
|
|
@@ -2865,9 +3040,19 @@ function outputSchema(outputDir, printer) {
|
|
|
2865
3040
|
if (ActionAsts[entity]) {
|
|
2866
3041
|
EntityDefAttrs.push(factory.createPropertySignature(undefined, factory.createIdentifier("ParticularAction"), undefined, factory.createTypeReferenceNode(factory.createIdentifier('ParticularAction'), undefined)));
|
|
2867
3042
|
}
|
|
2868
|
-
if (typeof Schema[entity].hasRelationDef === 'object' && ts.isTypeAliasDeclaration(Schema[entity].hasRelationDef)) {
|
|
2869
|
-
EntityDefAttrs.push(
|
|
2870
|
-
|
|
3043
|
+
/* if (typeof Schema[entity].hasRelationDef === 'object' && ts.isTypeAliasDeclaration(Schema[entity].hasRelationDef as ts.Node)) {
|
|
3044
|
+
EntityDefAttrs.push(
|
|
3045
|
+
factory.createPropertySignature(
|
|
3046
|
+
undefined,
|
|
3047
|
+
factory.createIdentifier("Relation"),
|
|
3048
|
+
undefined,
|
|
3049
|
+
factory.createTypeReferenceNode(
|
|
3050
|
+
factory.createIdentifier('Relation'),
|
|
3051
|
+
undefined
|
|
3052
|
+
)
|
|
3053
|
+
)
|
|
3054
|
+
);
|
|
3055
|
+
} */
|
|
2871
3056
|
statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDef"), undefined, factory.createTypeLiteralNode(EntityDefAttrs)));
|
|
2872
3057
|
var result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements), Schema[entity].sourceFile);
|
|
2873
3058
|
var fileName = path_1.default.join(outputDir, entity, 'Schema.ts');
|
|
@@ -3062,7 +3247,7 @@ function constructAttributes(entity) {
|
|
|
3062
3247
|
function outputLocale(outputDir, printer) {
|
|
3063
3248
|
var locales = {};
|
|
3064
3249
|
var entities = [];
|
|
3065
|
-
var
|
|
3250
|
+
var _loop_12 = function (entity) {
|
|
3066
3251
|
var _a = Schema[entity], locale = _a.locale, sourceFile = _a.sourceFile;
|
|
3067
3252
|
if (locale) {
|
|
3068
3253
|
var properties = locale.properties;
|
|
@@ -3086,7 +3271,7 @@ function outputLocale(outputDir, printer) {
|
|
|
3086
3271
|
}
|
|
3087
3272
|
};
|
|
3088
3273
|
for (var entity in Schema) {
|
|
3089
|
-
|
|
3274
|
+
_loop_12(entity);
|
|
3090
3275
|
}
|
|
3091
3276
|
for (var lng in locales) {
|
|
3092
3277
|
if (locales[lng].length < entities.length) {
|
|
@@ -3202,12 +3387,7 @@ function outputStorage(outputDir, printer) {
|
|
|
3202
3387
|
propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("static"), factory.createTrue()));
|
|
3203
3388
|
}
|
|
3204
3389
|
propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("actionType"), factory.createStringLiteral(actionType)));
|
|
3205
|
-
|
|
3206
|
-
propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("actions"), factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("actions"), factory.createIdentifier("concat")), undefined, [factory.createIdentifier("relationActions")])));
|
|
3207
|
-
}
|
|
3208
|
-
else {
|
|
3209
|
-
propertyAssignments.push(factory.createShorthandPropertyAssignment(factory.createIdentifier("actions"), undefined));
|
|
3210
|
-
}
|
|
3390
|
+
propertyAssignments.push(factory.createShorthandPropertyAssignment(factory.createIdentifier("actions"), undefined));
|
|
3211
3391
|
if (indexExpressions.length > 0) {
|
|
3212
3392
|
propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("indexes"), factory.createArrayLiteralExpression(indexExpressions, true)));
|
|
3213
3393
|
}
|
|
@@ -3273,28 +3453,28 @@ function resetOutputDir(outputDir) {
|
|
|
3273
3453
|
(0, fs_1.mkdirSync)(path_1.default.join(outputDir, '_locales'));
|
|
3274
3454
|
}
|
|
3275
3455
|
function addReverseRelationship() {
|
|
3276
|
-
var
|
|
3456
|
+
var e_19, _a;
|
|
3277
3457
|
for (var reverseEntity in ReversePointerRelations) {
|
|
3278
3458
|
if (!ReversePointerEntities.hasOwnProperty(reverseEntity)) {
|
|
3279
3459
|
throw new Error("\u300C".concat(reverseEntity, "\u300D\u88AB\u5F15\u7528\u4E3A\u4E00\u4E2A\u53CD\u6307\u5BF9\u8C61\uFF0C\u4F46\u5176\u5B9A\u4E49\u4E2D\u7684entity\u548CentityId\u4E0D\u7B26\u5408\u8981\u6C42"));
|
|
3280
3460
|
}
|
|
3281
3461
|
try {
|
|
3282
|
-
for (var _b = (
|
|
3462
|
+
for (var _b = (e_19 = void 0, tslib_1.__values(ReversePointerRelations[reverseEntity])), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3283
3463
|
var one = _c.value;
|
|
3284
3464
|
addRelationship(reverseEntity, one, 'entity', false);
|
|
3285
3465
|
}
|
|
3286
3466
|
}
|
|
3287
|
-
catch (
|
|
3467
|
+
catch (e_19_1) { e_19 = { error: e_19_1 }; }
|
|
3288
3468
|
finally {
|
|
3289
3469
|
try {
|
|
3290
3470
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3291
3471
|
}
|
|
3292
|
-
finally { if (
|
|
3472
|
+
finally { if (e_19) throw e_19.error; }
|
|
3293
3473
|
}
|
|
3294
3474
|
}
|
|
3295
3475
|
}
|
|
3296
3476
|
function outputIndexTs(outputDir) {
|
|
3297
|
-
var indexTs = "export * from './EntityDict';\n export * from './Storage';\n export * from './ActionDefDict';\n ";
|
|
3477
|
+
var indexTs = "export * from './EntityDict';\n export * from './Storage';\n export * from './ActionDefDict';\n export * from './Relation';\n ";
|
|
3298
3478
|
var filename = path_1.default.join(outputDir, 'index.ts');
|
|
3299
3479
|
(0, fs_1.writeFileSync)(filename, indexTs, { flag: 'w' });
|
|
3300
3480
|
}
|
|
@@ -3340,11 +3520,241 @@ function analyzeInModi() {
|
|
|
3340
3520
|
}
|
|
3341
3521
|
}
|
|
3342
3522
|
}
|
|
3523
|
+
var IGNORED_FOREIGN_KEY_MAP = {};
|
|
3524
|
+
var IGNORED_RELATION_PATH_MAP = {};
|
|
3525
|
+
var DEDUCED_RELATION_MAP = {};
|
|
3526
|
+
var SELECT_FREE_ENTITIES = [];
|
|
3527
|
+
var CREATE_FREE_ENTITIES = [];
|
|
3528
|
+
var UPDATE_FREE_ENTITIES = [];
|
|
3529
|
+
var FIXED_DESTINATION_PATH_MAP = {};
|
|
3530
|
+
var FIXED_FOR_ALL_DESTINATION_PATH_ENTITIES = [];
|
|
3531
|
+
function registerIgnoredForeignKeyMap(map) {
|
|
3532
|
+
IGNORED_FOREIGN_KEY_MAP = map;
|
|
3533
|
+
}
|
|
3534
|
+
exports.registerIgnoredForeignKeyMap = registerIgnoredForeignKeyMap;
|
|
3535
|
+
function registerFreeEntities(selectFreeEntities, createFreeEntities, updateFreeEntities) {
|
|
3536
|
+
if (selectFreeEntities === void 0) { selectFreeEntities = []; }
|
|
3537
|
+
if (createFreeEntities === void 0) { createFreeEntities = []; }
|
|
3538
|
+
if (updateFreeEntities === void 0) { updateFreeEntities = []; }
|
|
3539
|
+
SELECT_FREE_ENTITIES = selectFreeEntities;
|
|
3540
|
+
CREATE_FREE_ENTITIES = createFreeEntities;
|
|
3541
|
+
UPDATE_FREE_ENTITIES = updateFreeEntities;
|
|
3542
|
+
}
|
|
3543
|
+
exports.registerFreeEntities = registerFreeEntities;
|
|
3544
|
+
function registerIgnoredRelationPathMap(map) {
|
|
3545
|
+
for (var k in map) {
|
|
3546
|
+
IGNORED_RELATION_PATH_MAP[(0, string_1.firstLetterUpperCase)(k)] = map[k];
|
|
3547
|
+
}
|
|
3548
|
+
}
|
|
3549
|
+
exports.registerIgnoredRelationPathMap = registerIgnoredRelationPathMap;
|
|
3550
|
+
/**
|
|
3551
|
+
* 很多路径虽然最后指向同一对象,但不能封掉,封了会导致查询的时候找不到对应的路径path
|
|
3552
|
+
* @param map
|
|
3553
|
+
*/
|
|
3554
|
+
function registerFixedDestinationPathMap(map) {
|
|
3555
|
+
var _a;
|
|
3556
|
+
for (var k in map) {
|
|
3557
|
+
if (k === '.') {
|
|
3558
|
+
FIXED_FOR_ALL_DESTINATION_PATH_ENTITIES.push.apply(FIXED_FOR_ALL_DESTINATION_PATH_ENTITIES, tslib_1.__spreadArray([], tslib_1.__read(map[k]), false));
|
|
3559
|
+
}
|
|
3560
|
+
else if (FIXED_DESTINATION_PATH_MAP[k]) {
|
|
3561
|
+
(_a = FIXED_DESTINATION_PATH_MAP[k]).push.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(map[k]), false));
|
|
3562
|
+
}
|
|
3563
|
+
else {
|
|
3564
|
+
FIXED_DESTINATION_PATH_MAP[k] = map[k];
|
|
3565
|
+
}
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
exports.registerFixedDestinationPathMap = registerFixedDestinationPathMap;
|
|
3569
|
+
function registerDeducedRelationMap(map) {
|
|
3570
|
+
var _loop_13 = function (k) {
|
|
3571
|
+
var entity = (0, string_1.firstLetterUpperCase)(k);
|
|
3572
|
+
(0, assert_1.default)(Schema.hasOwnProperty(entity), "config/relation.ts\u4E2D\u914D\u7F6E\u7684DeducedRelationMap\u5305\u542B\u4E0D\u5408\u6CD5\u7684\u5BF9\u8C61\u540D\u79F0\u300C".concat(k, "\u300D"));
|
|
3573
|
+
// 定义的deduce的属性一定是多对一的外键,此时ReversePointerEntities还未处理
|
|
3574
|
+
if (ReversePointerEntities[entity] && map[k] === 'entity') {
|
|
3575
|
+
}
|
|
3576
|
+
else {
|
|
3577
|
+
var mto = ManyToOne[entity].find(function (ele) { return ele[1] === map[k]; });
|
|
3578
|
+
(0, assert_1.default)(mto, "config/relation.ts\u4E2D\u914D\u7F6E\u7684DeducedRelationMap\u6240\u5B9A\u4E49\u7684\u300C".concat(k, "\u300D\u7684deduce\u5C5E\u6027\u300C").concat(map[k], "\u300D\u4E0D\u662F\u4E00\u4E2A\u6709\u6548\u7684\u5916\u952E\u6307\u9488"));
|
|
3579
|
+
}
|
|
3580
|
+
DEDUCED_RELATION_MAP[entity] = map[k];
|
|
3581
|
+
};
|
|
3582
|
+
for (var k in map) {
|
|
3583
|
+
_loop_13(k);
|
|
3584
|
+
}
|
|
3585
|
+
}
|
|
3586
|
+
exports.registerDeducedRelationMap = registerDeducedRelationMap;
|
|
3587
|
+
/**
|
|
3588
|
+
* 输出所有和User相关的对象的后继
|
|
3589
|
+
*/
|
|
3590
|
+
function outputRelation(outputDir, printer) {
|
|
3591
|
+
var ExcludedEntities = ['Oper', 'User', 'OperEntity', 'Modi', 'ModiEntity', 'UserRelation', 'Relation', 'RelationAuth', 'ActionAuth'];
|
|
3592
|
+
var actionPath = [];
|
|
3593
|
+
var relationPath = [];
|
|
3594
|
+
var outputRecursively = function (root, entity, path, paths, isRelation) {
|
|
3595
|
+
var _a;
|
|
3596
|
+
if (ExcludedEntities.includes(entity)) {
|
|
3597
|
+
return;
|
|
3598
|
+
}
|
|
3599
|
+
if ((_a = IGNORED_RELATION_PATH_MAP[entity]) === null || _a === void 0 ? void 0 : _a.find(function (ele) { return path.includes(ele); })) {
|
|
3600
|
+
return;
|
|
3601
|
+
}
|
|
3602
|
+
if (paths.length > 12) {
|
|
3603
|
+
throw new Error('对象之间的关系深度过长,请优化设计加以避免');
|
|
3604
|
+
}
|
|
3605
|
+
actionPath.push([(0, string_1.firstLetterLowerCase)(entity), path, root, isRelation, paths]);
|
|
3606
|
+
if (Schema[entity].hasRelationDef) {
|
|
3607
|
+
// assert(!DEDUCED_RELATION_MAP[entity], `${entity}对象定义了deducedRelationMap,但它有relation`);
|
|
3608
|
+
relationPath.push([(0, string_1.firstLetterLowerCase)(entity), path, root, isRelation]);
|
|
3609
|
+
}
|
|
3610
|
+
var _b = OneToMany, _c = entity, parent = _b[_c];
|
|
3611
|
+
if (parent) {
|
|
3612
|
+
parent.forEach(function (_a) {
|
|
3613
|
+
var _b;
|
|
3614
|
+
var _c = tslib_1.__read(_a, 2), child = _c[0], foreignKey = _c[1];
|
|
3615
|
+
var child2 = (0, string_1.firstLetterLowerCase)(child);
|
|
3616
|
+
if (child === entity) {
|
|
3617
|
+
// 如果有层级关系对象,最多找3层。同时这里只找本身存在relation关系的对象,因为如果对象上没有relation,则其上的公共路径应当可以维护住层级关系
|
|
3618
|
+
// 例如在jichuang项目中,house上没有relation,通过其park外键所维护的路径不需要遍历其父亲。而parkCluster因为有relation,所以必须构造以之为根的所有的可能路径
|
|
3619
|
+
// 如果不是以之为根的,同样可以根据其上的公共路径去查找,parkCluster.system和parkCluster.parent.system必然是一样的
|
|
3620
|
+
if (!Schema[entity].hasRelationDef) {
|
|
3621
|
+
return;
|
|
3622
|
+
}
|
|
3623
|
+
if (paths.find(function (ele) { return ele !== child2; }) || paths.length > 2) {
|
|
3624
|
+
return;
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
else if (paths.indexOf(child2) >= 0) {
|
|
3628
|
+
// 除了层级之外的递归直接忽略
|
|
3629
|
+
return;
|
|
3630
|
+
}
|
|
3631
|
+
if ((_b = IGNORED_FOREIGN_KEY_MAP[child2]) === null || _b === void 0 ? void 0 : _b.includes(foreignKey)) {
|
|
3632
|
+
// 忽略的路径放弃
|
|
3633
|
+
return;
|
|
3634
|
+
}
|
|
3635
|
+
if (DEDUCED_RELATION_MAP[child] === foreignKey) {
|
|
3636
|
+
// 如果子对象本身由父对象推定,也放弃
|
|
3637
|
+
return;
|
|
3638
|
+
}
|
|
3639
|
+
var fk = foreignKey === 'entity' ? (0, string_1.firstLetterLowerCase)(entity) : foreignKey;
|
|
3640
|
+
var path2 = path ? "".concat(fk, ".").concat(path) : fk;
|
|
3641
|
+
outputRecursively(root, child, path2, paths.concat([(0, string_1.firstLetterLowerCase)(entity)]), isRelation);
|
|
3642
|
+
});
|
|
3643
|
+
}
|
|
3644
|
+
};
|
|
3645
|
+
// 所有属性中有指向user的对象
|
|
3646
|
+
var User = OneToMany.User;
|
|
3647
|
+
User.forEach(function (_a) {
|
|
3648
|
+
var _b;
|
|
3649
|
+
var _c = tslib_1.__read(_a, 2), entity3 = _c[0], foreignKey = _c[1];
|
|
3650
|
+
var fk = foreignKey === 'entity' ? 'user' : foreignKey;
|
|
3651
|
+
if (!((_b = IGNORED_FOREIGN_KEY_MAP[(0, string_1.firstLetterLowerCase)(entity3)]) === null || _b === void 0 ? void 0 : _b.includes(foreignKey))) {
|
|
3652
|
+
outputRecursively((0, string_1.firstLetterLowerCase)(entity3), entity3, fk, [fk], false);
|
|
3653
|
+
}
|
|
3654
|
+
});
|
|
3655
|
+
// 所有带relation的对象
|
|
3656
|
+
var hasRelationEntities = Object.keys(Schema).filter(function (entity) { return Schema[entity].hasRelationDef; });
|
|
3657
|
+
hasRelationEntities.forEach(function (entity3) {
|
|
3658
|
+
outputRecursively((0, string_1.firstLetterLowerCase)(entity3), entity3, '', [], true);
|
|
3659
|
+
});
|
|
3660
|
+
actionPath.sort(function (ele1, ele2) {
|
|
3661
|
+
// 先按sourceEntity来排序
|
|
3662
|
+
if (ele1[0] > ele2[0]) {
|
|
3663
|
+
return 1;
|
|
3664
|
+
}
|
|
3665
|
+
else if (ele1[0] < ele2[0]) {
|
|
3666
|
+
return -1;
|
|
3667
|
+
}
|
|
3668
|
+
else {
|
|
3669
|
+
// 再按destEntity
|
|
3670
|
+
if (ele1[2] > ele2[2]) {
|
|
3671
|
+
return 1;
|
|
3672
|
+
}
|
|
3673
|
+
else if (ele1[2] < ele2[2]) {
|
|
3674
|
+
return -1;
|
|
3675
|
+
}
|
|
3676
|
+
else {
|
|
3677
|
+
// 最后按paths的长度倒排
|
|
3678
|
+
return ele1[4].length - ele2[4].length;
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
});
|
|
3682
|
+
var entityRelations = [];
|
|
3683
|
+
for (var entity in Schema) {
|
|
3684
|
+
var hasRelationDef = Schema[entity].hasRelationDef;
|
|
3685
|
+
if (hasRelationDef) {
|
|
3686
|
+
var type = hasRelationDef.type;
|
|
3687
|
+
if (ts.isUnionTypeNode(type)) {
|
|
3688
|
+
var types = type.types;
|
|
3689
|
+
var relations = types.map(function (ele) {
|
|
3690
|
+
(0, assert_1.default)(ts.isLiteralTypeNode(ele) && ts.isStringLiteral(ele.literal));
|
|
3691
|
+
return ele.literal.text;
|
|
3692
|
+
});
|
|
3693
|
+
entityRelations.push([(0, string_1.firstLetterLowerCase)(entity), relations]);
|
|
3694
|
+
}
|
|
3695
|
+
else {
|
|
3696
|
+
(0, assert_1.default)(ts.isLiteralTypeNode(type));
|
|
3697
|
+
(0, assert_1.default)(ts.isStringLiteral(type.literal));
|
|
3698
|
+
var relations = [type.literal.text];
|
|
3699
|
+
entityRelations.push([(0, string_1.firstLetterLowerCase)(entity), relations]);
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
}
|
|
3703
|
+
var stmts = [
|
|
3704
|
+
factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
3705
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("AuthCascadePath")),
|
|
3706
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("AuthDeduceRelationMap"))
|
|
3707
|
+
])), factory.createStringLiteral("".concat((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(1), "Entity")), undefined),
|
|
3708
|
+
factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("EntityDict"))])), factory.createStringLiteral("./EntityDict"), undefined),
|
|
3709
|
+
factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("CreateOperationData"), factory.createIdentifier("Relation"))])), factory.createStringLiteral("./Relation/Schema"), undefined),
|
|
3710
|
+
factory.createVariableStatement([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("ActionCascadePathGraph"), undefined, factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier("AuthCascadePath"), [factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)])), factory.createArrayLiteralExpression(actionPath.map(function (_a) {
|
|
3711
|
+
var _b = tslib_1.__read(_a, 4), entity = _b[0], path = _b[1], root = _b[2], isRelation = _b[3];
|
|
3712
|
+
return factory.createArrayLiteralExpression([
|
|
3713
|
+
factory.createStringLiteral(entity),
|
|
3714
|
+
factory.createStringLiteral(path),
|
|
3715
|
+
factory.createStringLiteral(root),
|
|
3716
|
+
isRelation ? factory.createTrue() : factory.createFalse()
|
|
3717
|
+
], false);
|
|
3718
|
+
}), true))], ts.NodeFlags.Const)),
|
|
3719
|
+
factory.createVariableStatement([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("RelationCascadePathGraph"), undefined, factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier("AuthCascadePath"), [factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)])), factory.createArrayLiteralExpression(relationPath.map(function (_a) {
|
|
3720
|
+
var _b = tslib_1.__read(_a, 4), entity = _b[0], path = _b[1], root = _b[2], isRelation = _b[3];
|
|
3721
|
+
return factory.createArrayLiteralExpression([
|
|
3722
|
+
factory.createStringLiteral(entity),
|
|
3723
|
+
factory.createStringLiteral(path),
|
|
3724
|
+
factory.createStringLiteral(root),
|
|
3725
|
+
isRelation ? factory.createTrue() : factory.createFalse()
|
|
3726
|
+
], false);
|
|
3727
|
+
}), true))], ts.NodeFlags.Const)),
|
|
3728
|
+
factory.createVariableStatement([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("relations"), undefined, factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier("Relation"), undefined)), factory.createArrayLiteralExpression((0, lodash_1.flatten)(entityRelations.map(function (_a) {
|
|
3729
|
+
var _b = tslib_1.__read(_a, 2), entity = _b[0], relations = _b[1];
|
|
3730
|
+
return relations.map(function (relation) { return factory.createObjectLiteralExpression([
|
|
3731
|
+
factory.createPropertyAssignment(factory.createIdentifier("id"), factory.createStringLiteral((0, uuid_1.formUuid)(entity, relation))),
|
|
3732
|
+
factory.createPropertyAssignment(factory.createIdentifier("entity"), factory.createStringLiteral(entity)),
|
|
3733
|
+
factory.createPropertyAssignment(factory.createIdentifier("name"), factory.createStringLiteral(relation))
|
|
3734
|
+
], true); });
|
|
3735
|
+
})), true))], ts.NodeFlags.Const))
|
|
3736
|
+
];
|
|
3737
|
+
stmts.push(factory.createVariableStatement([
|
|
3738
|
+
factory.createToken(ts.SyntaxKind.ExportKeyword)
|
|
3739
|
+
], factory.createVariableDeclarationList([
|
|
3740
|
+
factory.createVariableDeclaration(factory.createIdentifier("deducedRelationMap"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("AuthDeduceRelationMap"), [factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)]), factory.createObjectLiteralExpression(Object.keys(DEDUCED_RELATION_MAP).map(function (ele) { return factory.createPropertyAssignment(factory.createIdentifier((0, string_1.firstLetterLowerCase)(ele)), factory.createStringLiteral(DEDUCED_RELATION_MAP[ele])); }), true))
|
|
3741
|
+
], ts.NodeFlags.Const)));
|
|
3742
|
+
stmts.push(factory.createVariableStatement([
|
|
3743
|
+
factory.createToken(ts.SyntaxKind.ExportKeyword)
|
|
3744
|
+
], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("selectFreeEntities"), undefined, factory.createArrayTypeNode(factory.createParenthesizedType(factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)))), factory.createArrayLiteralExpression(SELECT_FREE_ENTITIES.map(function (ele) { return factory.createStringLiteral(ele); }), false))], ts.NodeFlags.Const)), factory.createVariableStatement([
|
|
3745
|
+
factory.createToken(ts.SyntaxKind.ExportKeyword)
|
|
3746
|
+
], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("updateFreeEntities"), undefined, factory.createArrayTypeNode(factory.createParenthesizedType(factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)))), factory.createArrayLiteralExpression(UPDATE_FREE_ENTITIES.map(function (ele) { return factory.createStringLiteral(ele); }), false))], ts.NodeFlags.Const)), factory.createVariableStatement([
|
|
3747
|
+
factory.createToken(ts.SyntaxKind.ExportKeyword)
|
|
3748
|
+
], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("createFreeEntities"), undefined, factory.createArrayTypeNode(factory.createParenthesizedType(factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)))), factory.createArrayLiteralExpression(CREATE_FREE_ENTITIES.map(function (ele) { return factory.createStringLiteral(ele); }), false))], ts.NodeFlags.Const)));
|
|
3749
|
+
var result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(stmts), ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS));
|
|
3750
|
+
var filename = path_1.default.join(outputDir, 'Relation.ts');
|
|
3751
|
+
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
|
3752
|
+
}
|
|
3343
3753
|
function analyzeEntities(inputDir, relativePath) {
|
|
3344
3754
|
var files = (0, fs_1.readdirSync)(inputDir);
|
|
3345
3755
|
var fullFilenames = files.map(function (ele) {
|
|
3346
3756
|
var entity = ele.slice(0, ele.indexOf('.'));
|
|
3347
|
-
if (env_1.
|
|
3757
|
+
if (env_1.RESERVED_ENTITY_NAMES.includes(entity) || env_1.RESERVED_ENTITY_NAMES.find(function (ele2) { return entity.startsWith(ele2); })) {
|
|
3348
3758
|
throw new Error("".concat(ele, "\u662F\u7CFB\u7EDF\u4FDD\u7559\u5B57\uFF0C\u8BF7\u52FF\u4F7F\u7528\u5176\u5F53\u5BF9\u8C61\u540D\u6216\u5BF9\u8C61\u540D\u524D\u7F00"));
|
|
3349
3759
|
}
|
|
3350
3760
|
return "".concat(inputDir, "/").concat(ele);
|
|
@@ -3359,6 +3769,7 @@ function analyzeEntities(inputDir, relativePath) {
|
|
|
3359
3769
|
exports.analyzeEntities = analyzeEntities;
|
|
3360
3770
|
function buildSchema(outputDir) {
|
|
3361
3771
|
addReverseRelationship();
|
|
3772
|
+
// setRelationEntities();
|
|
3362
3773
|
var printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
3363
3774
|
resetOutputDir(outputDir);
|
|
3364
3775
|
outputSchema(outputDir, printer);
|
|
@@ -3367,6 +3778,7 @@ function buildSchema(outputDir) {
|
|
|
3367
3778
|
outputAction(outputDir, printer);
|
|
3368
3779
|
outputEntityDict(outputDir, printer);
|
|
3369
3780
|
outputStorage(outputDir, printer);
|
|
3781
|
+
outputRelation(outputDir, printer);
|
|
3370
3782
|
outputIndexTs(outputDir);
|
|
3371
3783
|
if (!process.env.COMPLING_AS_LIB) {
|
|
3372
3784
|
outputPackageJson(outputDir);
|