@itwin/core-backend 5.9.0-dev.10 → 5.9.0-dev.12

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.
Files changed (47) hide show
  1. package/lib/cjs/EditTxn.d.ts +8 -0
  2. package/lib/cjs/EditTxn.d.ts.map +1 -1
  3. package/lib/cjs/EditTxn.js +27 -0
  4. package/lib/cjs/EditTxn.js.map +1 -1
  5. package/lib/cjs/IModelDb.d.ts +8 -1
  6. package/lib/cjs/IModelDb.d.ts.map +1 -1
  7. package/lib/cjs/IModelDb.js +10 -0
  8. package/lib/cjs/IModelDb.js.map +1 -1
  9. package/lib/cjs/TxnManager.d.ts +14 -0
  10. package/lib/cjs/TxnManager.d.ts.map +1 -1
  11. package/lib/cjs/TxnManager.js +25 -0
  12. package/lib/cjs/TxnManager.js.map +1 -1
  13. package/lib/cjs/internal/IntegrityCheck.d.ts +10 -10
  14. package/lib/cjs/internal/IntegrityCheck.js +22 -22
  15. package/lib/cjs/internal/IntegrityCheck.js.map +1 -1
  16. package/lib/esm/EditTxn.d.ts +8 -0
  17. package/lib/esm/EditTxn.d.ts.map +1 -1
  18. package/lib/esm/EditTxn.js +28 -1
  19. package/lib/esm/EditTxn.js.map +1 -1
  20. package/lib/esm/IModelDb.d.ts +8 -1
  21. package/lib/esm/IModelDb.d.ts.map +1 -1
  22. package/lib/esm/IModelDb.js +10 -0
  23. package/lib/esm/IModelDb.js.map +1 -1
  24. package/lib/esm/TxnManager.d.ts +14 -0
  25. package/lib/esm/TxnManager.d.ts.map +1 -1
  26. package/lib/esm/TxnManager.js +25 -0
  27. package/lib/esm/TxnManager.js.map +1 -1
  28. package/lib/esm/internal/IntegrityCheck.d.ts +10 -10
  29. package/lib/esm/internal/IntegrityCheck.js +22 -22
  30. package/lib/esm/internal/IntegrityCheck.js.map +1 -1
  31. package/lib/esm/test/IModelTestUtils.d.ts +1 -0
  32. package/lib/esm/test/IModelTestUtils.d.ts.map +1 -1
  33. package/lib/esm/test/IModelTestUtils.js +5 -0
  34. package/lib/esm/test/IModelTestUtils.js.map +1 -1
  35. package/lib/esm/test/element/DeleteDefinitionElements.test.js +810 -26
  36. package/lib/esm/test/element/DeleteDefinitionElements.test.js.map +1 -1
  37. package/lib/esm/test/imodel/SchemaXmlImport.test.js +64 -0
  38. package/lib/esm/test/imodel/SchemaXmlImport.test.js.map +1 -1
  39. package/lib/esm/test/standalone/DeleteElements.test.d.ts +2 -0
  40. package/lib/esm/test/standalone/DeleteElements.test.d.ts.map +1 -0
  41. package/lib/esm/test/standalone/DeleteElements.test.js +601 -0
  42. package/lib/esm/test/standalone/DeleteElements.test.js.map +1 -0
  43. package/lib/esm/test/standalone/IntegrityCheck.test.js +213 -4
  44. package/lib/esm/test/standalone/IntegrityCheck.test.js.map +1 -1
  45. package/lib/esm/test/standalone/TxnManager.test.js +90 -0
  46. package/lib/esm/test/standalone/TxnManager.test.js.map +1 -1
  47. package/package.json +13 -13
@@ -19,61 +19,61 @@ exports.integrityCheckTypeMap = {
19
19
  name: "Check Data Columns",
20
20
  resultType: "CheckDataColumnsResultRow",
21
21
  sqlCommand: "check_data_columns",
22
- sqlQuery: `PRAGMA integrity_check(check_data_columns) options enable_experimental_features`,
22
+ sqlQuery: `PRAGMA integrity_check(check_data_columns) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,
23
23
  },
24
24
  checkECProfile: {
25
25
  name: "Check EC Profile",
26
26
  resultType: "CheckECProfileResultRow",
27
27
  sqlCommand: "check_ec_profile",
28
- sqlQuery: `PRAGMA integrity_check(check_ec_profile) options enable_experimental_features`,
28
+ sqlQuery: `PRAGMA integrity_check(check_ec_profile) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,
29
29
  },
30
30
  checkNavigationClassIds: {
31
31
  name: "Check Navigation Class Ids",
32
32
  resultType: "CheckNavClassIdsResultRow",
33
33
  sqlCommand: "check_nav_class_ids",
34
- sqlQuery: `PRAGMA integrity_check(check_nav_class_ids) options enable_experimental_features`,
34
+ sqlQuery: `PRAGMA integrity_check(check_nav_class_ids) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,
35
35
  },
36
36
  checkNavigationIds: {
37
37
  name: "Check Navigation Ids",
38
38
  resultType: "CheckNavIdsResultRow",
39
39
  sqlCommand: "check_nav_ids",
40
- sqlQuery: `PRAGMA integrity_check(check_nav_ids) options enable_experimental_features`,
40
+ sqlQuery: `PRAGMA integrity_check(check_nav_ids) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,
41
41
  },
42
42
  checkLinktableForeignKeyClassIds: {
43
43
  name: "Check Link Table Foreign Key Class Ids",
44
44
  resultType: "CheckLinkTableFkClassIdsResultRow",
45
45
  sqlCommand: "check_linktable_fk_class_ids",
46
- sqlQuery: `PRAGMA integrity_check(check_linktable_fk_class_ids) options enable_experimental_features`,
46
+ sqlQuery: `PRAGMA integrity_check(check_linktable_fk_class_ids) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,
47
47
  },
48
48
  checkLinktableForeignKeyIds: {
49
49
  name: "Check Link Table Foreign Key Ids",
50
50
  resultType: "CheckLinkTableFkIdsResultRow",
51
51
  sqlCommand: "check_linktable_fk_ids",
52
- sqlQuery: `PRAGMA integrity_check(check_linktable_fk_ids) options enable_experimental_features`,
52
+ sqlQuery: `PRAGMA integrity_check(check_linktable_fk_ids) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,
53
53
  },
54
54
  checkClassIds: {
55
55
  name: "Check Class Ids",
56
56
  resultType: "CheckClassIdsResultRow",
57
57
  sqlCommand: "check_class_ids",
58
- sqlQuery: `PRAGMA integrity_check(check_class_ids) options enable_experimental_features`,
58
+ sqlQuery: `PRAGMA integrity_check(check_class_ids) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,
59
59
  },
60
60
  checkDataSchema: {
61
61
  name: "Check Data Schema",
62
62
  resultType: "CheckDataSchemaResultRow",
63
63
  sqlCommand: "check_data_schema",
64
- sqlQuery: `PRAGMA integrity_check(check_data_schema) options enable_experimental_features`,
64
+ sqlQuery: `PRAGMA integrity_check(check_data_schema) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,
65
65
  },
66
66
  checkSchemaLoad: {
67
67
  name: "Check Schema Load",
68
68
  resultType: "CheckSchemaLoadResultRow",
69
69
  sqlCommand: "check_schema_load",
70
- sqlQuery: `PRAGMA integrity_check(check_schema_load) options enable_experimental_features`,
70
+ sqlQuery: `PRAGMA integrity_check(check_schema_load) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,
71
71
  },
72
72
  checkMissingChildRows: {
73
73
  name: "Check Missing Child Rows",
74
74
  resultType: "CheckMissingChildRowsResultRow",
75
75
  sqlCommand: "check_missing_child_rows",
76
- sqlQuery: `PRAGMA integrity_check(check_missing_child_rows) options enable_experimental_features`,
76
+ sqlQuery: `PRAGMA integrity_check(check_missing_child_rows) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,
77
77
  },
78
78
  };
79
79
  /**
@@ -106,9 +106,9 @@ function getIntegrityCheckName(check) {
106
106
  * @internal
107
107
  */
108
108
  async function performQuickIntegrityCheck(iModel) {
109
- const integrityCheckQuery = "PRAGMA integrity_check options enable_experimental_features";
109
+ const integrityCheckQuery = "PRAGMA integrity_check ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES";
110
110
  const integrityCheckResults = [];
111
- for await (const row of iModel.createQueryReader(integrityCheckQuery)) {
111
+ for await (const row of iModel.createQueryReader(integrityCheckQuery, undefined, { usePrimaryConn: true })) {
112
112
  integrityCheckResults.push({ check: getIntegrityCheckName(row.check), passed: row.result, elapsedSeconds: row.elapsed_sec });
113
113
  }
114
114
  ;
@@ -118,70 +118,70 @@ async function performSpecificIntegrityCheck(iModel, check) {
118
118
  switch (check) {
119
119
  case "checkDataColumns": {
120
120
  const results = [];
121
- for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkDataColumns.sqlQuery)) {
121
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkDataColumns.sqlQuery, undefined, { usePrimaryConn: true })) {
122
122
  results.push({ sno: row.sno, table: row.table, column: row.column });
123
123
  }
124
124
  return results;
125
125
  }
126
126
  case "checkECProfile": {
127
127
  const results = [];
128
- for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkECProfile.sqlQuery)) {
128
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkECProfile.sqlQuery, undefined, { usePrimaryConn: true })) {
129
129
  results.push({ sno: row.sno, type: row.type, name: row.name, issue: row.issue });
130
130
  }
131
131
  return results;
132
132
  }
133
133
  case "checkNavigationClassIds": {
134
134
  const results = [];
135
- for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkNavigationClassIds.sqlQuery)) {
135
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkNavigationClassIds.sqlQuery, undefined, { usePrimaryConn: true })) {
136
136
  results.push({ sno: row.sno, id: row.id, class: row.class, property: row.property, navId: row.nav_id, navClassId: row.nav_classId });
137
137
  }
138
138
  return results;
139
139
  }
140
140
  case "checkNavigationIds": {
141
141
  const results = [];
142
- for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkNavigationIds.sqlQuery)) {
142
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkNavigationIds.sqlQuery, undefined, { usePrimaryConn: true })) {
143
143
  results.push({ sno: row.sno, id: row.id, class: row.class, property: row.property, navId: row.nav_id, primaryClass: row.primary_class });
144
144
  }
145
145
  return results;
146
146
  }
147
147
  case "checkLinktableForeignKeyClassIds": {
148
148
  const results = [];
149
- for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkLinktableForeignKeyClassIds.sqlQuery)) {
149
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkLinktableForeignKeyClassIds.sqlQuery, undefined, { usePrimaryConn: true })) {
150
150
  results.push({ sno: row.sno, id: row.id, relationship: row.relationship, property: row.property, keyId: row.key_id, keyClassId: row.key_classId });
151
151
  }
152
152
  return results;
153
153
  }
154
154
  case "checkLinktableForeignKeyIds": {
155
155
  const results = [];
156
- for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkLinktableForeignKeyIds.sqlQuery)) {
156
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkLinktableForeignKeyIds.sqlQuery, undefined, { usePrimaryConn: true })) {
157
157
  results.push({ sno: row.sno, id: row.id, relationship: row.relationship, property: row.property, keyId: row.key_id, primaryClass: row.primary_class });
158
158
  }
159
159
  return results;
160
160
  }
161
161
  case "checkClassIds": {
162
162
  const results = [];
163
- for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkClassIds.sqlQuery)) {
163
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkClassIds.sqlQuery, undefined, { usePrimaryConn: true })) {
164
164
  results.push({ sno: row.sno, class: row.class, id: row.id, classId: row.class_id, type: row.type });
165
165
  }
166
166
  return results;
167
167
  }
168
168
  case "checkDataSchema": {
169
169
  const results = [];
170
- for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkDataSchema.sqlQuery)) {
170
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkDataSchema.sqlQuery, undefined, { usePrimaryConn: true })) {
171
171
  results.push({ sno: row.sno, type: row.type, name: row.name });
172
172
  }
173
173
  return results;
174
174
  }
175
175
  case "checkSchemaLoad": {
176
176
  const results = [];
177
- for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkSchemaLoad.sqlQuery)) {
177
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkSchemaLoad.sqlQuery, undefined, { usePrimaryConn: true })) {
178
178
  results.push({ sno: row.sno, schema: row.schema });
179
179
  }
180
180
  return results;
181
181
  }
