oak-domain 5.1.16 → 5.1.18
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/base-app-domain/ActionAuth/Schema.d.ts +19 -171
- package/lib/base-app-domain/ActionAuth/Schema.js +2 -0
- package/lib/base-app-domain/ActionAuth/_baseSchema.d.ts +44 -0
- package/lib/base-app-domain/ActionAuth/_baseSchema.js +2 -0
- package/lib/base-app-domain/EntityDict.d.ts +695 -14
- package/lib/base-app-domain/I18n/Schema.d.ts +19 -129
- package/lib/base-app-domain/I18n/Schema.js +2 -0
- package/lib/base-app-domain/I18n/_baseSchema.d.ts +51 -0
- package/lib/base-app-domain/I18n/_baseSchema.js +2 -0
- package/lib/base-app-domain/Log/Schema.d.ts +19 -141
- package/lib/base-app-domain/Log/Schema.js +2 -0
- package/lib/base-app-domain/Log/Style.d.ts +2 -2
- package/lib/base-app-domain/Log/_baseSchema.d.ts +44 -0
- package/lib/base-app-domain/Log/_baseSchema.js +2 -0
- package/lib/base-app-domain/Modi/Schema.d.ts +19 -130
- package/lib/base-app-domain/Modi/Schema.js +2 -0
- package/lib/base-app-domain/Modi/Style.d.ts +2 -2
- package/lib/base-app-domain/Modi/_baseSchema.d.ts +61 -0
- package/lib/base-app-domain/Modi/_baseSchema.js +2 -0
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +19 -367
- package/lib/base-app-domain/ModiEntity/Schema.js +2 -0
- package/lib/base-app-domain/ModiEntity/Storage.js +1 -2
- package/lib/base-app-domain/ModiEntity/_baseSchema.d.ts +44 -0
- package/lib/base-app-domain/ModiEntity/_baseSchema.js +2 -0
- package/lib/base-app-domain/Oper/Schema.d.ts +19 -201
- package/lib/base-app-domain/Oper/Schema.js +2 -0
- package/lib/base-app-domain/Oper/Style.d.ts +2 -2
- package/lib/base-app-domain/Oper/_baseSchema.d.ts +67 -0
- package/lib/base-app-domain/Oper/_baseSchema.js +2 -0
- package/lib/base-app-domain/OperEntity/Schema.d.ts +19 -367
- package/lib/base-app-domain/OperEntity/Schema.js +2 -0
- package/lib/base-app-domain/OperEntity/Storage.js +1 -2
- package/lib/base-app-domain/OperEntity/_baseSchema.d.ts +44 -0
- package/lib/base-app-domain/OperEntity/_baseSchema.js +2 -0
- package/lib/base-app-domain/Path/Schema.d.ts +19 -157
- package/lib/base-app-domain/Path/Schema.js +2 -0
- package/lib/base-app-domain/Path/_baseSchema.d.ts +52 -0
- package/lib/base-app-domain/Path/_baseSchema.js +2 -0
- package/lib/base-app-domain/Relation/Schema.d.ts +19 -198
- package/lib/base-app-domain/Relation/Schema.js +2 -0
- package/lib/base-app-domain/Relation/_baseSchema.d.ts +48 -0
- package/lib/base-app-domain/Relation/_baseSchema.js +2 -0
- package/lib/base-app-domain/RelationAuth/Schema.d.ts +19 -199
- package/lib/base-app-domain/RelationAuth/Schema.js +2 -0
- package/lib/base-app-domain/RelationAuth/_baseSchema.d.ts +41 -0
- package/lib/base-app-domain/RelationAuth/_baseSchema.js +2 -0
- package/lib/base-app-domain/User/Schema.d.ts +19 -222
- package/lib/base-app-domain/User/Schema.js +2 -0
- package/lib/base-app-domain/User/Style.d.ts +2 -2
- package/lib/base-app-domain/User/_baseSchema.d.ts +53 -0
- package/lib/base-app-domain/User/_baseSchema.js +2 -0
- package/lib/base-app-domain/UserEntityClaim/Schema.d.ts +19 -264
- package/lib/base-app-domain/UserEntityClaim/Schema.js +2 -0
- package/lib/base-app-domain/UserEntityClaim/_baseSchema.d.ts +49 -0
- package/lib/base-app-domain/UserEntityClaim/_baseSchema.js +2 -0
- package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +19 -136
- package/lib/base-app-domain/UserEntityGrant/Schema.js +2 -0
- package/lib/base-app-domain/UserEntityGrant/_baseSchema.d.ts +46 -0
- package/lib/base-app-domain/UserEntityGrant/_baseSchema.js +2 -0
- package/lib/base-app-domain/UserRelation/Schema.d.ts +19 -212
- package/lib/base-app-domain/UserRelation/Schema.js +2 -0
- package/lib/base-app-domain/UserRelation/_baseSchema.d.ts +47 -0
- package/lib/base-app-domain/UserRelation/_baseSchema.js +2 -0
- package/lib/compiler/localeBuilder.d.ts +1 -0
- package/lib/compiler/localeBuilder.js +9 -2
- package/lib/compiler/schemalBuilder.d.ts +1 -0
- package/lib/compiler/schemalBuilder.js +1368 -186
- package/lib/data/i18n.d.ts +3 -0
- package/lib/data/i18n.js +32 -0
- package/lib/store/CascadeStore.d.ts +3 -3
- package/lib/store/CascadeStore.js +28 -27
- package/lib/store/RelationAuth.d.ts +1 -1
- package/lib/store/RelationAuth.js +6 -6
- package/lib/store/TriggerExecutor.js +11 -5
- package/lib/store/checker.js +1 -1
- package/lib/store/filter.d.ts +11 -11
- package/lib/store/filter.js +14 -8
- package/lib/store/modi.d.ts +2 -2
- package/lib/store/triggers.js +14 -14
- package/lib/timers/vaccum.d.ts +1 -1
- package/lib/types/Auth.d.ts +4 -4
- package/lib/types/Cluster.d.ts +1 -0
- package/lib/types/Configuration.d.ts +9 -0
- package/lib/types/Entity.d.ts +5 -1
- package/lib/types/EntityDesc.d.ts +1 -1
- package/lib/types/Exception.d.ts +26 -21
- package/lib/types/Exception.js +81 -71
- package/lib/types/Expression.d.ts +4 -1
- package/lib/types/Port.d.ts +1 -1
- package/lib/types/Trigger.d.ts +1 -1
- package/lib/types/Watcher.d.ts +3 -3
- package/lib/utils/projection.d.ts +2 -2
- package/lib/utils/relationPath.d.ts +4 -4
- package/lib/utils/relationPath.js +1 -1
- package/lib/utils/validator.d.ts +2 -2
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildSchema = exports.analyzeEntities = exports.registerDeducedRelationMap = exports.registerFixedDestinationPathMap = exports.registerIgnoredRelationPathMap = exports.registerFreeEntities = exports.registerIgnoredForeignKeyMap = void 0;
|
|
3
|
+
exports.buildSchema = exports.buildSchemaBackup = exports.analyzeEntities = exports.registerDeducedRelationMap = exports.registerFixedDestinationPathMap = exports.registerIgnoredRelationPathMap = exports.registerFreeEntities = exports.registerIgnoredForeignKeyMap = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
6
|
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
@@ -83,6 +83,9 @@ function createForeignRef(entity, foreignKey, ref) {
|
|
|
83
83
|
}
|
|
84
84
|
return factory.createQualifiedName(factory.createIdentifier(foreignKey), factory.createIdentifier(ref));
|
|
85
85
|
}
|
|
86
|
+
function createIndexedForeignRef(foreignEntity, ref) {
|
|
87
|
+
return factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(factory.createIdentifier(foreignEntity), undefined), factory.createLiteralTypeNode(factory.createStringLiteral(ref)));
|
|
88
|
+
}
|
|
86
89
|
function pushStatementIntoActionAst(moduleName, node, sourceFile) {
|
|
87
90
|
// let actionNames;
|
|
88
91
|
let actionDefName;
|
|
@@ -169,7 +172,7 @@ function checkActionDefNameConsistent(filename, actionDefNode) {
|
|
|
169
172
|
(0, assert_1.default)(ts.isTypeReferenceNode(actionNode) && ts.isTypeReferenceNode(stateNode), `文件${filename}中的ActionDef${name.text}类型声明中的action和state非法`);
|
|
170
173
|
(0, assert_1.default)(ts.isIdentifier(actionNode.typeName) && ts.isIdentifier(stateNode.typeName));
|
|
171
174
|
(0, assert_1.default)(actionNode.typeName.text.endsWith('Action'), `文件${filename}中的ActionDef${name.text}所引用的Action${actionNode.typeName}未以Action结尾`);
|
|
172
|
-
(0, assert_1.default)(stateNode.typeName.text.endsWith('State'), `文件${filename}中的ActionDef${name.text}所引用的
|
|
175
|
+
(0, assert_1.default)(stateNode.typeName.text.endsWith('State'), `文件${filename}中的ActionDef${name.text}所引用的State${stateNode.typeName}未以State结尾`);
|
|
173
176
|
const adfName = name.text.slice(0, name.text.length - 9);
|
|
174
177
|
const aName = actionNode.typeName.text.slice(0, actionNode.typeName.text.length - 6);
|
|
175
178
|
const sName = stateNode.typeName.text.slice(0, stateNode.typeName.text.length - 5);
|
|
@@ -913,24 +916,29 @@ function analyzeEntity(filename, path, program, relativePath) {
|
|
|
913
916
|
toLog = result.toLog;
|
|
914
917
|
extendsFrom = result.extendsFrom;
|
|
915
918
|
// 对于不是Modi和Oper的对象,全部建立和ModiEntity的反指关系
|
|
916
|
-
if (!['Modi', 'Oper', 'OperEntity', 'ModiEntity'].includes(moduleName) && !toModi) {
|
|
917
|
-
if (ReversePointerRelations['ModiEntity']
|
|
918
|
-
ReversePointerRelations['ModiEntity'].
|
|
919
|
+
/* if (!['Modi', 'Oper', 'OperEntity', 'ModiEntity'].includes(moduleName) && !toModi) {
|
|
920
|
+
if (ReversePointerRelations['ModiEntity']) {
|
|
921
|
+
if (!ReversePointerRelations['ModiEntity'].includes(moduleName)) {
|
|
922
|
+
ReversePointerRelations['ModiEntity'].push(moduleName);
|
|
923
|
+
}
|
|
919
924
|
}
|
|
920
925
|
else {
|
|
921
|
-
|
|
926
|
+
assign(ReversePointerRelations, {
|
|
922
927
|
['ModiEntity']: [moduleName],
|
|
923
928
|
});
|
|
924
929
|
}
|
|
925
|
-
|
|
926
|
-
|
|
930
|
+
|
|
931
|
+
if (ReversePointerRelations['OperEntity']) {
|
|
932
|
+
if (!ReversePointerRelations['OperEntity'].includes(moduleName)) {
|
|
933
|
+
ReversePointerRelations['OperEntity'].push(moduleName);
|
|
934
|
+
}
|
|
927
935
|
}
|
|
928
936
|
else {
|
|
929
|
-
|
|
937
|
+
assign(ReversePointerRelations, {
|
|
930
938
|
['OperEntity']: [moduleName],
|
|
931
939
|
});
|
|
932
940
|
}
|
|
933
|
-
}
|
|
941
|
+
} */
|
|
934
942
|
}
|
|
935
943
|
else if (beforeSchema) {
|
|
936
944
|
// 本地规定的一些形状定义,直接使用
|
|
@@ -1526,6 +1534,85 @@ function constructSchema(statements, entity) {
|
|
|
1526
1534
|
...otmAggrMappedNodes,
|
|
1527
1535
|
])));
|
|
1528
1536
|
}
|
|
1537
|
+
function _constructOpSchema(statements, entity) {
|
|
1538
|
+
const { schemaAttrs } = Schema[entity];
|
|
1539
|
+
const members = [];
|
|
1540
|
+
const members2 = [];
|
|
1541
|
+
const { [entity]: manyToOneSet } = ManyToOne;
|
|
1542
|
+
const { [entity]: oneToManySet } = OneToMany;
|
|
1543
|
+
const referenceEntities = [];
|
|
1544
|
+
for (const attr of schemaAttrs) {
|
|
1545
|
+
const { type, name, questionToken } = attr;
|
|
1546
|
+
const attrName = name.text;
|
|
1547
|
+
if (ts.isTypeReferenceNode(type)) {
|
|
1548
|
+
const { typeName } = type;
|
|
1549
|
+
if (ts.isIdentifier(typeName)) {
|
|
1550
|
+
const { text } = typeName;
|
|
1551
|
+
const text2 = text === 'Schema' ? entity : text;
|
|
1552
|
+
const manyToOneItem = manyToOneSet && manyToOneSet.find(([refEntity, attrName2]) => refEntity === text2 && attrName2 === attrName);
|
|
1553
|
+
if (manyToOneItem) {
|
|
1554
|
+
referenceEntities.push(text2);
|
|
1555
|
+
members2.push(factory.createPropertySignature(undefined, name, questionToken, questionToken ? factory.createUnionTypeNode([
|
|
1556
|
+
factory.createTypeReferenceNode(createForeignRef(entity, text2, 'Schema')),
|
|
1557
|
+
factory.createLiteralTypeNode(factory.createNull())
|
|
1558
|
+
]) : factory.createTypeReferenceNode(createForeignRef(entity, text2, 'Schema'))));
|
|
1559
|
+
const foreignKey = `${attrName}Id`;
|
|
1560
|
+
members.push(factory.createPropertySignature(undefined, factory.createIdentifier(foreignKey), questionToken, questionToken ? factory.createUnionTypeNode([
|
|
1561
|
+
factory.createTypeReferenceNode(factory.createIdentifier('ForeignKey'), [
|
|
1562
|
+
factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(text2)))
|
|
1563
|
+
]),
|
|
1564
|
+
factory.createLiteralTypeNode(factory.createNull())
|
|
1565
|
+
]) : factory.createTypeReferenceNode(factory.createIdentifier('ForeignKey'), [
|
|
1566
|
+
factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(text2)))
|
|
1567
|
+
])));
|
|
1568
|
+
}
|
|
1569
|
+
else {
|
|
1570
|
+
// assert(types.includes(text), `${entity}中的属性${name.toString()}有非法的属性类型定义`);
|
|
1571
|
+
// 处理entity这种特殊情况
|
|
1572
|
+
if (ReversePointerRelations[entity] && attrName === 'entity') {
|
|
1573
|
+
const entityUnionTypeNode = ReversePointerRelations[entity].map(ele => factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(ele))));
|
|
1574
|
+
if (process.env.COMPLING_AS_LIB) {
|
|
1575
|
+
// 如果是建立 base-domain,还要容纳可能的其它对象引用
|
|
1576
|
+
entityUnionTypeNode.push(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
|
|
1577
|
+
}
|
|
1578
|
+
members.push(factory.createPropertySignature(undefined, name, questionToken, questionToken ? factory.createUnionTypeNode([
|
|
1579
|
+
factory.createUnionTypeNode(entityUnionTypeNode),
|
|
1580
|
+
factory.createLiteralTypeNode(factory.createNull())
|
|
1581
|
+
]) : factory.createUnionTypeNode(entityUnionTypeNode)));
|
|
1582
|
+
}
|
|
1583
|
+
else {
|
|
1584
|
+
members.push(factory.createPropertySignature(undefined, name, questionToken, questionToken ? factory.createUnionTypeNode([
|
|
1585
|
+
type,
|
|
1586
|
+
factory.createLiteralTypeNode(factory.createNull())
|
|
1587
|
+
]) : type));
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
else {
|
|
1592
|
+
(0, assert_1.default)(false); // 这是什么case,不确定
|
|
1593
|
+
members.push(attr);
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
else {
|
|
1597
|
+
// assert(ts.isUnionTypeNode(type!) || ts.isLiteralTypeNode(type!), `${entity}有非法的属性类型定义${(<ts.Identifier>name).text}`);
|
|
1598
|
+
members.push(factory.createPropertySignature(undefined, name, questionToken, questionToken ? factory.createUnionTypeNode([
|
|
1599
|
+
type,
|
|
1600
|
+
factory.createLiteralTypeNode(factory.createNull())
|
|
1601
|
+
]) : type));
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
// 在这里把需要直接拷贝过来的语句写入
|
|
1605
|
+
if (SchemaAsts[entity]) {
|
|
1606
|
+
statements.push(...SchemaAsts[entity].statements);
|
|
1607
|
+
}
|
|
1608
|
+
statements.push(factory.createTypeAliasDeclaration([
|
|
1609
|
+
factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
1610
|
+
], factory.createIdentifier('OpSchema'), undefined, factory.createIntersectionTypeNode([
|
|
1611
|
+
factory.createTypeReferenceNode('EntityShape'),
|
|
1612
|
+
factory.createTypeLiteralNode(members),
|
|
1613
|
+
factory.createMappedTypeNode(undefined, factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("A"), factory.createTypeReferenceNode(factory.createIdentifier("ExpressionKey"), undefined), undefined), undefined, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), undefined),
|
|
1614
|
+
])), factory.createTypeAliasDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("OpAttr"), undefined, factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeReferenceNode(factory.createIdentifier("OpSchema"), undefined))));
|
|
1615
|
+
}
|
|
1529
1616
|
/**
|
|
1530
1617
|
* 生成Query
|
|
1531
1618
|
* @param statements
|
|
@@ -1703,6 +1790,137 @@ function constructFilter(statements, entity) {
|
|
|
1703
1790
|
}
|
|
1704
1791
|
statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Filter"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("MakeFilter"), [factory.createIntersectionTypeNode(types)])));
|
|
1705
1792
|
}
|
|
1793
|
+
function _constructOpFilter(statements, entity) {
|
|
1794
|
+
const { schemaAttrs, fulltextIndex, enumAttributes } = Schema[entity];
|
|
1795
|
+
const members = [
|
|
1796
|
+
// id: Q_StringValue
|
|
1797
|
+
factory.createPropertySignature(undefined, factory.createIdentifier('id'), undefined, factory.createUnionTypeNode([
|
|
1798
|
+
factory.createTypeReferenceNode(factory.createIdentifier('Q_StringValue')),
|
|
1799
|
+
/* factory.createTypeReferenceNode(
|
|
1800
|
+
factory.createQualifiedName(
|
|
1801
|
+
factory.createIdentifier("SubQuery"),
|
|
1802
|
+
factory.createIdentifier(`${entity}IdSubQuery`)
|
|
1803
|
+
)
|
|
1804
|
+
) */
|
|
1805
|
+
])),
|
|
1806
|
+
// $$createAt$$: Q_DateValue
|
|
1807
|
+
factory.createPropertySignature(undefined, factory.createIdentifier('$$createAt$$'), undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_DateValue'))),
|
|
1808
|
+
// $$seq$$: Q_StringValue
|
|
1809
|
+
factory.createPropertySignature(undefined, factory.createIdentifier('$$seq$$'), undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_NumberValue'))),
|
|
1810
|
+
// $$updateAt$$: Q_DateValue
|
|
1811
|
+
factory.createPropertySignature(undefined, factory.createIdentifier('$$updateAt$$'), undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_DateValue')))
|
|
1812
|
+
];
|
|
1813
|
+
const entityUnionTypeNodes = ReversePointerRelations[entity] && ReversePointerRelations[entity].map(ele => factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(ele))));
|
|
1814
|
+
if (process.env.COMPLING_AS_LIB) {
|
|
1815
|
+
entityUnionTypeNodes && entityUnionTypeNodes.push(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
|
|
1816
|
+
}
|
|
1817
|
+
const { [entity]: manyToOneSet } = ManyToOne;
|
|
1818
|
+
for (const attr of schemaAttrs) {
|
|
1819
|
+
const { type, name } = attr;
|
|
1820
|
+
const attrName = name.text;
|
|
1821
|
+
if (ts.isTypeReferenceNode(type)) {
|
|
1822
|
+
const { typeName } = type;
|
|
1823
|
+
if (ts.isIdentifier(typeName)) {
|
|
1824
|
+
const { text } = typeName;
|
|
1825
|
+
let type2;
|
|
1826
|
+
switch (text) {
|
|
1827
|
+
case 'String':
|
|
1828
|
+
case 'Text':
|
|
1829
|
+
case 'Image':
|
|
1830
|
+
case 'File': {
|
|
1831
|
+
if (ReversePointerRelations[entity] && attrName === 'entity') {
|
|
1832
|
+
type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_EnumValue'), [
|
|
1833
|
+
factory.createUnionTypeNode(entityUnionTypeNodes)
|
|
1834
|
+
]);
|
|
1835
|
+
}
|
|
1836
|
+
else {
|
|
1837
|
+
type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_StringValue'));
|
|
1838
|
+
}
|
|
1839
|
+
break;
|
|
1840
|
+
}
|
|
1841
|
+
case 'Int':
|
|
1842
|
+
case 'Uint':
|
|
1843
|
+
case 'Float':
|
|
1844
|
+
case 'Double':
|
|
1845
|
+
case 'Price':
|
|
1846
|
+
case 'Decimal': {
|
|
1847
|
+
type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_NumberValue'));
|
|
1848
|
+
break;
|
|
1849
|
+
}
|
|
1850
|
+
case 'Boolean': {
|
|
1851
|
+
type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_BooleanValue'));
|
|
1852
|
+
break;
|
|
1853
|
+
}
|
|
1854
|
+
case 'Datetime': {
|
|
1855
|
+
type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_DateValue'));
|
|
1856
|
+
break;
|
|
1857
|
+
}
|
|
1858
|
+
case 'SingleGeo':
|
|
1859
|
+
case 'Geo': {
|
|
1860
|
+
// geo类型暂时只支持通过expr查询
|
|
1861
|
+
break;
|
|
1862
|
+
}
|
|
1863
|
+
case 'Object': {
|
|
1864
|
+
type2 = factory.createTypeReferenceNode(factory.createIdentifier('Object'));
|
|
1865
|
+
break;
|
|
1866
|
+
}
|
|
1867
|
+
default: {
|
|
1868
|
+
const text2 = text === 'Schema' ? entity : text;
|
|
1869
|
+
const manyToOneItem = manyToOneSet && manyToOneSet.find(([refEntity]) => refEntity === text2);
|
|
1870
|
+
if (manyToOneItem) {
|
|
1871
|
+
// 外键可能落到相应的子查询中
|
|
1872
|
+
members.push(factory.createPropertySignature(undefined, `${name.text}Id`, undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_StringValue'))));
|
|
1873
|
+
}
|
|
1874
|
+
else if (enumAttributes && enumAttributes[attrName] || ts.isUnionTypeNode(type)) {
|
|
1875
|
+
// 这里应该都是引用某个UnionType类型的定义了,如何判断?
|
|
1876
|
+
// const words = getStringTextFromUnionStringLiterals();
|
|
1877
|
+
type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_EnumValue'), [
|
|
1878
|
+
factory.createTypeReferenceNode(factory.createIdentifier(text), undefined)
|
|
1879
|
+
]);
|
|
1880
|
+
}
|
|
1881
|
+
else {
|
|
1882
|
+
// 非枚举类型的非结构化属性,用JSONFilter来形式化
|
|
1883
|
+
type2 = factory.createTypeReferenceNode(factory.createIdentifier('JsonFilter'), [
|
|
1884
|
+
factory.createTypeReferenceNode(factory.createIdentifier(text), undefined)
|
|
1885
|
+
]);
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
if (type2) {
|
|
1890
|
+
members.push(factory.createPropertySignature(undefined, name, undefined, type2));
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
else if (ts.isUnionTypeNode(type) && ts.isLiteralTypeNode(type.types[0]) || ts.isLiteralTypeNode(type)) {
|
|
1895
|
+
members.push(factory.createPropertySignature(undefined, name, undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_EnumValue'), [
|
|
1896
|
+
type
|
|
1897
|
+
])));
|
|
1898
|
+
}
|
|
1899
|
+
else {
|
|
1900
|
+
// 此时应当是引用本地定义的shape
|
|
1901
|
+
(0, assert_1.default)(type, `${entity}中的属性${name.toString()}有非法的属性类型定义`);
|
|
1902
|
+
members.push(factory.createPropertySignature(undefined, name, undefined, factory.createTypeReferenceNode(factory.createIdentifier('JsonFilter'), [
|
|
1903
|
+
type
|
|
1904
|
+
])));
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
const types = [
|
|
1908
|
+
factory.createTypeLiteralNode(members),
|
|
1909
|
+
factory.createTypeReferenceNode(factory.createIdentifier("ExprOp"), [
|
|
1910
|
+
process.env.COMPLING_AS_LIB ?
|
|
1911
|
+
factory.createUnionTypeNode([
|
|
1912
|
+
factory.createTypeReferenceNode(factory.createIdentifier('OpAttr')),
|
|
1913
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
|
|
1914
|
+
]) :
|
|
1915
|
+
factory.createTypeReferenceNode(factory.createIdentifier('OpAttr'))
|
|
1916
|
+
]),
|
|
1917
|
+
];
|
|
1918
|
+
// 如果还有其它类型的查询如全文,则加在types数组中
|
|
1919
|
+
if (fulltextIndex) {
|
|
1920
|
+
types.push(factory.createTypeReferenceNode('FulltextFilter'));
|
|
1921
|
+
}
|
|
1922
|
+
statements.push(factory.createTypeAliasDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("OpFilter"), undefined, factory.createIntersectionTypeNode(types)));
|
|
1923
|
+
}
|
|
1706
1924
|
/**
|
|
1707
1925
|
* 构造Projection和OneAttrProjection
|
|
1708
1926
|
* @param statements
|
|
@@ -1931,52 +2149,159 @@ function constructProjection(statements, entity) {
|
|
|
1931
2149
|
])));
|
|
1932
2150
|
}
|
|
1933
2151
|
}
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
2152
|
+
function _constructOpProjection(statements, entity) {
|
|
2153
|
+
const { schemaAttrs, enumAttributes } = Schema[entity];
|
|
2154
|
+
const properties = [
|
|
2155
|
+
['id', false],
|
|
2156
|
+
['$$createAt$$', false],
|
|
2157
|
+
['$$updateAt$$', false],
|
|
2158
|
+
['$$seq$$', false],
|
|
2159
|
+
];
|
|
2160
|
+
const { [entity]: manyToOneSet } = ManyToOne;
|
|
2161
|
+
for (const attr of schemaAttrs) {
|
|
2162
|
+
const { type, name } = attr;
|
|
2163
|
+
const attrName = name.text;
|
|
2164
|
+
if (ts.isTypeReferenceNode(type)) {
|
|
2165
|
+
const { typeName } = type;
|
|
2166
|
+
if (ts.isIdentifier(typeName)) {
|
|
2167
|
+
const { text } = typeName;
|
|
2168
|
+
switch (text) {
|
|
2169
|
+
case 'String':
|
|
2170
|
+
case 'Text':
|
|
2171
|
+
case 'Int':
|
|
2172
|
+
case 'Uint':
|
|
2173
|
+
case 'Float':
|
|
2174
|
+
case 'Double':
|
|
2175
|
+
case 'Boolean':
|
|
2176
|
+
case 'Datetime':
|
|
2177
|
+
case 'Image':
|
|
2178
|
+
case 'File':
|
|
2179
|
+
case 'SingleGeo':
|
|
2180
|
+
case 'Geo':
|
|
2181
|
+
case 'Price':
|
|
2182
|
+
case 'Decimal': {
|
|
2183
|
+
properties.push([name, false]);
|
|
2184
|
+
break;
|
|
2185
|
+
}
|
|
2186
|
+
case 'Object': {
|
|
2187
|
+
properties.push([name, false, factory.createUnionTypeNode([
|
|
2188
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
|
|
2189
|
+
factory.createTypeReferenceNode(factory.createIdentifier("Object"), undefined)
|
|
2190
|
+
])]);
|
|
2191
|
+
break;
|
|
2192
|
+
}
|
|
2193
|
+
default: {
|
|
2194
|
+
const text2 = text === 'Schema' ? entity : text;
|
|
2195
|
+
const manyToOneItem = manyToOneSet && manyToOneSet.find(([refEntity]) => refEntity === text2);
|
|
2196
|
+
if (manyToOneItem) {
|
|
2197
|
+
// 外键投影
|
|
2198
|
+
properties.push([`${attrName}Id`, false, undefined]);
|
|
2199
|
+
}
|
|
2200
|
+
else {
|
|
2201
|
+
if (!enumAttributes || !enumAttributes[attrName]) {
|
|
2202
|
+
// 引用的非enum类型shape
|
|
2203
|
+
properties.push([name, false, factory.createUnionTypeNode([
|
|
2204
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
|
|
2205
|
+
factory.createTypeReferenceNode(factory.createIdentifier("JsonProjection"), [type])
|
|
2206
|
+
])]);
|
|
2207
|
+
}
|
|
2208
|
+
else {
|
|
2209
|
+
// 引用的enum类型shape
|
|
2210
|
+
properties.push([name, false, undefined]);
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
else {
|
|
2217
|
+
(0, assert_1.default)(false);
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
else {
|
|
2221
|
+
// 增加了本身object的shape定义
|
|
2222
|
+
// assert(ts.isUnionTypeNode(type!) && ts.isLiteralTypeNode(type.types[0]) || ts.isLiteralTypeNode(type!));
|
|
2223
|
+
if (enumAttributes && enumAttributes[attrName] || ts.isUnionTypeNode(type) && ts.isLiteralTypeNode(type.types[0])) {
|
|
2224
|
+
properties.push([name, false, undefined]);
|
|
2225
|
+
}
|
|
2226
|
+
else {
|
|
2227
|
+
// 如果是非枚举类型的其它对象的union定义,加上JsonProjection
|
|
2228
|
+
properties.push([name, false, factory.createUnionTypeNode([
|
|
2229
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
|
|
2230
|
+
factory.createTypeReferenceNode(factory.createIdentifier("JsonProjection"), [type])
|
|
2231
|
+
])]);
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
const exprNode = factory.createTypeReferenceNode(factory.createIdentifier("Partial"), [
|
|
2236
|
+
factory.createTypeReferenceNode(factory.createIdentifier("ExprOp"), [
|
|
2237
|
+
process.env.COMPLING_AS_LIB ?
|
|
2238
|
+
factory.createUnionTypeNode([
|
|
2239
|
+
factory.createTypeReferenceNode(factory.createIdentifier('OpAttr')),
|
|
2240
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
|
|
2241
|
+
]) :
|
|
2242
|
+
factory.createTypeReferenceNode(factory.createIdentifier('OpAttr'))
|
|
2243
|
+
])
|
|
2244
|
+
]);
|
|
2245
|
+
const MetaPropertySignatures = [
|
|
2246
|
+
factory.createPropertySignature(undefined, factory.createStringLiteral("#id"), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode('NodeId'))
|
|
2247
|
+
];
|
|
2248
|
+
if (process.env.COMPLING_AS_LIB) {
|
|
2249
|
+
MetaPropertySignatures.push(factory.createIndexSignature(undefined, [factory.createParameterDeclaration(undefined, undefined, factory.createIdentifier("k"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)));
|
|
2250
|
+
}
|
|
2251
|
+
// OpProjection,原始属性投影
|
|
2252
|
+
statements.push(factory.createTypeAliasDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("OpProjection"), undefined, factory.createIntersectionTypeNode([
|
|
2253
|
+
factory.createTypeLiteralNode(MetaPropertySignatures.concat(properties.map(([n, q, v]) => {
|
|
2254
|
+
return factory.createPropertySignature(undefined, n, q ? undefined : factory.createToken(ts.SyntaxKind.QuestionToken), v || factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword));
|
|
2255
|
+
}))),
|
|
2256
|
+
exprNode,
|
|
2257
|
+
])));
|
|
2258
|
+
}
|
|
2259
|
+
/**
|
|
2260
|
+
* 构造Query
|
|
2261
|
+
* @param statements
|
|
2262
|
+
* @param entity
|
|
2263
|
+
*/
|
|
2264
|
+
function constructQuery(statements, entity) {
|
|
2265
|
+
const entityLc = (0, string_1.firstLetterLowerCase)(entity);
|
|
2266
|
+
/* statements.push(
|
|
2267
|
+
factory.createTypeAliasDeclaration(
|
|
2268
|
+
undefined,
|
|
2269
|
+
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
2270
|
+
factory.createIdentifier("Query"),
|
|
2271
|
+
undefined,
|
|
2272
|
+
factory.createIntersectionTypeNode([
|
|
2273
|
+
factory.createTypeLiteralNode([
|
|
2274
|
+
// 这里可以不写entity了
|
|
2275
|
+
factory.createPropertySignature(
|
|
2276
|
+
undefined,
|
|
2277
|
+
factory.createIdentifier("projection"),
|
|
2278
|
+
undefined,
|
|
2279
|
+
factory.createTypeReferenceNode(
|
|
2280
|
+
factory.createIdentifier("Projection"),
|
|
2281
|
+
undefined
|
|
2282
|
+
)
|
|
2283
|
+
),
|
|
2284
|
+
factory.createPropertySignature(
|
|
2285
|
+
undefined,
|
|
2286
|
+
factory.createIdentifier("sort"),
|
|
2287
|
+
factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
2288
|
+
factory.createTypeReferenceNode(
|
|
2289
|
+
factory.createIdentifier("Sorter"),
|
|
2290
|
+
undefined
|
|
2291
|
+
)
|
|
2292
|
+
)
|
|
2293
|
+
]),
|
|
2294
|
+
factory.createTypeReferenceNode(
|
|
2295
|
+
factory.createIdentifier("OakFilter"),
|
|
2296
|
+
[
|
|
2297
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("select")),
|
|
2298
|
+
factory.createTypeReferenceNode(
|
|
2299
|
+
factory.createIdentifier("Filter"),
|
|
2300
|
+
undefined
|
|
2301
|
+
)
|
|
2302
|
+
]
|
|
2303
|
+
),
|
|
2304
|
+
factory.createTypeReferenceNode(
|
|
1980
2305
|
factory.createIdentifier("OakOperation"),
|
|
1981
2306
|
[
|
|
1982
2307
|
factory.createTypeReferenceNode(
|
|
@@ -2169,72 +2494,80 @@ function constructSorter(statements, entity) {
|
|
|
2169
2494
|
*/
|
|
2170
2495
|
statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Sorter"), undefined, factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier("SortNode"), undefined))));
|
|
2171
2496
|
}
|
|
2172
|
-
function
|
|
2497
|
+
function _constructOpSortAttr(statements, entity) {
|
|
2498
|
+
const { schemaAttrs } = Schema[entity];
|
|
2499
|
+
const members = [
|
|
2500
|
+
// id: 1
|
|
2501
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("id"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword)),
|
|
2502
|
+
// $$createAt$$: 1
|
|
2503
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("$$createAt$$"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword)),
|
|
2504
|
+
// $$seq$$: 1
|
|
2505
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("$$seq$$"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword)),
|
|
2506
|
+
// $$updateAt$$: 1
|
|
2507
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("$$updateAt$$"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword)),
|
|
2508
|
+
];
|
|
2173
2509
|
const { [entity]: manyToOneSet } = ManyToOne;
|
|
2174
|
-
const
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2510
|
+
for (const attr of schemaAttrs) {
|
|
2511
|
+
const { type, name, questionToken } = attr;
|
|
2512
|
+
if (ts.isTypeReferenceNode(type)) {
|
|
2513
|
+
const { typeName } = type;
|
|
2514
|
+
if (ts.isIdentifier(typeName)) {
|
|
2515
|
+
const { text } = typeName;
|
|
2516
|
+
let type2;
|
|
2517
|
+
switch (text) {
|
|
2518
|
+
case 'String':
|
|
2519
|
+
case 'Text':
|
|
2520
|
+
case 'Int':
|
|
2521
|
+
case 'Float':
|
|
2522
|
+
case 'Double':
|
|
2523
|
+
case 'Boolean':
|
|
2524
|
+
case 'Datetime':
|
|
2525
|
+
case 'Image':
|
|
2526
|
+
case 'File':
|
|
2527
|
+
case 'Price': {
|
|
2528
|
+
type2 = factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword);
|
|
2529
|
+
break;
|
|
2530
|
+
}
|
|
2531
|
+
default: {
|
|
2532
|
+
const text2 = text === 'Schema' ? entity : text;
|
|
2533
|
+
const manyToOneItem = manyToOneSet && manyToOneSet.find(([refEntity]) => refEntity === text2);
|
|
2534
|
+
if (manyToOneItem) {
|
|
2535
|
+
factory.createPropertySignature(undefined, factory.createIdentifier(`${name.text}Id`), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword));
|
|
2536
|
+
}
|
|
2537
|
+
else if (!['Object'].includes(text)) {
|
|
2538
|
+
// todo 对State的专门处理
|
|
2539
|
+
type2 = factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword);
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2543
|
+
if (type2) {
|
|
2544
|
+
members.push(factory.createPropertySignature(undefined, name, undefined, type2));
|
|
2545
|
+
}
|
|
2186
2546
|
}
|
|
2187
2547
|
}
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
...mtoAttrs
|
|
2191
|
-
])));
|
|
2192
|
-
}
|
|
2193
|
-
else {
|
|
2194
|
-
statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("NativeAttr"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OpAttr"), undefined)));
|
|
2195
|
-
}
|
|
2196
|
-
const foreignKeySet = {};
|
|
2197
|
-
if (oneToManySet && oneToManySet.length > 0) {
|
|
2198
|
-
for (const oneToManyItem of oneToManySet) {
|
|
2199
|
-
const [entityName, foreignKey] = oneToManyItem;
|
|
2200
|
-
if (foreignKeySet.hasOwnProperty(entityName)) {
|
|
2201
|
-
foreignKeySet[entityName].push(foreignKey);
|
|
2202
|
-
}
|
|
2203
|
-
else {
|
|
2204
|
-
foreignKeySet[entityName] = [foreignKey];
|
|
2205
|
-
}
|
|
2548
|
+
else if (ts.isUnionTypeNode(type) && ts.isLiteralTypeNode(type.types[0]) || ts.isLiteralTypeNode(type)) {
|
|
2549
|
+
members.push(factory.createPropertySignature(undefined, name, undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword)));
|
|
2206
2550
|
}
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
const entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
|
|
2210
|
-
if (foreignKeySet[entityName].length > 1) {
|
|
2211
|
-
foreignKeySet[entityName].forEach((foreignKey) => {
|
|
2212
|
-
const head = `${entityNameLc}s$${foreignKey}`;
|
|
2213
|
-
otmAttrs.push(factory.createTemplateLiteralType(factory.createTemplateHead(`${head}$`, `${head}$`), [
|
|
2214
|
-
factory.createTemplateLiteralTypeSpan(factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword), factory.createTemplateMiddle(".", ".")),
|
|
2215
|
-
factory.createTemplateLiteralTypeSpan(factory.createTypeReferenceNode(entityName === entity
|
|
2216
|
-
? factory.createIdentifier("NativeAttr")
|
|
2217
|
-
: factory.createQualifiedName(factory.createIdentifier(entityName), factory.createIdentifier("NativeAttr")), undefined), factory.createTemplateTail("", ""))
|
|
2218
|
-
]));
|
|
2219
|
-
});
|
|
2220
|
-
}
|
|
2221
|
-
else {
|
|
2222
|
-
otmAttrs.push(factory.createTemplateLiteralType(factory.createTemplateHead(`${entityNameLc}s$`, `${entityNameLc}s$`), [
|
|
2223
|
-
factory.createTemplateLiteralTypeSpan(factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword), factory.createTemplateMiddle(".", ".")),
|
|
2224
|
-
factory.createTemplateLiteralTypeSpan(factory.createTypeReferenceNode(entityName === entity
|
|
2225
|
-
? factory.createIdentifier("NativeAttr")
|
|
2226
|
-
: factory.createQualifiedName(factory.createIdentifier(entityName), factory.createIdentifier("NativeAttr")), undefined), factory.createTemplateTail("", ""))
|
|
2227
|
-
]));
|
|
2228
|
-
}
|
|
2551
|
+
else {
|
|
2552
|
+
// 本地规定的shape,非结构化属性不参与排序
|
|
2229
2553
|
}
|
|
2230
|
-
statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("FullAttr"), undefined, factory.createUnionTypeNode([
|
|
2231
|
-
factory.createTypeReferenceNode(factory.createIdentifier("NativeAttr"), undefined),
|
|
2232
|
-
...otmAttrs
|
|
2233
|
-
])));
|
|
2234
2554
|
}
|
|
2235
|
-
|
|
2236
|
-
|
|
2555
|
+
if (process.env.COMPLING_AS_LIB) {
|
|
2556
|
+
members.push(factory.createIndexSignature(undefined, [factory.createParameterDeclaration(undefined, undefined, factory.createIdentifier("k"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)));
|
|
2237
2557
|
}
|
|
2558
|
+
statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("OpSortAttr"), undefined, factory.createTypeReferenceNode('Partial', [
|
|
2559
|
+
factory.createUnionTypeNode([
|
|
2560
|
+
factory.createTypeLiteralNode(members),
|
|
2561
|
+
factory.createTypeReferenceNode(factory.createIdentifier("ExprOp"), [
|
|
2562
|
+
process.env.COMPLING_AS_LIB ?
|
|
2563
|
+
factory.createUnionTypeNode([
|
|
2564
|
+
factory.createTypeReferenceNode(factory.createIdentifier('OpAttr')),
|
|
2565
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
|
|
2566
|
+
]) :
|
|
2567
|
+
factory.createTypeReferenceNode(factory.createIdentifier('OpAttr'))
|
|
2568
|
+
])
|
|
2569
|
+
])
|
|
2570
|
+
])));
|
|
2238
2571
|
}
|
|
2239
2572
|
function constructOperations(statements, entity) {
|
|
2240
2573
|
// Selection
|
|
@@ -3020,13 +3353,13 @@ function constructOperations(statements, entity) {
|
|
|
3020
3353
|
factory.createTypeReferenceNode(factory.createIdentifier("RemoveOperation"), undefined)
|
|
3021
3354
|
])));
|
|
3022
3355
|
}
|
|
3023
|
-
const initialStatements = () => [
|
|
3356
|
+
const initialStatements = (level) => [
|
|
3024
3357
|
// import { String, Text, Int, SpecificKey } from 'oak-domain/types/DataType';
|
|
3025
3358
|
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
3026
3359
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('PrimaryKey')),
|
|
3027
3360
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('ForeignKey')),
|
|
3028
3361
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('JsonProjection'))
|
|
3029
|
-
])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)()}DataType`)),
|
|
3362
|
+
])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(level)}DataType`)),
|
|
3030
3363
|
/* import {
|
|
3031
3364
|
Q_DateValue, Q_LogicKey, Q_NumberValue, FnCallKey, FnCallValue,
|
|
3032
3365
|
Q_StringValue, Q_FullTextKey, Q_FullTextValue, FnCallValueAs,
|
|
@@ -3045,11 +3378,11 @@ const initialStatements = () => [
|
|
|
3045
3378
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('ExpressionKey')),
|
|
3046
3379
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('JsonFilter')),
|
|
3047
3380
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('SubQueryPredicateMetadata')),
|
|
3048
|
-
])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)()}Demand`)),
|
|
3381
|
+
])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(level)}Demand`)),
|
|
3049
3382
|
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
3050
3383
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier("OneOf")),
|
|
3051
3384
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier("ValueOf"))
|
|
3052
|
-
])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)()}Polyfill`)),
|
|
3385
|
+
])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(level)}Polyfill`)),
|
|
3053
3386
|
// import * as SubQuery from '../_SubQuery';
|
|
3054
3387
|
/* factory.createImportDeclaration(
|
|
3055
3388
|
undefined,
|
|
@@ -3071,8 +3404,67 @@ const initialStatements = () => [
|
|
|
3071
3404
|
factory.createImportSpecifier(false, factory.createIdentifier("MakeAction"), factory.createIdentifier("OakMakeAction")),
|
|
3072
3405
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier("AggregationResult")),
|
|
3073
3406
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier("EntityShape")),
|
|
3407
|
+
])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(level)}Entity`), undefined)
|
|
3408
|
+
];
|
|
3409
|
+
const initialStatements2 = () => [
|
|
3410
|
+
// import { String, Text, Int, SpecificKey } from 'oak-domain/types/DataType';
|
|
3411
|
+
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
3412
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('PrimaryKey')),
|
|
3413
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('ForeignKey')),
|
|
3414
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('JsonProjection'))
|
|
3415
|
+
])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)()}DataType`)),
|
|
3416
|
+
/* import {
|
|
3417
|
+
Q_DateValue, Q_LogicKey, Q_NumberValue, FnCallKey, FnCallValue,
|
|
3418
|
+
Q_StringValue, Q_FullTextKey, Q_FullTextValue, FnCallValueAs,
|
|
3419
|
+
Q_BooleanValue,
|
|
3420
|
+
} from 'oak-domain/types/Demand'; */
|
|
3421
|
+
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
3422
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_DateValue')),
|
|
3423
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_BooleanValue')),
|
|
3424
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_NumberValue')),
|
|
3425
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_StringValue')),
|
|
3426
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_EnumValue')),
|
|
3427
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('NodeId')),
|
|
3428
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('MakeFilter')),
|
|
3429
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('FulltextFilter')),
|
|
3430
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('ExprOp')),
|
|
3431
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('ExpressionKey')),
|
|
3432
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('JsonFilter')),
|
|
3433
|
+
])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)()}Demand`)),
|
|
3434
|
+
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
3435
|
+
factory.createImportSpecifier(false, factory.createIdentifier("MakeAction"), factory.createIdentifier("OakMakeAction")),
|
|
3436
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("EntityShape")),
|
|
3074
3437
|
])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)()}Entity`), undefined)
|
|
3075
3438
|
];
|
|
3439
|
+
const initialStatements3 = (level) => [
|
|
3440
|
+
// import { String, Text, Int, SpecificKey } from 'oak-domain/types/DataType';
|
|
3441
|
+
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
3442
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('PrimaryKey')),
|
|
3443
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('ForeignKey')),
|
|
3444
|
+
])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(level)}DataType`)),
|
|
3445
|
+
/* import {
|
|
3446
|
+
Q_DateValue, Q_LogicKey, Q_NumberValue, FnCallKey, FnCallValue,
|
|
3447
|
+
Q_StringValue, Q_FullTextKey, Q_FullTextValue, FnCallValueAs,
|
|
3448
|
+
Q_BooleanValue,
|
|
3449
|
+
} from 'oak-domain/types/Demand'; */
|
|
3450
|
+
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
3451
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('NodeId')),
|
|
3452
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('MakeFilter')),
|
|
3453
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('FulltextFilter')),
|
|
3454
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('ExprOp')),
|
|
3455
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('ExpressionKey')),
|
|
3456
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('JsonFilter')),
|
|
3457
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('SubQueryPredicateMetadata')),
|
|
3458
|
+
])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(level)}Demand`)),
|
|
3459
|
+
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
3460
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("FormCreateData")),
|
|
3461
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("FormUpdateData")),
|
|
3462
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("DeduceAggregation")),
|
|
3463
|
+
factory.createImportSpecifier(false, factory.createIdentifier("Operation"), factory.createIdentifier("OakOperation")),
|
|
3464
|
+
factory.createImportSpecifier(false, factory.createIdentifier("Selection"), factory.createIdentifier("OakSelection")),
|
|
3465
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("AggregationResult")),
|
|
3466
|
+
])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(level)}Entity`), undefined)
|
|
3467
|
+
];
|
|
3076
3468
|
function outputSubQuery(outputDir, printer) {
|
|
3077
3469
|
const statements = [];
|
|
3078
3470
|
if (process.env.COMPLING_AS_LIB) {
|
|
@@ -3128,15 +3520,145 @@ function outputEntityDict(outputDir, printer) {
|
|
|
3128
3520
|
else {
|
|
3129
3521
|
statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDict"), undefined, factory.createTypeLiteralNode(propertySignatures)));
|
|
3130
3522
|
}
|
|
3131
|
-
const resultFile = ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS);
|
|
3132
|
-
const result = printer.printNode(ts.EmitHint.Unspecified, factory.createSourceFile(statements, factory.createToken(ts.SyntaxKind.EndOfFileToken), ts.NodeFlags.None), resultFile);
|
|
3133
|
-
const fileName = path_1.default.join(outputDir, 'EntityDict.ts');
|
|
3134
|
-
(0, fs_1.writeFileSync)(fileName, result, { flag: 'w' });
|
|
3523
|
+
const resultFile = ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS);
|
|
3524
|
+
const result = printer.printNode(ts.EmitHint.Unspecified, factory.createSourceFile(statements, factory.createToken(ts.SyntaxKind.EndOfFileToken), ts.NodeFlags.None), resultFile);
|
|
3525
|
+
const fileName = path_1.default.join(outputDir, 'EntityDict.ts');
|
|
3526
|
+
(0, fs_1.writeFileSync)(fileName, result, { flag: 'w' });
|
|
3527
|
+
}
|
|
3528
|
+
function outputSchema(outputDir, printer) {
|
|
3529
|
+
for (const entity in Schema) {
|
|
3530
|
+
const { importAttrFrom } = Schema[entity];
|
|
3531
|
+
const statements = initialStatements();
|
|
3532
|
+
if (ActionAsts[entity]) {
|
|
3533
|
+
const { importStateFrom } = ActionAsts[entity];
|
|
3534
|
+
const fromLocalActionSpecifiers = ['Action', 'ParticularAction'];
|
|
3535
|
+
const fromExtenalStates = {};
|
|
3536
|
+
for (const state in importStateFrom) {
|
|
3537
|
+
(0, assert_1.default)(state.endsWith('State'), `${state} should end with State`);
|
|
3538
|
+
if (importStateFrom[state][0] === './') {
|
|
3539
|
+
// 本地定义的State从 ./Action 中获取
|
|
3540
|
+
fromLocalActionSpecifiers.push(state);
|
|
3541
|
+
}
|
|
3542
|
+
else {
|
|
3543
|
+
// 否则从原来的import specifiers当中获取
|
|
3544
|
+
// todo 在additionalImports中如果有则去重
|
|
3545
|
+
const [from, propertyName] = importStateFrom[state];
|
|
3546
|
+
if (fromExtenalStates[from]) {
|
|
3547
|
+
fromExtenalStates[from].push([state, propertyName]);
|
|
3548
|
+
}
|
|
3549
|
+
else {
|
|
3550
|
+
fromExtenalStates[from] = [[state, propertyName]];
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3554
|
+
statements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports(fromLocalActionSpecifiers.map(ele => factory.createImportSpecifier(false, undefined, factory.createIdentifier(ele))))), factory.createStringLiteral('./Action'), undefined), factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
3555
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("RelationAction")),
|
|
3556
|
+
])), factory.createStringLiteral((0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)()), undefined));
|
|
3557
|
+
for (const external in fromExtenalStates) {
|
|
3558
|
+
statements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports(fromExtenalStates[external].map(ele => factory.createImportSpecifier(false, ele[1] === undefined ? undefined : factory.createIdentifier(ele[1]), factory.createIdentifier(ele[0]))))), factory.createStringLiteral(external), undefined));
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
else {
|
|
3562
|
+
statements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
3563
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("GenericAction")),
|
|
3564
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("AppendOnlyAction")),
|
|
3565
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("ReadOnlyAction")),
|
|
3566
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("ExcludeUpdateAction")),
|
|
3567
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("ExcludeRemoveAction")),
|
|
3568
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("RelationAction")),
|
|
3569
|
+
])), factory.createStringLiteral((0, env_1.ACTION_CONSTANT_IN_OAK_DOMAIN)()), undefined));
|
|
3570
|
+
}
|
|
3571
|
+
// 从外部引入的属性
|
|
3572
|
+
const fromExternalImportAttrs = {};
|
|
3573
|
+
for (const attr in importAttrFrom) {
|
|
3574
|
+
const [from, propertyName] = importAttrFrom[attr];
|
|
3575
|
+
if (fromExternalImportAttrs[from]) {
|
|
3576
|
+
fromExternalImportAttrs[from].push([attr, propertyName]);
|
|
3577
|
+
}
|
|
3578
|
+
else {
|
|
3579
|
+
fromExternalImportAttrs[from] = [[attr, propertyName]];
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
for (const external in fromExternalImportAttrs) {
|
|
3583
|
+
statements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports(fromExternalImportAttrs[external].map(ele => factory.createImportSpecifier(false, ele[1] === undefined ? undefined : factory.createIdentifier(ele[1]), factory.createIdentifier(ele[0]))))), factory.createStringLiteral(external), undefined));
|
|
3584
|
+
}
|
|
3585
|
+
// Relation定义加入
|
|
3586
|
+
/* if (typeof Schema[entity].hasRelationDef === 'object' && ts.isTypeAliasDeclaration(Schema[entity].hasRelationDef as ts.Node)) {
|
|
3587
|
+
const node = Schema[entity].hasRelationDef as ts.TypeAliasDeclaration;
|
|
3588
|
+
statements.push(
|
|
3589
|
+
factory.updateTypeAliasDeclaration(
|
|
3590
|
+
node,
|
|
3591
|
+
undefined,
|
|
3592
|
+
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
3593
|
+
node.name,
|
|
3594
|
+
node.typeParameters,
|
|
3595
|
+
node.type
|
|
3596
|
+
)
|
|
3597
|
+
);
|
|
3598
|
+
} */
|
|
3599
|
+
constructSchema(statements, entity);
|
|
3600
|
+
constructFilter(statements, entity);
|
|
3601
|
+
constructProjection(statements, entity);
|
|
3602
|
+
constructSorter(statements, entity);
|
|
3603
|
+
constructOperations(statements, entity);
|
|
3604
|
+
constructQuery(statements, entity);
|
|
3605
|
+
// 现在FullAttrs和NativeAttrs似乎没什么用,还会引起递归
|
|
3606
|
+
// constructFullAttrs(statements, entity);
|
|
3607
|
+
const makeActionArguments = [];
|
|
3608
|
+
if (ActionAsts[entity]) {
|
|
3609
|
+
makeActionArguments.push(factory.createTypeReferenceNode('Action'));
|
|
3610
|
+
}
|
|
3611
|
+
else {
|
|
3612
|
+
makeActionArguments.push(factory.createTypeReferenceNode(OriginActionDict[Schema[entity].actionType]));
|
|
3613
|
+
}
|
|
3614
|
+
if (Schema[entity].relations || entity === 'User') {
|
|
3615
|
+
makeActionArguments.push(factory.createTypeReferenceNode('RelationAction'));
|
|
3616
|
+
}
|
|
3617
|
+
const actionTypeNode = factory.createTypeReferenceNode(factory.createIdentifier('OakMakeAction'), makeActionArguments.length === 1 ? makeActionArguments : [factory.createUnionTypeNode(makeActionArguments)]);
|
|
3618
|
+
const EntityDefAttrs = [
|
|
3619
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Schema"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Schema"), undefined)),
|
|
3620
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("OpSchema"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OpSchema"), undefined)),
|
|
3621
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Action"), undefined, process.env.COMPLING_AS_LIB ?
|
|
3622
|
+
factory.createUnionTypeNode([
|
|
3623
|
+
actionTypeNode,
|
|
3624
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
|
|
3625
|
+
]) : actionTypeNode),
|
|
3626
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Selection"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Selection"), undefined)),
|
|
3627
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Aggregation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Aggregation"), undefined)),
|
|
3628
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Operation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Operation"), undefined)),
|
|
3629
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Create"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("CreateOperation"), undefined)),
|
|
3630
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Update"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("UpdateOperation"), undefined)),
|
|
3631
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Remove"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("RemoveOperation"), undefined)),
|
|
3632
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("CreateSingle"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("CreateSingleOperation"), undefined)),
|
|
3633
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("CreateMulti"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("CreateMultipleOperation"), undefined)),
|
|
3634
|
+
];
|
|
3635
|
+
if (ActionAsts[entity]) {
|
|
3636
|
+
EntityDefAttrs.push(factory.createPropertySignature(undefined, factory.createIdentifier("ParticularAction"), undefined, factory.createTypeReferenceNode(factory.createIdentifier('ParticularAction'), undefined)));
|
|
3637
|
+
}
|
|
3638
|
+
/* if (typeof Schema[entity].hasRelationDef === 'object' && ts.isTypeAliasDeclaration(Schema[entity].hasRelationDef as ts.Node)) {
|
|
3639
|
+
EntityDefAttrs.push(
|
|
3640
|
+
factory.createPropertySignature(
|
|
3641
|
+
undefined,
|
|
3642
|
+
factory.createIdentifier("Relation"),
|
|
3643
|
+
undefined,
|
|
3644
|
+
factory.createTypeReferenceNode(
|
|
3645
|
+
factory.createIdentifier('Relation'),
|
|
3646
|
+
undefined
|
|
3647
|
+
)
|
|
3648
|
+
)
|
|
3649
|
+
);
|
|
3650
|
+
} */
|
|
3651
|
+
statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDef"), undefined, factory.createTypeLiteralNode(EntityDefAttrs)));
|
|
3652
|
+
// 现在支持Schema extends,其继承的对象解析来自另一个文件,故不能再用原sourceFile来生成,否则printer会用sourceFile中的originText去取stringLiteral
|
|
3653
|
+
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements), undefined);
|
|
3654
|
+
const fileName = path_1.default.join(outputDir, entity, 'Schema.ts');
|
|
3655
|
+
(0, fs_1.writeFileSync)(fileName, result, { flag: 'w' });
|
|
3656
|
+
}
|
|
3135
3657
|
}
|
|
3136
|
-
function
|
|
3658
|
+
function _outputBaseSchema(outputDir, printer) {
|
|
3137
3659
|
for (const entity in Schema) {
|
|
3138
3660
|
const { importAttrFrom } = Schema[entity];
|
|
3139
|
-
const statements =
|
|
3661
|
+
const statements = initialStatements2();
|
|
3140
3662
|
if (ActionAsts[entity]) {
|
|
3141
3663
|
const { importStateFrom } = ActionAsts[entity];
|
|
3142
3664
|
const fromLocalActionSpecifiers = ['Action', 'ParticularAction'];
|
|
@@ -3190,31 +3712,15 @@ function outputSchema(outputDir, printer) {
|
|
|
3190
3712
|
for (const external in fromExternalImportAttrs) {
|
|
3191
3713
|
statements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports(fromExternalImportAttrs[external].map(ele => factory.createImportSpecifier(false, ele[1] === undefined ? undefined : factory.createIdentifier(ele[1]), factory.createIdentifier(ele[0]))))), factory.createStringLiteral(external), undefined));
|
|
3192
3714
|
}
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
factory.updateTypeAliasDeclaration(
|
|
3198
|
-
node,
|
|
3199
|
-
undefined,
|
|
3200
|
-
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
3201
|
-
node.name,
|
|
3202
|
-
node.typeParameters,
|
|
3203
|
-
node.type
|
|
3204
|
-
)
|
|
3205
|
-
);
|
|
3206
|
-
} */
|
|
3207
|
-
constructSchema(statements, entity);
|
|
3208
|
-
constructFilter(statements, entity);
|
|
3209
|
-
constructProjection(statements, entity);
|
|
3210
|
-
constructSorter(statements, entity);
|
|
3211
|
-
constructOperations(statements, entity);
|
|
3212
|
-
constructQuery(statements, entity);
|
|
3213
|
-
// 现在FullAttrs和NativeAttrs似乎没什么用,还会引起递归
|
|
3214
|
-
// constructFullAttrs(statements, entity);
|
|
3715
|
+
_constructOpSchema(statements, entity);
|
|
3716
|
+
_constructOpFilter(statements, entity);
|
|
3717
|
+
_constructOpProjection(statements, entity);
|
|
3718
|
+
_constructOpSortAttr(statements, entity);
|
|
3215
3719
|
const makeActionArguments = [];
|
|
3720
|
+
const makeUpdateActionArguments = [factory.createLiteralTypeNode(factory.createStringLiteral('update'))];
|
|
3216
3721
|
if (ActionAsts[entity]) {
|
|
3217
3722
|
makeActionArguments.push(factory.createTypeReferenceNode('Action'));
|
|
3723
|
+
makeUpdateActionArguments.push(factory.createTypeReferenceNode('ParticularAction'));
|
|
3218
3724
|
}
|
|
3219
3725
|
else {
|
|
3220
3726
|
makeActionArguments.push(factory.createTypeReferenceNode(OriginActionDict[Schema[entity].actionType]));
|
|
@@ -3222,44 +3728,14 @@ function outputSchema(outputDir, printer) {
|
|
|
3222
3728
|
if (Schema[entity].relations || entity === 'User') {
|
|
3223
3729
|
makeActionArguments.push(factory.createTypeReferenceNode('RelationAction'));
|
|
3224
3730
|
}
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
factory.createPropertySignature(undefined, factory.createIdentifier("OpSchema"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OpSchema"), undefined)),
|
|
3229
|
-
factory.createPropertySignature(undefined, factory.createIdentifier("Action"), undefined, process.env.COMPLING_AS_LIB ?
|
|
3230
|
-
factory.createUnionTypeNode([
|
|
3231
|
-
actionTypeNode,
|
|
3232
|
-
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
|
|
3233
|
-
]) : actionTypeNode),
|
|
3234
|
-
factory.createPropertySignature(undefined, factory.createIdentifier("Selection"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Selection"), undefined)),
|
|
3235
|
-
factory.createPropertySignature(undefined, factory.createIdentifier("Aggregation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Aggregation"), undefined)),
|
|
3236
|
-
factory.createPropertySignature(undefined, factory.createIdentifier("Operation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Operation"), undefined)),
|
|
3237
|
-
factory.createPropertySignature(undefined, factory.createIdentifier("Create"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("CreateOperation"), undefined)),
|
|
3238
|
-
factory.createPropertySignature(undefined, factory.createIdentifier("Update"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("UpdateOperation"), undefined)),
|
|
3239
|
-
factory.createPropertySignature(undefined, factory.createIdentifier("Remove"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("RemoveOperation"), undefined)),
|
|
3240
|
-
factory.createPropertySignature(undefined, factory.createIdentifier("CreateSingle"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("CreateSingleOperation"), undefined)),
|
|
3241
|
-
factory.createPropertySignature(undefined, factory.createIdentifier("CreateMulti"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("CreateMultipleOperation"), undefined)),
|
|
3242
|
-
];
|
|
3243
|
-
if (ActionAsts[entity]) {
|
|
3244
|
-
EntityDefAttrs.push(factory.createPropertySignature(undefined, factory.createIdentifier("ParticularAction"), undefined, factory.createTypeReferenceNode(factory.createIdentifier('ParticularAction'), undefined)));
|
|
3731
|
+
if (process.env.COMPLING_AS_LIB) {
|
|
3732
|
+
makeActionArguments.push(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
|
|
3733
|
+
makeUpdateActionArguments.push(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
|
|
3245
3734
|
}
|
|
3246
|
-
|
|
3247
|
-
EntityDefAttrs.push(
|
|
3248
|
-
factory.createPropertySignature(
|
|
3249
|
-
undefined,
|
|
3250
|
-
factory.createIdentifier("Relation"),
|
|
3251
|
-
undefined,
|
|
3252
|
-
factory.createTypeReferenceNode(
|
|
3253
|
-
factory.createIdentifier('Relation'),
|
|
3254
|
-
undefined
|
|
3255
|
-
)
|
|
3256
|
-
)
|
|
3257
|
-
);
|
|
3258
|
-
} */
|
|
3259
|
-
statements.push(factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDef"), undefined, factory.createTypeLiteralNode(EntityDefAttrs)));
|
|
3735
|
+
statements.push(factory.createTypeAliasDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("OpAction"), undefined, factory.createTypeReferenceNode(factory.createIdentifier('OakMakeAction'), [factory.createUnionTypeNode(makeActionArguments)])), factory.createTypeAliasDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("OpUpdateAction"), undefined, factory.createUnionTypeNode(makeUpdateActionArguments)));
|
|
3260
3736
|
// 现在支持Schema extends,其继承的对象解析来自另一个文件,故不能再用原sourceFile来生成,否则printer会用sourceFile中的originText去取stringLiteral
|
|
3261
3737
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements), undefined);
|
|
3262
|
-
const fileName = path_1.default.join(outputDir, entity, '
|
|
3738
|
+
const fileName = path_1.default.join(outputDir, entity, '_baseSchema.ts');
|
|
3263
3739
|
(0, fs_1.writeFileSync)(fileName, result, { flag: 'w' });
|
|
3264
3740
|
}
|
|
3265
3741
|
}
|
|
@@ -4266,12 +4742,13 @@ function outputStyleDict(outputDir, printer) {
|
|
|
4266
4742
|
for (const entity in StyleAsts) {
|
|
4267
4743
|
const stmts = [
|
|
4268
4744
|
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
4269
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier("
|
|
4745
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("Action")),
|
|
4746
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("OpSchema"))
|
|
4270
4747
|
])), factory.createStringLiteral("./Schema"), undefined),
|
|
4271
4748
|
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("StyleDef"))])), factory.createStringLiteral(`${(0, env_1.TYPE_PATH_IN_OAK_DOMAIN)()}Style`), undefined),
|
|
4272
4749
|
factory.createVariableStatement([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("style"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("StyleDef"), [
|
|
4273
|
-
factory.
|
|
4274
|
-
factory.
|
|
4750
|
+
factory.createTypeReferenceNode('OpSchema'),
|
|
4751
|
+
factory.createTypeReferenceNode('Action')
|
|
4275
4752
|
]), StyleAsts[entity])], ts.NodeFlags.Const))
|
|
4276
4753
|
];
|
|
4277
4754
|
const { sourceFile } = Schema[entity];
|
|
@@ -4308,7 +4785,7 @@ function analyzeEntities(inputDir, relativePath) {
|
|
|
4308
4785
|
uniqRelationships();
|
|
4309
4786
|
}
|
|
4310
4787
|
exports.analyzeEntities = analyzeEntities;
|
|
4311
|
-
function
|
|
4788
|
+
function buildSchemaBackup(outputDir) {
|
|
4312
4789
|
addReverseRelationship();
|
|
4313
4790
|
// setRelationEntities();
|
|
4314
4791
|
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
@@ -4326,4 +4803,709 @@ function buildSchema(outputDir) {
|
|
|
4326
4803
|
outputPackageJson(outputDir);
|
|
4327
4804
|
}
|
|
4328
4805
|
}
|
|
4806
|
+
exports.buildSchemaBackup = buildSchemaBackup;
|
|
4807
|
+
function _getAggrKey(entity, foreignKey) {
|
|
4808
|
+
const aggrKey = `${entity}$${foreignKey}`;
|
|
4809
|
+
if (process.env.COMPLING_AS_LIB) {
|
|
4810
|
+
return `${aggrKey}$$aggr`;
|
|
4811
|
+
}
|
|
4812
|
+
return factory.createUnionTypeNode([
|
|
4813
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(`${aggrKey}$$aggr`)),
|
|
4814
|
+
factory.createTemplateLiteralType(factory.createTemplateHead(`${aggrKey}$$`, `${aggrKey}$$`), [factory.createTemplateLiteralTypeSpan(factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword), factory.createTemplateTail("$$aggr", "$$aggr"))])
|
|
4815
|
+
]);
|
|
4816
|
+
}
|
|
4817
|
+
function _outputEntityDict(outputDir, printer) {
|
|
4818
|
+
const statements = initialStatements3(1);
|
|
4819
|
+
for (const entity in Schema) {
|
|
4820
|
+
statements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamespaceImport(factory.createIdentifier(`Base${entity}`))), factory.createStringLiteral(`./${entity}/_baseSchema`), undefined));
|
|
4821
|
+
}
|
|
4822
|
+
for (const entity in Schema) {
|
|
4823
|
+
const entityLc = (0, string_1.firstLetterLowerCase)(entity);
|
|
4824
|
+
const getSchema = () => {
|
|
4825
|
+
const { schemaAttrs } = Schema[entity];
|
|
4826
|
+
const { [entity]: manyToOneSet } = ManyToOne;
|
|
4827
|
+
const { [entity]: oneToManySet } = OneToMany;
|
|
4828
|
+
const members = [];
|
|
4829
|
+
for (const attr of schemaAttrs) {
|
|
4830
|
+
const { type, name, questionToken } = attr;
|
|
4831
|
+
const attrName = name.text;
|
|
4832
|
+
if (ts.isTypeReferenceNode(type)) {
|
|
4833
|
+
const { typeName } = type;
|
|
4834
|
+
if (ts.isIdentifier(typeName)) {
|
|
4835
|
+
const { text } = typeName;
|
|
4836
|
+
const text2 = text === 'Schema' ? entity : text;
|
|
4837
|
+
const manyToOneItem = manyToOneSet && manyToOneSet.find(([refEntity, attrName2]) => refEntity === text2 && attrName2 === attrName);
|
|
4838
|
+
if (manyToOneItem) {
|
|
4839
|
+
const foreignKeyNode = createIndexedForeignRef(text2, 'Schema');
|
|
4840
|
+
members.push(factory.createPropertySignature(undefined, name, questionToken, foreignKeyNode));
|
|
4841
|
+
}
|
|
4842
|
+
}
|
|
4843
|
+
else {
|
|
4844
|
+
(0, assert_1.default)(false); // 这是什么case,不确定
|
|
4845
|
+
}
|
|
4846
|
+
}
|
|
4847
|
+
}
|
|
4848
|
+
// 处理reverserPointer
|
|
4849
|
+
const reverseOnes = ReversePointerRelations[entity];
|
|
4850
|
+
if (reverseOnes) {
|
|
4851
|
+
reverseOnes.forEach((one) => {
|
|
4852
|
+
members.push(factory.createPropertySignature(undefined, (0, string_1.firstLetterLowerCase)(one), factory.createToken(ts.SyntaxKind.QuestionToken), createIndexedForeignRef(one, 'Schema')));
|
|
4853
|
+
});
|
|
4854
|
+
}
|
|
4855
|
+
const foreignKeySet = {};
|
|
4856
|
+
if (oneToManySet) {
|
|
4857
|
+
for (const oneToManyItem of oneToManySet) {
|
|
4858
|
+
const [entityName, foreignKey] = oneToManyItem;
|
|
4859
|
+
if (foreignKeySet.hasOwnProperty(entityName)) {
|
|
4860
|
+
foreignKeySet[entityName].push(foreignKey);
|
|
4861
|
+
}
|
|
4862
|
+
else {
|
|
4863
|
+
foreignKeySet[entityName] = [foreignKey];
|
|
4864
|
+
}
|
|
4865
|
+
}
|
|
4866
|
+
for (const entityName in foreignKeySet) {
|
|
4867
|
+
const entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
|
|
4868
|
+
foreignKeySet[entityName].forEach((foreignKey) => {
|
|
4869
|
+
const identifier = `${entityNameLc}$${foreignKey}`;
|
|
4870
|
+
members.push(factory.createPropertySignature(undefined, identifier, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(factory.createIdentifier("Array"), [
|
|
4871
|
+
factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
|
|
4872
|
+
createIndexedForeignRef(entityName, 'Schema'),
|
|
4873
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey))
|
|
4874
|
+
])
|
|
4875
|
+
])));
|
|
4876
|
+
});
|
|
4877
|
+
}
|
|
4878
|
+
}
|
|
4879
|
+
const otmAggrMappedNodes = [];
|
|
4880
|
+
for (const entityName in foreignKeySet) {
|
|
4881
|
+
const entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
|
|
4882
|
+
foreignKeySet[entityName].forEach((foreignKey) => {
|
|
4883
|
+
const aggrKeyNode = _getAggrKey(entityNameLc, foreignKey);
|
|
4884
|
+
const aggrNode = factory.createTypeReferenceNode(factory.createIdentifier("AggregationResult"), [factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
|
|
4885
|
+
createIndexedForeignRef(entityName, 'Schema'),
|
|
4886
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey))
|
|
4887
|
+
])]);
|
|
4888
|
+
if (typeof aggrKeyNode === 'string') {
|
|
4889
|
+
members.push(factory.createPropertySignature(undefined, aggrKeyNode, factory.createToken(ts.SyntaxKind.QuestionToken), aggrNode));
|
|
4890
|
+
}
|
|
4891
|
+
else {
|
|
4892
|
+
otmAggrMappedNodes.push(factory.createMappedTypeNode(undefined, factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("A"), aggrKeyNode, undefined), undefined, factory.createToken(ts.SyntaxKind.QuestionToken), aggrNode, undefined));
|
|
4893
|
+
}
|
|
4894
|
+
});
|
|
4895
|
+
}
|
|
4896
|
+
return factory.createIntersectionTypeNode([
|
|
4897
|
+
factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpSchema"))),
|
|
4898
|
+
factory.createTypeLiteralNode(members),
|
|
4899
|
+
...otmAggrMappedNodes,
|
|
4900
|
+
]);
|
|
4901
|
+
};
|
|
4902
|
+
const getProjection = () => {
|
|
4903
|
+
const { schemaAttrs, enumAttributes } = Schema[entity];
|
|
4904
|
+
const properties = [];
|
|
4905
|
+
const { [entity]: manyToOneSet } = ManyToOne;
|
|
4906
|
+
for (const attr of schemaAttrs) {
|
|
4907
|
+
const { type, name } = attr;
|
|
4908
|
+
const attrName = name.text;
|
|
4909
|
+
if (ts.isTypeReferenceNode(type)) {
|
|
4910
|
+
const { typeName } = type;
|
|
4911
|
+
if (ts.isIdentifier(typeName)) {
|
|
4912
|
+
const { text } = typeName;
|
|
4913
|
+
switch (text) {
|
|
4914
|
+
case 'String':
|
|
4915
|
+
case 'Text':
|
|
4916
|
+
case 'Int':
|
|
4917
|
+
case 'Uint':
|
|
4918
|
+
case 'Float':
|
|
4919
|
+
case 'Double':
|
|
4920
|
+
case 'Boolean':
|
|
4921
|
+
case 'Datetime':
|
|
4922
|
+
case 'Image':
|
|
4923
|
+
case 'File':
|
|
4924
|
+
case 'SingleGeo':
|
|
4925
|
+
case 'Geo':
|
|
4926
|
+
case 'Price':
|
|
4927
|
+
case 'Decimal':
|
|
4928
|
+
case 'Object': {
|
|
4929
|
+
break;
|
|
4930
|
+
}
|
|
4931
|
+
default: {
|
|
4932
|
+
const text2 = text === 'Schema' ? entity : text;
|
|
4933
|
+
const manyToOneItem = manyToOneSet && manyToOneSet.find(([refEntity]) => refEntity === text2);
|
|
4934
|
+
if (manyToOneItem) {
|
|
4935
|
+
// 外键投影
|
|
4936
|
+
properties.push([name, false, createIndexedForeignRef(text2, 'Projection')]);
|
|
4937
|
+
}
|
|
4938
|
+
}
|
|
4939
|
+
}
|
|
4940
|
+
}
|
|
4941
|
+
else {
|
|
4942
|
+
(0, assert_1.default)(false);
|
|
4943
|
+
}
|
|
4944
|
+
}
|
|
4945
|
+
}
|
|
4946
|
+
if (ReversePointerRelations[entity]) {
|
|
4947
|
+
ReversePointerRelations[entity].forEach((one) => {
|
|
4948
|
+
const text2 = one === 'Schema' ? entity : one;
|
|
4949
|
+
properties.push([(0, string_1.firstLetterLowerCase)(one), false, createIndexedForeignRef(text2, 'Projection')]);
|
|
4950
|
+
});
|
|
4951
|
+
}
|
|
4952
|
+
// 一对多的projection
|
|
4953
|
+
const otmAggrMappedNodes = [];
|
|
4954
|
+
const { [entity]: oneToManySet } = OneToMany;
|
|
4955
|
+
if (oneToManySet) {
|
|
4956
|
+
const foreignKeySet = {};
|
|
4957
|
+
for (const oneToManyItem of oneToManySet) {
|
|
4958
|
+
const [entityName, foreignKey] = oneToManyItem;
|
|
4959
|
+
if (foreignKeySet.hasOwnProperty(entityName)) {
|
|
4960
|
+
foreignKeySet[entityName].push(foreignKey);
|
|
4961
|
+
}
|
|
4962
|
+
else {
|
|
4963
|
+
foreignKeySet[entityName] = [foreignKey];
|
|
4964
|
+
}
|
|
4965
|
+
}
|
|
4966
|
+
for (const entityName in foreignKeySet) {
|
|
4967
|
+
const entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
|
|
4968
|
+
foreignKeySet[entityName].forEach((foreignKey) => {
|
|
4969
|
+
const identifier = `${entityNameLc}$${foreignKey}`;
|
|
4970
|
+
const aggrKey = _getAggrKey(entityNameLc, foreignKey);
|
|
4971
|
+
properties.push([identifier, false,
|
|
4972
|
+
factory.createIntersectionTypeNode([
|
|
4973
|
+
factory.createTypeReferenceNode(factory.createIdentifier("OakSelection"), [
|
|
4974
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("select")),
|
|
4975
|
+
factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
|
|
4976
|
+
createIndexedForeignRef(entityName, 'Projection'),
|
|
4977
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(entityLc))
|
|
4978
|
+
]),
|
|
4979
|
+
factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
|
|
4980
|
+
createIndexedForeignRef(entityName, 'Filter'),
|
|
4981
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(entityLc))
|
|
4982
|
+
]),
|
|
4983
|
+
createIndexedForeignRef(entityName, 'Sorter')
|
|
4984
|
+
]),
|
|
4985
|
+
factory.createTypeLiteralNode([
|
|
4986
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("$entity"), undefined, factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(entityName))))
|
|
4987
|
+
])
|
|
4988
|
+
])
|
|
4989
|
+
]);
|
|
4990
|
+
const otmAggrNode = factory.createIntersectionTypeNode([
|
|
4991
|
+
factory.createTypeReferenceNode(factory.createIdentifier("DeduceAggregation"), [
|
|
4992
|
+
factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
|
|
4993
|
+
createIndexedForeignRef(entityName, 'Projection'),
|
|
4994
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(entityLc))
|
|
4995
|
+
]),
|
|
4996
|
+
factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
|
|
4997
|
+
createIndexedForeignRef(entityName, 'Filter'),
|
|
4998
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(entityLc))
|
|
4999
|
+
]),
|
|
5000
|
+
createIndexedForeignRef(entityName, 'Sorter')
|
|
5001
|
+
]),
|
|
5002
|
+
factory.createTypeLiteralNode([
|
|
5003
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("$entity"), undefined, factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(entityName))))
|
|
5004
|
+
])
|
|
5005
|
+
]);
|
|
5006
|
+
if (typeof aggrKey === 'string') {
|
|
5007
|
+
properties.push([
|
|
5008
|
+
aggrKey,
|
|
5009
|
+
false,
|
|
5010
|
+
otmAggrNode
|
|
5011
|
+
]);
|
|
5012
|
+
}
|
|
5013
|
+
else {
|
|
5014
|
+
otmAggrMappedNodes.push(factory.createMappedTypeNode(undefined, factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("A"), aggrKey, undefined), undefined, factory.createToken(ts.SyntaxKind.QuestionToken), otmAggrNode, undefined));
|
|
5015
|
+
}
|
|
5016
|
+
});
|
|
5017
|
+
}
|
|
5018
|
+
}
|
|
5019
|
+
return factory.createIntersectionTypeNode([
|
|
5020
|
+
factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpProjection"))),
|
|
5021
|
+
factory.createTypeLiteralNode(properties.map(([n, q, v]) => {
|
|
5022
|
+
return factory.createPropertySignature(undefined, n, q ? undefined : factory.createToken(ts.SyntaxKind.QuestionToken), v || factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword));
|
|
5023
|
+
})),
|
|
5024
|
+
...otmAggrMappedNodes,
|
|
5025
|
+
]);
|
|
5026
|
+
};
|
|
5027
|
+
const getFilterUnit = () => {
|
|
5028
|
+
const { schemaAttrs, fulltextIndex } = Schema[entity];
|
|
5029
|
+
const members = [];
|
|
5030
|
+
const { [entity]: manyToOneSet } = ManyToOne;
|
|
5031
|
+
const entityUnionTypeNodes = ReversePointerRelations[entity] && ReversePointerRelations[entity].map(ele => factory.createLiteralTypeNode(factory.createStringLiteral((0, string_1.firstLetterLowerCase)(ele))));
|
|
5032
|
+
if (process.env.COMPLING_AS_LIB) {
|
|
5033
|
+
entityUnionTypeNodes && entityUnionTypeNodes.push(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
|
|
5034
|
+
}
|
|
5035
|
+
for (const attr of schemaAttrs) {
|
|
5036
|
+
const { type, name } = attr;
|
|
5037
|
+
const attrName = name.text;
|
|
5038
|
+
if (ts.isTypeReferenceNode(type)) {
|
|
5039
|
+
const { typeName } = type;
|
|
5040
|
+
if (ts.isIdentifier(typeName)) {
|
|
5041
|
+
const { text } = typeName;
|
|
5042
|
+
let type2;
|
|
5043
|
+
switch (text) {
|
|
5044
|
+
case 'String':
|
|
5045
|
+
case 'Text':
|
|
5046
|
+
case 'Image':
|
|
5047
|
+
case 'File':
|
|
5048
|
+
case 'Int':
|
|
5049
|
+
case 'Uint':
|
|
5050
|
+
case 'Float':
|
|
5051
|
+
case 'Double':
|
|
5052
|
+
case 'Price':
|
|
5053
|
+
case 'Decimal':
|
|
5054
|
+
case 'Boolean':
|
|
5055
|
+
case 'Datetime':
|
|
5056
|
+
case 'SingleGeo':
|
|
5057
|
+
case 'Geo':
|
|
5058
|
+
case 'Object': {
|
|
5059
|
+
break;
|
|
5060
|
+
}
|
|
5061
|
+
default: {
|
|
5062
|
+
const text2 = text === 'Schema' ? entity : text;
|
|
5063
|
+
const manyToOneItem = manyToOneSet && manyToOneSet.find(([refEntity]) => refEntity === text2);
|
|
5064
|
+
if (manyToOneItem) {
|
|
5065
|
+
type2 = factory.createTypeReferenceNode('MakeFilter', [
|
|
5066
|
+
createIndexedForeignRef(text2, 'FilterUnit')
|
|
5067
|
+
]);
|
|
5068
|
+
}
|
|
5069
|
+
}
|
|
5070
|
+
}
|
|
5071
|
+
if (type2) {
|
|
5072
|
+
members.push(factory.createPropertySignature(undefined, name, undefined, type2));
|
|
5073
|
+
}
|
|
5074
|
+
}
|
|
5075
|
+
}
|
|
5076
|
+
}
|
|
5077
|
+
// type AttrFilter = {};
|
|
5078
|
+
if (ReversePointerRelations[entity]) {
|
|
5079
|
+
// 有反向指针,将反向指针关联的对象的Filter也注入
|
|
5080
|
+
ReversePointerRelations[entity].forEach(ele => members.push(factory.createPropertySignature(undefined, (0, string_1.firstLetterLowerCase)(ele), undefined, factory.createTypeReferenceNode('MakeFilter', [
|
|
5081
|
+
createIndexedForeignRef(ele, 'FilterUnit')
|
|
5082
|
+
]))));
|
|
5083
|
+
}
|
|
5084
|
+
// 一对多的生成子查询
|
|
5085
|
+
const { [entity]: oneToManySet } = OneToMany;
|
|
5086
|
+
if (oneToManySet) {
|
|
5087
|
+
const foreignKeySet = {};
|
|
5088
|
+
for (const oneToManyItem of oneToManySet) {
|
|
5089
|
+
const [entityName, foreignKey] = oneToManyItem;
|
|
5090
|
+
if (foreignKeySet.hasOwnProperty(entityName)) {
|
|
5091
|
+
foreignKeySet[entityName].push(foreignKey);
|
|
5092
|
+
}
|
|
5093
|
+
else {
|
|
5094
|
+
foreignKeySet[entityName] = [foreignKey];
|
|
5095
|
+
}
|
|
5096
|
+
}
|
|
5097
|
+
for (const entityName in foreignKeySet) {
|
|
5098
|
+
const entityNameLc = (0, string_1.firstLetterLowerCase)(entityName);
|
|
5099
|
+
foreignKeySet[entityName].forEach((foreignKey) => {
|
|
5100
|
+
const identifier = `${entityNameLc}$${foreignKey}`;
|
|
5101
|
+
members.push(factory.createPropertySignature(undefined, identifier, undefined, factory.createIntersectionTypeNode([
|
|
5102
|
+
factory.createTypeReferenceNode('MakeFilter', [
|
|
5103
|
+
factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
|
|
5104
|
+
createIndexedForeignRef(entityName, 'FilterUnit'),
|
|
5105
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(foreignKey))
|
|
5106
|
+
])
|
|
5107
|
+
]),
|
|
5108
|
+
factory.createTypeReferenceNode('SubQueryPredicateMetadata')
|
|
5109
|
+
])));
|
|
5110
|
+
});
|
|
5111
|
+
}
|
|
5112
|
+
}
|
|
5113
|
+
const types = [
|
|
5114
|
+
factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpFilter"))),
|
|
5115
|
+
factory.createTypeLiteralNode(members)
|
|
5116
|
+
];
|
|
5117
|
+
// 如果还有其它类型的查询如全文,则加在types数组中
|
|
5118
|
+
if (fulltextIndex) {
|
|
5119
|
+
types.push(factory.createTypeReferenceNode('FulltextFilter'));
|
|
5120
|
+
}
|
|
5121
|
+
return factory.createIntersectionTypeNode(types);
|
|
5122
|
+
};
|
|
5123
|
+
const getSortAttr = () => {
|
|
5124
|
+
const { schemaAttrs } = Schema[entity];
|
|
5125
|
+
const members = [];
|
|
5126
|
+
const { [entity]: manyToOneSet } = ManyToOne;
|
|
5127
|
+
for (const attr of schemaAttrs) {
|
|
5128
|
+
const { type, name, questionToken } = attr;
|
|
5129
|
+
if (ts.isTypeReferenceNode(type)) {
|
|
5130
|
+
const { typeName } = type;
|
|
5131
|
+
if (ts.isIdentifier(typeName)) {
|
|
5132
|
+
const { text } = typeName;
|
|
5133
|
+
let type2;
|
|
5134
|
+
switch (text) {
|
|
5135
|
+
case 'String':
|
|
5136
|
+
case 'Text':
|
|
5137
|
+
case 'Int':
|
|
5138
|
+
case 'Float':
|
|
5139
|
+
case 'Double':
|
|
5140
|
+
case 'Boolean':
|
|
5141
|
+
case 'Datetime':
|
|
5142
|
+
case 'Image':
|
|
5143
|
+
case 'File':
|
|
5144
|
+
case 'Price': {
|
|
5145
|
+
break;
|
|
5146
|
+
}
|
|
5147
|
+
default: {
|
|
5148
|
+
const text2 = text === 'Schema' ? entity : text;
|
|
5149
|
+
const manyToOneItem = manyToOneSet && manyToOneSet.find(([refEntity]) => refEntity === text2);
|
|
5150
|
+
if (manyToOneItem) {
|
|
5151
|
+
type2 = createIndexedForeignRef(text2, 'SortAttr');
|
|
5152
|
+
}
|
|
5153
|
+
}
|
|
5154
|
+
}
|
|
5155
|
+
if (type2) {
|
|
5156
|
+
members.push(factory.createPropertySignature(undefined, name, undefined, type2));
|
|
5157
|
+
}
|
|
5158
|
+
}
|
|
5159
|
+
}
|
|
5160
|
+
}
|
|
5161
|
+
if (ReversePointerRelations[entity]) {
|
|
5162
|
+
ReversePointerRelations[entity].forEach((one) => {
|
|
5163
|
+
members.push(factory.createPropertySignature(undefined, (0, string_1.firstLetterLowerCase)(one), undefined, createIndexedForeignRef(one, 'SortAttr')));
|
|
5164
|
+
});
|
|
5165
|
+
}
|
|
5166
|
+
return factory.createTypeReferenceNode('Partial', [
|
|
5167
|
+
factory.createUnionTypeNode([
|
|
5168
|
+
factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpSortAttr"))),
|
|
5169
|
+
factory.createTypeLiteralNode(members),
|
|
5170
|
+
])
|
|
5171
|
+
]);
|
|
5172
|
+
};
|
|
5173
|
+
const getOperations = () => {
|
|
5174
|
+
const { [entity]: manyToOneSet } = ManyToOne;
|
|
5175
|
+
const { [entity]: oneToManySet } = OneToMany;
|
|
5176
|
+
const foreignKeySet = {};
|
|
5177
|
+
if (oneToManySet) {
|
|
5178
|
+
for (const oneToManyItem of oneToManySet) {
|
|
5179
|
+
const [entityName, foreignKey] = oneToManyItem;
|
|
5180
|
+
if (foreignKeySet.hasOwnProperty(entityName)) {
|
|
5181
|
+
foreignKeySet[entityName].push(foreignKey);
|
|
5182
|
+
}
|
|
5183
|
+
else {
|
|
5184
|
+
foreignKeySet[entityName] = [foreignKey];
|
|
5185
|
+
}
|
|
5186
|
+
}
|
|
5187
|
+
}
|
|
5188
|
+
const cascadeCreateElements = [];
|
|
5189
|
+
const cascadeUpdateElements = [];
|
|
5190
|
+
{
|
|
5191
|
+
const addManyToOneCascade = (foreignEntity, foreignKey) => {
|
|
5192
|
+
// 切断modiEntity和其它对象的关联(太多了)
|
|
5193
|
+
if (entity === 'ModiEntity' && foreignEntity !== 'Modi') {
|
|
5194
|
+
return;
|
|
5195
|
+
}
|
|
5196
|
+
if (entity === 'OperEntity' && foreignEntity !== 'Oper') {
|
|
5197
|
+
return;
|
|
5198
|
+
}
|
|
5199
|
+
const propertyName = foreignKey === 'entity' ? (0, string_1.firstLetterLowerCase)(foreignEntity) : foreignKey;
|
|
5200
|
+
const createCasNode = factory.createTypeReferenceNode('OakOperation', [
|
|
5201
|
+
factory.createLiteralTypeNode(factory.createStringLiteral('create')),
|
|
5202
|
+
createIndexedForeignRef(foreignEntity, 'CreateOperationData')
|
|
5203
|
+
]);
|
|
5204
|
+
const updateCasNode = factory.createTypeReferenceNode('OakOperation', [
|
|
5205
|
+
factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${foreignEntity}`), factory.createIdentifier("OpUpdateAction"))),
|
|
5206
|
+
createIndexedForeignRef(foreignEntity, 'UpdateOperationData'),
|
|
5207
|
+
createIndexedForeignRef(foreignEntity, 'Filter'),
|
|
5208
|
+
]);
|
|
5209
|
+
const removeCasNode = factory.createTypeReferenceNode('OakOperation', [
|
|
5210
|
+
factory.createLiteralTypeNode(factory.createStringLiteral('remove')),
|
|
5211
|
+
createIndexedForeignRef(foreignEntity, 'RemoveOperationData'),
|
|
5212
|
+
createIndexedForeignRef(foreignEntity, 'Filter')
|
|
5213
|
+
]);
|
|
5214
|
+
if (!Schema[foreignEntity].static) {
|
|
5215
|
+
switch (Schema[foreignEntity].actionType) {
|
|
5216
|
+
case 'crud': {
|
|
5217
|
+
cascadeCreateElements.push(factory.createPropertySignature(undefined, propertyName, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
|
|
5218
|
+
createCasNode,
|
|
5219
|
+
updateCasNode
|
|
5220
|
+
])));
|
|
5221
|
+
cascadeUpdateElements.push(factory.createPropertySignature(undefined, propertyName, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
|
|
5222
|
+
createCasNode,
|
|
5223
|
+
updateCasNode,
|
|
5224
|
+
removeCasNode,
|
|
5225
|
+
])));
|
|
5226
|
+
break;
|
|
5227
|
+
}
|
|
5228
|
+
case 'excludeRemove': {
|
|
5229
|
+
cascadeCreateElements.push(factory.createPropertySignature(undefined, propertyName, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
|
|
5230
|
+
createCasNode,
|
|
5231
|
+
updateCasNode
|
|
5232
|
+
])));
|
|
5233
|
+
cascadeUpdateElements.push(factory.createPropertySignature(undefined, propertyName, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
|
|
5234
|
+
createCasNode,
|
|
5235
|
+
updateCasNode,
|
|
5236
|
+
])));
|
|
5237
|
+
break;
|
|
5238
|
+
}
|
|
5239
|
+
case 'excludeUpdate': {
|
|
5240
|
+
cascadeCreateElements.push(factory.createPropertySignature(undefined, propertyName, factory.createToken(ts.SyntaxKind.QuestionToken), createCasNode));
|
|
5241
|
+
cascadeUpdateElements.push(factory.createPropertySignature(undefined, propertyName, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
|
|
5242
|
+
createCasNode,
|
|
5243
|
+
removeCasNode,
|
|
5244
|
+
])));
|
|
5245
|
+
break;
|
|
5246
|
+
}
|
|
5247
|
+
case 'appendOnly': {
|
|
5248
|
+
cascadeCreateElements.push(factory.createPropertySignature(undefined, propertyName, factory.createToken(ts.SyntaxKind.QuestionToken), createCasNode));
|
|
5249
|
+
cascadeUpdateElements.push(factory.createPropertySignature(undefined, propertyName, factory.createToken(ts.SyntaxKind.QuestionToken), createCasNode));
|
|
5250
|
+
break;
|
|
5251
|
+
}
|
|
5252
|
+
case 'readOnly': {
|
|
5253
|
+
break;
|
|
5254
|
+
}
|
|
5255
|
+
default: {
|
|
5256
|
+
(0, assert_1.default)(false);
|
|
5257
|
+
}
|
|
5258
|
+
}
|
|
5259
|
+
}
|
|
5260
|
+
};
|
|
5261
|
+
// 多对一
|
|
5262
|
+
if (manyToOneSet) {
|
|
5263
|
+
for (const one of manyToOneSet) {
|
|
5264
|
+
addManyToOneCascade(one[0], one[1]);
|
|
5265
|
+
}
|
|
5266
|
+
}
|
|
5267
|
+
// 一对多
|
|
5268
|
+
const addOneToManyCascade = (foreignEntity, foreignKey) => {
|
|
5269
|
+
// 切断modiEntity和其它对象的关联(太多了)
|
|
5270
|
+
if (foreignEntity === 'ModiEntity' && entity !== 'Modi') {
|
|
5271
|
+
return;
|
|
5272
|
+
}
|
|
5273
|
+
if (foreignEntity === 'OperEntity' && entity !== 'Oper') {
|
|
5274
|
+
return;
|
|
5275
|
+
}
|
|
5276
|
+
const foreignEntityLc = (0, string_1.firstLetterLowerCase)(foreignEntity);
|
|
5277
|
+
const otmKey = `${foreignEntityLc}$${foreignKey}`;
|
|
5278
|
+
const mtoKey = foreignKey === 'entity' ? (0, string_1.firstLetterLowerCase)(entity) : foreignKey;
|
|
5279
|
+
const otmCreateData = factory.createTypeReferenceNode('Omit', [
|
|
5280
|
+
createIndexedForeignRef(foreignEntity, 'CreateOperationData'),
|
|
5281
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(mtoKey))
|
|
5282
|
+
]);
|
|
5283
|
+
const otmUpdateData = factory.createTypeReferenceNode('Omit', [
|
|
5284
|
+
createIndexedForeignRef(foreignEntity, 'UpdateOperationData'),
|
|
5285
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(mtoKey))
|
|
5286
|
+
]);
|
|
5287
|
+
const createCasNode = factory.createTypeReferenceNode('OakOperation', [
|
|
5288
|
+
factory.createLiteralTypeNode(factory.createStringLiteral('create')),
|
|
5289
|
+
factory.createUnionTypeNode([
|
|
5290
|
+
otmCreateData,
|
|
5291
|
+
factory.createArrayTypeNode(otmCreateData)
|
|
5292
|
+
])
|
|
5293
|
+
]);
|
|
5294
|
+
const updateCasNode = factory.createTypeReferenceNode('OakOperation', [
|
|
5295
|
+
factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${foreignEntity}`), factory.createIdentifier("OpUpdateAction"))),
|
|
5296
|
+
otmUpdateData,
|
|
5297
|
+
createIndexedForeignRef(foreignEntity, 'Filter'),
|
|
5298
|
+
]);
|
|
5299
|
+
const removeCasNode = factory.createTypeReferenceNode('OakOperation', [
|
|
5300
|
+
factory.createLiteralTypeNode(factory.createStringLiteral('remove')),
|
|
5301
|
+
createIndexedForeignRef(foreignEntity, 'RemoveOperationData'),
|
|
5302
|
+
createIndexedForeignRef(foreignEntity, 'Filter')
|
|
5303
|
+
]);
|
|
5304
|
+
if (!Schema[foreignEntity].static) {
|
|
5305
|
+
switch (Schema[foreignEntity].actionType) {
|
|
5306
|
+
case 'crud': {
|
|
5307
|
+
cascadeCreateElements.push(factory.createPropertySignature(undefined, otmKey, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createArrayTypeNode(factory.createUnionTypeNode([
|
|
5308
|
+
createCasNode,
|
|
5309
|
+
updateCasNode
|
|
5310
|
+
]))));
|
|
5311
|
+
cascadeUpdateElements.push(factory.createPropertySignature(undefined, otmKey, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createArrayTypeNode(factory.createUnionTypeNode([
|
|
5312
|
+
createCasNode,
|
|
5313
|
+
updateCasNode,
|
|
5314
|
+
removeCasNode,
|
|
5315
|
+
]))));
|
|
5316
|
+
break;
|
|
5317
|
+
}
|
|
5318
|
+
case 'excludeRemove': {
|
|
5319
|
+
cascadeCreateElements.push(factory.createPropertySignature(undefined, otmKey, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createArrayTypeNode(factory.createUnionTypeNode([
|
|
5320
|
+
createCasNode,
|
|
5321
|
+
updateCasNode
|
|
5322
|
+
]))));
|
|
5323
|
+
cascadeUpdateElements.push(factory.createPropertySignature(undefined, otmKey, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createArrayTypeNode(factory.createUnionTypeNode([
|
|
5324
|
+
createCasNode,
|
|
5325
|
+
updateCasNode,
|
|
5326
|
+
]))));
|
|
5327
|
+
break;
|
|
5328
|
+
}
|
|
5329
|
+
case 'excludeUpdate': {
|
|
5330
|
+
cascadeCreateElements.push(factory.createPropertySignature(undefined, otmKey, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createArrayTypeNode(createCasNode)));
|
|
5331
|
+
cascadeUpdateElements.push(factory.createPropertySignature(undefined, otmKey, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createArrayTypeNode(factory.createUnionTypeNode([
|
|
5332
|
+
createCasNode,
|
|
5333
|
+
removeCasNode,
|
|
5334
|
+
]))));
|
|
5335
|
+
break;
|
|
5336
|
+
}
|
|
5337
|
+
case 'appendOnly': {
|
|
5338
|
+
cascadeCreateElements.push(factory.createPropertySignature(undefined, otmKey, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createArrayTypeNode(createCasNode)));
|
|
5339
|
+
cascadeUpdateElements.push(factory.createPropertySignature(undefined, otmKey, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createArrayTypeNode(createCasNode)));
|
|
5340
|
+
break;
|
|
5341
|
+
}
|
|
5342
|
+
case 'readOnly': {
|
|
5343
|
+
break;
|
|
5344
|
+
}
|
|
5345
|
+
default: {
|
|
5346
|
+
(0, assert_1.default)(false);
|
|
5347
|
+
}
|
|
5348
|
+
}
|
|
5349
|
+
}
|
|
5350
|
+
};
|
|
5351
|
+
if (oneToManySet) {
|
|
5352
|
+
for (const entityName in foreignKeySet) {
|
|
5353
|
+
foreignKeySet[entityName].forEach((foreignKey) => {
|
|
5354
|
+
addOneToManyCascade(entityName, foreignKey);
|
|
5355
|
+
});
|
|
5356
|
+
}
|
|
5357
|
+
}
|
|
5358
|
+
if (process.env.COMPLING_AS_LIB) {
|
|
5359
|
+
// 如果是base,要包容更多可能的反指
|
|
5360
|
+
/* cascadeCreateElements.push(
|
|
5361
|
+
factory.createIndexSignature(
|
|
5362
|
+
undefined,
|
|
5363
|
+
[factory.createParameterDeclaration(
|
|
5364
|
+
undefined,
|
|
5365
|
+
undefined,
|
|
5366
|
+
factory.createIdentifier("K"),
|
|
5367
|
+
undefined,
|
|
5368
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
|
|
5369
|
+
undefined
|
|
5370
|
+
)],
|
|
5371
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)
|
|
5372
|
+
)
|
|
5373
|
+
);
|
|
5374
|
+
cascadeUpdateElements.push(
|
|
5375
|
+
factory.createIndexSignature(
|
|
5376
|
+
undefined,
|
|
5377
|
+
[factory.createParameterDeclaration(
|
|
5378
|
+
undefined,
|
|
5379
|
+
undefined,
|
|
5380
|
+
factory.createIdentifier("K"),
|
|
5381
|
+
undefined,
|
|
5382
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
|
|
5383
|
+
undefined
|
|
5384
|
+
)],
|
|
5385
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)
|
|
5386
|
+
)
|
|
5387
|
+
); */
|
|
5388
|
+
}
|
|
5389
|
+
}
|
|
5390
|
+
return {
|
|
5391
|
+
CreateOperationData: factory.createTypeReferenceNode('FormCreateData', [
|
|
5392
|
+
cascadeCreateElements.length ? factory.createIntersectionTypeNode([
|
|
5393
|
+
factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpSchema"))),
|
|
5394
|
+
factory.createTypeLiteralNode(cascadeCreateElements),
|
|
5395
|
+
]) : factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpSchema")))
|
|
5396
|
+
]),
|
|
5397
|
+
UpdateOperationData: factory.createTypeReferenceNode('FormUpdateData', [
|
|
5398
|
+
cascadeUpdateElements.length ? factory.createIntersectionTypeNode([
|
|
5399
|
+
factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpSchema"))),
|
|
5400
|
+
factory.createTypeLiteralNode(cascadeUpdateElements),
|
|
5401
|
+
]) : factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpSchema")))
|
|
5402
|
+
]),
|
|
5403
|
+
RemoveOperationData: factory.createTypeLiteralNode([]), // RemoveOperate暂时不支持Cascade
|
|
5404
|
+
};
|
|
5405
|
+
};
|
|
5406
|
+
const { CreateOperationData, UpdateOperationData, RemoveOperationData, } = getOperations();
|
|
5407
|
+
statements.push(factory.createTypeAliasDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier(entity), undefined, factory.createTypeLiteralNode([
|
|
5408
|
+
factory.createPropertySignature(undefined, 'OpSchema', undefined, factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpSchema")))),
|
|
5409
|
+
factory.createPropertySignature(undefined, 'Action', undefined, factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpAction")))),
|
|
5410
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Schema"), undefined, getSchema()),
|
|
5411
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Projection"), undefined, getProjection()),
|
|
5412
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("FilterUnit"), undefined, getFilterUnit()),
|
|
5413
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Filter"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("MakeFilter"), [
|
|
5414
|
+
createIndexedForeignRef(entity, 'FilterUnit')
|
|
5415
|
+
])),
|
|
5416
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("SortAttr"), undefined, getSortAttr()),
|
|
5417
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("SortNode"), undefined, factory.createTypeLiteralNode([
|
|
5418
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("$attr"), undefined, createIndexedForeignRef(entity, 'SortAttr')),
|
|
5419
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("$direction"), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
|
|
5420
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("asc")),
|
|
5421
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("desc"))
|
|
5422
|
+
]))
|
|
5423
|
+
])),
|
|
5424
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Sorter"), undefined, factory.createArrayTypeNode(createIndexedForeignRef(entity, 'SortNode'))),
|
|
5425
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Selection"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OakSelection"), [
|
|
5426
|
+
factory.createLiteralTypeNode(factory.createStringLiteral("select")),
|
|
5427
|
+
createIndexedForeignRef(entity, 'Projection'),
|
|
5428
|
+
createIndexedForeignRef(entity, 'Filter'),
|
|
5429
|
+
createIndexedForeignRef(entity, 'Sorter')
|
|
5430
|
+
])),
|
|
5431
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Aggregation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("DeduceAggregation"), [
|
|
5432
|
+
createIndexedForeignRef(entity, 'Projection'),
|
|
5433
|
+
createIndexedForeignRef(entity, 'Filter'),
|
|
5434
|
+
createIndexedForeignRef(entity, 'Sorter')
|
|
5435
|
+
])),
|
|
5436
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("CreateOperationData"), undefined, CreateOperationData),
|
|
5437
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("CreateSingle"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
|
|
5438
|
+
factory.createLiteralTypeNode(factory.createStringLiteral('create')),
|
|
5439
|
+
createIndexedForeignRef(entity, 'CreateOperationData')
|
|
5440
|
+
])),
|
|
5441
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("CreateMulti"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
|
|
5442
|
+
factory.createLiteralTypeNode(factory.createStringLiteral('create')),
|
|
5443
|
+
factory.createTypeReferenceNode(factory.createIdentifier("Array"), [
|
|
5444
|
+
createIndexedForeignRef(entity, 'CreateOperationData')
|
|
5445
|
+
])
|
|
5446
|
+
])),
|
|
5447
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Create"), undefined, factory.createUnionTypeNode([
|
|
5448
|
+
createIndexedForeignRef(entity, 'CreateSingle'),
|
|
5449
|
+
createIndexedForeignRef(entity, 'CreateMulti')
|
|
5450
|
+
])),
|
|
5451
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("UpdateOperationData"), undefined, UpdateOperationData),
|
|
5452
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Update"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
|
|
5453
|
+
factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpUpdateAction"))),
|
|
5454
|
+
createIndexedForeignRef(entity, 'UpdateOperationData'),
|
|
5455
|
+
createIndexedForeignRef(entity, 'Filter'),
|
|
5456
|
+
createIndexedForeignRef(entity, 'Sorter'),
|
|
5457
|
+
])),
|
|
5458
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("RemoveOperationData"), undefined, RemoveOperationData),
|
|
5459
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Remove"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
|
|
5460
|
+
factory.createLiteralTypeNode(factory.createStringLiteral('remove')),
|
|
5461
|
+
createIndexedForeignRef(entity, 'RemoveOperationData'),
|
|
5462
|
+
createIndexedForeignRef(entity, 'Filter'),
|
|
5463
|
+
createIndexedForeignRef(entity, 'Sorter'),
|
|
5464
|
+
])),
|
|
5465
|
+
factory.createPropertySignature(undefined, factory.createIdentifier("Operation"), undefined, factory.createUnionTypeNode([
|
|
5466
|
+
createIndexedForeignRef(entity, 'Create'),
|
|
5467
|
+
createIndexedForeignRef(entity, 'Update'),
|
|
5468
|
+
createIndexedForeignRef(entity, 'Remove'),
|
|
5469
|
+
])),
|
|
5470
|
+
])));
|
|
5471
|
+
}
|
|
5472
|
+
statements.push(factory.createTypeAliasDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDict"), undefined, factory.createTypeLiteralNode(Object.keys(Schema).map((ele) => factory.createPropertySignature(undefined, (0, string_1.firstLetterLowerCase)(ele), undefined, factory.createTypeReferenceNode(factory.createIdentifier(ele)))))));
|
|
5473
|
+
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements), undefined);
|
|
5474
|
+
const fileName = path_1.default.join(outputDir, 'EntityDict.ts');
|
|
5475
|
+
(0, fs_1.writeFileSync)(fileName, result, { flag: 'w' });
|
|
5476
|
+
}
|
|
5477
|
+
function _outputSchema(outputDir, printer) {
|
|
5478
|
+
for (const entity in Schema) {
|
|
5479
|
+
const statements = [
|
|
5480
|
+
factory.createExportDeclaration(undefined, false, undefined, factory.createStringLiteral("./_baseSchema"), undefined),
|
|
5481
|
+
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
5482
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier(entity))
|
|
5483
|
+
])), factory.createStringLiteral("../EntityDict"), undefined),
|
|
5484
|
+
];
|
|
5485
|
+
const keys = [
|
|
5486
|
+
'Schema', 'Action', 'Projection', 'Filter', 'SortNode', 'Sorter', 'Selection',
|
|
5487
|
+
'Aggregation', 'CreateOperationData', 'CreateSingle', 'CreateMulti', 'Create',
|
|
5488
|
+
'UpdateOperationData', 'Update', 'RemoveOperationData', 'Remove', 'Operation'
|
|
5489
|
+
];
|
|
5490
|
+
statements.push(...keys.map((ele) => factory.createTypeAliasDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier(ele), undefined, factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(factory.createIdentifier(entity), undefined), factory.createLiteralTypeNode(factory.createStringLiteral(ele))))));
|
|
5491
|
+
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements), undefined);
|
|
5492
|
+
const fileName = path_1.default.join(outputDir, entity, 'Schema.ts');
|
|
5493
|
+
(0, fs_1.writeFileSync)(fileName, result, { flag: 'w' });
|
|
5494
|
+
}
|
|
5495
|
+
}
|
|
5496
|
+
function buildSchema(outputDir) {
|
|
5497
|
+
addReverseRelationship();
|
|
5498
|
+
// setRelationEntities();
|
|
5499
|
+
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
5500
|
+
resetOutputDir(outputDir);
|
|
5501
|
+
outputAction(outputDir, printer);
|
|
5502
|
+
_outputBaseSchema(outputDir, printer);
|
|
5503
|
+
outputLocale(outputDir, printer);
|
|
5504
|
+
_outputEntityDict(outputDir, printer);
|
|
5505
|
+
_outputSchema(outputDir, printer);
|
|
5506
|
+
outputStorage(outputDir, printer);
|
|
5507
|
+
outputRelation2(outputDir, printer);
|
|
5508
|
+
outputStyleDict(outputDir, printer);
|
|
5509
|
+
outputIndexTs(outputDir);
|
|
5510
|
+
}
|
|
4329
5511
|
exports.buildSchema = buildSchema;
|