@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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ems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import { IModelStatus } from "@itwin/core-bentley";
6
+ import { IModelError } from "@itwin/core-common";
7
+ /**
8
+ * Information about each integrity check type, including the name, expected result type, and SQL query to execute
9
+ * @internal
10
+ */
11
+ export const integrityCheckTypeMap = {
12
+ checkDataColumns: {
13
+ name: "Check Data Columns",
14
+ resultType: "CheckDataColumnsResultRow",
15
+ sqlCommand: "check_data_columns",
16
+ sqlQuery: `PRAGMA integrity_check(check_data_columns) options enable_experimental_features`,
17
+ },
18
+ checkECProfile: {
19
+ name: "Check EC Profile",
20
+ resultType: "CheckECProfileResultRow",
21
+ sqlCommand: "check_ec_profile",
22
+ sqlQuery: `PRAGMA integrity_check(check_ec_profile) options enable_experimental_features`,
23
+ },
24
+ checkNavigationClassIds: {
25
+ name: "Check Navigation Class Ids",
26
+ resultType: "CheckNavClassIdsResultRow",
27
+ sqlCommand: "check_nav_class_ids",
28
+ sqlQuery: `PRAGMA integrity_check(check_nav_class_ids) options enable_experimental_features`,
29
+ },
30
+ checkNavigationIds: {
31
+ name: "Check Navigation Ids",
32
+ resultType: "CheckNavIdsResultRow",
33
+ sqlCommand: "check_nav_ids",
34
+ sqlQuery: `PRAGMA integrity_check(check_nav_ids) options enable_experimental_features`,
35
+ },
36
+ checkLinktableForeignKeyClassIds: {
37
+ name: "Check Link Table Foreign Key Class Ids",
38
+ resultType: "CheckLinkTableFkClassIdsResultRow",
39
+ sqlCommand: "check_linktable_fk_class_ids",
40
+ sqlQuery: `PRAGMA integrity_check(check_linktable_fk_class_ids) options enable_experimental_features`,
41
+ },
42
+ checkLinktableForeignKeyIds: {
43
+ name: "Check Link Table Foreign Key Ids",
44
+ resultType: "CheckLinkTableFkIdsResultRow",
45
+ sqlCommand: "check_linktable_fk_ids",
46
+ sqlQuery: `PRAGMA integrity_check(check_linktable_fk_ids) options enable_experimental_features`,
47
+ },
48
+ checkClassIds: {
49
+ name: "Check Class Ids",
50
+ resultType: "CheckClassIdsResultRow",
51
+ sqlCommand: "check_class_ids",
52
+ sqlQuery: `PRAGMA integrity_check(check_class_ids) options enable_experimental_features`,
53
+ },
54
+ checkDataSchema: {
55
+ name: "Check Data Schema",
56
+ resultType: "CheckDataSchemaResultRow",
57
+ sqlCommand: "check_data_schema",
58
+ sqlQuery: `PRAGMA integrity_check(check_data_schema) options enable_experimental_features`,
59
+ },
60
+ checkSchemaLoad: {
61
+ name: "Check Schema Load",
62
+ resultType: "CheckSchemaLoadResultRow",
63
+ sqlCommand: "check_schema_load",
64
+ sqlQuery: `PRAGMA integrity_check(check_schema_load) options enable_experimental_features`,
65
+ },
66
+ checkMissingChildRows: {
67
+ name: "Check Missing Child Rows",
68
+ resultType: "CheckMissingChildRowsResultRow",
69
+ sqlCommand: "check_missing_child_rows",
70
+ sqlQuery: `PRAGMA integrity_check(check_missing_child_rows) options enable_experimental_features`,
71
+ },
72
+ };
73
+ /**
74
+ * Gets the user-friendly name of an integrity check based on its key or SQL command.
75
+ * 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.
76
+ * If still not found, it returns the original check string.
77
+ * @param check - The integrity check key or SQL command to get the name of
78
+ * @returns The user-friendly name of the integrity check, or the original check string if no match is found
79
+ * @internal
80
+ */
81
+ export function getIntegrityCheckName(check) {
82
+ // First try direct lookup by key
83
+ const directLookup = integrityCheckTypeMap[check];
84
+ if (directLookup) {
85
+ return directLookup.name;
86
+ }
87
+ // If not found, search by sqlCommand
88
+ for (const [, value] of Object.entries(integrityCheckTypeMap)) {
89
+ if (value.sqlCommand === check) {
90
+ return value.name;
91
+ }
92
+ }
93
+ // Fallback to the original check string
94
+ return check;
95
+ }
96
+ /**
97
+ * Performs a quick integrity check on the given iModel.
98
+ * @param iModel The IModelDb instance to perform the integrity check on
99
+ * @returns An array of results for each check performed, including the check name, whether it passed, and the elapsed time in seconds
100
+ * @internal
101
+ */
102
+ export async function performQuickIntegrityCheck(iModel) {
103
+ const integrityCheckQuery = "PRAGMA integrity_check options enable_experimental_features";
104
+ const integrityCheckResults = [];
105
+ for await (const row of iModel.createQueryReader(integrityCheckQuery)) {
106
+ integrityCheckResults.push({ check: getIntegrityCheckName(row.check), passed: row.result, elapsedSeconds: row.elapsed_sec });
107
+ }
108
+ ;
109
+ return integrityCheckResults;
110
+ }
111
+ export async function performSpecificIntegrityCheck(iModel, check) {
112
+ switch (check) {
113
+ case "checkDataColumns": {
114
+ const results = [];
115
+ for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkDataColumns.sqlQuery)) {
116
+ results.push({ sno: row.sno, table: row.table, column: row.column });
117
+ }
118
+ return results;
119
+ }
120
+ case "checkECProfile": {
121
+ const results = [];
122
+ for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkECProfile.sqlQuery)) {
123
+ results.push({ sno: row.sno, type: row.type, name: row.name, issue: row.issue });
124
+ }
125
+ return results;
126
+ }
127
+ case "checkNavigationClassIds": {
128
+ const results = [];
129
+ for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkNavigationClassIds.sqlQuery)) {
130
+ results.push({ sno: row.sno, id: row.id, class: row.class, property: row.property, navId: row.nav_id, navClassId: row.nav_classId });
131
+ }
132
+ return results;
133
+ }
134
+ case "checkNavigationIds": {
135
+ const results = [];
136
+ for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkNavigationIds.sqlQuery)) {
137
+ results.push({ sno: row.sno, id: row.id, class: row.class, property: row.property, navId: row.nav_id, primaryClass: row.primary_class });
138
+ }
139
+ return results;
140
+ }
141
+ case "checkLinktableForeignKeyClassIds": {
142
+ const results = [];
143
+ for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkLinktableForeignKeyClassIds.sqlQuery)) {
144
+ results.push({ sno: row.sno, id: row.id, relationship: row.relationship, property: row.property, keyId: row.key_id, keyClassId: row.key_classId });
145
+ }
146
+ return results;
147
+ }
148
+ case "checkLinktableForeignKeyIds": {
149
+ const results = [];
150
+ for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkLinktableForeignKeyIds.sqlQuery)) {
151
+ results.push({ sno: row.sno, id: row.id, relationship: row.relationship, property: row.property, keyId: row.key_id, primaryClass: row.primary_class });
152
+ }
153
+ return results;
154
+ }
155
+ case "checkClassIds": {
156
+ const results = [];
157
+ for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkClassIds.sqlQuery)) {
158
+ results.push({ sno: row.sno, class: row.class, id: row.id, classId: row.class_id, type: row.type });
159
+ }
160
+ return results;
161
+ }
162
+ case "checkDataSchema": {
163
+ const results = [];
164
+ for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkDataSchema.sqlQuery)) {
165
+ results.push({ sno: row.sno, type: row.type, name: row.name });
166
+ }
167
+ return results;
168
+ }
169
+ case "checkSchemaLoad": {
170
+ const results = [];
171
+ for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkSchemaLoad.sqlQuery)) {
172
+ results.push({ sno: row.sno, schema: row.schema });
173
+ }
174
+ return results;
175
+ }
176
+ case "checkMissingChildRows": {
177
+ const results = [];
178
+ for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkMissingChildRows.sqlQuery)) {
179
+ results.push({ sno: row.sno, class: row.class, id: row.id, classId: row.class_id, missingRowInTables: row.MissingRowInTables });
180
+ }
181
+ return results;
182
+ }
183
+ default:
184
+ throw new IModelError(IModelStatus.BadRequest, `Unknown integrity check type: ${check}`);
185
+ }
186
+ }
187
+ //# sourceMappingURL=IntegrityCheck.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntegrityCheck.js","sourceRoot":"","sources":["../../../src/internal/IntegrityCheck.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACn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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,qBAAqB,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,qBAAqB,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,WAAW,CAAC,YAAY,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}"]}