182
182
  case "checkMissingChildRows": {
183
183
  const results = [];
184
- for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkMissingChildRows.sqlQuery)) {
184
+ for await (const row of iModel.createQueryReader(exports.integrityCheckTypeMap.checkMissingChildRows.sqlQuery, undefined, { usePrimaryConn: true })) {
185
185
  results.push({ sno: row.sno, class: row.class, id: row.id, classId: row.class_id, missingRowInTables: row.MissingRowInTables });
186
186
  }
187
187
  return results;
@@ -1 +1 @@
1
- {"version":3,"file":"IntegrityCheck.js","sourceRoot":"","sources":["../../../src/internal/IntegrityCheck.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAwO/F,sDAcC;AAQD,gEAOC;AAqBD,sEA2EC;AAnWD,sDAAmD;AACnD,oDAAiD;AAGjD;;;GAGG;AACU,QAAA,qBAAqB,GAAG;IACnC,gBAAgB,EAAE;QAChB,IAAI,EAAE,oBAAoB;QAC1B,UAAU,EAAE,2BAA2B;QACvC,UAAU,EAAE,oBAAoB;QAChC,QAAQ,EAAE,iFAAiF;KAC5F;IACD,cAAc,EAAE;QACd,IAAI,EAAE,kBAAkB;QACxB,UAAU,EAAE,yBAAyB;QACrC,UAAU,EAAE,kBAAkB;QAC9B,QAAQ,EAAE,+EAA+E;KAC1F;IACD,uBAAuB,EAAE;QACvB,IAAI,EAAE,4BAA4B;QAClC,UAAU,EAAE,2BAA2B;QACvC,UAAU,EAAE,qBAAqB;QACjC,QAAQ,EAAE,kFAAkF;KAC7F;IACD,kBAAkB,EAAE;QAClB,IAAI,EAAE,sBAAsB;QAC5B,UAAU,EAAE,sBAAsB;QAClC,UAAU,EAAE,eAAe;QAC3B,QAAQ,EAAE,4EAA4E;KACvF;IACD,gCAAgC,EAAE;QAChC,IAAI,EAAE,wCAAwC;QAC9C,UAAU,EAAE,mCAAmC;QAC/C,UAAU,EAAE,8BAA8B;QAC1C,QAAQ,EAAE,2FAA2F;KACtG;IACD,2BAA2B,EAAE;QAC3B,IAAI,EAAE,kCAAkC;QACxC,UAAU,EAAE,8BAA8B;QAC1C,UAAU,EAAE,wBAAwB;QACpC,QAAQ,EAAE,qFAAqF;KAChG;IACD,aAAa,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OAAO,CAAC;QACjB,CAAC;QACD;YACE,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,UAAU,EAAE,8BAA8B,CAAC,CAAC;IACnF,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { IModelStatus } from \"@itwin/core-bentley\";\nimport { IModelError } from \"@itwin/core-common\";\nimport { IModelDb } from \"../IModelDb\";\n\n/**\n * Information about each integrity check type, including the name, expected result type, and SQL query to execute\n * @internal\n */\nexport const integrityCheckTypeMap = {\n checkDataColumns: {\n name: \"Check Data Columns\",\n resultType: \"CheckDataColumnsResultRow\",\n sqlCommand: \"check_data_columns\",\n sqlQuery: `PRAGMA integrity_check(check_data_columns) options enable_experimental_features`,\n },\n checkECProfile: {\n name: \"Check EC Profile\",\n resultType: \"CheckECProfileResultRow\",\n sqlCommand: \"check_ec_profile\",\n sqlQuery: `PRAGMA integrity_check(check_ec_profile) options enable_experimental_features`,\n },\n checkNavigationClassIds: {\n name: \"Check Navigation Class Ids\",\n resultType: \"CheckNavClassIdsResultRow\",\n sqlCommand: \"check_nav_class_ids\",\n sqlQuery: `PRAGMA integrity_check(check_nav_class_ids) options enable_experimental_features`,\n },\n checkNavigationIds: {\n name: \"Check Navigation Ids\",\n resultType: \"CheckNavIdsResultRow\",\n sqlCommand: \"check_nav_ids\",\n sqlQuery: `PRAGMA integrity_check(check_nav_ids) options enable_experimental_features`,\n },\n checkLinktableForeignKeyClassIds: {\n name: \"Check Link Table Foreign Key Class Ids\",\n resultType: \"CheckLinkTableFkClassIdsResultRow\",\n sqlCommand: \"check_linktable_fk_class_ids\",\n sqlQuery: `PRAGMA integrity_check(check_linktable_fk_class_ids) options enable_experimental_features`,\n },\n checkLinktableForeignKeyIds: {\n name: \"Check Link Table Foreign Key Ids\",\n resultType: \"CheckLinkTableFkIdsResultRow\",\n sqlCommand: \"check_linktable_fk_ids\",\n sqlQuery: `PRAGMA integrity_check(check_linktable_fk_ids) options enable_experimental_features`,\n },\n checkClassIds: {\n name: \"Check Class Ids\",\n resultType: \"CheckClassIdsResultRow\",\n sqlCommand: \"check_class_ids\",\n sqlQuery: `PRAGMA integrity_check(check_class_ids) options enable_experimental_features`,\n },\n checkDataSchema: {\n name: \"Check Data Schema\",\n resultType: \"CheckDataSchemaResultRow\",\n sqlCommand: \"check_data_schema\",\n sqlQuery: `PRAGMA integrity_check(check_data_schema) options enable_experimental_features`,\n },\n checkSchemaLoad: {\n name: \"Check Schema Load\",\n resultType: \"CheckSchemaLoadResultRow\",\n sqlCommand: \"check_schema_load\",\n sqlQuery: `PRAGMA integrity_check(check_schema_load) options enable_experimental_features`,\n },\n checkMissingChildRows: {\n name: \"Check Missing Child Rows\",\n resultType: \"CheckMissingChildRowsResultRow\",\n sqlCommand: \"check_missing_child_rows\",\n sqlQuery: `PRAGMA integrity_check(check_missing_child_rows) options enable_experimental_features`,\n },\n} as const;\n\n/**\n * Type representing the keys of the integrityCheckType map, which correspond to the different types of integrity checks that can be performed.\n */\nexport type IntegrityCheckKey = keyof typeof integrityCheckTypeMap;\n\n/** Map of integrity check keys to their result row types */\ninterface IntegrityCheckResultTypeMap {\n checkDataColumns: CheckDataColumnsResultRow;\n checkECProfile: CheckECProfileResultRow;\n checkNavigationClassIds: CheckNavClassIdsResultRow;\n checkNavigationIds: CheckNavIdsResultRow;\n checkLinktableForeignKeyClassIds: CheckLinkTableFkClassIdsResultRow;\n checkLinktableForeignKeyIds: CheckLinkTableFkIdsResultRow;\n checkClassIds: CheckClassIdsResultRow;\n checkDataSchema: CheckDataSchemaResultRow;\n checkSchemaLoad: CheckSchemaLoadResultRow;\n checkMissingChildRows: CheckMissingChildRowsResultRow;\n}\n\n/** Checks the Map to give the return type of a specific integrity check */\ntype IntegrityCheckResultRow<K extends IntegrityCheckKey> = IntegrityCheckResultTypeMap[K];\n\n/**\n * Return type for quick integrity check\n */\nexport interface QuickIntegrityCheckResultRow {\n check: string;\n passed: boolean;\n elapsedSeconds: string;\n}\n\n/**\n * Return type for Check Data Columns integrity check\n */\nexport interface CheckDataColumnsResultRow {\n sno: number;\n table: string;\n column: string;\n}\n\n/**\n * Return type for Check EC Profile integrity check\n */\nexport interface CheckECProfileResultRow {\n sno: number;\n type: string;\n name: string;\n issue: string;\n}\n\n/**\n * Return type for Check Navigation Class Ids integrity check\n */\nexport interface CheckNavClassIdsResultRow {\n sno: number;\n id: string;\n class: string;\n property: string;\n navId: string;\n navClassId: string;\n}\n\n/**\n * Return type for Check Navigation Ids integrity check\n */\nexport interface CheckNavIdsResultRow {\n sno: number;\n id: string;\n class: string;\n property: string;\n navId: string;\n primaryClass: string;\n}\n\n/**\n * Return type for Check Link Table Foreign Key Class Ids integrity check\n */\nexport interface CheckLinkTableFkClassIdsResultRow {\n sno: number;\n id: string;\n relationship: string;\n property: string;\n keyId: string;\n keyClassId: string;\n}\n\n/**\n * Return type for Check Link Table Foreign Key Ids integrity check\n */\nexport interface CheckLinkTableFkIdsResultRow {\n sno: number;\n id: string;\n relationship: string;\n property: string;\n keyId: string;\n primaryClass: string;\n}\n\n/**\n * Return type for Check Class Ids integrity check\n */\nexport interface CheckClassIdsResultRow {\n sno: number;\n class: string;\n id: string;\n classId: string;\n type: string;\n}\n\n/**\n * Return type for Check Data Schema integrity check\n */\nexport interface CheckDataSchemaResultRow {\n sno: number;\n type: string;\n name: string;\n}\n\n/**\n * Return type for Check Schema Load integrity check\n */\nexport interface CheckSchemaLoadResultRow {\n sno: number;\n schema: string;\n}\n\n/**\n * Return type for Check Missing Child Rows integrity check\n */\nexport interface CheckMissingChildRowsResultRow {\n sno: number;\n class: string;\n id: string;\n classId: string;\n missingRowInTables: string;\n}\n\n/**\n * Return type for integrity check results, including the check name, whether it passed, and the specific results (if any)\n */\nexport interface IntegrityCheckResult {\n /** The name of the integrity check that was performed */\n check: string;\n /** Whether the integrity check passed (i.e. no issues were found = true) */\n passed: boolean;\n /** The specific results returned by the integrity check, which may include details about any issues that were found.\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,\n * or an array of quick integrity check results if it was a quick check. */\n results: IntegrityCheckResultRow<IntegrityCheckKey>[] | QuickIntegrityCheckResultRow[];\n}\n\n/**\n * Gets the user-friendly name of an integrity check based on its key or SQL command.\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.\n * If still not found, it returns the original check string.\n * @param check - The integrity check key or SQL command to get the name of\n * @returns The user-friendly name of the integrity check, or the original check string if no match is found\n * @internal\n */\nexport function getIntegrityCheckName(check: string): string {\n // First try direct lookup by key\n const directLookup = integrityCheckTypeMap[check as IntegrityCheckKey];\n if (directLookup) {\n return directLookup.name;\n }\n // If not found, search by sqlCommand\n for (const [, value] of Object.entries(integrityCheckTypeMap)) {\n if (value.sqlCommand === check) {\n return value.name;\n }\n }\n // Fallback to the original check string\n return check;\n}\n\n/**\n * Performs a quick integrity check on the given iModel.\n * @param iModel The IModelDb instance to perform the integrity check on\n * @returns An array of results for each check performed, including the check name, whether it passed, and the elapsed time in seconds\n * @internal\n */\nexport async function performQuickIntegrityCheck(iModel: IModelDb): Promise<QuickIntegrityCheckResultRow[]> {\n const integrityCheckQuery = \"PRAGMA integrity_check options enable_experimental_features\";\n const integrityCheckResults: QuickIntegrityCheckResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckQuery)) {\n integrityCheckResults.push({ check: getIntegrityCheckName(row.check), passed: row.result, elapsedSeconds: row.elapsed_sec});\n };\n return integrityCheckResults;\n}\n\n/**\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.\n * @param iModel The IModelDb instance to perform the integrity check on\n * @param check The key of the specific integrity check to perform\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.\n * @throws IModelError with status BadRequest if an unknown integrity check key is provided\n * @internal\n */\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkDataColumns\"): Promise<IntegrityCheckResultRow<\"checkDataColumns\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkECProfile\"): Promise<IntegrityCheckResultRow<\"checkECProfile\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkNavigationClassIds\"): Promise<IntegrityCheckResultRow<\"checkNavigationClassIds\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkNavigationIds\"): Promise<IntegrityCheckResultRow<\"checkNavigationIds\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkLinktableForeignKeyClassIds\"): Promise<IntegrityCheckResultRow<\"checkLinktableForeignKeyClassIds\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkLinktableForeignKeyIds\"): Promise<IntegrityCheckResultRow<\"checkLinktableForeignKeyIds\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkClassIds\"): Promise<IntegrityCheckResultRow<\"checkClassIds\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkDataSchema\"): Promise<IntegrityCheckResultRow<\"checkDataSchema\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkSchemaLoad\"): Promise<IntegrityCheckResultRow<\"checkSchemaLoad\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkMissingChildRows\"): Promise<IntegrityCheckResultRow<\"checkMissingChildRows\">[]>;\nexport async function performSpecificIntegrityCheck<K extends IntegrityCheckKey>(iModel: IModelDb, check: K): Promise<IntegrityCheckResultRow<K>[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: IntegrityCheckKey): Promise<IntegrityCheckResultRow<IntegrityCheckKey>[]> {\n switch (check) {\n case \"checkDataColumns\": {\n const results: CheckDataColumnsResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkDataColumns.sqlQuery)) {\n results.push({ sno: row.sno, table: row.table, column: row.column });\n }\n return results;\n }\n case \"checkECProfile\": {\n const results: CheckECProfileResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkECProfile.sqlQuery)) {\n results.push({ sno: row.sno, type: row.type, name: row.name, issue: row.issue });\n }\n return results;\n }\n case \"checkNavigationClassIds\": {\n const results: CheckNavClassIdsResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkNavigationClassIds.sqlQuery)) {\n results.push({ sno: row.sno, id: row.id, class: row.class, property: row.property, navId: row.nav_id, navClassId: row.nav_classId });\n }\n return results;\n }\n case \"checkNavigationIds\": {\n const results: CheckNavIdsResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkNavigationIds.sqlQuery)) {\n results.push({ sno: row.sno, id: row.id, class: row.class, property: row.property, navId: row.nav_id, primaryClass: row.primary_class });\n }\n return results;\n }\n case \"checkLinktableForeignKeyClassIds\": {\n const results: CheckLinkTableFkClassIdsResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkLinktableForeignKeyClassIds.sqlQuery)) {\n results.push({ sno: row.sno, id: row.id, relationship: row.relationship, property: row.property, keyId: row.key_id, keyClassId: row.key_classId });\n }\n return results;\n }\n case \"checkLinktableForeignKeyIds\": {\n const results: CheckLinkTableFkIdsResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkLinktableForeignKeyIds.sqlQuery)) {\n results.push({ sno: row.sno, id: row.id, relationship: row.relationship, property: row.property, keyId: row.key_id, primaryClass: row.primary_class });\n }\n return results;\n }\n case \"checkClassIds\": {\n const results: CheckClassIdsResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkClassIds.sqlQuery)) {\n results.push({ sno: row.sno, class: row.class, id: row.id, classId: row.class_id, type: row.type });\n }\n return results;\n }\n case \"checkDataSchema\": {\n const results: CheckDataSchemaResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkDataSchema.sqlQuery)) {\n results.push({ sno: row.sno, type: row.type, name: row.name });\n }\n return results;\n }\n case \"checkSchemaLoad\": {\n const results: CheckSchemaLoadResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkSchemaLoad.sqlQuery)) {\n results.push({ sno: row.sno, schema: row.schema });\n }\n return results;\n }\n case \"checkMissingChildRows\": {\n const results: CheckMissingChildRowsResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkMissingChildRows.sqlQuery)) {\n results.push({ sno: row.sno, class: row.class, id: row.id, classId: row.class_id, missingRowInTables: row.MissingRowInTables });\n }\n return results;\n }\n default:\n throw new IModelError(IModelStatus.BadRequest, `Unknown integrity check type`);\n }\n}"]}
1
+ {"version":3,"file":"IntegrityCheck.js","sourceRoot":"","sources":["../../../src/internal/IntegrityCheck.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAwO/F,sDAcC;AAQD,gEAOC;AAqBD,sEA2EC;AAnWD,sDAAmD;AACnD,oDAAiD;AAGjD;;;GAGG;AACU,QAAA,qBAAqB,GAAG;IACnC,gBAAgB,EAAE;QAChB,IAAI,EAAE,oBAAoB;QAC1B,UAAU,EAAE,2BAA2B;QACvC,UAAU,EAAE,oBAAoB;QAChC,QAAQ,EAAE,sFAAsF;KACjG;IACD,cAAc,EAAE;QACd,IAAI,EAAE,kBAAkB;QACxB,UAAU,EAAE,yBAAyB;QACrC,UAAU,EAAE,kBAAkB;QAC9B,QAAQ,EAAE,oFAAoF;KAC/F;IACD,uBAAuB,EAAE;QACvB,IAAI,EAAE,4BAA4B;QAClC,UAAU,EAAE,2BAA2B;QACvC,UAAU,EAAE,qBAAqB;QACjC,QAAQ,EAAE,uFAAuF;KAClG;IACD,kBAAkB,EAAE;QAClB,IAAI,EAAE,sBAAsB;QAC5B,UAAU,EAAE,sBAAsB;QAClC,UAAU,EAAE,eAAe;QAC3B,QAAQ,EAAE,iFAAiF;KAC5F;IACD,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G,IAAI,MAAM,CAAC,iBAAiB,CAAC,6BAAqB,CAAC,eAAe,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;gBACtI,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,EAAE,SAAS,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;gBAC5I,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,8BAA8B,CAAC,CAAC;IACnF,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { IModelStatus } from \"@itwin/core-bentley\";\nimport { IModelError } from \"@itwin/core-common\";\nimport { IModelDb } from \"../IModelDb\";\n\n/**\n * Information about each integrity check type, including the name, expected result type, and SQL query to execute\n * @internal\n */\nexport const integrityCheckTypeMap = {\n checkDataColumns: {\n name: \"Check Data Columns\",\n resultType: \"CheckDataColumnsResultRow\",\n sqlCommand: \"check_data_columns\",\n sqlQuery: `PRAGMA integrity_check(check_data_columns) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,\n },\n checkECProfile: {\n name: \"Check EC Profile\",\n resultType: \"CheckECProfileResultRow\",\n sqlCommand: \"check_ec_profile\",\n sqlQuery: `PRAGMA integrity_check(check_ec_profile) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,\n },\n checkNavigationClassIds: {\n name: \"Check Navigation Class Ids\",\n resultType: \"CheckNavClassIdsResultRow\",\n sqlCommand: \"check_nav_class_ids\",\n sqlQuery: `PRAGMA integrity_check(check_nav_class_ids) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,\n },\n checkNavigationIds: {\n name: \"Check Navigation Ids\",\n resultType: \"CheckNavIdsResultRow\",\n sqlCommand: \"check_nav_ids\",\n sqlQuery: `PRAGMA integrity_check(check_nav_ids) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,\n },\n checkLinktableForeignKeyClassIds: {\n name: \"Check Link Table Foreign Key Class Ids\",\n resultType: \"CheckLinkTableFkClassIdsResultRow\",\n sqlCommand: \"check_linktable_fk_class_ids\",\n sqlQuery: `PRAGMA integrity_check(check_linktable_fk_class_ids) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,\n },\n checkLinktableForeignKeyIds: {\n name: \"Check Link Table Foreign Key Ids\",\n resultType: \"CheckLinkTableFkIdsResultRow\",\n sqlCommand: \"check_linktable_fk_ids\",\n sqlQuery: `PRAGMA integrity_check(check_linktable_fk_ids) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,\n },\n checkClassIds: {\n name: \"Check Class Ids\",\n resultType: \"CheckClassIdsResultRow\",\n sqlCommand: \"check_class_ids\",\n sqlQuery: `PRAGMA integrity_check(check_class_ids) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,\n },\n checkDataSchema: {\n name: \"Check Data Schema\",\n resultType: \"CheckDataSchemaResultRow\",\n sqlCommand: \"check_data_schema\",\n sqlQuery: `PRAGMA integrity_check(check_data_schema) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,\n },\n checkSchemaLoad: {\n name: \"Check Schema Load\",\n resultType: \"CheckSchemaLoadResultRow\",\n sqlCommand: \"check_schema_load\",\n sqlQuery: `PRAGMA integrity_check(check_schema_load) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,\n },\n checkMissingChildRows: {\n name: \"Check Missing Child Rows\",\n resultType: \"CheckMissingChildRowsResultRow\",\n sqlCommand: \"check_missing_child_rows\",\n sqlQuery: `PRAGMA integrity_check(check_missing_child_rows) ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES`,\n },\n} as const;\n\n/**\n * Type representing the keys of the integrityCheckType map, which correspond to the different types of integrity checks that can be performed.\n */\nexport type IntegrityCheckKey = keyof typeof integrityCheckTypeMap;\n\n/** Map of integrity check keys to their result row types */\ninterface IntegrityCheckResultTypeMap {\n checkDataColumns: CheckDataColumnsResultRow;\n checkECProfile: CheckECProfileResultRow;\n checkNavigationClassIds: CheckNavClassIdsResultRow;\n checkNavigationIds: CheckNavIdsResultRow;\n checkLinktableForeignKeyClassIds: CheckLinkTableFkClassIdsResultRow;\n checkLinktableForeignKeyIds: CheckLinkTableFkIdsResultRow;\n checkClassIds: CheckClassIdsResultRow;\n checkDataSchema: CheckDataSchemaResultRow;\n checkSchemaLoad: CheckSchemaLoadResultRow;\n checkMissingChildRows: CheckMissingChildRowsResultRow;\n}\n\n/** Checks the Map to give the return type of a specific integrity check */\ntype IntegrityCheckResultRow<K extends IntegrityCheckKey> = IntegrityCheckResultTypeMap[K];\n\n/**\n * Return type for quick integrity check\n */\nexport interface QuickIntegrityCheckResultRow {\n check: string;\n passed: boolean;\n elapsedSeconds: string;\n}\n\n/**\n * Return type for Check Data Columns integrity check\n */\nexport interface CheckDataColumnsResultRow {\n sno: number;\n table: string;\n column: string;\n}\n\n/**\n * Return type for Check EC Profile integrity check\n */\nexport interface CheckECProfileResultRow {\n sno: number;\n type: string;\n name: string;\n issue: string;\n}\n\n/**\n * Return type for Check Navigation Class Ids integrity check\n */\nexport interface CheckNavClassIdsResultRow {\n sno: number;\n id: string;\n class: string;\n property: string;\n navId: string;\n navClassId: string;\n}\n\n/**\n * Return type for Check Navigation Ids integrity check\n */\nexport interface CheckNavIdsResultRow {\n sno: number;\n id: string;\n class: string;\n property: string;\n navId: string;\n primaryClass: string;\n}\n\n/**\n * Return type for Check Link Table Foreign Key Class Ids integrity check\n */\nexport interface CheckLinkTableFkClassIdsResultRow {\n sno: number;\n id: string;\n relationship: string;\n property: string;\n keyId: string;\n keyClassId: string;\n}\n\n/**\n * Return type for Check Link Table Foreign Key Ids integrity check\n */\nexport interface CheckLinkTableFkIdsResultRow {\n sno: number;\n id: string;\n relationship: string;\n property: string;\n keyId: string;\n primaryClass: string;\n}\n\n/**\n * Return type for Check Class Ids integrity check\n */\nexport interface CheckClassIdsResultRow {\n sno: number;\n class: string;\n id: string;\n classId: string;\n type: string;\n}\n\n/**\n * Return type for Check Data Schema integrity check\n */\nexport interface CheckDataSchemaResultRow {\n sno: number;\n type: string;\n name: string;\n}\n\n/**\n * Return type for Check Schema Load integrity check\n */\nexport interface CheckSchemaLoadResultRow {\n sno: number;\n schema: string;\n}\n\n/**\n * Return type for Check Missing Child Rows integrity check\n */\nexport interface CheckMissingChildRowsResultRow {\n sno: number;\n class: string;\n id: string;\n classId: string;\n missingRowInTables: string;\n}\n\n/**\n * Return type for integrity check results, including the check name, whether it passed, and the specific results (if any)\n */\nexport interface IntegrityCheckResult {\n /** The name of the integrity check that was performed */\n check: string;\n /** Whether the integrity check passed (i.e. no issues were found = true) */\n passed: boolean;\n /** The specific results returned by the integrity check, which may include details about any issues that were found.\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,\n * or an array of quick integrity check results if it was a quick check. */\n results: IntegrityCheckResultRow<IntegrityCheckKey>[] | QuickIntegrityCheckResultRow[];\n}\n\n/**\n * Gets the user-friendly name of an integrity check based on its key or SQL command.\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.\n * If still not found, it returns the original check string.\n * @param check - The integrity check key or SQL command to get the name of\n * @returns The user-friendly name of the integrity check, or the original check string if no match is found\n * @internal\n */\nexport function getIntegrityCheckName(check: string): string {\n // First try direct lookup by key\n const directLookup = integrityCheckTypeMap[check as IntegrityCheckKey];\n if (directLookup) {\n return directLookup.name;\n }\n // If not found, search by sqlCommand\n for (const [, value] of Object.entries(integrityCheckTypeMap)) {\n if (value.sqlCommand === check) {\n return value.name;\n }\n }\n // Fallback to the original check string\n return check;\n}\n\n/**\n * Performs a quick integrity check on the given iModel.\n * @param iModel The IModelDb instance to perform the integrity check on\n * @returns An array of results for each check performed, including the check name, whether it passed, and the elapsed time in seconds\n * @internal\n */\nexport async function performQuickIntegrityCheck(iModel: IModelDb): Promise<QuickIntegrityCheckResultRow[]> {\n const integrityCheckQuery = \"PRAGMA integrity_check ECSQLOPTIONS ENABLE_EXPERIMENTAL_FEATURES\";\n const integrityCheckResults: QuickIntegrityCheckResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckQuery, undefined, { usePrimaryConn: true })) {\n integrityCheckResults.push({ check: getIntegrityCheckName(row.check), passed: row.result, elapsedSeconds: row.elapsed_sec});\n };\n return integrityCheckResults;\n}\n\n/**\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.\n * @param iModel The IModelDb instance to perform the integrity check on\n * @param check The key of the specific integrity check to perform\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.\n * @throws IModelError with status BadRequest if an unknown integrity check key is provided\n * @internal\n */\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkDataColumns\"): Promise<IntegrityCheckResultRow<\"checkDataColumns\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkECProfile\"): Promise<IntegrityCheckResultRow<\"checkECProfile\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkNavigationClassIds\"): Promise<IntegrityCheckResultRow<\"checkNavigationClassIds\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkNavigationIds\"): Promise<IntegrityCheckResultRow<\"checkNavigationIds\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkLinktableForeignKeyClassIds\"): Promise<IntegrityCheckResultRow<\"checkLinktableForeignKeyClassIds\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkLinktableForeignKeyIds\"): Promise<IntegrityCheckResultRow<\"checkLinktableForeignKeyIds\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkClassIds\"): Promise<IntegrityCheckResultRow<\"checkClassIds\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkDataSchema\"): Promise<IntegrityCheckResultRow<\"checkDataSchema\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkSchemaLoad\"): Promise<IntegrityCheckResultRow<\"checkSchemaLoad\">[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: \"checkMissingChildRows\"): Promise<IntegrityCheckResultRow<\"checkMissingChildRows\">[]>;\nexport async function performSpecificIntegrityCheck<K extends IntegrityCheckKey>(iModel: IModelDb, check: K): Promise<IntegrityCheckResultRow<K>[]>;\nexport async function performSpecificIntegrityCheck(iModel: IModelDb, check: IntegrityCheckKey): Promise<IntegrityCheckResultRow<IntegrityCheckKey>[]> {\n switch (check) {\n case \"checkDataColumns\": {\n const results: CheckDataColumnsResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkDataColumns.sqlQuery, undefined, { usePrimaryConn: true })) {\n results.push({ sno: row.sno, table: row.table, column: row.column });\n }\n return results;\n }\n case \"checkECProfile\": {\n const results: CheckECProfileResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkECProfile.sqlQuery, undefined, { usePrimaryConn: true })) {\n results.push({ sno: row.sno, type: row.type, name: row.name, issue: row.issue });\n }\n return results;\n }\n case \"checkNavigationClassIds\": {\n const results: CheckNavClassIdsResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkNavigationClassIds.sqlQuery, undefined, { usePrimaryConn: true })) {\n results.push({ sno: row.sno, id: row.id, class: row.class, property: row.property, navId: row.nav_id, navClassId: row.nav_classId });\n }\n return results;\n }\n case \"checkNavigationIds\": {\n const results: CheckNavIdsResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkNavigationIds.sqlQuery, undefined, { usePrimaryConn: true })) {\n results.push({ sno: row.sno, id: row.id, class: row.class, property: row.property, navId: row.nav_id, primaryClass: row.primary_class });\n }\n return results;\n }\n case \"checkLinktableForeignKeyClassIds\": {\n const results: CheckLinkTableFkClassIdsResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkLinktableForeignKeyClassIds.sqlQuery, undefined, { usePrimaryConn: true })) {\n results.push({ sno: row.sno, id: row.id, relationship: row.relationship, property: row.property, keyId: row.key_id, keyClassId: row.key_classId });\n }\n return results;\n }\n case \"checkLinktableForeignKeyIds\": {\n const results: CheckLinkTableFkIdsResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkLinktableForeignKeyIds.sqlQuery, undefined, { usePrimaryConn: true })) {\n results.push({ sno: row.sno, id: row.id, relationship: row.relationship, property: row.property, keyId: row.key_id, primaryClass: row.primary_class });\n }\n return results;\n }\n case \"checkClassIds\": {\n const results: CheckClassIdsResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkClassIds.sqlQuery, undefined, { usePrimaryConn: true })) {\n results.push({ sno: row.sno, class: row.class, id: row.id, classId: row.class_id, type: row.type });\n }\n return results;\n }\n case \"checkDataSchema\": {\n const results: CheckDataSchemaResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkDataSchema.sqlQuery, undefined, { usePrimaryConn: true })) {\n results.push({ sno: row.sno, type: row.type, name: row.name });\n }\n return results;\n }\n case \"checkSchemaLoad\": {\n const results: CheckSchemaLoadResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkSchemaLoad.sqlQuery, undefined, { usePrimaryConn: true })) {\n results.push({ sno: row.sno, schema: row.schema });\n }\n return results;\n }\n case \"checkMissingChildRows\": {\n const results: CheckMissingChildRowsResultRow[] = [];\n for await (const row of iModel.createQueryReader(integrityCheckTypeMap.checkMissingChildRows.sqlQuery, undefined, { usePrimaryConn: true })) {\n results.push({ sno: row.sno, class: row.class, id: row.id, classId: row.class_id, missingRowInTables: row.MissingRowInTables });\n }\n return results;\n }\n default:\n throw new IModelError(IModelStatus.BadRequest, `Unknown integrity check type`);\n }\n}"]}
@@ -97,6 +97,14 @@ export declare class EditTxn {
97
97
  * @throws [[ITwinError]] if deletion fails.
98
98
  */
99
99
  deleteElement(ids: Id64Arg): void;
100
+ /**
101
+ * Delete multiple elements from the iModel.
102
+ * @param ids The ids of the elements to delete. All ids must be well-formed and valid [[Id64String]]s.
103
+ * @returns A set of ids for any elements that could not be deleted.
104
+ * @throws [[ITwinError]] if any of the supplied ids are not well-formed/valid [[Id64String]]s.
105
+ * @beta
106
+ */
107
+ deleteElements(ids: Id64Array): Id64Set;
100
108
  /** Insert a new aspect into the iModel.
101
109
  * @param aspectProps The properties of the new aspect.
102
110
  * @returns The newly inserted aspect Id.
@@ -1 +1 @@
1
- {"version":3,"file":"EditTxn.d.ts","sourceRoot":"","sources":["../../src/EditTxn.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,OAAO,EAAkB,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAA0B,MAAM,qBAAqB,CAAC;AACtH,OAAO,EAAgB,iBAAiB,EAAgB,kBAAkB,EAAE,YAAY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;AAC/F;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,eAAe,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC"}
@@ -5,7 +5,7 @@
5
5
  /** @packageDocumentation
6
6
  * @module iModels
7
7
  */
8
- import { DbResult, Id64, IModelStatus, OpenMode } from "@itwin/core-bentley";
8
+ import { DbResult, Id64, IModelStatus, ITwinError, OpenMode } from "@itwin/core-bentley";
9
9
  import { EcefLocation, EditTxnError, IModelError } from "@itwin/core-common";
10
10
  import { Range3d } from "@itwin/core-geometry";
11
11
  import { _activeTxn, _cache, _instanceKeyCache, _nativeDb } from "./internal/Symbols";
@@ -194,6 +194,33 @@ export class EditTxn {
194
194
  }
195
195
  });
