@itwin/core-backend 5.6.0 → 5.6.2

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.
@@ -0,0 +1,240 @@
1
+ import { IModelDb } from "../IModelDb";
2
+ /**
3
+ * Information about each integrity check type, including the name, expected result type, and SQL query to execute
4
+ * @internal
5
+ */
6
+ export declare const integrityCheckTypeMap: {
7
+ readonly checkDataColumns: {
8
+ readonly name: "Check Data Columns";
9
+ readonly resultType: "CheckDataColumnsResultRow";
10
+ readonly sqlCommand: "check_data_columns";
11
+ readonly sqlQuery: "PRAGMA integrity_check(check_data_columns) options enable_experimental_features";
12
+ };
13
+ readonly checkECProfile: {
14
+ readonly name: "Check EC Profile";
15
+ readonly resultType: "CheckECProfileResultRow";
16
+ readonly sqlCommand: "check_ec_profile";
17
+ readonly sqlQuery: "PRAGMA integrity_check(check_ec_profile) options enable_experimental_features";
18
+ };
19
+ readonly checkNavigationClassIds: {
20
+ readonly name: "Check Navigation Class Ids";
21
+ readonly resultType: "CheckNavClassIdsResultRow";
22
+ readonly sqlCommand: "check_nav_class_ids";
23
+ readonly sqlQuery: "PRAGMA integrity_check(check_nav_class_ids) options enable_experimental_features";
24
+ };
25
+ readonly checkNavigationIds: {
26
+ readonly name: "Check Navigation Ids";
27
+ readonly resultType: "CheckNavIdsResultRow";
28
+ readonly sqlCommand: "check_nav_ids";
29
+ readonly sqlQuery: "PRAGMA integrity_check(check_nav_ids) options enable_experimental_features";
30
+ };
31
+ readonly checkLinktableForeignKeyClassIds: {
32
+ readonly name: "Check Link Table Foreign Key Class Ids";
33
+ readonly resultType: "CheckLinkTableFkClassIdsResultRow";
34
+ readonly sqlCommand: "check_linktable_fk_class_ids";
35
+ readonly sqlQuery: "PRAGMA integrity_check(check_linktable_fk_class_ids) options enable_experimental_features";
36
+ };
37
+ readonly checkLinktableForeignKeyIds: {
38
+ readonly name: "Check Link Table Foreign Key Ids";
39
+ readonly resultType: "CheckLinkTableFkIdsResultRow";
40
+ readonly sqlCommand: "check_linktable_fk_ids";
41
+ readonly sqlQuery: "PRAGMA integrity_check(check_linktable_fk_ids) options enable_experimental_features";
42
+ };
43
+ readonly checkClassIds: {
44
+ readonly name: "Check Class Ids";
45
+ readonly resultType: "CheckClassIdsResultRow";
46
+ readonly sqlCommand: "check_class_ids";
47
+ readonly sqlQuery: "PRAGMA integrity_check(check_class_ids) options enable_experimental_features";
48
+ };
49
+ readonly checkDataSchema: {
50
+ readonly name: "Check Data Schema";
51
+ readonly resultType: "CheckDataSchemaResultRow";
52
+ readonly sqlCommand: "check_data_schema";
53
+ readonly sqlQuery: "PRAGMA integrity_check(check_data_schema) options enable_experimental_features";
54
+ };
55
+ readonly checkSchemaLoad: {
56
+ readonly name: "Check Schema Load";
57
+ readonly resultType: "CheckSchemaLoadResultRow";
58
+ readonly sqlCommand: "check_schema_load";
59
+ readonly sqlQuery: "PRAGMA integrity_check(check_schema_load) options enable_experimental_features";
60
+ };
61
+ readonly checkMissingChildRows: {
62
+ readonly name: "Check Missing Child Rows";
63
+ readonly resultType: "CheckMissingChildRowsResultRow";
64
+ readonly sqlCommand: "check_missing_child_rows";
65
+ readonly sqlQuery: "PRAGMA integrity_check(check_missing_child_rows) options enable_experimental_features";
66
+ };
67
+ };
68
+ /**
69
+ * Type representing the keys of the integrityCheckType map, which correspond to the different types of integrity checks that can be performed.
70
+ */
71
+ export type IntegrityCheckKey = keyof typeof integrityCheckTypeMap;
72
+ /** Map of integrity check keys to their result row types */
73
+ interface IntegrityCheckResultTypeMap {
74
+ checkDataColumns: CheckDataColumnsResultRow;
75
+ checkECProfile: CheckECProfileResultRow;
76
+ checkNavigationClassIds: CheckNavClassIdsResultRow;
77
+ checkNavigationIds: CheckNavIdsResultRow;
78
+ checkLinktableForeignKeyClassIds: CheckLinkTableFkClassIdsResultRow;
79
+ checkLinktableForeignKeyIds: CheckLinkTableFkIdsResultRow;
80
+ checkClassIds: CheckClassIdsResultRow;
81
+ checkDataSchema: CheckDataSchemaResultRow;
82
+ checkSchemaLoad: CheckSchemaLoadResultRow;
83
+ checkMissingChildRows: CheckMissingChildRowsResultRow;
84
+ }
85
+ /** Checks the Map to give the return type of a specific integrity check */
86
+ type IntegrityCheckResultRow<K extends IntegrityCheckKey> = IntegrityCheckResultTypeMap[K];
87
+ /**
88
+ * Return type for quick integrity check
89
+ */
90
+ export interface QuickIntegrityCheckResultRow {
91
+ check: string;
92
+ passed: boolean;
93
+ elapsedSeconds: string;
94
+ }
95
+ /**
96
+ * Return type for Check Data Columns integrity check
97
+ */
98
+ export interface CheckDataColumnsResultRow {
99
+ sno: number;
100
+ table: string;
101
+ column: string;
102
+ }
103
+ /**
104
+ * Return type for Check EC Profile integrity check
105
+ */
106
+ export interface CheckECProfileResultRow {
107
+ sno: number;
108
+ type: string;
109
+ name: string;
110
+ issue: string;
111
+ }
112
+ /**
113
+ * Return type for Check Navigation Class Ids integrity check
114
+ */
115
+ export interface CheckNavClassIdsResultRow {
116
+ sno: number;
117
+ id: string;
118
+ class: string;
119
+ property: string;
120
+ navId: string;
121
+ navClassId: string;
122
+ }
123
+ /**
124
+ * Return type for Check Navigation Ids integrity check
125
+ */
126
+ export interface CheckNavIdsResultRow {
127
+ sno: number;
128
+ id: string;
129
+ class: string;
130
+ property: string;
131
+ navId: string;
132
+ primaryClass: string;
133
+ }
134
+ /**
135
+ * Return type for Check Link Table Foreign Key Class Ids integrity check
136
+ */
137
+ export interface CheckLinkTableFkClassIdsResultRow {
138
+ sno: number;
139
+ id: string;
140
+ relationship: string;
141
+ property: string;
142
+ keyId: string;
143
+ keyClassId: string;
144
+ }
145
+ /**
146
+ * Return type for Check Link Table Foreign Key Ids integrity check
147
+ */
148
+ export interface CheckLinkTableFkIdsResultRow {
149
+ sno: number;
150
+ id: string;
151
+ relationship: string;
152
+ property: string;
153
+ keyId: string;
154
+ primaryClass: string;
155
+ }
156
+ /**
157
+ * Return type for Check Class Ids integrity check
158
+ */
159
+ export interface CheckClassIdsResultRow {
160
+ sno: number;
161
+ class: string;
162
+ id: string;
163
+ classId: string;
164
+ type: string;
165
+ }
166
+ /**
167
+ * Return type for Check Data Schema integrity check
168
+ */
169
+ export interface CheckDataSchemaResultRow {
170
+ sno: number;
171
+ type: string;
172
+ name: string;
173
+ }
174
+ /**
175
+ * Return type for Check Schema Load integrity check
176
+ */
177
+ export interface CheckSchemaLoadResultRow {
178
+ sno: number;
179
+ schema: string;
180
+ }
181
+ /**
182
+ * Return type for Check Missing Child Rows integrity check
183
+ */
184
+ export interface CheckMissingChildRowsResultRow {
185
+ sno: number;
186
+ class: string;
187
+ id: string;
188
+ classId: string;
189
+ missingRowInTables: string;
190
+ }
191
+ /**
192
+ * Return type for integrity check results, including the check name, whether it passed, and the specific results (if any)
193
+ */
194
+ export interface IntegrityCheckResult {
195
+ /** The name of the integrity check that was performed */
196
+ check: string;
197
+ /** Whether the integrity check passed (i.e. no issues were found = true) */
198
+ passed: boolean;
199
+ /** The specific results returned by the integrity check, which may include details about any issues that were found.
200
+ * In the case where issues are found, this will be an array of result rows specific to the type of check that was performed,
201
+ * or an array of quick integrity check results if it was a quick check. */
202
+ results: IntegrityCheckResultRow<IntegrityCheckKey>[] | QuickIntegrityCheckResultRow[];
203
+ }
204
+ /**
205
+ * Gets the user-friendly name of an integrity check based on its key or SQL command.
206
+ * It first attempts to find a direct match for the key in the integrityCheckTypeMap. If not found, it searches for a match based on the SQL command.
207
+ * If still not found, it returns the original check string.
208
+ * @param check - The integrity check key or SQL command to get the name of
209
+ * @returns The user-friendly name of the integrity check, or the original check string if no match is found
210
+ * @internal
211
+ */
212
+ export declare function getIntegrityCheckName(check: string): string;
213
+ /**
214
+ * Performs a quick integrity check on the given iModel.
215
+ * @param iModel The IModelDb instance to perform the integrity check on
216
+ * @returns An array of results for each check performed, including the check name, whether it passed, and the elapsed time in seconds
217
+ * @internal
218
+ */
219
+ export declare function performQuickIntegrityCheck(iModel: IModelDb): Promise<QuickIntegrityCheckResultRow[]>;
220
+ /**
221
+ * Performs a specific integrity check on the given iModel based on the provided check key, and returns the results specific to that check type.
222
+ * @param iModel The IModelDb instance to perform the integrity check on
223
+ * @param check The key of the specific integrity check to perform
224
+ * @return An array of results specific to the integrity check that was performed. The type of the result rows will depend on the check that was executed.
225
+ * @throws IModelError with status BadRequest if an unknown integrity check key is provided
226
+ * @internal
227
+ */
228
+ export declare function performSpecificIntegrityCheck(iModel: IModelDb, check: "checkDataColumns"): Promise<IntegrityCheckResultRow<"checkDataColumns">[]>;
229
+ export declare function performSpecificIntegrityCheck(iModel: IModelDb, check: "checkECProfile"): Promise<IntegrityCheckResultRow<"checkECProfile">[]>;
230
+ export declare function performSpecificIntegrityCheck(iModel: IModelDb, check: "checkNavigationClassIds"): Promise<IntegrityCheckResultRow<"checkNavigationClassIds">[]>;
231
+ export declare function performSpecificIntegrityCheck(iModel: IModelDb, check: "checkNavigationIds"): Promise<IntegrityCheckResultRow<"checkNavigationIds">[]>;
232
+ export declare function performSpecificIntegrityCheck(iModel: IModelDb, check: "checkLinktableForeignKeyClassIds"): Promise<IntegrityCheckResultRow<"checkLinktableForeignKeyClassIds">[]>;
233
+ export declare function performSpecificIntegrityCheck(iModel: IModelDb, check: "checkLinktableForeignKeyIds"): Promise<IntegrityCheckResultRow<"checkLinktableForeignKeyIds">[]>;
234
+ export declare function performSpecificIntegrityCheck(iModel: IModelDb, check: "checkClassIds"): Promise<IntegrityCheckResultRow<"checkClassIds">[]>;
235
+ export declare function performSpecificIntegrityCheck(iModel: IModelDb, check: "checkDataSchema"): Promise<IntegrityCheckResultRow<"checkDataSchema">[]>;
236
+ export declare function performSpecificIntegrityCheck(iModel: IModelDb, check: "checkSchemaLoad"): Promise<IntegrityCheckResultRow<"checkSchemaLoad">[]>;
237
+ export declare function performSpecificIntegrityCheck(iModel: IModelDb, check: "checkMissingChildRows"): Promise<IntegrityCheckResultRow<"checkMissingChildRows">[]>;
238
+ export declare function performSpecificIntegrityCheck<K extends IntegrityCheckKey>(iModel: IModelDb, check: K): Promise<IntegrityCheckResultRow<K>[]>;
239
+ export {};
240
+ //# sourceMappingURL=IntegrityCheck.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntegrityCheck.d.ts","sourceRoot":"","sources":["../../../src/internal/IntegrityCheck.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6DxB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,qBAAqB,CAAC;AAEnE,4DAA4D;AAC5D,UAAU,2BAA2B;IACnC,gBAAgB,EAAE,yBAAyB,CAAC;IAC5C,cAAc,EAAE,uBAAuB,CAAC;IACxC,uBAAuB,EAAE,yBAAyB,CAAC;IACnD,kBAAkB,EAAE,oBAAoB,CAAC;IACzC,gCAAgC,EAAE,iCAAiC,CAAC;IACpE,2BAA2B,EAAE,4BAA4B,CAAC;IAC1D,aAAa,EAAE,sBAAsB,CAAC;IACtC,eAAe,EAAE,wBAAwB,CAAC;IAC1C,eAAe,EAAE,wBAAwB,CAAC;IAC1C,qBAAqB,EAAE,8BAA8B,CAAC;CACvD;AAED,2EAA2E;AAC3E,KAAK,uBAAuB,CAAC,CAAC,SAAS,iBAAiB,IAAI,2BAA2B,CAAC,CAAC,CAAC,CAAC;AAE3F;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC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right (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.integrityCheckTypeMap = void 0;
8
+ exports.getIntegrityCheckName = getIntegrityCheckName;
9
+ exports.performQuickIntegrityCheck = performQuickIntegrityCheck;
10
+ exports.performSpecificIntegrityCheck = performSpecificIntegrityCheck;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const core_common_1 = require("@itwin/core-common");
13
+ /**
14
+ * Information about each integrity check type, including the name, expected result type, and SQL query to execute
15
+ * @internal
16
+ */
17
+ exports.integrityCheckTypeMap = {
18
+ checkDataColumns: {
19
+ name: "Check Data Columns",
20
+ resultType: "CheckDataColumnsResultRow",
21
+ sqlCommand: "check_data_columns",
22
+ sqlQuery: `PRAGMA integrity_check(check_data_columns) options enable_experimental_features`,
23
+ },
24
+ checkECProfile: {
25
+ name: "Check EC Profile",
26
+ resultType: "CheckECProfileResultRow",
27
+ sqlCommand: "check_ec_profile",
28
+ sqlQuery: `PRAGMA integrity_check(check_ec_profile) options enable_experimental_features`,
29
+ },
30
+ checkNavigationClassIds: {
31
+ name: "Check Navigation Class Ids",
32
+ resultType: "CheckNavClassIdsResultRow",
33
+ sqlCommand: "check_nav_class_ids",
34
+ sqlQuery: `PRAGMA integrity_check(check_nav_class_ids) options enable_experimental_features`,
35
+ },
36
+ checkNavigationIds: {
37
+ name: "Check Navigation Ids",
38
+ resultType: "CheckNavIdsResultRow",
39
+ sqlCommand: "check_nav_ids",
40
+ sqlQuery: `PRAGMA integrity_check(check_nav_ids) options enable_experimental_features`,
41
+ },
42
+ checkLinktableForeignKeyClassIds: {
43
+ name: "Check Link Table Foreign Key Class Ids",
44
+ resultType: "CheckLinkTableFkClassIdsResultRow",
45
+ sqlCommand: "check_linktable_fk_class_ids",
46
+ sqlQuery: `PRAGMA integrity_check(check_linktable_fk_class_ids) options enable_experimental_features`,
47
+ },
48
+ checkLinktableForeignKeyIds: {
49
+ name: "Check Link Table Foreign Key Ids",
50
+ resultType: "CheckLinkTableFkIdsResultRow",
51
+ sqlCommand: "check_linktable_fk_ids",
52
+ sqlQuery: `PRAGMA integrity_check(check_linktable_fk_ids) options enable_experimental_features`,
53
+ },
54
+ checkClassIds: {
55
+ name: "Check Class Ids",
56
+ resultType: "CheckClassIdsResultRow",
57
+ sqlCommand: "check_class_ids",
58
+ sqlQuery: `PRAGMA integrity_check(check_class_ids) options enable_experimental_features`,
59
+ },
60
+ checkDataSchema: {
61
+ name: "Check Data Schema",
62
+ resultType: "CheckDataSchemaResultRow",
63
+ sqlCommand: "check_data_schema",
64
+ sqlQuery: `PRAGMA integrity_check(check_data_schema) options enable_experimental_features`,
65
+ },
66
+ checkSchemaLoad: {
67
+ name: "Check Schema Load",
68
+ resultType: "CheckSchemaLoadResultRow",
69
+ sqlCommand: "check_schema_load",
70
+ sqlQuery: `PRAGMA integrity_check(check_schema_load) options enable_experimental_features`,
71
+ },
72
+ checkMissingChildRows: {
73
+ name: "Check Missing Child Rows",
74
+ resultType: "CheckMissingChildRowsResultRow",
75
+ sqlCommand: "check_missing_child_rows",
76
+ sqlQuery: `PRAGMA integrity_check(check_missing_child_rows) options enable_experimental_features`,
77
+ },
78
+ };
79
+ /**
80
+ * Gets the user-friendly name of an integrity check based on its key or SQL command.
81
+ * It first attempts to find a direct match for the key in the integrityCheckTypeMap. If not found, it searches for a match based on the SQL command.
82
+ * If still not found, it returns the original check string.
83
+ * @param check - The integrity check key or SQL command to get the name of
84
+ * @returns The user-friendly name of the integrity check, or the original check string if no match is found
85
+ * @internal
86
+ */
87
+ function getIntegrityCheckName(check) {
88
+ // First try direct lookup by key
89
+ const directLookup = exports.integrityCheckTypeMap[check];
90
+ if (directLookup) {
91
+ return directLookup.name;
92
+ }
93
+ // If not found, search by sqlCommand
94
+ for (const [, value] of Object.entries(exports.integrityCheckTypeMap)) {
95
+ if (value.sqlCommand === check) {
96
+ return value.name;
97
+ }
98
+ }
99
+ // Fallback to the original check string
100
+ return check;
101
+ }
102
+ /**
103
+ * Performs a quick integrity check on the given iModel.
104
+ * @param iModel The IModelDb instance to perform the integrity check on
105
+ * @returns An array of results for each check performed, including the check name, whether it passed, and the elapsed time in seconds
106
+ * @internal
107
+ */
108
+ async function performQuickIntegrityCheck(iModel) {
109
+ const integrityCheckQuery = "PRAGMA integrity_check options enable_experimental_features";
110
+ const integrityCheckResults = [];
111
+ for await (const row of iModel.createQueryReader(integrityCheckQuery)) {
112
+ integrityCheckResults.push({ check: getIntegrityCheckName(row.check), passed: row.result, elapsedSeconds: row.elapsed_sec });
113
+ }
114
+ ;
115
+ return integrityCheckResults;
116
+ }
117
+ async function performSpecificIntegrityCheck(iModel, check) {
118
+ switch (check) {
119
+ case "checkDataColumns": {
120
+ const results = [];
121
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkDataColumns.sqlQuery)) {
122
+ results.push({ sno: row.sno, table: row.table, column: row.column });
123
+ }
124
+ return results;
125
+ }
126
+ case "checkECProfile": {
127
+ const results = [];
128
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkECProfile.sqlQuery)) {
129
+ results.push({ sno: row.sno, type: row.type, name: row.name, issue: row.issue });
130
+ }
131
+ return results;
132
+ }
133
+ case "checkNavigationClassIds": {
134
+ const results = [];
135
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkNavigationClassIds.sqlQuery)) {
136
+ results.push({ sno: row.sno, id: row.id, class: row.class, property: row.property, navId: row.nav_id, navClassId: row.nav_classId });
137
+ }
138
+ return results;
139
+ }
140
+ case "checkNavigationIds": {
141
+ const results = [];
142
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkNavigationIds.sqlQuery)) {
143
+ results.push({ sno: row.sno, id: row.id, class: row.class, property: row.property, navId: row.nav_id, primaryClass: row.primary_class });
144
+ }
145
+ return results;
146
+ }
147
+ case "checkLinktableForeignKeyClassIds": {
148
+ const results = [];
149
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkLinktableForeignKeyClassIds.sqlQuery)) {
150
+ results.push({ sno: row.sno, id: row.id, relationship: row.relationship, property: row.property, keyId: row.key_id, keyClassId: row.key_classId });
151
+ }
152
+ return results;
153
+ }
154
+ case "checkLinktableForeignKeyIds": {
155
+ const results = [];
156
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkLinktableForeignKeyIds.sqlQuery)) {
157
+ results.push({ sno: row.sno, id: row.id, relationship: row.relationship, property: row.property, keyId: row.key_id, primaryClass: row.primary_class });
158
+ }
159
+ return results;
160
+ }
161
+ case "checkClassIds": {
162
+ const results = [];
163
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkClassIds.sqlQuery)) {
164
+ results.push({ sno: row.sno, class: row.class, id: row.id, classId: row.class_id, type: row.type });
165
+ }
166
+ return results;
167
+ }
168
+ case "checkDataSchema": {
169
+ const results = [];
170
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkDataSchema.sqlQuery)) {
171
+ results.push({ sno: row.sno, type: row.type, name: row.name });
172
+ }
173
+ return results;
174
+ }
175
+ case "checkSchemaLoad": {
176
+ const results = [];
177
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkSchemaLoad.sqlQuery)) {
178
+ results.push({ sno: row.sno, schema: row.schema });
179
+ }
180
+ return results;
181
+ }
182
+ case "checkMissingChildRows": {
183
+ const results = [];
184
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkMissingChildRows.sqlQuery)) {
185
+ results.push({ sno: row.sno, class: row.class, id: row.id, classId: row.class_id, missingRowInTables: row.MissingRowInTables });
186
+ }
187
+ return results;
188
+ }
189
+ default:
190
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadRequest, `Unknown integrity check type: ${check}`);
191
+ }
192
+ }
193
+ //# sourceMappingURL=IntegrityCheck.js.map
@@ -0,0 +1 @@
1
+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C;gBACjG,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;YACjE,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,KAAK,iBAAiB,CAAC,CAAC,CAAC;YACvB,MAAM,OAAO,GAA+B,EAAE,CAAC;YAC/C,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,MAAM,CAAC,iBAAiB,CAAC,6BAAqB,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACjG,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;YACrD,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,KAAK,uBAAuB,CAAC,CAAC,CAAC;YAC7B,MAAM,OAAO,GAAqC,EAAE,CAAC;YACrD,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,MAAM,CAAC,iBAAiB,CAAC,6BAAqB,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACvG,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,QAAQ,EAAE,kBAAkB,EAAE,GAAG,CAAC,kBAAkB,EAAE,CAAC,CAAC;YAClI,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;QACD;YACE,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,UAAU,EAAE,iCAAiC,KAAK,EAAE,CAAC,CAAC;IAC7F,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { IModelStatus } from \"@itwin/core-bentley\";\r\nimport { IModelError } from \"@itwin/core-common\";\r\nimport { IModelDb } from \"../IModelDb\";\r\n\r\n/**\r\n * Information about each integrity check type, including the name, expected result type, and SQL query to execute\r\n * @internal\r\n */\r\nexport const integrityCheckTypeMap = {\r\n checkDataColumns: {\r\n name: \"Check Data Columns\",\r\n resultType: \"CheckDataColumnsResultRow\",\r\n sqlCommand: \"check_data_columns\",\r\n sqlQuery: `PRAGMA integrity_check(check_data_columns) options enable_experimental_features`,\r\n },\r\n checkECProfile: {\r\n name: \"Check EC Profile\",\r\n resultType: \"CheckECProfileResultRow\",\r\n sqlCommand: \"check_ec_profile\",\r\n sqlQuery: `PRAGMA integrity_check(check_ec_profile) options enable_experimental_features`,\r\n },\r\n checkNavigationClassIds: {\r\n name: \"Check Navigation Class Ids\",\r\n resultType: \"CheckNavClassIdsResultRow\",\r\n sqlCommand: \"check_nav_class_ids\",\r\n sqlQuery: `PRAGMA integrity_check(check_nav_class_ids) options enable_experimental_features`,\r\n },\r\n checkNavigationIds: {\r\n name: \"Check Navigation Ids\",\r\n resultType: \"CheckNavIdsResultRow\",\r\n sqlCommand: \"check_nav_ids\",\r\n sqlQuery: `PRAGMA integrity_check(check_nav_ids) options enable_experimental_features`,\r\n },\r\n checkLinktableForeignKeyClassIds: {\r\n name: \"Check Link Table Foreign Key Class Ids\",\r\n resultType: \"CheckLinkTableFkClassIdsResultRow\",\r\n sqlCommand: \"check_linktable_fk_class_ids\",\r\n sqlQuery: `PRAGMA integrity_check(check_linktable_fk_class_ids) options enable_experimental_features`,\r\n },\r\n checkLinktableForeignKeyIds: {\r\n name: \"Check Link Table Foreign Key Ids\",\r\n resultType: \"CheckLinkTableFkIdsResultRow\",\r\n sqlCommand: \"check_linktable_fk_ids\",\r\n sqlQuery: `PRAGMA integrity_check(check_linktable_fk_ids) options enable_experimental_features`,\r\n },\r\n checkClassIds: {\r\n name: \"Check Class Ids\",\r\n resultType: \"CheckClassIdsResultRow\",\r\n sqlCommand: \"check_class_ids\",\r\n sqlQuery: `PRAGMA integrity_check(check_class_ids) options enable_experimental_features`,\r\n },\r\n checkDataSchema: {\r\n name: \"Check Data Schema\",\r\n resultType: \"CheckDataSchemaResultRow\",\r\n sqlCommand: \"check_data_schema\",\r\n sqlQuery: `PRAGMA integrity_check(check_data_schema) options enable_experimental_features`,\r\n },\r\n checkSchemaLoad: {\r\n name: \"Check Schema Load\",\r\n resultType: \"CheckSchemaLoadResultRow\",\r\n sqlCommand: \"check_schema_load\",\r\n sqlQuery: `PRAGMA integrity_check(check_schema_load) options enable_experimental_features`,\r\n },\r\n checkMissingChildRows: {\r\n name: \"Check Missing Child Rows\",\r\n resultType: \"CheckMissingChildRowsResultRow\",\r\n sqlCommand: \"check_missing_child_rows\",\r\n sqlQuery: `PRAGMA integrity_check(check_missing_child_rows) options enable_experimental_features`,\r\n },\r\n} as const;\r\n\r\n/**\r\n * Type representing the keys of the integrityCheckType map, which correspond to the different types of integrity checks that can be performed.\r\n */\r\nexport type IntegrityCheckKey = keyof typeof integrityCheckTypeMap;\r\n\r\n/** Map of integrity check keys to their result row types */\r\ninterface IntegrityCheckResultTypeMap {\r\n checkDataColumns: CheckDataColumnsResultRow;\r\n checkECProfile: CheckECProfileResultRow;\r\n checkNavigationClassIds: CheckNavClassIdsResultRow;\r\n checkNavigationIds: CheckNavIdsResultRow;\r\n checkLinktableForeignKeyClassIds: CheckLinkTableFkClassIdsResultRow;\r\n checkLinktableForeignKeyIds: CheckLinkTableFkIdsResultRow;\r\n checkClassIds: CheckClassIdsResultRow;\r\n checkDataSchema: CheckDataSchemaResultRow;\r\n checkSchemaLoad: CheckSchemaLoadResultRow;\r\n checkMissingChildRows: CheckMissingChildRowsResultRow;\r\n}\r\n\r\n/** Checks the Map to give the return type of a specific integrity check */\r\ntype IntegrityCheckResultRow<K extends IntegrityCheckKey> = IntegrityCheckResultTypeMap[K];\r\n\r\n/**\r\n * Return type for quick integrity check\r\n */\r\nexport interface QuickIntegrityCheckResultRow {\r\n check: string;\r\n passed: boolean;\r\n elapsedSeconds: string;\r\n}\r\n\r\n/**\r\n * Return type for Check Data Columns integrity check\r\n */\r\nexport interface CheckDataColumnsResultRow {\r\n sno: number;\r\n table: string;\r\n column: string;\r\n}\r\n\r\n/**\r\n * Return type for Check EC Profile integrity check\r\n */\r\nexport interface CheckECProfileResultRow {\r\n sno: number;\r\n type: string;\r\n name: string;\r\n issue: string;\r\n}\r\n\r\n/**\r\n * Return type for Check Navigation Class Ids integrity check\r\n */\r\nexport interface CheckNavClassIdsResultRow {\r\n sno: number;\r\n id: string;\r\n class: string;\r\n property: string;\r\n navId: string;\r\n navClassId: string;\r\n}\r\n\r\n/**\r\n * Return type for Check Navigation Ids integrity check\r\n */\r\nexport interface CheckNavIdsResultRow {\r\n sno: number;\r\n id: string;\r\n class: string;\r\n property: string;\r\n navId: string;\r\n primaryClass: string;\r\n}\r\n\r\n/**\r\n * Return type for Check Link Table Foreign Key Class Ids integrity check\r\n */\r\nexport interface CheckLinkTableFkClassIdsResultRow {\r\n sno: number;\r\n id: string;\r\n relationship: string;\r\n property: string;\r\n keyId: string;\r\n keyClassId: string;\r\n}\r\n\r\n/**\r\n * Return type for Check Link Table Foreign Key Ids integrity check\r\n */\r\nexport interface CheckLinkTableFkIdsResultRow {\r\n sno: number;\r\n id: string;\r\n relationship: string;\r\n property: string;\r\n keyId: string;\r\n primaryClass: string;\r\n}\r\n\r\n/**\r\n * Return type for Check Class Ids integrity check\r\n */\r\nexport interface CheckClassIdsResultRow {\r\n sno: number;\r\n class: string;\r\n id: string;\r\n classId: string;\r\n type: string;\r\n}\r\n\r\n/**\r\n * Return type for Check Data Schema integrity check\r\n */\r\nexport interface CheckDataSchemaResultRow {\r\n sno: number;\r\n type: string;\r\n name: string;\r\n}\r\n\r\n/**\r\n * Return type for Check Schema Load integrity check\r\n */\r\nexport interface CheckSchemaLoadResultRow {\r\n sno: number;\r\n schema: string;\r\n}\r\n\r\n/**\r\n * Return type for Check Missing Child Rows integrity check\r\n */\r\nexport interface CheckMissingChildRowsResultRow {\r\n sno: number;\r\n class: string;\r\n id: string;\r\n classId: string;\r\n missingRowInTables: string;\r\n}\r\n\r\n/**\r\n * Return type for integrity check results, including the check name, whether it passed, and the specific results (if any)\r\n */\r\nexport interface IntegrityCheckResult {\r\n /** The name of the integrity check that was performed */\r\n check: string;\r\n /** Whether the integrity check passed (i.e. no issues were found = true) */\r\n passed: boolean;\r\n /** The specific results returned by the integrity check, which may include details about any issues that were found.\r\n * In the case where issues are found, this will be an array of result rows specific to the type of check that was performed,\r\n * or an array of quick integrity check results if it was a quick check. */\r\n results: IntegrityCheckResultRow<IntegrityCheckKey>[] | QuickIntegrityCheckResultRow[];\r\n}\r\n\r\n/**\r\n * Gets the user-friendly name of an integrity check based on its key or SQL command.\r\n * It first attempts to find a direct match for the key in the integrityCheckTypeMap. If not found, it searches for a match based on the SQL command.\r\n * If still not found, it returns the original check string.\r\n * @param check - The integrity check key or SQL command to get the name of\r\n * @returns The user-friendly name of the integrity check, or the original check string if no match is found\r\n * @internal\r\n */\r\nexport function getIntegrityCheckName(check: string): string {\r\n // First try direct lookup by key\r\n const directLookup = integrityCheckTypeMap[check as IntegrityCheckKey];\r\n if (directLookup) {\r\n return directLookup.name;\r\n }\r\n // If not found, search by sqlCommand\r\n for (const [, value] of Object.entries(integrityCheckTypeMap)) {\r\n if (value.sqlCommand === check) {\r\n return value.name;\r\n }\r\n }\r\n // Fallback to the original check string\r\n return check;\r\n}\r\n\r\n/**\r\n * Performs a quick integrity check on the given iModel.\r\n * @param iModel The IModelDb instance to perform the integrity check on\r\n * @returns An array of results for each check performed, including the check name, whether it passed, and the elapsed time in seconds\r\n * @internal\r\n */\r\nexport async function performQuickIntegrityCheck(iModel: IModelDb): Promise<QuickIntegrityCheckResultRow[]> {\r\n const integrityCheckQuery = \"PRAGMA integrity_check options enable_experimental_features\";\r\n const integrityCheckResults: QuickIntegrityCheckResultRow[] = [];\r\n for await (const row of iModel.createQueryReader(integrityCheckQuery)) {\r\n integrityCheckResults.push({ check: getIntegrityCheckName(row.check), passed: row.result, elapsedSeconds: row.elapsed_sec});\r\n };\r\n return integrityCheckResults;\r\n}\r\n\r\n/**\r\n * Performs a specific integrity check on the given iModel based on the provided check key, and returns the results specific to that check type.\r\n * @param iModel The IModelDb instance to perform the integrity check on\r\n * @param check The key of the specific integrity check to perform\r\n * @return An array of results specific to the integrity check that was performed. The type of the result rows will depend on the check that was executed.\r\n * @throws IModelError with status BadRequest if an unknown integrity check key is provided\r\n * @internal\r\n */\r\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkDataColumns\"): Promise<IntegrityCheckResultRow<\"checkDataColumns\">[]>;\r\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkECProfile\"): Promise<IntegrityCheckResultRow<\"checkECProfile\">[]>;\r\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkNavigationClassIds\"): Promise<IntegrityCheckResultRow<\"checkNavigationClassIds\">[]>;\r\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkNavigationIds\"): Promise<IntegrityCheckResultRow<\"checkNavigationIds\">[]>;\r\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkLinktableForeignKeyClassIds\"): Promise<IntegrityCheckResultRow<\"checkLinktableForeignKeyClassIds\">[]>;\r\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkLinktableForeignKeyIds\"): Promise<IntegrityCheckResultRow<\"checkLinktableForeignKeyIds\">[]>;\r\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkClassIds\"): Promise<IntegrityCheckResultRow<\"checkClassIds\">[]>;\r\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkDataSchema\"): Promise<IntegrityCheckResultRow<\"checkDataSchema\">[]>;\r\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkSchemaLoad\"): Promise<IntegrityCheckResultRow<\"checkSchemaLoad\">[]>;\r\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkMissingChildRows\"): Promise<IntegrityCheckResultRow<\"checkMissingChildRows\">[]>;\r\nexport async function performSpecificIntegrityCheck<K extends IntegrityCheckKey>(iModel: IModelDb, check: K): Promise<IntegrityCheckResultRow<K>[]>;\r\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: IntegrityCheckKey): Promise<IntegrityCheckResultRow<IntegrityCheckKey>[]> {\r\n switch (check) {\r\n case \"checkDataColumns\": {\r\n const results: CheckDataColumnsResultRow[] = [];\r\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkDataColumns.sqlQuery)) {\r\n results.push({ sno: row.sno, table: row.table, column: row.column });\r\n }\r\n return results;\r\n }\r\n case \"checkECProfile\": {\r\n const results: CheckECProfileResultRow[] = [];\r\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkECProfile.sqlQuery)) {\r\n results.push({ sno: row.sno, type: row.type, name: row.name, issue: row.issue });\r\n }\r\n return results;\r\n }\r\n case \"checkNavigationClassIds\": {\r\n const results: CheckNavClassIdsResultRow[] = [];\r\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkNavigationClassIds.sqlQuery)) {\r\n results.push({ sno: row.sno, id: row.id, class: row.class, property: row.property, navId: row.nav_id, navClassId: row.nav_classId });\r\n }\r\n return results;\r\n }\r\n case \"checkNavigationIds\": {\r\n const results: CheckNavIdsResultRow[] = [];\r\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkNavigationIds.sqlQuery)) {\r\n results.push({ sno: row.sno, id: row.id, class: row.class, property: row.property, navId: row.nav_id, primaryClass: row.primary_class });\r\n }\r\n return results;\r\n }\r\n case \"checkLinktableForeignKeyClassIds\": {\r\n const results: CheckLinkTableFkClassIdsResultRow[] = [];\r\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkLinktableForeignKeyClassIds.sqlQuery)) {\r\n results.push({ sno: row.sno, id: row.id, relationship: row.relationship, property: row.property, keyId: row.key_id, keyClassId: row.key_classId });\r\n }\r\n return results;\r\n }\r\n case \"checkLinktableForeignKeyIds\": {\r\n const results: CheckLinkTableFkIdsResultRow[] = [];\r\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkLinktableForeignKeyIds.sqlQuery)) {\r\n results.push({ sno: row.sno, id: row.id, relationship: row.relationship, property: row.property, keyId: row.key_id, primaryClass: row.primary_class });\r\n }\r\n return results;\r\n }\r\n case \"checkClassIds\": {\r\n const results: CheckClassIdsResultRow[] = [];\r\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkClassIds.sqlQuery)) {\r\n results.push({ sno: row.sno, class: row.class, id: row.id, classId: row.class_id, type: row.type });\r\n }\r\n return results;\r\n }\r\n case \"checkDataSchema\": {\r\n const results: CheckDataSchemaResultRow[] = [];\r\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkDataSchema.sqlQuery)) {\r\n results.push({ sno: row.sno, type: row.type, name: row.name });\r\n }\r\n return results;\r\n }\r\n case \"checkSchemaLoad\": {\r\n const results: CheckSchemaLoadResultRow[] = [];\r\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkSchemaLoad.sqlQuery)) {\r\n results.push({ sno: row.sno, schema: row.schema });\r\n }\r\n return results;\r\n }\r\n case \"checkMissingChildRows\": {\r\n const results: CheckMissingChildRowsResultRow[] = [];\r\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkMissingChildRows.sqlQuery)) {\r\n results.push({ sno: row.sno, class: row.class, id: row.id, classId: row.class_id, missingRowInTables: row.MissingRowInTables });\r\n }\r\n return results;\r\n }\r\n default:\r\n throw new IModelError(IModelStatus.BadRequest, `Unknown integrity check type: ${check}`);\r\n }\r\n}"]}
@@ -34,6 +34,7 @@ import { _cache, _instanceKeyCache, _nativeDb, _resetIModelDb } from "./internal
34
34
  import { ECVersion, SchemaContext } from "@itwin/ecschema-metadata";
