• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

typeorm / typeorm / 15219332477

23 May 2025 09:13PM UTC coverage: 17.216% (-59.1%) from 76.346%
15219332477

Pull #11332

github

naorpeled
cr comments - move if block
Pull Request #11332: feat: add new undefined and null behavior flags

1603 of 12759 branches covered (12.56%)

Branch coverage included in aggregate %.

0 of 31 new or added lines in 3 files covered. (0.0%)

14132 existing lines in 166 files now uncovered.

4731 of 24033 relevant lines covered (19.69%)

60.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

18.18
/src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts
1
import { EntityMetadata } from "../metadata/EntityMetadata"
1✔
2
import { ColumnMetadata } from "../metadata/ColumnMetadata"
1✔
3
import { ForeignKeyMetadata } from "../metadata/ForeignKeyMetadata"
1✔
4
import { DataSource } from "../data-source/DataSource"
5
import { IndexMetadata } from "../metadata/IndexMetadata"
1✔
6

7
/**
8
 * Creates EntityMetadata for junction tables of the closure entities.
9
 * Closure junction tables are tables generated by closure entities.
10
 */
11
export class ClosureJunctionEntityMetadataBuilder {
1✔
12
    // -------------------------------------------------------------------------
13
    // Constructor
14
    // -------------------------------------------------------------------------
15

16
    constructor(private connection: DataSource) {}
84✔
17

18
    // -------------------------------------------------------------------------
19
    // Public Methods
20
    // -------------------------------------------------------------------------
21

22
    /**
23
     * Builds EntityMetadata for the closure junction of the given closure entity.
24
     */
25
    build(parentClosureEntityMetadata: EntityMetadata) {
26
        // create entity metadata itself
UNCOV
27
        const entityMetadata = new EntityMetadata({
×
28
            parentClosureEntityMetadata: parentClosureEntityMetadata,
29
            connection: this.connection,
30
            args: {
31
                target: "",
32
                name:
33
                    parentClosureEntityMetadata.treeOptions &&
×
34
                    parentClosureEntityMetadata.treeOptions.closureTableName
35
                        ? parentClosureEntityMetadata.treeOptions
36
                              .closureTableName
37
                        : parentClosureEntityMetadata.tableNameWithoutPrefix,
38
                type: "closure-junction",
39
            },
40
        })
UNCOV
41
        entityMetadata.build()
×
42

43
        // create ancestor and descendant columns for new closure junction table
UNCOV
44
        parentClosureEntityMetadata.primaryColumns.forEach((primaryColumn) => {
×
UNCOV
45
            entityMetadata.ownColumns.push(
×
46
                new ColumnMetadata({
47
                    connection: this.connection,
48
                    entityMetadata: entityMetadata,
49
                    closureType: "ancestor",
50
                    referencedColumn: primaryColumn,
51
                    args: {
52
                        target: "",
53
                        mode: "virtual",
54
                        propertyName:
55
                            parentClosureEntityMetadata.treeOptions &&
×
56
                            parentClosureEntityMetadata.treeOptions
57
                                .ancestorColumnName
58
                                ? parentClosureEntityMetadata.treeOptions.ancestorColumnName(
59
                                      primaryColumn,
60
                                  )
61
                                : primaryColumn.propertyName + "_ancestor",
62
                        options: {
63
                            primary: true,
64
                            length: primaryColumn.length,
65
                            type: primaryColumn.type,
66
                        },
67
                    },
68
                }),
69
            )
UNCOV
70
            entityMetadata.ownColumns.push(
×
71
                new ColumnMetadata({
72
                    connection: this.connection,
73
                    entityMetadata: entityMetadata,
74
                    closureType: "descendant",
75
                    referencedColumn: primaryColumn,
76
                    args: {
77
                        target: "",
78
                        mode: "virtual",
79
                        propertyName:
80
                            parentClosureEntityMetadata.treeOptions &&
×
81
                            parentClosureEntityMetadata.treeOptions
82
                                .descendantColumnName
83
                                ? parentClosureEntityMetadata.treeOptions.descendantColumnName(
84
                                      primaryColumn,
85
                                  )
86
                                : primaryColumn.propertyName + "_descendant",
87
                        options: {
88
                            primary: true,
89
                            length: primaryColumn.length,
90
                            type: primaryColumn.type,
91
                        },
92
                    },
93
                }),
94
            )
95
        })
96

UNCOV
97
        entityMetadata.ownIndices = [
×
98
            new IndexMetadata({
99
                entityMetadata: entityMetadata,
100
                columns: [entityMetadata.ownColumns[0]],
101
                args: {
102
                    target: entityMetadata.target,
103
                    synchronize: true,
104
                },
105
            }),
106
            new IndexMetadata({
107
                entityMetadata: entityMetadata,
108
                columns: [entityMetadata.ownColumns[1]],
109
                args: {
110
                    target: entityMetadata.target,
111
                    synchronize: true,
112
                },
113
            }),
114
        ]
115

116
        // if tree level column was defined by a closure entity then add it to the junction columns as well
UNCOV
117
        if (parentClosureEntityMetadata.treeLevelColumn) {
×
UNCOV
118
            entityMetadata.ownColumns.push(
×
119
                new ColumnMetadata({
120
                    connection: this.connection,
121
                    entityMetadata: entityMetadata,
122
                    args: {
123
                        target: "",
124
                        mode: "virtual",
125
                        propertyName: "level",
126
                        options: {
127
                            type: this.connection.driver.mappedDataTypes
128
                                .treeLevel,
129
                        },
130
                    },
131
                }),
132
            )
133
        }
134

135
        // create junction table foreign keys
136
        // Note: CASCADE is not applied to mssql because it does not support multi cascade paths
UNCOV
137
        entityMetadata.foreignKeys = [
×
138
            new ForeignKeyMetadata({
139
                entityMetadata: entityMetadata,
140
                referencedEntityMetadata: parentClosureEntityMetadata,
141
                columns: [entityMetadata.ownColumns[0]],
142
                referencedColumns: parentClosureEntityMetadata.primaryColumns,
143
                onDelete:
144
                    this.connection.driver.options.type === "mssql"
×
145
                        ? "NO ACTION"
146
                        : "CASCADE",
147
            }),
148
            new ForeignKeyMetadata({
149
                entityMetadata: entityMetadata,
150
                referencedEntityMetadata: parentClosureEntityMetadata,
151
                columns: [entityMetadata.ownColumns[1]],
152
                referencedColumns: parentClosureEntityMetadata.primaryColumns,
153
                onDelete:
154
                    this.connection.driver.options.type === "mssql"
×
155
                        ? "NO ACTION"
156
                        : "CASCADE",
157
            }),
158
        ]
159

UNCOV
160
        return entityMetadata
×
161
    }
162
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc