From 6ae7235a5a06c7368a21792f111040f0039e4c0f Mon Sep 17 00:00:00 2001 From: Xc Date: Thu, 11 Apr 2024 20:13:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=AF=91=E5=99=A8=E5=A4=84=E7=90=86?= =?UTF-8?q?=E4=BA=86Schema=E7=BB=A7=E6=89=BF=E8=BF=87=E7=A8=8B=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E5=A4=9A=E6=AC=A1=E5=BC=95=E7=94=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/compiler/schemalBuilder.js | 20 +++++++++++++++++--- src/compiler/schemalBuilder.ts | 20 +++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/compiler/schemalBuilder.js b/lib/compiler/schemalBuilder.js index bb9454b..1e0633b 100644 --- a/lib/compiler/schemalBuilder.js +++ b/lib/compiler/schemalBuilder.js @@ -30,11 +30,21 @@ const ActionImportStatements = () => [ const StyleAsts = {}; const ActionAsts = {}; const SchemaAsts = {}; +/** + * 部分项目目前存在引用了Schema但是不依赖于其包,因此目前先在此去重。 + * 后续要修正这种行为,让继承的schema分层编译 + * @param many + * @param one + * @param key + * @param notNull + */ function addRelationship(many, one, key, notNull) { const { [many]: manySet } = ManyToOne; const one2 = one === 'Schema' ? many : one; if (manySet) { - manySet.push([one2, key, notNull]); + if (!manySet.find(ele => ele[1] === key && ele[0] === one2)) { + manySet.push([one2, key, notNull]); + } } else { (0, lodash_1.assign)(ManyToOne, { @@ -43,7 +53,9 @@ function addRelationship(many, one, key, notNull) { } const { [one2]: oneSet } = OneToMany; if (oneSet) { - oneSet.push([many, key, notNull]); + if (!oneSet.find(ele => ele[1] === key && ele[0] === many)) { + oneSet.push([many, key, notNull]); + } } else { (0, lodash_1.assign)(OneToMany, { @@ -676,7 +688,9 @@ function analyzeSchemaDefinition(node, moduleName, filename, path, program, refe // 这也是一对多的反指定义 const reverseEntity = typeName.text; if (ReversePointerRelations[reverseEntity]) { - ReversePointerRelations[reverseEntity].push(moduleName); + if (!ReversePointerRelations[reverseEntity].includes(moduleName)) { + ReversePointerRelations[reverseEntity].push(moduleName); + } } else { (0, lodash_1.assign)(ReversePointerRelations, { diff --git a/src/compiler/schemalBuilder.ts b/src/compiler/schemalBuilder.ts index 4825a22..d50398d 100644 --- a/src/compiler/schemalBuilder.ts +++ b/src/compiler/schemalBuilder.ts @@ -122,11 +122,21 @@ const SchemaAsts: { }; } = {}; +/** + * 部分项目目前存在引用了Schema但是不依赖于其包,因此目前先在此去重。 + * 后续要修正这种行为,让继承的schema分层编译 + * @param many + * @param one + * @param key + * @param notNull + */ function addRelationship(many: string, one: string, key: string, notNull: boolean) { const { [many]: manySet } = ManyToOne; const one2 = one === 'Schema' ? many : one; if (manySet) { - manySet.push([one2, key, notNull]); + if (!manySet.find(ele => ele[1] === key && ele[0] === one2)) { + manySet.push([one2, key, notNull]); + } } else { assign(ManyToOne, { @@ -136,7 +146,9 @@ function addRelationship(many: string, one: string, key: string, notNull: boolea const { [one2]: oneSet } = OneToMany; if (oneSet) { - oneSet.push([many, key, notNull]); + if (!oneSet.find(ele => ele[1] === key && ele[0] === many)) { + oneSet.push([many, key, notNull]); + } } else { assign(OneToMany, { @@ -936,7 +948,9 @@ function analyzeSchemaDefinition( // 这也是一对多的反指定义 const reverseEntity = typeName.text; if (ReversePointerRelations[reverseEntity]) { - ReversePointerRelations[reverseEntity].push(moduleName); + if (!ReversePointerRelations[reverseEntity].includes(moduleName)) { + ReversePointerRelations[reverseEntity].push(moduleName); + } } else { assign(ReversePointerRelations, {