File tree Expand file tree Collapse file tree
packages/database/src/core/utilities Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- export function mergeMultiJoin ( baseMultiJoin , multiJoinToMerge ) {
2- if ( ! multiJoinToMerge ) {
3- return baseMultiJoin ;
4- }
5- const checkJoinIsUnique = join => ! baseMultiJoin . find ( j => j . joinWith === join . joinWith ) ;
6- return [ ...baseMultiJoin ] . concat ( ...multiJoinToMerge . filter ( checkJoinIsUnique ) ) ;
1+ /**
2+ * @typedef {import('../BaseDatabase').JoinType } JoinType
3+ * @typedef {{
4+ * joinWith: string;
5+ * joinAs?: string;
6+ * joinType?: JoinType;
7+ * joinCondition: [string, string];
8+ * fields?: Record<string, string | undefined>;
9+ * }} MultiJoinItem
10+ */
11+
12+ /**
13+ * @template {readonly MultiJoinItem[]} Base
14+ * @param {readonly Base } base
15+ * @param {readonly MultiJoinItem[] } source
16+ * @returns {[...Base, ...MultiJoinItem[]] }
17+ */
18+ export function mergeMultiJoin ( base , source ) {
19+ if ( ! source || source . length === 0 ) return base ;
20+
21+ const existingJoinTables = new Set ( base . map ( j => j . joinWith ) ) ;
22+ const uniques = source . filter ( j => ! existingJoinTables . has ( j . joinWith ) ) ;
23+
24+ return [ ...base , ...uniques ] ;
725}
You can’t perform that action at this time.
0 commit comments