196
196
  }
197
+ /**
198
+ * Delete multiple elements from the iModel.
199
+ * @param ids The ids of the elements to delete. All ids must be well-formed and valid [[Id64String]]s.
200
+ * @returns A set of ids for any elements that could not be deleted.
201
+ * @throws [[ITwinError]] if any of the supplied ids are not well-formed/valid [[Id64String]]s.
202
+ * @beta
203
+ */
204
+ deleteElements(ids) {
205
+ this.verifyWriteable();
206
+ const invalidIds = new Set();
207
+ for (const id of ids) {
208
+ if (!Id64.isValidId64(id))
209
+ invalidIds.add(id);
210
+ }
211
+ if (invalidIds.size > 0) {
212
+ ITwinError.throwError({ message: `Invalid element ids: ${Array.from(invalidIds).join(", ")}`, iTwinErrorId: { scope: "imodel", key: "invalid-arguments" } });
213
+ }
214
+ const failedToDelete = this.iModel[_nativeDb].deleteElements(ids);
215
+ const failedToDeleteSet = failedToDelete ? Id64.toIdSet(failedToDelete) : new Set();
216
+ for (const id of ids) {
217
+ if (!failedToDeleteSet.has(id)) {
218
+ this.iModel.elements[_cache].delete({ id });
219
+ this.iModel.elements[_instanceKeyCache].deleteById(id);
220
+ }
221
+ }
222
+ return failedToDeleteSet;
223
+ }
197
224
  /** Insert a new aspect into the iModel.
198
225
  * @param aspectProps The properties of the new aspect.
199
226
  * @returns The newly inserted aspect Id.
@@ -1 +1 @@
1
- {"version":3,"file":"EditTxn.js","sourceRoot":"","sources":["../../src/EditTxn.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAA2C,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACtH,OAAO,EAAE,YAAY,EAAqB,YAAY,EAAuD,WAAW,EAAkD,MAAM,oBAAoB,CAAC;AACrM,OAAO,EAAE,OAAO,EAAgB,MAAM,sBAAsB,CAAC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEtF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,OAAO;IAClB;;;;;;;;;;;;;OAaG;IACI,MAAM,CAAC,wBAAwB,GAA6B,OAAO,CAAC;IAE3E,0CAA0C;IAC1B,MAAM,CAAW;IAEjC,kFAAkF;IAC3E,WAAW,CAAS;IAE3B,wEAAwE;IACxE,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;IAC1C,CAAC;IAED,YAAmB,MAAgB,EAAE,WAAmB;QACtD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAEM,eAAe;QACpB,8DAA8D;QAC9D,IAAI,CAAC,IAAI,CAAC,QAAQ;YAChB,YAAY,CAAC,UAAU,CAAC,YAAY,EAAE,uBAAuB,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACpF,CAAC;IAED;;OAEG;IACI,KAAK;QACV,IAAI,IAAI,CAAC,QAAQ;YACf,YAAY,CAAC,UA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,MAAM,YAAY,OAAO,EAAE,CAAC;YAC9B,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC3B,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;gBAC1B,OAAO,KAAK,CAAC;YACf,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE;gBACT,IAAI,GAAG,CAAC,QAAQ;oBACd,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;gBAErB,MAAM,GAAG,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC;QAED,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAC1B,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,CAAC,QAAQ;YACd,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAErB,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** @packageDocumentation\n * @module iModels\n */\n\nimport { DbResult, Id64, Id64Arg, Id64Array, Id64Set, Id64String, IModelStatus, OpenMode } from \"@itwin/core-bentley\";\nimport { EcefLocation, EcefLocationProps, EditTxnError, ElementAspectProps, ElementProps, FilePropertyProps, IModelError, ModelProps, RelationshipProps, SaveChangesArgs } from \"@itwin/core-common\";\nimport { Range3d, Range3dProps } from \"@itwin/core-geometry\";\nimport type { CloudSqlite } from \"./CloudSqlite\";\nimport type { ImplicitWriteEnforcement } from \"./IModelHost\";\nimport type { IModelDb, InsertElementOptions, UpdateModelOptions } from \"./IModelDb\";\nimport type { SettingsContainer } from \"./workspace/Settings\";\nimport { _activeTxn, _cache, _instanceKeyCache, _nativeDb } from \"./internal/Symbols\";\n\n/**\n * Represents an explicit editing transaction for an iModel.\n *\n * An explicit EditTxn lets callers define a deliberate unit of work by choosing when editing\n * starts (`start`) and how it ends (`end()` / `end(\"save\")` or `end(\"abandon\")`). This avoids mixing\n * unrelated edits into one implicit unit of work and makes save/rollback boundaries explicit.\n *\n * Explicit EditTxn instances must be active before mutating operations are performed, regardless of enforcement level.\n * In other words, explicit transaction behavior is independent of `implicitWriteEnforcement`.\n *\n * @see [EditTxn transaction model and migration guidance]($docs/learning/backend/EditTxn.md)\n *\n * *During indirect changes (commit processing):* Use callback args (`indirectEditTxn`) in callbacks like\n * [[Relationship.onRootChangedArg]] and [[Relationship.onDeletedDependencyArg]] that fire during indirect processing.\n *\n * @beta\n */\nexport class EditTxn {\n /** Controls how writes through the implicit transaction are handled.\n *\n * This does not relax activation requirements for explicit transactions: explicit EditTxn writes\n * must always come from the active EditTxn.\n *\n * - `allow`: allow implicit writes for backwards compatibility, even while an explicit EditTxn is active.\n * - `log`: allow implicit writes but log `implicit-txn-write-disallowed` errors.\n * - `throw`: reject implicit writes with `implicit-txn-write-disallowed`.\n *\n * This is initialized from [[IModelHostOptions.implicitWriteEnforcement]] during [[IModelHost.startup]].\n *\n * Defaults to `allow` for backwards compatibility.\n * @beta\n */\n public static implicitWriteEnforcement: ImplicitWriteEnforcement = \"allow\";\n\n /** The iModel this EditTxn may modify. */\n public readonly iModel: IModelDb;\n\n /** Default description passed to [[saveChanges]] when saving this transaction. */\n public description: string;\n\n /** True if this transaction currently owns the iModel write surface. */\n public get isActive(): boolean {\n return this.iModel[_activeTxn] === this;\n }\n\n public constructor(iModel: IModelDb, description: string) {\n this.iModel = iModel;\n this.description = description;\n }\n\n public verifyWriteable(): void {\n // Explicit transactions must always be active before writing.\n if (!this.isActive)\n EditTxnError.throwError(\"not-active\", \"EditTxn is not active\", this.iModel.key);\n }\n\n /** Start this EditTxn, making it the active transaction for the iModel.\n * @throws EditTxnError if this EditTxn is already active, another EditTxn is already active, or if unsaved changes are present.\n */\n public start(): void {\n if (this.isActive)\n EditTxnError.throwError(\"already-active\", \"This EditTxn is already active\", this.iModel.key);\n\n const activeTxn = this.iModel[_activeTxn];\n if (undefined !== activeTxn)\n EditTxnError.throwError(\"already-active\", \"Cannot start EditTxn while another EditTxn is active\", this.iModel.key, activeTxn.description);\n\n if (this.iModel[_nativeDb].hasUnsavedChanges())\n EditTxnError.throwError(\"unsaved-changes\", \"Cannot start a new EditTxn with unsaved changes\", this.iModel.key);\n\n this.iModel[_activeTxn] = this;\n }\n\n /** End this EditTxn, either by saving or abandoning the changes.\n * @param mode Whether to \"save\" or \"abandon\" the changes. Defaults to \"save\".\n * @param args Save changes arguments when saving.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if saving changes fails.\n */\n public end(): void;\n public end(mode: \"save\" | \"abandon\", args?: string | SaveChangesArgs): void;\n public end(mode: \"save\" | \"abandon\" = \"save\", args?: string | SaveChangesArgs): void {\n if (!this.isActive)\n EditTxnError.throwError(\"not-active\", \"EditTxn is not active\", this.iModel.key);\n\n if (mode === \"save\") {\n this.saveChanges(args);\n } else {\n this.abandonChanges();\n }\n this.iModel[_activeTxn] = undefined;\n }\n\n /** Invoked when the owning iModel is closing.\n * The base implementation commits unsaved changes. Subclasses may override to customize how\n * their changes are handled before the iModel closes.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if saving on close fails.\n */\n public onClose(): void {\n if (!this.iModel.isReadonly && this.iModel[_nativeDb].hasUnsavedChanges())\n this.saveChanges();\n }\n\n /** Abandon database changes while keeping this EditTxn active.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public abandonChanges(): void {\n this.verifyWriteable();\n this.iModel.clearCaches({ instanceCachesOnly: true });\n this.iModel[_nativeDb].abandonChanges();\n }\n\n /** Save changes with additional arguments.\n * @param args Save changes arguments.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if the iModel is readonly, if indirect changes are active, or if the native save fails.\n */\n public saveChanges(args?: string | SaveChangesArgs): void {\n this.verifyWriteable();\n const iModel = this.iModel;\n if (iModel.openMode === OpenMode.Readonly)\n throw new IModelError(IModelStatus.ReadOnly, \"IModelDb was opened read-only\");\n\n if (iModel.isBriefcaseDb() && iModel.txns.isIndirectChanges)\n throw new IModelError(IModelStatus.BadRequest, \"Cannot save changes while in an indirect change scope\");\n\n args ??= this.description;\n const saveArgs = typeof args === \"string\" ? { description: args } : args;\n const stat = iModel[_nativeDb].saveChanges(JSON.stringify(saveArgs));\n if (DbResult.BE_SQLITE_ERROR_PropagateChangesFailed === stat)\n throw new IModelError(stat, \"Could not save changes due to propagation failure.\");\n\n if (DbResult.BE_SQLITE_OK !== stat)\n throw new IModelError(stat, `Could not save changes (${saveArgs.description})`);\n }\n\n /** Insert a new element into the iModel.\n * @param elProps The properties of the new element.\n * @returns The newly inserted element's Id.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws [[ITwinError]] if insertion fails.\n */\n public insertElement(elProps: ElementProps, options?: InsertElementOptions): Id64String {\n this.verifyWriteable();\n try {\n this.iModel.elements[_cache].delete({\n id: elProps.id,\n federationGuid: elProps.federationGuid,\n code: elProps.code,\n });\n return elProps.id = this.iModel[_nativeDb].insertElement(elProps, options);\n } catch (err: any) {\n err.message = `Error inserting element [${err.message}]`;\n err.metadata = { elProps };\n throw err;\n }\n }\n\n /** Update an existing element in the iModel.\n * @param elProps The properties to update.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws [[ITwinError]] if update fails.\n */\n public updateElement<T extends ElementProps>(elProps: Partial<T>): void {\n this.verifyWriteable();\n try {\n if (elProps.id) {\n this.iModel.elements[_instanceKeyCache].deleteById(elProps.id);\n } else {\n this.iModel.elements[_instanceKeyCache].delete({\n federationGuid: elProps.federationGuid,\n code: elProps.code,\n });\n }\n this.iModel.elements[_cache].delete({\n id: elProps.id,\n federationGuid: elProps.federationGuid,\n code: elProps.code,\n });\n this.iModel[_nativeDb].updateElement(elProps);\n } catch (err: any) {\n err.message = `Error updating element [${err.message}], id: ${elProps.id}`;\n err.metadata = { elProps };\n throw err;\n }\n }\n\n /** Delete elements from the iModel.\n * @param ids The Ids of the elements to delete.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws [[ITwinError]] if deletion fails.\n */\n public deleteElement(ids: Id64Arg): void {\n this.verifyWriteable();\n const iModel = this.iModel;\n Id64.toIdSet(ids).forEach((id) => {\n try {\n this.iModel.elements[_cache].delete({ id });\n this.iModel.elements[_instanceKeyCache].deleteById(id);\n iModel[_nativeDb].deleteElement(id);\n } catch (err: any) {\n err.message = `Error deleting element [${err.message}], id: ${id}`;\n err.metadata = { elementId: id };\n throw err;\n }\n });\n }\n\n /** Insert a new aspect into the iModel.\n * @param aspectProps The properties of the new aspect.\n * @returns The newly inserted aspect Id.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if insertion fails.\n */\n public insertAspect(aspectProps: ElementAspectProps): Id64String {\n this.verifyWriteable();\n try {\n return this.iModel[_nativeDb].insertElementAspect(aspectProps);\n } catch (err: any) {\n const error = new IModelError(err.errorNumber, `Error inserting ElementAspect [${err.message}], class: ${aspectProps.classFullName}`, aspectProps);\n error.cause = err;\n throw error;\n }\n }\n\n /** Update an existing aspect in the iModel.\n * @param aspectProps The properties of the aspect to update.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if update fails.\n */\n public updateAspect(aspectProps: ElementAspectProps): void {\n this.verifyWriteable();\n try {\n this.iModel[_nativeDb].updateElementAspect(aspectProps);\n } catch (err: any) {\n const error = new IModelError(err.errorNumber, `Error updating ElementAspect [${err.message}], id: ${aspectProps.id}`, aspectProps);\n error.cause = err;\n throw error;\n }\n }\n\n /** Delete one or more aspects from the iModel.\n * @param aspectInstanceIds The Ids of the aspects to delete.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if deletion fails.\n */\n public deleteAspect(aspectInstanceIds: Id64Arg): void {\n this.verifyWriteable();\n Id64.toIdSet(aspectInstanceIds).forEach((aspectInstanceId) => {\n try {\n this.iModel[_nativeDb].deleteElementAspect(aspectInstanceId);\n } catch (err: any) {\n const error = new IModelError(err.errorNumber, `Error deleting ElementAspect [${err.message}], id: ${aspectInstanceId}`);\n error.cause = err;\n throw error;\n }\n });\n }\n\n /** Delete definition elements from the iModel when they are not referenced.\n * @param definitionElementIds The Ids of the definition elements to attempt to delete.\n * @returns The set of definition elements that were still in use and therefore not deleted.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if usage queries fail.\n */\n public deleteDefinitionElements(definitionElementIds: Id64Array): Id64Set {\n this.verifyWriteable();\n const usageInfo = this.iModel[_nativeDb].queryDefinitionElementUsage(definitionElementIds);\n if (!usageInfo)\n throw new IModelError(IModelStatus.BadRequest, \"Error querying for DefinitionElement usage\");\n\n const usedIdSet = usageInfo.usedIds ? Id64.toIdSet(usageInfo.usedIds) : new Set<Id64String>();\n const deleteIfUnused = (ids: Id64Array | undefined, used: Id64Set): void => {\n ids?.forEach((id) => {\n if (!used.has(id))\n this.deleteElement(id);\n });\n };\n\n try {\n this.iModel[_nativeDb].beginPurgeOperation();\n deleteIfUnused(usageInfo.spatialCategoryIds, usedIdSet);\n deleteIfUnused(usageInfo.drawingCategoryIds, usedIdSet);\n deleteIfUnused(usageInfo.viewDefinitionIds, usedIdSet);\n deleteIfUnused(usageInfo.geometryPartIds, usedIdSet);\n deleteIfUnused(usageInfo.lineStyleIds, usedIdSet);\n deleteIfUnused(usageInfo.renderMaterialIds, usedIdSet);\n deleteIfUnused(usageInfo.subCategoryIds, usedIdSet);\n deleteIfUnused(usageInfo.textureIds, usedIdSet);\n deleteIfUnused(usageInfo.displayStyleIds, usedIdSet);\n deleteIfUnused(usageInfo.categorySelectorIds, usedIdSet);\n deleteIfUnused(usageInfo.modelSelectorIds, usedIdSet);\n if (usageInfo.otherDefinitionElementIds)\n this.deleteElement(usageInfo.otherDefinitionElementIds);\n } finally {\n this.iModel[_nativeDb].endPurgeOperation();\n }\n\n if (usageInfo.viewDefinitionIds) {\n // Recheck view-related definitions after deleting view definitions that may have been their last reference.\n let viewRelatedIds: Id64Array = [];\n if (usageInfo.displayStyleIds)\n viewRelatedIds = viewRelatedIds.concat(usageInfo.displayStyleIds.filter((id) => usedIdSet.has(id)));\n\n if (usageInfo.categorySelectorIds)\n viewRelatedIds = viewRelatedIds.concat(usageInfo.categorySelectorIds.filter((id) => usedIdSet.has(id)));\n\n if (usageInfo.modelSelectorIds)\n viewRelatedIds = viewRelatedIds.concat(usageInfo.modelSelectorIds.filter((id) => usedIdSet.has(id)));\n\n if (viewRelatedIds.length > 0) {\n const viewRelatedUsageInfo = this.iModel[_nativeDb].queryDefinitionElementUsage(viewRelatedIds);\n if (viewRelatedUsageInfo) {\n const usedViewRelatedIdSet: Id64Set = viewRelatedUsageInfo.usedIds ? Id64.toIdSet(viewRelatedUsageInfo.usedIds) : new Set<Id64String>();\n try {\n this.iModel[_nativeDb].beginPurgeOperation();\n deleteIfUnused(viewRelatedUsageInfo.displayStyleIds, usedViewRelatedIdSet);\n deleteIfUnused(viewRelatedUsageInfo.categorySelectorIds, usedViewRelatedIdSet);\n deleteIfUnused(viewRelatedUsageInfo.modelSelectorIds, usedViewRelatedIdSet);\n } finally {\n this.iModel[_nativeDb].endPurgeOperation();\n }\n\n viewRelatedIds.forEach((id) => {\n if (!usedViewRelatedIdSet.has(id))\n usedIdSet.delete(id);\n });\n }\n }\n }\n\n return usedIdSet;\n }\n\n /** Insert a new model into the iModel.\n * @param props The data for the new model.\n * @returns The newly inserted model's Id.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if insertion fails.\n */\n public insertModel(props: ModelProps): Id64String {\n this.verifyWriteable();\n try {\n return props.id = this.iModel[_nativeDb].insertModel(props);\n } catch (err: any) {\n const error = new IModelError(err.errorNumber, `Error inserting model [${err.message}], class=${props.classFullName}`);\n error.cause = err;\n throw error;\n }\n }\n\n /** Update an existing model in the iModel.\n * @param props the properties of the model to change\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if update fails.\n */\n public updateModel(props: UpdateModelOptions): void {\n this.verifyWriteable();\n try {\n if (props.id)\n this.iModel.models[_cache].delete(props.id);\n\n this.iModel[_nativeDb].updateModel(props);\n } catch (err: any) {\n const error = new IModelError(err.errorNumber, `Error updating model [${err.message}], id: ${props.id}`);\n error.cause = err;\n throw error;\n }\n }\n\n /** Update the geometry guid of a model.\n * @param modelId The Id of the model to update.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if the update fails.\n */\n public updateGeometryGuid(modelId: Id64String): void {\n this.verifyWriteable();\n this.iModel.models[_cache].delete(modelId);\n const error = this.iModel[_nativeDb].updateModelGeometryGuid(modelId);\n if (error !== IModelStatus.Success)\n throw new IModelError(error, `Error updating geometry guid for model ${modelId}`);\n }\n\n /** Delete models from the iModel.\n * @param ids The Ids of the models to delete.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if deletion fails.\n */\n public deleteModel(ids: Id64Arg): void {\n this.verifyWriteable();\n Id64.toIdSet(ids).forEach((id) => {\n try {\n this.iModel.models[_cache].delete(id);\n this.iModel.models[_instanceKeyCache].deleteById(id);\n this.iModel[_nativeDb].deleteModel(id);\n } catch (err: any) {\n const error = new IModelError(err.errorNumber, `Error deleting model [${err.message}], id: ${id}`);\n error.cause = err;\n throw error;\n }\n });\n }\n\n /** Insert a new relationship into the iModel.\n * @param props The properties of the new relationship.\n * @returns The Id of the newly inserted relationship.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if the class is invalid for link-table insertion.\n */\n public insertRelationship(props: RelationshipProps): Id64String {\n this.verifyWriteable();\n if (!this.iModel[_nativeDb].isLinkTableRelationship(props.classFullName.replace(\".\", \":\")))\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Class '${props.classFullName}' must be a relationship class and it should be subclass of BisCore:ElementRefersToElements or BisCore:ElementDrivesElement.`);\n\n return props.id = this.iModel[_nativeDb].insertLinkTableRelationship(props);\n }\n\n /** Update an existing relationship in the iModel.\n * @param props the properties of the relationship to update.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public updateRelationship(props: RelationshipProps): void {\n this.verifyWriteable();\n this.iModel[_nativeDb].updateLinkTableRelationship(props);\n }\n\n /** Delete a relationship from the iModel.\n * @param props The properties of the relationship to delete.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public deleteRelationship(props: RelationshipProps): void {\n this.verifyWriteable();\n this.iModel[_nativeDb].deleteLinkTableRelationship(props);\n }\n\n /** Delete multiple relationships from the iModel.\n * @param props The properties of the relationships to delete.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public deleteRelationships(props: ReadonlyArray<RelationshipProps>): void {\n this.verifyWriteable();\n this.iModel[_nativeDb].deleteLinkTableRelationships(props);\n }\n\n\n /** Save a file property to the iModel.\n * @param prop The file property to save.\n * @param strValue String value.\n * @param blobVal Blob value.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public saveFileProperty(prop: FilePropertyProps, strValue: string | undefined, blobVal?: Uint8Array): void {\n this.verifyWriteable();\n const imodel = this.iModel;\n if (imodel.isBriefcaseDb()) {\n if (imodel.txns.isIndirectChanges) {\n throw new IModelError(IModelStatus.BadRequest, \"Cannot save file property while in an indirect change scope\");\n }\n }\n imodel[_nativeDb].saveFileProperty(prop, strValue, blobVal);\n }\n\n /** Delete a file property from the iModel.\n * @param prop The file property to delete.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public deleteFileProperty(prop: FilePropertyProps): void {\n this.saveFileProperty(prop, undefined, undefined);\n }\n\n /** Update the project extents of the iModel.\n * @param newExtents The new project extents.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if extents are invalid.\n */\n public updateProjectExtents(newExtents: Range3dProps): void {\n this.verifyWriteable();\n const extents = Range3d.fromJSON(newExtents);\n if (extents.isNull)\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Invalid project extents\");\n\n this.iModel.projectExtents = extents;\n this.updateIModelProps();\n }\n\n /** Update the ECEF location of the iModel.\n * @param ecef The new ECEF location.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public updateEcefLocation(ecef: EcefLocationProps): void {\n this.verifyWriteable();\n this.iModel.setEcefLocation(new EcefLocation(ecef));\n this.updateIModelProps();\n }\n\n /** Update the iModel props in the database from the current in-memory state.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public updateIModelProps(): void {\n this.verifyWriteable();\n this.iModel[_nativeDb].updateIModelProps(this.iModel.toJSON());\n }\n\n private static readonly _settingPropNamespace = \"settings\";\n private static readonly _viewStoreProperty: FilePropertyProps = { namespace: \"itwinjs\", name: \"DefaultViewStore\" };\n\n /** Save a `SettingDictionary` in this iModel.\n * @param name The name for the SettingDictionary. If a dictionary by that name already exists, its value is replaced.\n * @param dict The SettingDictionary object to stringify and save.\n * @throws EditTxnError if this EditTxn is not active.\n * @beta\n */\n public saveSettingDictionary(name: string, dict: SettingsContainer): void {\n this.verifyWriteable();\n this.iModel.withSqliteStatement(\"REPLACE INTO be_Prop(id,SubId,TxnMode,Namespace,Name,strData) VALUES(0,0,0,?,?,?)\", (stmt) => {\n stmt.bindString(1, EditTxn._settingPropNamespace);\n stmt.bindString(2, name);\n stmt.bindString(3, JSON.stringify(dict));\n stmt.stepForWrite();\n });\n this.saveChanges(\"add settings\");\n }\n\n /** Delete a SettingDictionary from this iModel.\n * @param name The name of the dictionary to delete.\n * @throws EditTxnError if this EditTxn is not active.\n * @beta\n */\n public deleteSettingDictionary(name: string): void {\n this.verifyWriteable();\n this.iModel.withSqliteStatement(\"DELETE FROM be_Prop WHERE Namespace=? AND Name=?\", (stmt) => {\n stmt.bindString(1, EditTxn._settingPropNamespace);\n stmt.bindString(2, name);\n stmt.stepForWrite();\n });\n this.saveChanges(\"delete settings\");\n }\n\n /** Save a default ViewStore container reference in this iModel.\n * @param arg The cloud container properties for the ViewStore.\n * @throws EditTxnError if this EditTxn is not active.\n * @beta\n */\n public saveDefaultViewStore(arg: CloudSqlite.ContainerProps): void {\n this.verifyWriteable();\n const props = { baseUri: arg.baseUri, containerId: arg.containerId, storageType: arg.storageType }; // sanitize to only known properties\n this.saveFileProperty(EditTxn._viewStoreProperty, JSON.stringify(props));\n this.saveChanges(\"update default ViewStore\");\n }\n}\n\n/** Execute a callback within an explicit editing transaction. A new [[EditTxn]] is created, started,\n * and passed to `fn`. If `fn` returns normally (or its returned Promise resolves), the transaction\n * is committed. If `fn` throws (or its returned Promise rejects), the transaction is abandoned —\n * none of the changes made during the callback are saved — and the error is re-thrown.\n *\n * This is the recommended way to perform a scoped unit of work on an iModel. It ensures that\n * edits are committed atomically on success and rolled back on failure, without the caller needing\n * to manage `start` / `end` manually.\n *\n * @param iModel The iModel to edit.\n * @param fn A callback that receives the active [[EditTxn]] and performs edits.\n * @returns The value returned by `fn`.\n * @throws EditTxnError if the transaction cannot be started (e.g. unsaved changes or another EditTxn is active).\n * @throws Re-throws any error thrown by `fn` after abandoning the transaction.\n * @beta\n */\nexport function withEditTxn<T>(iModel: IModelDb, fn: (txn: EditTxn) => T): T;\n/** Execute a callback within an explicit editing transaction, supplying commit arguments.\n * @param iModel The iModel to edit.\n * @param saveArgs Description or structured arguments passed to [[EditTxn.saveChanges]] on save.\n * @param fn A callback that receives the active [[EditTxn]] and performs edits.\n * @returns The value returned by `fn`.\n * @beta\n */\nexport function withEditTxn<T>(iModel: IModelDb, saveArgs: string | SaveChangesArgs, fn: (txn: EditTxn) => T): T;\n/** Execute an async callback within an explicit editing transaction.\n * @param iModel The iModel to edit.\n * @param fn An async callback that receives the active [[EditTxn]] and performs edits.\n * @returns A Promise that resolves to the value returned by `fn`.\n * @beta\n */\nexport function withEditTxn<T>(iModel: IModelDb, fn: (txn: EditTxn) => Promise<T>): Promise<T>;\n/** Execute an async callback within an explicit editing transaction, supplying commit arguments.\n * @param iModel The iModel to edit.\n * @param saveArgs Description or structured arguments passed to [[EditTxn.saveChanges]] on save.\n * @param fn An async callback that receives the active [[EditTxn]] and performs edits.\n * @returns A Promise that resolves to the value returned by `fn`.\n * @beta\n */\nexport function withEditTxn<T>(iModel: IModelDb, saveArgs: string | SaveChangesArgs, fn: (txn: EditTxn) => Promise<T>): Promise<T>;\nexport function withEditTxn<T>(iModel: IModelDb, saveArgsOrFn: string | SaveChangesArgs | ((txn: EditTxn) => T | Promise<T>), maybeFn?: (txn: EditTxn) => T | Promise<T>): T | Promise<T> {\n const saveArgs = \"function\" === typeof saveArgsOrFn ? undefined : saveArgsOrFn;\n const fn = \"function\" === typeof saveArgsOrFn ? saveArgsOrFn : maybeFn;\n\n if (undefined === fn)\n throw new Error(\"withEditTxn requires a callback\");\n\n const txn = new EditTxn(iModel, \"\");\n txn.start();\n\n try {\n const result = fn(txn);\n if (result instanceof Promise) {\n return result.then((value) => {\n txn.end(\"save\", saveArgs);\n return value;\n }, (err) => {\n if (txn.isActive)\n txn.end(\"abandon\");\n\n throw err;\n });\n }\n\n txn.end(\"save\", saveArgs);\n return result;\n } catch (err) {\n if (txn.isActive)\n txn.end(\"abandon\");\n\n throw err;\n }\n}\n"]}
1
+ {"version":3,"file":"EditTxn.js","sourceRoot":"","sources":["../../src/EditTxn.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAA2C,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAClI,OAAO,EAAE,YAAY,EAAqB,YAAY,EAAuD,WAAW,EAAkD,MAAM,oBAAoB,CAAC;AACrM,OAAO,EAAE,OAAO,EAAgB,MAAM,sBAAsB,CAAC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEtF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,OAAO;IAClB;;;;;;;;;;;;;OAaG;IACI,MAAM,CAAC,wBAAwB,GAA6B,OAAO,CAAC;IAE3E,0CAA0C;IAC1B,MAAM,CAAW;IAEjC,kFAAkF;IAC3E,WAAW,CAAS;IAE3B,wEAAwE;IACxE,IAAW,QAAQ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CAAC,CAAC,CAAC,YAAY,CAAC;IAC/E,MAAM,EAAE,GAAG,UAAU,KAAK,OAAO,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC;IAEvE,IAAI,SAAS,KAAK,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IAErD,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACpC,GAAG,CAAC,KAAK,EAAE,CAAC;IAEZ,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QACvB,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;YAC9B,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC3B,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;gBAC1B,OAAO,KAAK,CAAC;YACf,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE;gBACT,IAAI,GAAG,CAAC,QAAQ;oBACd,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;gBAErB,MAAM,GAAG,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC;QAED,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAC1B,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,CAAC,QAAQ;YACd,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAErB,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** @packageDocumentation\n * @module iModels\n */\n\nimport { DbResult, Id64, Id64Arg, Id64Array, Id64Set, Id64String, IModelStatus, ITwinError, OpenMode } from \"@itwin/core-bentley\";\nimport { EcefLocation, EcefLocationProps, EditTxnError, ElementAspectProps, ElementProps, FilePropertyProps, IModelError, ModelProps, RelationshipProps, SaveChangesArgs } from \"@itwin/core-common\";\nimport { Range3d, Range3dProps } from \"@itwin/core-geometry\";\nimport type { CloudSqlite } from \"./CloudSqlite\";\nimport type { ImplicitWriteEnforcement } from \"./IModelHost\";\nimport type { IModelDb, InsertElementOptions, UpdateModelOptions } from \"./IModelDb\";\nimport type { SettingsContainer } from \"./workspace/Settings\";\nimport { _activeTxn, _cache, _instanceKeyCache, _nativeDb } from \"./internal/Symbols\";\n\n/**\n * Represents an explicit editing transaction for an iModel.\n *\n * An explicit EditTxn lets callers define a deliberate unit of work by choosing when editing\n * starts (`start`) and how it ends (`end()` / `end(\"save\")` or `end(\"abandon\")`). This avoids mixing\n * unrelated edits into one implicit unit of work and makes save/rollback boundaries explicit.\n *\n * Explicit EditTxn instances must be active before mutating operations are performed, regardless of enforcement level.\n * In other words, explicit transaction behavior is independent of `implicitWriteEnforcement`.\n *\n * @see [EditTxn transaction model and migration guidance]($docs/learning/backend/EditTxn.md)\n *\n * *During indirect changes (commit processing):* Use callback args (`indirectEditTxn`) in callbacks like\n * [[Relationship.onRootChangedArg]] and [[Relationship.onDeletedDependencyArg]] that fire during indirect processing.\n *\n * @beta\n */\nexport class EditTxn {\n /** Controls how writes through the implicit transaction are handled.\n *\n * This does not relax activation requirements for explicit transactions: explicit EditTxn writes\n * must always come from the active EditTxn.\n *\n * - `allow`: allow implicit writes for backwards compatibility, even while an explicit EditTxn is active.\n * - `log`: allow implicit writes but log `implicit-txn-write-disallowed` errors.\n * - `throw`: reject implicit writes with `implicit-txn-write-disallowed`.\n *\n * This is initialized from [[IModelHostOptions.implicitWriteEnforcement]] during [[IModelHost.startup]].\n *\n * Defaults to `allow` for backwards compatibility.\n * @beta\n */\n public static implicitWriteEnforcement: ImplicitWriteEnforcement = \"allow\";\n\n /** The iModel this EditTxn may modify. */\n public readonly iModel: IModelDb;\n\n /** Default description passed to [[saveChanges]] when saving this transaction. */\n public description: string;\n\n /** True if this transaction currently owns the iModel write surface. */\n public get isActive(): boolean {\n return this.iModel[_activeTxn] === this;\n }\n\n public constructor(iModel: IModelDb, description: string) {\n this.iModel = iModel;\n this.description = description;\n }\n\n public verifyWriteable(): void {\n // Explicit transactions must always be active before writing.\n if (!this.isActive)\n EditTxnError.throwError(\"not-active\", \"EditTxn is not active\", this.iModel.key);\n }\n\n /** Start this EditTxn, making it the active transaction for the iModel.\n * @throws EditTxnError if this EditTxn is already active, another EditTxn is already active, or if unsaved changes are present.\n */\n public start(): void {\n if (this.isActive)\n EditTxnError.throwError(\"already-active\", \"This EditTxn is already active\", this.iModel.key);\n\n const activeTxn = this.iModel[_activeTxn];\n if (undefined !== activeTxn)\n EditTxnError.throwError(\"already-active\", \"Cannot start EditTxn while another EditTxn is active\", this.iModel.key, activeTxn.description);\n\n if (this.iModel[_nativeDb].hasUnsavedChanges())\n EditTxnError.throwError(\"unsaved-changes\", \"Cannot start a new EditTxn with unsaved changes\", this.iModel.key);\n\n this.iModel[_activeTxn] = this;\n }\n\n /** End this EditTxn, either by saving or abandoning the changes.\n * @param mode Whether to \"save\" or \"abandon\" the changes. Defaults to \"save\".\n * @param args Save changes arguments when saving.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if saving changes fails.\n */\n public end(): void;\n public end(mode: \"save\" | \"abandon\", args?: string | SaveChangesArgs): void;\n public end(mode: \"save\" | \"abandon\" = \"save\", args?: string | SaveChangesArgs): void {\n if (!this.isActive)\n EditTxnError.throwError(\"not-active\", \"EditTxn is not active\", this.iModel.key);\n\n if (mode === \"save\") {\n this.saveChanges(args);\n } else {\n this.abandonChanges();\n }\n this.iModel[_activeTxn] = undefined;\n }\n\n /** Invoked when the owning iModel is closing.\n * The base implementation commits unsaved changes. Subclasses may override to customize how\n * their changes are handled before the iModel closes.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if saving on close fails.\n */\n public onClose(): void {\n if (!this.iModel.isReadonly && this.iModel[_nativeDb].hasUnsavedChanges())\n this.saveChanges();\n }\n\n /** Abandon database changes while keeping this EditTxn active.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public abandonChanges(): void {\n this.verifyWriteable();\n this.iModel.clearCaches({ instanceCachesOnly: true });\n this.iModel[_nativeDb].abandonChanges();\n }\n\n /** Save changes with additional arguments.\n * @param args Save changes arguments.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if the iModel is readonly, if indirect changes are active, or if the native save fails.\n */\n public saveChanges(args?: string | SaveChangesArgs): void {\n this.verifyWriteable();\n const iModel = this.iModel;\n if (iModel.openMode === OpenMode.Readonly)\n throw new IModelError(IModelStatus.ReadOnly, \"IModelDb was opened read-only\");\n\n if (iModel.isBriefcaseDb() && iModel.txns.isIndirectChanges)\n throw new IModelError(IModelStatus.BadRequest, \"Cannot save changes while in an indirect change scope\");\n\n args ??= this.description;\n const saveArgs = typeof args === \"string\" ? { description: args } : args;\n const stat = iModel[_nativeDb].saveChanges(JSON.stringify(saveArgs));\n if (DbResult.BE_SQLITE_ERROR_PropagateChangesFailed === stat)\n throw new IModelError(stat, \"Could not save changes due to propagation failure.\");\n\n if (DbResult.BE_SQLITE_OK !== stat)\n throw new IModelError(stat, `Could not save changes (${saveArgs.description})`);\n }\n\n /** Insert a new element into the iModel.\n * @param elProps The properties of the new element.\n * @returns The newly inserted element's Id.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws [[ITwinError]] if insertion fails.\n */\n public insertElement(elProps: ElementProps, options?: InsertElementOptions): Id64String {\n this.verifyWriteable();\n try {\n this.iModel.elements[_cache].delete({\n id: elProps.id,\n federationGuid: elProps.federationGuid,\n code: elProps.code,\n });\n return elProps.id = this.iModel[_nativeDb].insertElement(elProps, options);\n } catch (err: any) {\n err.message = `Error inserting element [${err.message}]`;\n err.metadata = { elProps };\n throw err;\n }\n }\n\n /** Update an existing element in the iModel.\n * @param elProps The properties to update.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws [[ITwinError]] if update fails.\n */\n public updateElement<T extends ElementProps>(elProps: Partial<T>): void {\n this.verifyWriteable();\n try {\n if (elProps.id) {\n this.iModel.elements[_instanceKeyCache].deleteById(elProps.id);\n } else {\n this.iModel.elements[_instanceKeyCache].delete({\n federationGuid: elProps.federationGuid,\n code: elProps.code,\n });\n }\n this.iModel.elements[_cache].delete({\n id: elProps.id,\n federationGuid: elProps.federationGuid,\n code: elProps.code,\n });\n this.iModel[_nativeDb].updateElement(elProps);\n } catch (err: any) {\n err.message = `Error updating element [${err.message}], id: ${elProps.id}`;\n err.metadata = { elProps };\n throw err;\n }\n }\n\n /** Delete elements from the iModel.\n * @param ids The Ids of the elements to delete.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws [[ITwinError]] if deletion fails.\n */\n public deleteElement(ids: Id64Arg): void {\n this.verifyWriteable();\n const iModel = this.iModel;\n Id64.toIdSet(ids).forEach((id) => {\n try {\n this.iModel.elements[_cache].delete({ id });\n this.iModel.elements[_instanceKeyCache].deleteById(id);\n iModel[_nativeDb].deleteElement(id);\n } catch (err: any) {\n err.message = `Error deleting element [${err.message}], id: ${id}`;\n err.metadata = { elementId: id };\n throw err;\n }\n });\n }\n\n /**\n * Delete multiple elements from the iModel.\n * @param ids The ids of the elements to delete. All ids must be well-formed and valid [[Id64String]]s.\n * @returns A set of ids for any elements that could not be deleted.\n * @throws [[ITwinError]] if any of the supplied ids are not well-formed/valid [[Id64String]]s.\n * @beta\n */\n public deleteElements(ids: Id64Array): Id64Set {\n this.verifyWriteable();\n const invalidIds: Id64Set = new Set<Id64String>();\n for (const id of ids) {\n if (!Id64.isValidId64(id))\n invalidIds.add(id);\n }\n\n if (invalidIds.size > 0) {\n ITwinError.throwError({ message: `Invalid element ids: ${Array.from(invalidIds).join(\", \")}`, iTwinErrorId: { scope: \"imodel\", key: \"invalid-arguments\" } });\n }\n\n const failedToDelete = this.iModel[_nativeDb].deleteElements(ids);\n const failedToDeleteSet = failedToDelete ? Id64.toIdSet(failedToDelete) : new Set<Id64String>();\n\n for (const id of ids) {\n if (!failedToDeleteSet.has(id)) {\n this.iModel.elements[_cache].delete({ id });\n this.iModel.elements[_instanceKeyCache].deleteById(id);\n }\n }\n\n return failedToDeleteSet;\n }\n\n /** Insert a new aspect into the iModel.\n * @param aspectProps The properties of the new aspect.\n * @returns The newly inserted aspect Id.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if insertion fails.\n */\n public insertAspect(aspectProps: ElementAspectProps): Id64String {\n this.verifyWriteable();\n try {\n return this.iModel[_nativeDb].insertElementAspect(aspectProps);\n } catch (err: any) {\n const error = new IModelError(err.errorNumber, `Error inserting ElementAspect [${err.message}], class: ${aspectProps.classFullName}`, aspectProps);\n error.cause = err;\n throw error;\n }\n }\n\n /** Update an existing aspect in the iModel.\n * @param aspectProps The properties of the aspect to update.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if update fails.\n */\n public updateAspect(aspectProps: ElementAspectProps): void {\n this.verifyWriteable();\n try {\n this.iModel[_nativeDb].updateElementAspect(aspectProps);\n } catch (err: any) {\n const error = new IModelError(err.errorNumber, `Error updating ElementAspect [${err.message}], id: ${aspectProps.id}`, aspectProps);\n error.cause = err;\n throw error;\n }\n }\n\n /** Delete one or more aspects from the iModel.\n * @param aspectInstanceIds The Ids of the aspects to delete.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if deletion fails.\n */\n public deleteAspect(aspectInstanceIds: Id64Arg): void {\n this.verifyWriteable();\n Id64.toIdSet(aspectInstanceIds).forEach((aspectInstanceId) => {\n try {\n this.iModel[_nativeDb].deleteElementAspect(aspectInstanceId);\n } catch (err: any) {\n const error = new IModelError(err.errorNumber, `Error deleting ElementAspect [${err.message}], id: ${aspectInstanceId}`);\n error.cause = err;\n throw error;\n }\n });\n }\n\n /** Delete definition elements from the iModel when they are not referenced.\n * @param definitionElementIds The Ids of the definition elements to attempt to delete.\n * @returns The set of definition elements that were still in use and therefore not deleted.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if usage queries fail.\n */\n public deleteDefinitionElements(definitionElementIds: Id64Array): Id64Set {\n this.verifyWriteable();\n const usageInfo = this.iModel[_nativeDb].queryDefinitionElementUsage(definitionElementIds);\n if (!usageInfo)\n throw new IModelError(IModelStatus.BadRequest, \"Error querying for DefinitionElement usage\");\n\n const usedIdSet = usageInfo.usedIds ? Id64.toIdSet(usageInfo.usedIds) : new Set<Id64String>();\n const deleteIfUnused = (ids: Id64Array | undefined, used: Id64Set): void => {\n ids?.forEach((id) => {\n if (!used.has(id))\n this.deleteElement(id);\n });\n };\n\n try {\n this.iModel[_nativeDb].beginPurgeOperation();\n deleteIfUnused(usageInfo.spatialCategoryIds, usedIdSet);\n deleteIfUnused(usageInfo.drawingCategoryIds, usedIdSet);\n deleteIfUnused(usageInfo.viewDefinitionIds, usedIdSet);\n deleteIfUnused(usageInfo.geometryPartIds, usedIdSet);\n deleteIfUnused(usageInfo.lineStyleIds, usedIdSet);\n deleteIfUnused(usageInfo.renderMaterialIds, usedIdSet);\n deleteIfUnused(usageInfo.subCategoryIds, usedIdSet);\n deleteIfUnused(usageInfo.textureIds, usedIdSet);\n deleteIfUnused(usageInfo.displayStyleIds, usedIdSet);\n deleteIfUnused(usageInfo.categorySelectorIds, usedIdSet);\n deleteIfUnused(usageInfo.modelSelectorIds, usedIdSet);\n if (usageInfo.otherDefinitionElementIds)\n this.deleteElement(usageInfo.otherDefinitionElementIds);\n } finally {\n this.iModel[_nativeDb].endPurgeOperation();\n }\n\n if (usageInfo.viewDefinitionIds) {\n // Recheck view-related definitions after deleting view definitions that may have been their last reference.\n let viewRelatedIds: Id64Array = [];\n if (usageInfo.displayStyleIds)\n viewRelatedIds = viewRelatedIds.concat(usageInfo.displayStyleIds.filter((id) => usedIdSet.has(id)));\n\n if (usageInfo.categorySelectorIds)\n viewRelatedIds = viewRelatedIds.concat(usageInfo.categorySelectorIds.filter((id) => usedIdSet.has(id)));\n\n if (usageInfo.modelSelectorIds)\n viewRelatedIds = viewRelatedIds.concat(usageInfo.modelSelectorIds.filter((id) => usedIdSet.has(id)));\n\n if (viewRelatedIds.length > 0) {\n const viewRelatedUsageInfo = this.iModel[_nativeDb].queryDefinitionElementUsage(viewRelatedIds);\n if (viewRelatedUsageInfo) {\n const usedViewRelatedIdSet: Id64Set = viewRelatedUsageInfo.usedIds ? Id64.toIdSet(viewRelatedUsageInfo.usedIds) : new Set<Id64String>();\n try {\n this.iModel[_nativeDb].beginPurgeOperation();\n deleteIfUnused(viewRelatedUsageInfo.displayStyleIds, usedViewRelatedIdSet);\n deleteIfUnused(viewRelatedUsageInfo.categorySelectorIds, usedViewRelatedIdSet);\n deleteIfUnused(viewRelatedUsageInfo.modelSelectorIds, usedViewRelatedIdSet);\n } finally {\n this.iModel[_nativeDb].endPurgeOperation();\n }\n\n viewRelatedIds.forEach((id) => {\n if (!usedViewRelatedIdSet.has(id))\n usedIdSet.delete(id);\n });\n }\n }\n }\n\n return usedIdSet;\n }\n\n /** Insert a new model into the iModel.\n * @param props The data for the new model.\n * @returns The newly inserted model's Id.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if insertion fails.\n */\n public insertModel(props: ModelProps): Id64String {\n this.verifyWriteable();\n try {\n return props.id = this.iModel[_nativeDb].insertModel(props);\n } catch (err: any) {\n const error = new IModelError(err.errorNumber, `Error inserting model [${err.message}], class=${props.classFullName}`);\n error.cause = err;\n throw error;\n }\n }\n\n /** Update an existing model in the iModel.\n * @param props the properties of the model to change\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if update fails.\n */\n public updateModel(props: UpdateModelOptions): void {\n this.verifyWriteable();\n try {\n if (props.id)\n this.iModel.models[_cache].delete(props.id);\n\n this.iModel[_nativeDb].updateModel(props);\n } catch (err: any) {\n const error = new IModelError(err.errorNumber, `Error updating model [${err.message}], id: ${props.id}`);\n error.cause = err;\n throw error;\n }\n }\n\n /** Update the geometry guid of a model.\n * @param modelId The Id of the model to update.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if the update fails.\n */\n public updateGeometryGuid(modelId: Id64String): void {\n this.verifyWriteable();\n this.iModel.models[_cache].delete(modelId);\n const error = this.iModel[_nativeDb].updateModelGeometryGuid(modelId);\n if (error !== IModelStatus.Success)\n throw new IModelError(error, `Error updating geometry guid for model ${modelId}`);\n }\n\n /** Delete models from the iModel.\n * @param ids The Ids of the models to delete.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if deletion fails.\n */\n public deleteModel(ids: Id64Arg): void {\n this.verifyWriteable();\n Id64.toIdSet(ids).forEach((id) => {\n try {\n this.iModel.models[_cache].delete(id);\n this.iModel.models[_instanceKeyCache].deleteById(id);\n this.iModel[_nativeDb].deleteModel(id);\n } catch (err: any) {\n const error = new IModelError(err.errorNumber, `Error deleting model [${err.message}], id: ${id}`);\n error.cause = err;\n throw error;\n }\n });\n }\n\n /** Insert a new relationship into the iModel.\n * @param props The properties of the new relationship.\n * @returns The Id of the newly inserted relationship.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if the class is invalid for link-table insertion.\n */\n public insertRelationship(props: RelationshipProps): Id64String {\n this.verifyWriteable();\n if (!this.iModel[_nativeDb].isLinkTableRelationship(props.classFullName.replace(\".\", \":\")))\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Class '${props.classFullName}' must be a relationship class and it should be subclass of BisCore:ElementRefersToElements or BisCore:ElementDrivesElement.`);\n\n return props.id = this.iModel[_nativeDb].insertLinkTableRelationship(props);\n }\n\n /** Update an existing relationship in the iModel.\n * @param props the properties of the relationship to update.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public updateRelationship(props: RelationshipProps): void {\n this.verifyWriteable();\n this.iModel[_nativeDb].updateLinkTableRelationship(props);\n }\n\n /** Delete a relationship from the iModel.\n * @param props The properties of the relationship to delete.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public deleteRelationship(props: RelationshipProps): void {\n this.verifyWriteable();\n this.iModel[_nativeDb].deleteLinkTableRelationship(props);\n }\n\n /** Delete multiple relationships from the iModel.\n * @param props The properties of the relationships to delete.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public deleteRelationships(props: ReadonlyArray<RelationshipProps>): void {\n this.verifyWriteable();\n this.iModel[_nativeDb].deleteLinkTableRelationships(props);\n }\n\n\n /** Save a file property to the iModel.\n * @param prop The file property to save.\n * @param strValue String value.\n * @param blobVal Blob value.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public saveFileProperty(prop: FilePropertyProps, strValue: string | undefined, blobVal?: Uint8Array): void {\n this.verifyWriteable();\n const imodel = this.iModel;\n if (imodel.isBriefcaseDb()) {\n if (imodel.txns.isIndirectChanges) {\n throw new IModelError(IModelStatus.BadRequest, \"Cannot save file property while in an indirect change scope\");\n }\n }\n imodel[_nativeDb].saveFileProperty(prop, strValue, blobVal);\n }\n\n /** Delete a file property from the iModel.\n * @param prop The file property to delete.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public deleteFileProperty(prop: FilePropertyProps): void {\n this.saveFileProperty(prop, undefined, undefined);\n }\n\n /** Update the project extents of the iModel.\n * @param newExtents The new project extents.\n * @throws EditTxnError if this EditTxn is not active.\n * @throws IModelError if extents are invalid.\n */\n public updateProjectExtents(newExtents: Range3dProps): void {\n this.verifyWriteable();\n const extents = Range3d.fromJSON(newExtents);\n if (extents.isNull)\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Invalid project extents\");\n\n this.iModel.projectExtents = extents;\n this.updateIModelProps();\n }\n\n /** Update the ECEF location of the iModel.\n * @param ecef The new ECEF location.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public updateEcefLocation(ecef: EcefLocationProps): void {\n this.verifyWriteable();\n this.iModel.setEcefLocation(new EcefLocation(ecef));\n this.updateIModelProps();\n }\n\n /** Update the iModel props in the database from the current in-memory state.\n * @throws EditTxnError if this EditTxn is not active.\n */\n public updateIModelProps(): void {\n this.verifyWriteable();\n this.iModel[_nativeDb].updateIModelProps(this.iModel.toJSON());\n }\n\n private static readonly _settingPropNamespace = \"settings\";\n private static readonly _viewStoreProperty: FilePropertyProps = { namespace: \"itwinjs\", name: \"DefaultViewStore\" };\n\n /** Save a `SettingDictionary` in this iModel.\n * @param name The name for the SettingDictionary. If a dictionary by that name already exists, its value is replaced.\n * @param dict The SettingDictionary object to stringify and save.\n * @throws EditTxnError if this EditTxn is not active.\n * @beta\n */\n public saveSettingDictionary(name: string, dict: SettingsContainer): void {\n this.verifyWriteable();\n this.iModel.withSqliteStatement(\"REPLACE INTO be_Prop(id,SubId,TxnMode,Namespace,Name,strData) VALUES(0,0,0,?,?,?)\", (stmt) => {\n stmt.bindString(1, EditTxn._settingPropNamespace);\n stmt.bindString(2, name);\n stmt.bindString(3, JSON.stringify(dict));\n stmt.stepForWrite();\n });\n this.saveChanges(\"add settings\");\n }\n\n /** Delete a SettingDictionary from this iModel.\n * @param name The name of the dictionary to delete.\n * @throws EditTxnError if this EditTxn is not active.\n * @beta\n */\n public deleteSettingDictionary(name: string): void {\n this.verifyWriteable();\n this.iModel.withSqliteStatement(\"DELETE FROM be_Prop WHERE Namespace=? AND Name=?\", (stmt) => {\n stmt.bindString(1, EditTxn._settingPropNamespace);\n stmt.bindString(2, name);\n stmt.stepForWrite();\n });\n this.saveChanges(\"delete settings\");\n }\n\n /** Save a default ViewStore container reference in this iModel.\n * @param arg The cloud container properties for the ViewStore.\n * @throws EditTxnError if this EditTxn is not active.\n * @beta\n */\n public saveDefaultViewStore(arg: CloudSqlite.ContainerProps): void {\n this.verifyWriteable();\n const props = { baseUri: arg.baseUri, containerId: arg.containerId, storageType: arg.storageType }; // sanitize to only known properties\n this.saveFileProperty(EditTxn._viewStoreProperty, JSON.stringify(props));\n this.saveChanges(\"update default ViewStore\");\n }\n}\n\n/** Execute a callback within an explicit editing transaction. A new [[EditTxn]] is created, started,\n * and passed to `fn`. If `fn` returns normally (or its returned Promise resolves), the transaction\n * is committed. If `fn` throws (or its returned Promise rejects), the transaction is abandoned —\n * none of the changes made during the callback are saved — and the error is re-thrown.\n *\n * This is the recommended way to perform a scoped unit of work on an iModel. It ensures that\n * edits are committed atomically on success and rolled back on failure, without the caller needing\n * to manage `start` / `end` manually.\n *\n * @param iModel The iModel to edit.\n * @param fn A callback that receives the active [[EditTxn]] and performs edits.\n * @returns The value returned by `fn`.\n * @throws EditTxnError if the transaction cannot be started (e.g. unsaved changes or another EditTxn is active).\n * @throws Re-throws any error thrown by `fn` after abandoning the transaction.\n * @beta\n */\nexport function withEditTxn<T>(iModel: IModelDb, fn: (txn: EditTxn) => T): T;\n/** Execute a callback within an explicit editing transaction, supplying commit arguments.\n * @param iModel The iModel to edit.\n * @param saveArgs Description or structured arguments passed to [[EditTxn.saveChanges]] on save.\n * @param fn A callback that receives the active [[EditTxn]] and performs edits.\n * @returns The value returned by `fn`.\n * @beta\n */\nexport function withEditTxn<T>(iModel: IModelDb, saveArgs: string | SaveChangesArgs, fn: (txn: EditTxn) => T): T;\n/** Execute an async callback within an explicit editing transaction.\n * @param iModel The iModel to edit.\n * @param fn An async callback that receives the active [[EditTxn]] and performs edits.\n * @returns A Promise that resolves to the value returned by `fn`.\n * @beta\n */\nexport function withEditTxn<T>(iModel: IModelDb, fn: (txn: EditTxn) => Promise<T>): Promise<T>;\n/** Execute an async callback within an explicit editing transaction, supplying commit arguments.\n * @param iModel The iModel to edit.\n * @param saveArgs Description or structured arguments passed to [[EditTxn.saveChanges]] on save.\n * @param fn An async callback that receives the active [[EditTxn]] and performs edits.\n * @returns A Promise that resolves to the value returned by `fn`.\n * @beta\n */\nexport function withEditTxn<T>(iModel: IModelDb, saveArgs: string | SaveChangesArgs, fn: (txn: EditTxn) => Promise<T>): Promise<T>;\nexport function withEditTxn<T>(iModel: IModelDb, saveArgsOrFn: string | SaveChangesArgs | ((txn: EditTxn) => T | Promise<T>), maybeFn?: (txn: EditTxn) => T | Promise<T>): T | Promise<T> {\n const saveArgs = \"function\" === typeof saveArgsOrFn ? undefined : saveArgsOrFn;\n const fn = \"function\" === typeof saveArgsOrFn ? saveArgsOrFn : maybeFn;\n\n if (undefined === fn)\n throw new Error(\"withEditTxn requires a callback\");\n\n const txn = new EditTxn(iModel, \"\");\n txn.start();\n\n try {\n const result = fn(txn);\n if (result instanceof Promise) {\n return result.then((value) => {\n txn.end(\"save\", saveArgs);\n return value;\n }, (err) => {\n if (txn.isActive)\n txn.end(\"abandon\");\n\n throw err;\n });\n }\n\n txn.end(\"save\", saveArgs);\n return result;\n } catch (err) {\n if (txn.isActive)\n txn.end(\"abandon\");\n\n throw err;\n }\n}\n"]}
@@ -32,7 +32,7 @@ import { LockControl } from "./LockControl";
32
32
  import type { BlobContainer } from "./BlobContainerService";