35
35
  import { SchemaMap } from "./Schema";
36
36
  import { ElementLRUCache, InstanceKeyLRUCache } from "./internal/ElementLRUCache";
37
+ import { IntegrityCheckResult } from "./internal/IntegrityCheck";
37
38
  /** Options for [[IModelDb.Models.updateModel]]
38
39
  * @note To mark *only* the geometry as changed, use [[IModelDb.Models.updateGeometryGuid]] instead.
39
40
  * @public
@@ -82,6 +83,37 @@ export interface ComputedProjectExtents {
82
83
  /** If requested by caller, the Ids of outlier elements excluded from the computed extents. */
83
84
  outliers?: Id64Array;
84
85
  }
86
+ /**
87
+ * Options for performing integrity checks on an iModel.
88
+ * @beta
89
+ */
90
+ export interface IntegrityCheckOptions {
91
+ /** If true, perform a quick integrity check that only reports whether each check passed or failed, without detailed results. */
92
+ quickCheck?: boolean;
93
+ /** Options for performing specific integrity checks with detailed results. */
94
+ specificChecks?: {
95
+ /** If true, checks if all the required columns exist in data tables. Issues are returned as a list of those tables/columns. */
96
+ checkDataColumns?: boolean;
97
+ /** If true, checks if the profile table, indexes, and triggers are present. Does not check be_* tables. Issues are returned as a list of tables/indexes/triggers which were not found or have different DDL. */
98
+ checkECProfile?: boolean;
99
+ /** If true, checks if RelClassId of a Navigation property is a valid ECClassId. It does not check the value to match the relationship class. */
100
+ checkNavigationClassIds?: boolean;
101
+ /** If true, checks if Id of a Navigation property matches a valid row primary class. */
102
+ checkNavigationIds?: boolean;
103
+ /** If true, checks if SourceECClassId or TargetECClassId of a link table matches a valid ECClassId. */
104
+ checkLinktableForeignKeyClassIds?: boolean;
105
+ /** If true, checks if SourceECInstanceId or TargetECInstanceId of a link table matches a valid row in primary class. */
106
+ checkLinktableForeignKeyIds?: boolean;
107
+ /** If true, checks persisted ECClassId in all data tables and makes sure they are valid. */
108
+ checkClassIds?: boolean;
109
+ /** If true, checks if all the required data tables and indexes exist for mapped classes. Issues are returned as a list of tables/columns which were not found or have different DDL. */
110
+ checkDataSchema?: boolean;
111
+ /** If true, checks if all schemas can be loaded into memory. */
112
+ checkSchemaLoad?: boolean;
113
+ /** If true, checks if all child rows have a corresponding parent row. */
114
+ checkMissingChildRows?: boolean;
115
+ };
116
+ }
85
117
  /**
86
118
  * Options for the importing of schemas
87
119
  * @public
@@ -385,6 +417,31 @@ export declare abstract class IModelDb extends IModel {
385
417
  * @beta
386
418
  */
