333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
1
{"version":3,"sources":["../../src/query-builder/relation-count/RelationCountAttribute.ts"],"names":[],"mappings":";;;AACA,0DAAuD;AAIvD,sDAAmD;AAEnD;IAsBI,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,gCAAoB,aAAiC,EACzC,sBAAwD;QADhD,kBAAa,GAAb,aAAa,CAAoB;QAEjD,yBAAW,CAAC,MAAM,CAAC,IAAI,EAAE,sBAAsB,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;IAMD,sBAAI,2DAAuB;QAJ3B,4EAA4E;QAC5E,iBAAiB;QACjB,4EAA4E;aAE5E;YACI,OAAO,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC;QAC/C,CAAC;;;OAAA;IAQD,sBAAI,+CAAW;QANf;;;;;WAKG;aACH;YACI,IAAI,CAAC,qCAAiB,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC;gBACrD,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;YAErF,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3C,CAAC;;;OAAA;IASD,sBAAI,oDAAgB;QAPpB;;;;;;WAMG;aACH;YACI,IAAI,CAAC,qCAAiB,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC;gBACrD,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;YAEhF,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3C,CAAC;;;OAAA;IAED,sBAAI,iDAAa;aAAjB;YACU,IAAA,oDAA8D,EAA7D,mBAAW,EAAE,wBAAgD,CAAC;YACrE,OAAO,WAAW,GAAG,GAAG,GAAG,gBAAgB,GAAG,KAAK,CAAC;QACxD,CAAC;;;OAAA;IAOD,sBAAI,4CAAQ;QALZ;;;;WAIG;aACH;YACI,IAAI,CAAC,qCAAiB,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC;gBACrD,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;YAE1E,IAAA,oDAA0D,EAAzD,mBAAW,EAAE,oBAA4C,CAAC;YACjE,IAAM,sBAAsB,GAAG,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;YAC/E,IAAM,QAAQ,GAAG,sBAAsB,CAAC,QAAQ,CAAC,4BAA4B,CAAC,YAAY,CAAC,CAAC;YAC5F,IAAI,CAAC,QAAQ;gBACT,MAAM,IAAI,KAAK,CAAC,iCAA+B,YAAY,8BAA2B,CAAC,CAAC;YAC5F,OAAO,QAAQ,CAAC;QACpB,CAAC;;;OAAA;IAMD,sBAAI,4CAAQ;QAJZ;;;WAGG;aACH;YACI,IAAI,CAAC,qCAAiB,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC;gBACrD,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;YAEhF,IAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACpD,IAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;YAClE,OAAO,SAAS,CAAC,QAAQ,CAAC;QAC9B,CAAC;;;OAAA;IAED,sBAAI,6DAAyB;aAA7B;YACI,OAAO,IAAI,CAAC,aAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7C,CAAC;;;OAAA;IAEL,6BAAC;AAAD,CAzGA,AAyGC,IAAA;AAzGY,wDAAsB","file":"RelationCountAttribute.js","sourcesContent":["import {EntityMetadata} from \"../../metadata/EntityMetadata\";\nimport {QueryBuilderUtils} from \"../QueryBuilderUtils\";\nimport {RelationMetadata} from \"../../metadata/RelationMetadata\";\nimport {QueryExpressionMap} from \"../QueryExpressionMap\";\nimport {SelectQueryBuilder} from \"../SelectQueryBuilder\";\nimport {ObjectUtils} from \"../../util/ObjectUtils\";\n\nexport class RelationCountAttribute {\n\n    /**\n     * Alias of the joined (destination) table.\n     */\n    alias?: string;\n\n    /**\n     * Name of relation.\n     */\n    relationName: string;\n\n    /**\n     * Property + alias of the object where to joined data should be mapped.\n     */\n    mapToProperty: string;\n\n    /**\n     * Extra condition applied to \"ON\" section of join.\n     */\n    queryBuilderFactory?: (qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>;\n\n    // -------------------------------------------------------------------------\n    // Constructor\n    // -------------------------------------------------------------------------\n\n    constructor(private expressionMap: QueryExpressionMap,\n                relationCountAttribute?: Partial<RelationCountAttribute>) {\n        ObjectUtils.assign(this, relationCountAttribute || {});\n    }\n\n    // -------------------------------------------------------------------------\n    // Public Methods\n    // -------------------------------------------------------------------------\n\n    get joinInverseSideMetadata(): EntityMetadata {\n        return this.relation.inverseEntityMetadata;\n    }\n\n    /**\n     * Alias of the parent of this join.\n     * For example, if we join (\"post.category\", \"categoryAlias\") then \"post\" is a parent alias.\n     * This value is extracted from entityOrProperty value.\n     * This is available when join was made using \"post.category\" syntax.\n     */\n    get parentAlias(): string {\n        if (!QueryBuilderUtils.isAliasProperty(this.relationName))\n            throw new Error(`Given value must be a string representation of alias property`);\n\n        return this.relationName.split(\".\")[0];\n    }\n\n    /**\n     * Relation property name of the parent.\n     * This is used to understand what is joined.\n     * For example, if we join (\"post.category\", \"categoryAlias\") then \"category\" is a relation property.\n     * This value is extracted from entityOrProperty value.\n     * This is available when join was made using \"post.category\" syntax.\n     */\n    get relationProperty(): string|undefined {\n        if (!QueryBuilderUtils.isAliasProperty(this.relationName))\n            throw new Error(`Given value is a string representation of alias property`);\n\n        return this.relationName.split(\".\")[1];\n    }\n\n    get junctionAlias(): string {\n        const [parentAlias, relationProperty] = this.relationName.split(\".\");\n        return parentAlias + \"_\" + relationProperty + \"_rc\";\n    }\n\n    /**\n     * Relation of the parent.\n     * This is used to understand what is joined.\n     * This is available when join was made using \"post.category\" syntax.\n     */\n    get relation(): RelationMetadata {\n        if (!QueryBuilderUtils.isAliasProperty(this.relationName))\n            throw new Error(`Given value is a string representation of alias property`);\n\n        const [parentAlias, propertyPath] = this.relationName.split(\".\");\n        const relationOwnerSelection = this.expressionMap.findAliasByName(parentAlias);\n        const relation = relationOwnerSelection.metadata.findRelationWithPropertyPath(propertyPath);\n        if (!relation)\n            throw new Error(`Relation with property path ${propertyPath} in entity was not found.`);\n        return relation;\n    }\n\n    /**\n     * Metadata of the joined entity.\n     * If table without entity was joined, then it will return undefined.\n     */\n    get metadata(): EntityMetadata {\n        if (!QueryBuilderUtils.isAliasProperty(this.relationName))\n            throw new Error(`Given value is a string representation of alias property`);\n\n        const parentAlias = this.relationName.split(\".\")[0];\n        const selection = this.expressionMap.findAliasByName(parentAlias);\n        return selection.metadata;\n    }\n\n    get mapToPropertyPropertyName(): string {\n        return this.mapToProperty!.split(\".\")[1];\n    }\n\n}\n"],"sourceRoot":"../.."}