33
33
  import { IModelDbFonts } from "./IModelDbFonts";
34
34
  import { _activeTxn, _cache, _implicitTxn, _instanceKeyCache, _nativeDb, _resetIModelDb } from "./internal/Symbols";
35
- import { ECVersion, SchemaContext } from "@itwin/ecschema-metadata";
35
+ import { ECSpecVersion, ECVersion, SchemaContext } from "@itwin/ecschema-metadata";
36
36
  import { SchemaMap } from "./Schema";
37
37
  import { ElementLRUCache, InstanceKeyLRUCache } from "./internal/ElementLRUCache";
38
38
  import { IntegrityCheckResult } from "./internal/IntegrityCheck";
@@ -1135,6 +1135,13 @@ export declare abstract class IModelDb extends IModel {
1135
1135
  * @beta
1136
1136
  */
1137
1137
  exportSchemas(outputDirectory: LocalFileName): void;
1138
+ /** Serializes the specified ECSchema to an XML string.
1139
+ * @param schemaName The name of the schema to serialize.
1140
+ * @param ecSpecVersion The ECXml specification version to use for the output XML.
1141
+ * @returns The schema XML string, or `undefined` if the schema was not found or serialization failed.
1142
+ * @beta
1143
+ */
1144
+ exportSchemaXmlString(schemaName: string, ecSpecVersion?: ECSpecVersion): string | undefined;
1138
1145
  /** Attempt to simplify the geometry stream of a single [[GeometricElement]] or [[GeometryPart]] as specified by `args`.
1139
1146
  * @beta
1140
1147
  */