387
419
  analyze(): void;
420
+ /**
421
+ * Performs integrity checks on this iModel.
422
+ * Types of integrity checks that can be performed are:
423
+ *
424
+ * Default Check:
425
+ * - Quick Check: Runs all integrity checks below and returns whether each check passed or failed, without detailed results.
426
+ *
427
+ * Specific Checks:
428
+ * - Data Columns Check: Checks if all the required columns exist in data tables. Issues are returned as a list of those tables/columns.
429
+ * - EC Profile Check: Checks if the profile table, indexes, and triggers are present. Does not check be_* tables. Issues are returned as a list of tables/indexes/triggers which were not found or have different DDL.
430
+ * - Navigation Class Ids Check: Checks if RelClassId of a Navigation property is a valid ECClassId. It does not check the value to match the relationship class.
431
+ * - Navigation Ids Check: Checks if Id of a Navigation property matches a valid row primary class.
432
+ * - Linktable Foreign Key Class Ids Check: Checks if SourceECClassId or TargetECClassId of a link table matches a valid ECClassId.
433
+ * - Linktable Foreign Key Ids Check: Checks if SourceECInstanceId or TargetECInstanceId of a link table matches a valid row in primary class.
434
+ * - Class Ids Check: Checks persisted ECClassId in all data tables and makes sure they are valid.
435
+ * - Data Schema Check: Checks if all the required data tables and indexes exist for mapped classes. Issues are returned as a list of tables/columns which were not found or have different DDL.
436
+ * - Schema Load Check: Checks if all schemas can be loaded into memory.
437
+ * - Missing Child Rows Check: Checks if all child rows have a corresponding parent row.
438
+ *
439
+ * @param options Options specifying which integrity checks to perform. If no options are provided or all options are false, a quick check will be performed by default.
440
+ * @returns An array of integrity check results.
441
+ * @throws [[IModelError]] if the iModel is not open.
442
+ * @beta
443
+ */
444
+ integrityCheck(options?: IntegrityCheckOptions): Promise<IntegrityCheckResult[]>;
388
445
  /** @internal */
389
446
  refreshContainerForRpc(_userAccessToken: AccessToken): Promise<void>;
390
447
  /** Event called when the iModel is about to be closed. */