@itwin/imodel-transformer 2.0.0-dev.72 → 2.0.0-dev.73
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.
- package/README.md +11 -0
- package/lib/Algo.d.ts.map +1 -0
- package/lib/{cjs/Algo.js → Algo.js} +1 -4
- package/lib/Algo.js.map +1 -0
- package/lib/BigMap.d.ts.map +1 -0
- package/lib/{cjs/BigMap.js → BigMap.js} +1 -5
- package/lib/BigMap.js.map +1 -0
- package/lib/BranchProvenanceInitializer.d.ts.map +1 -0
- package/lib/{cjs/BranchProvenanceInitializer.js → BranchProvenanceInitializer.js} +34 -37
- package/lib/BranchProvenanceInitializer.js.map +1 -0
- package/lib/ChangedElementForest.d.ts.map +1 -0
- package/lib/{cjs/ChangedElementForest.js → ChangedElementForest.js} +12 -14
- package/lib/ChangedElementForest.js.map +1 -0
- package/lib/{cjs/ChangesetScanner.d.ts → ChangesetScanner.d.ts} +2 -2
- package/lib/ChangesetScanner.d.ts.map +1 -0
- package/lib/{cjs/ChangesetScanner.js → ChangesetScanner.js} +19 -24
- package/lib/ChangesetScanner.js.map +1 -0
- package/lib/ECReferenceTypesCache.d.ts.map +1 -0
- package/lib/{cjs/ECReferenceTypesCache.js → ECReferenceTypesCache.js} +32 -37
- package/lib/ECReferenceTypesCache.js.map +1 -0
- package/lib/ECSqlReaderAsyncIterableIteratorAdapter.d.ts.map +1 -0
- package/lib/{cjs/ECSqlReaderAsyncIterableIteratorAdapter.js → ECSqlReaderAsyncIterableIteratorAdapter.js} +2 -7
- package/lib/ECSqlReaderAsyncIterableIteratorAdapter.js.map +1 -0
- package/lib/ElementAspectCleanup.d.ts.map +1 -0
- package/lib/{cjs/ElementAspectCleanup.js → ElementAspectCleanup.js} +9 -13
- package/lib/ElementAspectCleanup.js.map +1 -0
- package/lib/ElementAspectExportCoordinator.d.ts.map +1 -0
- package/lib/{cjs/ElementAspectExportCoordinator.js → ElementAspectExportCoordinator.js} +1 -5
- package/lib/ElementAspectExportCoordinator.js.map +1 -0
- package/lib/ElementAspectExportProcessor.d.ts.map +1 -0
- package/lib/{cjs/ElementAspectExportProcessor.js → ElementAspectExportProcessor.js} +10 -14
- package/lib/ElementAspectExportProcessor.js.map +1 -0
- package/lib/ElementBulkDelete.d.ts.map +1 -0
- package/lib/{cjs/ElementBulkDelete.js → ElementBulkDelete.js} +9 -12
- package/lib/{cjs/ElementBulkDelete.js.map → ElementBulkDelete.js.map} +1 -1
- package/lib/EntityExistenceCache.d.ts.map +1 -0
- package/lib/{cjs/EntityExistenceCache.js → EntityExistenceCache.js} +4 -8
- package/lib/EntityExistenceCache.js.map +1 -0
- package/lib/EntityUnifier.d.ts.map +1 -0
- package/lib/{cjs/EntityUnifier.js → EntityUnifier.js} +21 -22
- package/lib/EntityUnifier.js.map +1 -0
- package/lib/{cjs/IModelCloneContext.d.ts → IModelCloneContext.d.ts} +2 -2
- package/lib/IModelCloneContext.d.ts.map +1 -0
- package/lib/{cjs/IModelCloneContext.js → IModelCloneContext.js} +52 -56
- package/lib/IModelCloneContext.js.map +1 -0
- package/lib/{cjs/IModelExporter.d.ts → IModelExporter.d.ts} +1 -1
- package/lib/IModelExporter.d.ts.map +1 -0
- package/lib/{cjs/IModelExporter.js → IModelExporter.js} +156 -161
- package/lib/IModelExporter.js.map +1 -0
- package/lib/{cjs/IModelImporter.d.ts → IModelImporter.d.ts} +3 -3
- package/lib/IModelImporter.d.ts.map +1 -0
- package/lib/{cjs/IModelImporter.js → IModelImporter.js} +104 -109
- package/lib/IModelImporter.js.map +1 -0
- package/lib/IModelTransformContext.d.ts.map +1 -0
- package/lib/IModelTransformContext.js +2 -0
- package/lib/IModelTransformContext.js.map +1 -0
- package/lib/{cjs/IModelTransformer.d.ts → IModelTransformer.d.ts} +6 -6
- package/lib/IModelTransformer.d.ts.map +1 -0
- package/lib/{cjs/IModelTransformer.js → IModelTransformer.js} +240 -276
- package/lib/IModelTransformer.js.map +1 -0
- package/lib/IModelTransformerError.d.ts.map +1 -0
- package/lib/{cjs/IModelTransformerError.js → IModelTransformerError.js} +3 -6
- package/lib/IModelTransformerError.js.map +1 -0
- package/lib/{cjs/ProvenanceManager.d.ts → ProvenanceManager.d.ts} +3 -3
- package/lib/ProvenanceManager.d.ts.map +1 -0
- package/lib/{cjs/ProvenanceManager.js → ProvenanceManager.js} +69 -73
- package/lib/ProvenanceManager.js.map +1 -0
- package/lib/SourceClassKinds.d.ts.map +1 -0
- package/lib/{cjs/SourceClassKinds.js → SourceClassKinds.js} +1 -5
- package/lib/SourceClassKinds.js.map +1 -0
- package/lib/SyncTypeResolver.d.ts.map +1 -0
- package/lib/{cjs/SyncTypeResolver.js → SyncTypeResolver.js} +15 -19
- package/lib/SyncTypeResolver.js.map +1 -0
- package/lib/TransformerLoggerCategory.d.ts.map +1 -0
- package/lib/{cjs/TransformerLoggerCategory.js → TransformerLoggerCategory.js} +2 -5
- package/lib/TransformerLoggerCategory.js.map +1 -0
- package/lib/TransformerPackageMetadata.d.ts.map +1 -0
- package/lib/TransformerPackageMetadata.js +8 -0
- package/lib/TransformerPackageMetadata.js.map +1 -0
- package/lib/{cjs/imodel-transformer.d.ts → imodel-transformer.d.ts} +9 -9
- package/lib/imodel-transformer.d.ts.map +1 -0
- package/lib/imodel-transformer.js +88 -0
- package/lib/imodel-transformer.js.map +1 -0
- package/lib/{cjs/schema-processing → schema-processing}/DynamicSchemaUnionStrategy.d.ts +1 -1
- package/lib/schema-processing/DynamicSchemaUnionStrategy.d.ts.map +1 -0
- package/lib/{cjs/schema-processing → schema-processing}/DynamicSchemaUnionStrategy.js +16 -20
- package/lib/schema-processing/DynamicSchemaUnionStrategy.js.map +1 -0
- package/lib/{cjs/schema-processing → schema-processing}/SchemaProcessingCoordinator.d.ts +2 -2
- package/lib/schema-processing/SchemaProcessingCoordinator.d.ts.map +1 -0
- package/lib/{cjs/schema-processing → schema-processing}/SchemaProcessingCoordinator.js +15 -52
- package/lib/schema-processing/SchemaProcessingCoordinator.js.map +1 -0
- package/lib/schema-processing/SchemaProcessingStrategy.d.ts.map +1 -0
- package/lib/{cjs/schema-processing → schema-processing}/SchemaProcessingStrategy.js +1 -5
- package/lib/schema-processing/SchemaProcessingStrategy.js.map +1 -0
- package/lib/schema-processing.d.ts +7 -0
- package/lib/schema-processing.d.ts.map +1 -0
- package/lib/schema-processing.js +11 -0
- package/lib/schema-processing.js.map +1 -0
- package/package.json +14 -14
- package/lib/cjs/Algo.d.ts.map +0 -1
- package/lib/cjs/Algo.js.map +0 -1
- package/lib/cjs/BigMap.d.ts.map +0 -1
- package/lib/cjs/BigMap.js.map +0 -1
- package/lib/cjs/BranchProvenanceInitializer.d.ts.map +0 -1
- package/lib/cjs/BranchProvenanceInitializer.js.map +0 -1
- package/lib/cjs/ChangedElementForest.d.ts.map +0 -1
- package/lib/cjs/ChangedElementForest.js.map +0 -1
- package/lib/cjs/ChangesetScanner.d.ts.map +0 -1
- package/lib/cjs/ChangesetScanner.js.map +0 -1
- package/lib/cjs/ECReferenceTypesCache.d.ts.map +0 -1
- package/lib/cjs/ECReferenceTypesCache.js.map +0 -1
- package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.d.ts.map +0 -1
- package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.js.map +0 -1
- package/lib/cjs/ElementAspectCleanup.d.ts.map +0 -1
- package/lib/cjs/ElementAspectCleanup.js.map +0 -1
- package/lib/cjs/ElementAspectExportCoordinator.d.ts.map +0 -1
- package/lib/cjs/ElementAspectExportCoordinator.js.map +0 -1
- package/lib/cjs/ElementAspectExportProcessor.d.ts.map +0 -1
- package/lib/cjs/ElementAspectExportProcessor.js.map +0 -1
- package/lib/cjs/ElementBulkDelete.d.ts.map +0 -1
- package/lib/cjs/EntityExistenceCache.d.ts.map +0 -1
- package/lib/cjs/EntityExistenceCache.js.map +0 -1
- package/lib/cjs/EntityUnifier.d.ts.map +0 -1
- package/lib/cjs/EntityUnifier.js.map +0 -1
- package/lib/cjs/IModelCloneContext.d.ts.map +0 -1
- package/lib/cjs/IModelCloneContext.js.map +0 -1
- package/lib/cjs/IModelExporter.d.ts.map +0 -1
- package/lib/cjs/IModelExporter.js.map +0 -1
- package/lib/cjs/IModelImporter.d.ts.map +0 -1
- package/lib/cjs/IModelImporter.js.map +0 -1
- package/lib/cjs/IModelTransformContext.d.ts.map +0 -1
- package/lib/cjs/IModelTransformContext.js +0 -3
- package/lib/cjs/IModelTransformContext.js.map +0 -1
- package/lib/cjs/IModelTransformer.d.ts.map +0 -1
- package/lib/cjs/IModelTransformer.js.map +0 -1
- package/lib/cjs/IModelTransformerError.d.ts.map +0 -1
- package/lib/cjs/IModelTransformerError.js.map +0 -1
- package/lib/cjs/ProvenanceManager.d.ts.map +0 -1
- package/lib/cjs/ProvenanceManager.js.map +0 -1
- package/lib/cjs/SourceClassKinds.d.ts.map +0 -1
- package/lib/cjs/SourceClassKinds.js.map +0 -1
- package/lib/cjs/SyncTypeResolver.d.ts.map +0 -1
- package/lib/cjs/SyncTypeResolver.js.map +0 -1
- package/lib/cjs/TransformerLoggerCategory.d.ts.map +0 -1
- package/lib/cjs/TransformerLoggerCategory.js.map +0 -1
- package/lib/cjs/TransformerPackageMetadata.d.ts.map +0 -1
- package/lib/cjs/TransformerPackageMetadata.js +0 -47
- package/lib/cjs/TransformerPackageMetadata.js.map +0 -1
- package/lib/cjs/imodel-transformer.d.ts.map +0 -1
- package/lib/cjs/imodel-transformer.js +0 -125
- package/lib/cjs/imodel-transformer.js.map +0 -1
- package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.d.ts.map +0 -1
- package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.js.map +0 -1
- package/lib/cjs/schema-processing/SchemaProcessingCoordinator.d.ts.map +0 -1
- package/lib/cjs/schema-processing/SchemaProcessingCoordinator.js.map +0 -1
- package/lib/cjs/schema-processing/SchemaProcessingStrategy.d.ts.map +0 -1
- package/lib/cjs/schema-processing/SchemaProcessingStrategy.js.map +0 -1
- package/lib/cjs/schema-processing.d.ts +0 -7
- package/lib/cjs/schema-processing.d.ts.map +0 -1
- package/lib/cjs/schema-processing.js +0 -27
- package/lib/cjs/schema-processing.js.map +0 -1
- /package/lib/{cjs/Algo.d.ts → Algo.d.ts} +0 -0
- /package/lib/{cjs/BigMap.d.ts → BigMap.d.ts} +0 -0
- /package/lib/{cjs/BranchProvenanceInitializer.d.ts → BranchProvenanceInitializer.d.ts} +0 -0
- /package/lib/{cjs/ChangedElementForest.d.ts → ChangedElementForest.d.ts} +0 -0
- /package/lib/{cjs/ECReferenceTypesCache.d.ts → ECReferenceTypesCache.d.ts} +0 -0
- /package/lib/{cjs/ECSqlReaderAsyncIterableIteratorAdapter.d.ts → ECSqlReaderAsyncIterableIteratorAdapter.d.ts} +0 -0
- /package/lib/{cjs/ElementAspectCleanup.d.ts → ElementAspectCleanup.d.ts} +0 -0
- /package/lib/{cjs/ElementAspectExportCoordinator.d.ts → ElementAspectExportCoordinator.d.ts} +0 -0
- /package/lib/{cjs/ElementAspectExportProcessor.d.ts → ElementAspectExportProcessor.d.ts} +0 -0
- /package/lib/{cjs/ElementBulkDelete.d.ts → ElementBulkDelete.d.ts} +0 -0
- /package/lib/{cjs/EntityExistenceCache.d.ts → EntityExistenceCache.d.ts} +0 -0
- /package/lib/{cjs/EntityUnifier.d.ts → EntityUnifier.d.ts} +0 -0
- /package/lib/{cjs/IModelTransformContext.d.ts → IModelTransformContext.d.ts} +0 -0
- /package/lib/{cjs/IModelTransformerError.d.ts → IModelTransformerError.d.ts} +0 -0
- /package/lib/{cjs/SourceClassKinds.d.ts → SourceClassKinds.d.ts} +0 -0
- /package/lib/{cjs/SyncTypeResolver.d.ts → SyncTypeResolver.d.ts} +0 -0
- /package/lib/{cjs/TransformerLoggerCategory.d.ts → TransformerLoggerCategory.d.ts} +0 -0
- /package/lib/{cjs/TransformerPackageMetadata.d.ts → TransformerPackageMetadata.d.ts} +0 -0
- /package/lib/{cjs/schema-processing → schema-processing}/SchemaProcessingStrategy.d.ts +0 -0
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IModelImporter = void 0;
|
|
4
|
-
exports.hasEntityChanged = hasEntityChanged;
|
|
5
1
|
/*---------------------------------------------------------------------------------------------
|
|
6
2
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
7
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
@@ -9,16 +5,16 @@ exports.hasEntityChanged = hasEntityChanged;
|
|
|
9
5
|
/** @packageDocumentation
|
|
10
6
|
* @module iModels
|
|
11
7
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const loggerCategory =
|
|
8
|
+
import { Guid, Id64, IModelStatus, ITwinError, Logger, } from "@itwin/core-bentley";
|
|
9
|
+
import { Base64EncodedString, ConcreteEntityTypes, ECJsNames, IModel, IModelError, RelatedElement, } from "@itwin/core-common";
|
|
10
|
+
import { TransformerLoggerCategory } from "./TransformerLoggerCategory.js";
|
|
11
|
+
import { BulkDeleteElementsStatus, EntityReferences, IModelDb, SubCategory, } from "@itwin/core-backend";
|
|
12
|
+
import { strict as assert } from "node:assert";
|
|
13
|
+
import { ElementAspectCleanup } from "./ElementAspectCleanup.js";
|
|
14
|
+
import { EntityClass, PropertyType, RelationshipClass, } from "@itwin/ecschema-metadata";
|
|
15
|
+
import { IModelTransformerError, IModelTransformerErrorScope, } from "./IModelTransformerError.js";
|
|
16
|
+
import { planBulkDelete } from "./ElementBulkDelete.js";
|
|
17
|
+
const loggerCategory = TransformerLoggerCategory.IModelImporter;
|
|
22
18
|
/** Lists the first kept references for a log message. */
|
|
23
19
|
function formatKeptReferences(keptReferences) {
|
|
24
20
|
const maxListed = 10;
|
|
@@ -35,7 +31,7 @@ function formatKeptReferences(keptReferences) {
|
|
|
35
31
|
* @see [IModelTransformer]($transformer)
|
|
36
32
|
* @beta
|
|
37
33
|
*/
|
|
38
|
-
class IModelImporter {
|
|
34
|
+
export class IModelImporter {
|
|
39
35
|
/** The read/write target iModel. */
|
|
40
36
|
targetDb;
|
|
41
37
|
/** The [[EditTxn]] used for write operations on the target iModel.
|
|
@@ -90,8 +86,8 @@ class IModelImporter {
|
|
|
90
86
|
doNotUpdateElementIds = new Set([]);
|
|
91
87
|
/** This set is ONLY used for elements that are always present even in an "empty" iModel. We will use this set to filter out changes to root elements if [[IModelTransformOptions.skipPropagateChangesToRootElements]] is false. */
|
|
92
88
|
_rootElementIds = new Set([
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
IModel.rootSubjectId,
|
|
90
|
+
IModel.dictionaryId,
|
|
95
91
|
IModelImporter._realityDataSourceLinkPartitionStaticId,
|
|
96
92
|
]);
|
|
97
93
|
/** The number of entity changes before incremental progress should be reported via the [[onProgress]] callback. */
|
|
@@ -116,7 +112,7 @@ class IModelImporter {
|
|
|
116
112
|
skipPropagateChangesToRootElements: options?.skipPropagateChangesToRootElements ?? true,
|
|
117
113
|
};
|
|
118
114
|
this._duplicateCodeValueMap = new Map();
|
|
119
|
-
this._elementAspectCleanup = new
|
|
115
|
+
this._elementAspectCleanup = new ElementAspectCleanup(this.targetDb, this._editTxn, async (aspect) => this.onDeleteElementAspect(aspect));
|
|
120
116
|
}
|
|
121
117
|
/** Register a transformation-scoped existence cache for delete invalidation.
|
|
122
118
|
* @internal
|
|
@@ -152,16 +148,16 @@ class IModelImporter {
|
|
|
152
148
|
}
|
|
153
149
|
/** Import the specified ModelProps (either as an insert or an update) into the target iModel. */
|
|
154
150
|
async importModel(modelProps) {
|
|
155
|
-
if (undefined === modelProps.id || !
|
|
156
|
-
|
|
151
|
+
if (undefined === modelProps.id || !Id64.isValidId64(modelProps.id))
|
|
152
|
+
ITwinError.throwError({
|
|
157
153
|
iTwinErrorId: {
|
|
158
|
-
scope:
|
|
159
|
-
key:
|
|
154
|
+
scope: IModelTransformerErrorScope,
|
|
155
|
+
key: IModelTransformerError.InvalidModelId,
|
|
160
156
|
},
|
|
161
157
|
message: "Model Id not provided, should be the same as the ModeledElementId",
|
|
162
158
|
});
|
|
163
159
|
if (this.doNotUpdateElement(modelProps.id)) {
|
|
164
|
-
|
|
160
|
+
Logger.logInfo(loggerCategory, `Do not update target model ${modelProps.id}`);
|
|
165
161
|
return;
|
|
166
162
|
}
|
|
167
163
|
try {
|
|
@@ -172,8 +168,8 @@ class IModelImporter {
|
|
|
172
168
|
}
|
|
173
169
|
catch (error) {
|
|
174
170
|
// catch NotFound error and insertModel
|
|
175
|
-
if (error instanceof
|
|
176
|
-
error.errorNumber ===
|
|
171
|
+
if (error instanceof IModelError &&
|
|
172
|
+
error.errorNumber === IModelStatus.NotFound) {
|
|
177
173
|
await this.onInsertModel(modelProps);
|
|
178
174
|
return;
|
|
179
175
|
}
|
|
@@ -186,17 +182,17 @@ class IModelImporter {
|
|
|
186
182
|
async onInsertModel(modelProps) {
|
|
187
183
|
try {
|
|
188
184
|
const modelId = this._editTxn.insertModel(modelProps);
|
|
189
|
-
|
|
185
|
+
Logger.logInfo(loggerCategory, `Inserted ${this.formatModelForLogger(modelProps)}`);
|
|
190
186
|
await this.trackProgress();
|
|
191
187
|
return modelId;
|
|
192
188
|
}
|
|
193
189
|
catch (error) {
|
|
194
190
|
if (!this.targetDb.containsClass(modelProps.classFullName)) {
|
|
195
191
|
// Translate only confirmed missing-class failures; otherwise retain the backend error's identity.
|
|
196
|
-
|
|
192
|
+
ITwinError.throwError({
|
|
197
193
|
iTwinErrorId: {
|
|
198
|
-
scope:
|
|
199
|
-
key:
|
|
194
|
+
scope: IModelTransformerErrorScope,
|
|
195
|
+
key: IModelTransformerError.TargetClassNotFound,
|
|
200
196
|
},
|
|
201
197
|
message: `Model class "${modelProps.classFullName}" not found in the target iModel. Was the latest version of the schema imported?`,
|
|
202
198
|
cause: error,
|
|
@@ -210,7 +206,7 @@ class IModelImporter {
|
|
|
210
206
|
*/
|
|
211
207
|
async onUpdateModel(modelProps) {
|
|
212
208
|
this._editTxn.updateModel(modelProps);
|
|
213
|
-
|
|
209
|
+
Logger.logInfo(loggerCategory, `Updated ${this.formatModelForLogger(modelProps)}`);
|
|
214
210
|
await this.trackProgress();
|
|
215
211
|
}
|
|
216
212
|
/** Format a Model for the Logger. */
|
|
@@ -227,12 +223,12 @@ class IModelImporter {
|
|
|
227
223
|
await this.onUpdateElement(elemProps);
|
|
228
224
|
}
|
|
229
225
|
catch (err) {
|
|
230
|
-
if (err.errorNumber ===
|
|
231
|
-
(
|
|
226
|
+
if (err.errorNumber === IModelStatus.DuplicateCode) {
|
|
227
|
+
assert(elemProps.code.value !== undefined, "NULL code values are always considered unique and cannot clash");
|
|
232
228
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
233
229
|
this._duplicateCodeValueMap.set(elemProps.id, elemProps.code.value);
|
|
234
230
|
// Using NULL code values as an alternative is not valid because definition elements cannot have NULL code values.
|
|
235
|
-
elemProps.code.value =
|
|
231
|
+
elemProps.code.value = Guid.createValue();
|
|
236
232
|
await this.onUpdateElement(elemProps);
|
|
237
233
|
}
|
|
238
234
|
else {
|
|
@@ -244,15 +240,15 @@ class IModelImporter {
|
|
|
244
240
|
async importElement(elementProps) {
|
|
245
241
|
if (undefined !== elementProps.id &&
|
|
246
242
|
this.doNotUpdateElement(elementProps.id)) {
|
|
247
|
-
|
|
243
|
+
Logger.logInfo(loggerCategory, `Do not update target element ${elementProps.id}`);
|
|
248
244
|
return elementProps.id;
|
|
249
245
|
}
|
|
250
246
|
if (this.options.preserveElementIdsForFiltering) {
|
|
251
247
|
if (elementProps.id === undefined) {
|
|
252
|
-
|
|
248
|
+
ITwinError.throwError({
|
|
253
249
|
iTwinErrorId: {
|
|
254
|
-
scope:
|
|
255
|
-
key:
|
|
250
|
+
scope: IModelTransformerErrorScope,
|
|
251
|
+
key: IModelTransformerError.ElementIdRequired,
|
|
256
252
|
},
|
|
257
253
|
message: "elementProps.id must be defined during a preserveIds operation",
|
|
258
254
|
});
|
|
@@ -296,23 +292,23 @@ class IModelImporter {
|
|
|
296
292
|
});
|
|
297
293
|
// set the id like [IModelDb.insertElement]($backend), does, the raw nativeDb method does not
|
|
298
294
|
elementProps.id = elementId;
|
|
299
|
-
|
|
295
|
+
Logger.logInfo(loggerCategory, `Inserted ${this.formatElementForLogger(elementProps)}`);
|
|
300
296
|
await this.trackProgress();
|
|
301
297
|
if (this.options.simplifyElementGeometry) {
|
|
302
298
|
this.targetDb.simplifyElementGeometry({
|
|
303
299
|
id: elementId,
|
|
304
300
|
convertBReps: true,
|
|
305
301
|
});
|
|
306
|
-
|
|
302
|
+
Logger.logInfo(loggerCategory, `Simplified element geometry for ${this.formatElementForLogger(elementProps)}`);
|
|
307
303
|
}
|
|
308
304
|
return elementId;
|
|
309
305
|
}
|
|
310
306
|
catch (error) {
|
|
311
307
|
if (!this.targetDb.containsClass(elementProps.classFullName)) {
|
|
312
|
-
|
|
308
|
+
ITwinError.throwError({
|
|
313
309
|
iTwinErrorId: {
|
|
314
|
-
scope:
|
|
315
|
-
key:
|
|
310
|
+
scope: IModelTransformerErrorScope,
|
|
311
|
+
key: IModelTransformerError.TargetClassNotFound,
|
|
316
312
|
},
|
|
317
313
|
message: `Element class "${elementProps.classFullName}" not found in the target iModel. Was the latest version of the schema imported?`,
|
|
318
314
|
cause: error,
|
|
@@ -326,23 +322,23 @@ class IModelImporter {
|
|
|
326
322
|
*/
|
|
327
323
|
async onUpdateElement(elementProps) {
|
|
328
324
|
if (!elementProps.id) {
|
|
329
|
-
|
|
325
|
+
ITwinError.throwError({
|
|
330
326
|
iTwinErrorId: {
|
|
331
|
-
scope:
|
|
332
|
-
key:
|
|
327
|
+
scope: IModelTransformerErrorScope,
|
|
328
|
+
key: IModelTransformerError.ElementIdRequired,
|
|
333
329
|
},
|
|
334
330
|
message: "ElementId not provided",
|
|
335
331
|
});
|
|
336
332
|
}
|
|
337
333
|
this._editTxn.updateElement(elementProps);
|
|
338
|
-
|
|
334
|
+
Logger.logInfo(loggerCategory, `Updated ${this.formatElementForLogger(elementProps)}`);
|
|
339
335
|
await this.trackProgress();
|
|
340
336
|
if (this.options.simplifyElementGeometry) {
|
|
341
337
|
this.targetDb.simplifyElementGeometry({
|
|
342
338
|
id: elementProps.id,
|
|
343
339
|
convertBReps: true,
|
|
344
340
|
});
|
|
345
|
-
|
|
341
|
+
Logger.logInfo(loggerCategory, `Simplified element geometry for ${this.formatElementForLogger(elementProps)}`);
|
|
346
342
|
}
|
|
347
343
|
}
|
|
348
344
|
/** Deletes one target element tree through [[deleteElements]]. */
|
|
@@ -355,9 +351,9 @@ class IModelImporter {
|
|
|
355
351
|
* @note An override must call `super.onDeleteElements` once to perform the deletion.
|
|
356
352
|
*/
|
|
357
353
|
async onDeleteElements(elementIds) {
|
|
358
|
-
const plan = await
|
|
354
|
+
const plan = await planBulkDelete(this.targetDb, elementIds);
|
|
359
355
|
if (plan.keptReferences.size > 0) {
|
|
360
|
-
|
|
356
|
+
Logger.logWarning(loggerCategory, `Kept ${plan.keptReferences.size} elements that elements outside the deleted trees still reference, and the elements that contain them: ${formatKeptReferences(plan.keptReferences)}`);
|
|
361
357
|
}
|
|
362
358
|
if (plan.phases.length === 0)
|
|
363
359
|
return;
|
|
@@ -366,18 +362,18 @@ class IModelImporter {
|
|
|
366
362
|
rootCount += roots.length;
|
|
367
363
|
this.deleteElementRoots(roots);
|
|
368
364
|
}
|
|
369
|
-
|
|
365
|
+
Logger.logInfo(loggerCategory, `Deleted ${elementIds.size} requested element trees using ${rootCount} native deletion roots in ${plan.phases.length} native operations`);
|
|
370
366
|
await this.trackProgress(elementIds.size);
|
|
371
367
|
}
|
|
372
368
|
deleteElementRoots(roots) {
|
|
373
369
|
const result = this._editTxn.deleteElements(roots);
|
|
374
|
-
if (result.status !==
|
|
375
|
-
|
|
370
|
+
if (result.status !== BulkDeleteElementsStatus.Success) {
|
|
371
|
+
ITwinError.throwError({
|
|
376
372
|
iTwinErrorId: {
|
|
377
|
-
scope:
|
|
378
|
-
key:
|
|
373
|
+
scope: IModelTransformerErrorScope,
|
|
374
|
+
key: IModelTransformerError.ElementBulkDeleteFailed,
|
|
379
375
|
},
|
|
380
|
-
message: `Bulk element deletion failed: status ${
|
|
376
|
+
message: `Bulk element deletion failed: status ${BulkDeleteElementsStatus[result.status]}, ` +
|
|
381
377
|
`SQLite status ${result.sqlDeleteStatus}, failed element IDs: ${[
|
|
382
378
|
...result.failedIds,
|
|
383
379
|
].join(", ")}`,
|
|
@@ -399,7 +395,7 @@ class IModelImporter {
|
|
|
399
395
|
idsToDelete.add(elementId);
|
|
400
396
|
continue;
|
|
401
397
|
}
|
|
402
|
-
|
|
398
|
+
Logger.logInfo(loggerCategory, `Do not delete target element ${elementId}`);
|
|
403
399
|
}
|
|
404
400
|
if (idsToDelete.size === 0)
|
|
405
401
|
return;
|
|
@@ -413,13 +409,13 @@ class IModelImporter {
|
|
|
413
409
|
*/
|
|
414
410
|
async onDeleteModel(modelId) {
|
|
415
411
|
this._editTxn.deleteModel(modelId);
|
|
416
|
-
|
|
412
|
+
Logger.logInfo(loggerCategory, `Deleted model ${modelId}`);
|
|
417
413
|
await this.trackProgress();
|
|
418
414
|
}
|
|
419
415
|
/** Delete the specified Model from the target iModel. */
|
|
420
416
|
async deleteModel(modelId) {
|
|
421
417
|
await this.onDeleteModel(modelId);
|
|
422
|
-
const modelReference =
|
|
418
|
+
const modelReference = EntityReferences.fromEntityType(modelId, ConcreteEntityTypes.Model);
|
|
423
419
|
for (const cache of this._entityExistenceCaches)
|
|
424
420
|
cache.invalidate(this.targetDb, modelReference);
|
|
425
421
|
}
|
|
@@ -506,7 +502,7 @@ class IModelImporter {
|
|
|
506
502
|
}
|
|
507
503
|
}
|
|
508
504
|
}
|
|
509
|
-
(
|
|
505
|
+
assert(result.every((r) => r !== undefined));
|
|
510
506
|
return result;
|
|
511
507
|
}
|
|
512
508
|
/** Insert the ElementAspect into the target iModel.
|
|
@@ -515,16 +511,16 @@ class IModelImporter {
|
|
|
515
511
|
async onInsertElementAspect(aspectProps) {
|
|
516
512
|
try {
|
|
517
513
|
const id = this._editTxn.insertAspect(aspectProps);
|
|
518
|
-
|
|
514
|
+
Logger.logInfo(loggerCategory, `Inserted ${this.formatElementAspectForLogger(aspectProps)}`);
|
|
519
515
|
await this.trackProgress();
|
|
520
516
|
return id;
|
|
521
517
|
}
|
|
522
518
|
catch (error) {
|
|
523
519
|
if (!this.targetDb.containsClass(aspectProps.classFullName)) {
|
|
524
|
-
|
|
520
|
+
ITwinError.throwError({
|
|
525
521
|
iTwinErrorId: {
|
|
526
|
-
scope:
|
|
527
|
-
key:
|
|
522
|
+
scope: IModelTransformerErrorScope,
|
|
523
|
+
key: IModelTransformerError.TargetClassNotFound,
|
|
528
524
|
},
|
|
529
525
|
message: `ElementAspect class "${aspectProps.classFullName}" not found in the target iModel. Was the latest version of the schema imported?`,
|
|
530
526
|
cause: error,
|
|
@@ -538,7 +534,7 @@ class IModelImporter {
|
|
|
538
534
|
*/
|
|
539
535
|
async onUpdateElementAspect(aspectProps) {
|
|
540
536
|
this._editTxn.updateAspect(aspectProps);
|
|
541
|
-
|
|
537
|
+
Logger.logInfo(loggerCategory, `Updated ${this.formatElementAspectForLogger(aspectProps)}`);
|
|
542
538
|
await this.trackProgress();
|
|
543
539
|
}
|
|
544
540
|
/** Delete the specified ElementAspect from the target iModel.
|
|
@@ -546,7 +542,7 @@ class IModelImporter {
|
|
|
546
542
|
*/
|
|
547
543
|
async onDeleteElementAspect(targetElementAspect) {
|
|
548
544
|
this._editTxn.deleteAspect(targetElementAspect.id);
|
|
549
|
-
|
|
545
|
+
Logger.logInfo(loggerCategory, `Deleted ${this.formatElementAspectForLogger(targetElementAspect)}`);
|
|
550
546
|
await this.trackProgress();
|
|
551
547
|
}
|
|
552
548
|
/** Format an ElementAspect for the Logger. */
|
|
@@ -558,14 +554,14 @@ class IModelImporter {
|
|
|
558
554
|
*/
|
|
559
555
|
async importRelationship(relationshipProps) {
|
|
560
556
|
if (undefined === relationshipProps.sourceId ||
|
|
561
|
-
!
|
|
562
|
-
|
|
563
|
-
return
|
|
557
|
+
!Id64.isValidId64(relationshipProps.sourceId)) {
|
|
558
|
+
Logger.logInfo(loggerCategory, `Ignoring ${relationshipProps.classFullName} instance because of invalid RelationshipProps.sourceId`);
|
|
559
|
+
return Id64.invalid;
|
|
564
560
|
}
|
|
565
561
|
if (undefined === relationshipProps.targetId ||
|
|
566
|
-
!
|
|
567
|
-
|
|
568
|
-
return
|
|
562
|
+
!Id64.isValidId64(relationshipProps.targetId)) {
|
|
563
|
+
Logger.logInfo(loggerCategory, `Ignoring ${relationshipProps.classFullName} instance because of invalid RelationshipProps.targetId`);
|
|
564
|
+
return Id64.invalid;
|
|
569
565
|
}
|
|
570
566
|
// check for an existing relationship
|
|
571
567
|
const relSourceAndTarget = {
|
|
@@ -592,16 +588,16 @@ class IModelImporter {
|
|
|
592
588
|
async onInsertRelationship(relationshipProps) {
|
|
593
589
|
try {
|
|
594
590
|
const targetRelInstanceId = this._editTxn.insertRelationship(relationshipProps);
|
|
595
|
-
|
|
591
|
+
Logger.logInfo(loggerCategory, `Inserted ${this.formatRelationshipForLogger(relationshipProps)}`);
|
|
596
592
|
await this.trackProgress();
|
|
597
593
|
return targetRelInstanceId;
|
|
598
594
|
}
|
|
599
595
|
catch (error) {
|
|
600
596
|
if (!this.targetDb.containsClass(relationshipProps.classFullName)) {
|
|
601
|
-
|
|
597
|
+
ITwinError.throwError({
|
|
602
598
|
iTwinErrorId: {
|
|
603
|
-
scope:
|
|
604
|
-
key:
|
|
599
|
+
scope: IModelTransformerErrorScope,
|
|
600
|
+
key: IModelTransformerError.TargetClassNotFound,
|
|
605
601
|
},
|
|
606
602
|
message: `Relationship class "${relationshipProps.classFullName}" not found in the target iModel. Was the latest version of the schema imported?`,
|
|
607
603
|
cause: error,
|
|
@@ -615,16 +611,16 @@ class IModelImporter {
|
|
|
615
611
|
*/
|
|
616
612
|
async onUpdateRelationship(relationshipProps) {
|
|
617
613
|
if (!relationshipProps.id) {
|
|
618
|
-
|
|
614
|
+
ITwinError.throwError({
|
|
619
615
|
iTwinErrorId: {
|
|
620
|
-
scope:
|
|
621
|
-
key:
|
|
616
|
+
scope: IModelTransformerErrorScope,
|
|
617
|
+
key: IModelTransformerError.RelationshipIdRequired,
|
|
622
618
|
},
|
|
623
619
|
message: "Relationship instance Id not provided",
|
|
624
620
|
});
|
|
625
621
|
}
|
|
626
622
|
this._editTxn.updateRelationship(relationshipProps);
|
|
627
|
-
|
|
623
|
+
Logger.logInfo(loggerCategory, `Updated ${this.formatRelationshipForLogger(relationshipProps)}`);
|
|
628
624
|
await this.trackProgress();
|
|
629
625
|
}
|
|
630
626
|
/** Delete the specified Relationship from the target iModel. */
|
|
@@ -634,7 +630,7 @@ class IModelImporter {
|
|
|
634
630
|
id: relationshipProps.id,
|
|
635
631
|
classFullName: relationshipProps.classFullName,
|
|
636
632
|
});
|
|
637
|
-
|
|
633
|
+
Logger.logInfo(loggerCategory, `Deleted relationship ${relationshipProps.classFullName} id=${relationshipProps.id}`);
|
|
638
634
|
await this.trackProgress();
|
|
639
635
|
}
|
|
640
636
|
/** Delete the specified Relationship from the target iModel. */
|
|
@@ -667,9 +663,9 @@ class IModelImporter {
|
|
|
667
663
|
reportExtentsWithOutliers: true,
|
|
668
664
|
reportOutliers: true,
|
|
669
665
|
});
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
666
|
+
Logger.logInfo(loggerCategory, `Current projectExtents=${JSON.stringify(this.targetDb.projectExtents)}`);
|
|
667
|
+
Logger.logInfo(loggerCategory, `Computed projectExtents without outliers=${JSON.stringify(computedProjectExtents.extents)}`);
|
|
668
|
+
Logger.logInfo(loggerCategory, `Computed projectExtents with outliers=${JSON.stringify(computedProjectExtents.extentsWithOutliers)}`);
|
|
673
669
|
if (this.options.autoExtendProjectExtents) {
|
|
674
670
|
const excludeOutliers = typeof this.options.autoExtendProjectExtents === "object"
|
|
675
671
|
? this.options.autoExtendProjectExtents.excludeOutliers
|
|
@@ -683,21 +679,21 @@ class IModelImporter {
|
|
|
683
679
|
: computedProjectExtents.extents;
|
|
684
680
|
if (!newProjectExtents.isAlmostEqual(this.targetDb.projectExtents)) {
|
|
685
681
|
this._editTxn.updateProjectExtents(newProjectExtents);
|
|
686
|
-
|
|
682
|
+
Logger.logInfo(loggerCategory, `Updated projectExtents=${JSON.stringify(this.targetDb.projectExtents)}`);
|
|
687
683
|
}
|
|
688
684
|
if (!excludeOutliers &&
|
|
689
685
|
computedProjectExtents.outliers &&
|
|
690
686
|
computedProjectExtents.outliers.length > 0) {
|
|
691
|
-
|
|
687
|
+
Logger.logInfo(loggerCategory, `${computedProjectExtents.outliers.length} outliers detected within projectExtents`);
|
|
692
688
|
}
|
|
693
689
|
}
|
|
694
690
|
else {
|
|
695
691
|
if (!this.targetDb.projectExtents.containsRange(computedProjectExtents.extents)) {
|
|
696
|
-
|
|
692
|
+
Logger.logWarning(loggerCategory, "Current project extents may be too small");
|
|
697
693
|
}
|
|
698
694
|
if (computedProjectExtents.outliers &&
|
|
699
695
|
computedProjectExtents.outliers.length > 0) {
|
|
700
|
-
|
|
696
|
+
Logger.logInfo(loggerCategory, `${computedProjectExtents.outliers.length} outliers detected within projectExtents`);
|
|
701
697
|
}
|
|
702
698
|
}
|
|
703
699
|
}
|
|
@@ -708,7 +704,7 @@ class IModelImporter {
|
|
|
708
704
|
optimizeGeometry(options) {
|
|
709
705
|
if (options.inlineUniqueGeometryParts) {
|
|
710
706
|
const result = this.targetDb.inlineGeometryParts();
|
|
711
|
-
|
|
707
|
+
Logger.logInfo(loggerCategory, `Inlined ${result.numRefsInlined} references to ${result.numCandidateParts} geometry parts and deleted ${result.numPartsDeleted} parts.`);
|
|
712
708
|
}
|
|
713
709
|
}
|
|
714
710
|
resolveDuplicateCodeValues() {
|
|
@@ -730,32 +726,31 @@ class IModelImporter {
|
|
|
730
726
|
this.resolveDuplicateCodeValues();
|
|
731
727
|
}
|
|
732
728
|
}
|
|
733
|
-
exports.IModelImporter = IModelImporter;
|
|
734
729
|
/** Returns true if a change within an Entity is detected.
|
|
735
730
|
* @param entity The current persistent Entity.
|
|
736
731
|
* @param entityProps The new EntityProps to compare against
|
|
737
732
|
* @note This method should only be called if changeset information is not available.
|
|
738
733
|
* @internal
|
|
739
734
|
*/
|
|
740
|
-
function hasEntityChanged(entity, entityProps, namesToIgnore) {
|
|
735
|
+
export function hasEntityChanged(entity, entityProps, namesToIgnore) {
|
|
741
736
|
let changed = false;
|
|
742
737
|
const entityClass = entity.iModel.schemaContext.getSchemaItemSync(entity.schemaItemKey);
|
|
743
|
-
(
|
|
744
|
-
|
|
738
|
+
assert(EntityClass.isEntityClass(entityClass) ||
|
|
739
|
+
RelationshipClass.isRelationshipClass(entityClass), `Cannot get metadata for ${entity.classFullName}.`);
|
|
745
740
|
for (const property of entityClass.getPropertiesSync()) {
|
|
746
741
|
const propertyName = property.name;
|
|
747
742
|
if (!changed) {
|
|
748
743
|
if (namesToIgnore && namesToIgnore.has(propertyName)) {
|
|
749
744
|
// skip
|
|
750
745
|
}
|
|
751
|
-
else if (
|
|
752
|
-
changed = hasBinaryValueChanged(entity.asAny[
|
|
746
|
+
else if (PropertyType.Binary === property.propertyType) {
|
|
747
|
+
changed = hasBinaryValueChanged(entity.asAny[ECJsNames.toJsName(propertyName)], entityProps[ECJsNames.toJsName(propertyName)]);
|
|
753
748
|
}
|
|
754
749
|
else if (property.isNavigation()) {
|
|
755
|
-
changed = hasNavigationValueChanged(entity.asAny[
|
|
750
|
+
changed = hasNavigationValueChanged(entity.asAny[ECJsNames.toJsName(propertyName)], entityProps[ECJsNames.toJsName(propertyName)]);
|
|
756
751
|
}
|
|
757
752
|
else {
|
|
758
|
-
changed = hasValueChanged(entity.asAny[
|
|
753
|
+
changed = hasValueChanged(entity.asAny[ECJsNames.toJsName(propertyName)], entityProps[ECJsNames.toJsName(propertyName)]);
|
|
759
754
|
}
|
|
760
755
|
}
|
|
761
756
|
}
|
|
@@ -763,14 +758,14 @@ function hasEntityChanged(entity, entityProps, namesToIgnore) {
|
|
|
763
758
|
}
|
|
764
759
|
/** Returns true if the specified binary values are different. */
|
|
765
760
|
function hasBinaryValueChanged(binaryProperty1, binaryProperty2) {
|
|
766
|
-
const jsonString1 = JSON.stringify(binaryProperty1,
|
|
767
|
-
const jsonString2 = JSON.stringify(binaryProperty2,
|
|
761
|
+
const jsonString1 = JSON.stringify(binaryProperty1, Base64EncodedString.replacer);
|
|
762
|
+
const jsonString2 = JSON.stringify(binaryProperty2, Base64EncodedString.replacer);
|
|
768
763
|
return jsonString1 !== jsonString2;
|
|
769
764
|
}
|
|
770
765
|
/** Returns true if the specified navigation property values are different. */
|
|
771
766
|
function hasNavigationValueChanged(navigationProperty1, navigationProperty2) {
|
|
772
|
-
const relatedElement1 =
|
|
773
|
-
const relatedElement2 =
|
|
767
|
+
const relatedElement1 = RelatedElement.fromJSON(navigationProperty1);
|
|
768
|
+
const relatedElement2 = RelatedElement.fromJSON(navigationProperty2);
|
|
774
769
|
const jsonString1 = JSON.stringify(relatedElement1);
|
|
775
770
|
const jsonString2 = JSON.stringify(relatedElement2);
|
|
776
771
|
return jsonString1 !== jsonString2;
|
|
@@ -781,28 +776,28 @@ function hasValueChanged(property1, property2) {
|
|
|
781
776
|
}
|
|
782
777
|
/** check if element props are a subcategory */
|
|
783
778
|
function isSubCategory(props) {
|
|
784
|
-
return props.classFullName ===
|
|
779
|
+
return props.classFullName === SubCategory.classFullName;
|
|
785
780
|
}
|
|
786
781
|
/** check if element props are a subcategory without loading the element */
|
|
787
782
|
function isDefaultSubCategory(props) {
|
|
788
783
|
if (props.id === undefined)
|
|
789
784
|
return false;
|
|
790
|
-
if (!
|
|
791
|
-
|
|
785
|
+
if (!Id64.isId64(props.id))
|
|
786
|
+
ITwinError.throwError({
|
|
792
787
|
iTwinErrorId: {
|
|
793
|
-
scope:
|
|
794
|
-
key:
|
|
788
|
+
scope: IModelTransformerErrorScope,
|
|
789
|
+
key: IModelTransformerError.InvalidSubCategory,
|
|
795
790
|
},
|
|
796
791
|
message: "subcategory had invalid id",
|
|
797
792
|
});
|
|
798
793
|
if (props.parent?.id === undefined)
|
|
799
|
-
|
|
794
|
+
ITwinError.throwError({
|
|
800
795
|
iTwinErrorId: {
|
|
801
|
-
scope:
|
|
802
|
-
key:
|
|
796
|
+
scope: IModelTransformerErrorScope,
|
|
797
|
+
key: IModelTransformerError.InvalidSubCategory,
|
|
803
798
|
},
|
|
804
799
|
message: `subcategory with id ${props.id} had no parent`,
|
|
805
800
|
});
|
|
806
|
-
return props.id ===
|
|
801
|
+
return props.id === IModelDb.getDefaultSubCategoryId(props.parent.id);
|
|
807
802
|
}
|
|
808
803
|
//# sourceMappingURL=IModelImporter.js.map
|