@itwin/imodel-transformer 2.0.0-dev.2 → 2.0.0-dev.21
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/CHANGELOG.md +9 -1
- package/lib/cjs/BranchProvenanceInitializer.d.ts.map +1 -1
- package/lib/cjs/BranchProvenanceInitializer.js +26 -20
- package/lib/cjs/BranchProvenanceInitializer.js.map +1 -1
- package/lib/cjs/DetachedExportElementAspectsStrategy.d.ts.map +1 -1
- package/lib/cjs/DetachedExportElementAspectsStrategy.js +8 -6
- package/lib/cjs/DetachedExportElementAspectsStrategy.js.map +1 -1
- package/lib/cjs/ECReferenceTypesCache.d.ts +3 -0
- package/lib/cjs/ECReferenceTypesCache.d.ts.map +1 -1
- package/lib/cjs/ECReferenceTypesCache.js +103 -40
- package/lib/cjs/ECReferenceTypesCache.js.map +1 -1
- package/lib/cjs/ElementCascadingDeleter.d.ts +3 -3
- package/lib/cjs/ElementCascadingDeleter.d.ts.map +1 -1
- package/lib/cjs/ElementCascadingDeleter.js +12 -12
- package/lib/cjs/ElementCascadingDeleter.js.map +1 -1
- package/lib/cjs/EntityUnifier.d.ts +4 -8
- package/lib/cjs/EntityUnifier.d.ts.map +1 -1
- package/lib/cjs/EntityUnifier.js +8 -25
- package/lib/cjs/EntityUnifier.js.map +1 -1
- package/lib/cjs/ExportElementAspectsStrategy.d.ts +4 -4
- package/lib/cjs/ExportElementAspectsStrategy.d.ts.map +1 -1
- package/lib/cjs/ExportElementAspectsStrategy.js +1 -1
- package/lib/cjs/ExportElementAspectsStrategy.js.map +1 -1
- package/lib/cjs/ExportElementAspectsWithElementsStrategy.d.ts.map +1 -1
- package/lib/cjs/ExportElementAspectsWithElementsStrategy.js +17 -16
- package/lib/cjs/ExportElementAspectsWithElementsStrategy.js.map +1 -1
- package/lib/cjs/IModelCloneContext.d.ts +3 -3
- package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
- package/lib/cjs/IModelCloneContext.js +60 -52
- package/lib/cjs/IModelCloneContext.js.map +1 -1
- package/lib/cjs/IModelExporter.d.ts +28 -19
- package/lib/cjs/IModelExporter.d.ts.map +1 -1
- package/lib/cjs/IModelExporter.js +145 -119
- package/lib/cjs/IModelExporter.js.map +1 -1
- package/lib/cjs/IModelImporter.d.ts +32 -24
- package/lib/cjs/IModelImporter.d.ts.map +1 -1
- package/lib/cjs/IModelImporter.js +107 -90
- package/lib/cjs/IModelImporter.js.map +1 -1
- package/lib/cjs/IModelTransformer.d.ts +117 -187
- package/lib/cjs/IModelTransformer.d.ts.map +1 -1
- package/lib/cjs/IModelTransformer.js +399 -1010
- package/lib/cjs/IModelTransformer.js.map +1 -1
- package/lib/cjs/ProvenanceManager.d.ts +165 -0
- package/lib/cjs/ProvenanceManager.d.ts.map +1 -0
- package/lib/cjs/ProvenanceManager.js +692 -0
- package/lib/cjs/ProvenanceManager.js.map +1 -0
- package/lib/cjs/SyncTypeResolver.d.ts +34 -0
- package/lib/cjs/SyncTypeResolver.d.ts.map +1 -0
- package/lib/cjs/SyncTypeResolver.js +84 -0
- package/lib/cjs/SyncTypeResolver.js.map +1 -0
- package/lib/cjs/TransformerLoggerCategory.d.ts +6 -5
- package/lib/cjs/TransformerLoggerCategory.d.ts.map +1 -1
- package/lib/cjs/TransformerLoggerCategory.js +6 -5
- package/lib/cjs/TransformerLoggerCategory.js.map +1 -1
- package/lib/cjs/imodel-transformer.js +2 -2
- package/lib/cjs/imodel-transformer.js.map +1 -1
- package/package.json +38 -33
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelImporter.d.ts","sourceRoot":"","sources":["../../src/IModelImporter.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,OAAO,EAGL,UAAU,EAGX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAGL,kBAAkB,EAClB,YAAY,EACZ,WAAW,EAGX,UAAU,
|
|
1
|
+
{"version":3,"file":"IModelImporter.d.ts","sourceRoot":"","sources":["../../src/IModelImporter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BAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI;IAU/D,OAAO,CAAC,0BAA0B;IASlC;;;;;OAKG;IACI,QAAQ,IAAI,IAAI;CAGxB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAC1B,OAAO,CA0BT"}
|
|
@@ -15,6 +15,7 @@ const TransformerLoggerCategory_1 = require("./TransformerLoggerCategory");
|
|
|
15
15
|
const core_backend_1 = require("@itwin/core-backend");
|
|
16
16
|
const assert = require("assert");
|
|
17
17
|
const ElementCascadingDeleter_1 = require("./ElementCascadingDeleter");
|
|
18
|
+
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
18
19
|
const loggerCategory = TransformerLoggerCategory_1.TransformerLoggerCategory.IModelImporter;
|
|
19
20
|
/** Base class for importing data into an iModel.
|
|
20
21
|
* @see [iModel Transformation and Data Exchange]($docs/learning/transformer/index.md)
|
|
@@ -25,6 +26,16 @@ const loggerCategory = TransformerLoggerCategory_1.TransformerLoggerCategory.IMo
|
|
|
25
26
|
class IModelImporter {
|
|
26
27
|
/** The read/write target iModel. */
|
|
27
28
|
targetDb;
|
|
29
|
+
/** The [[EditTxn]] used for write operations on the target iModel.
|
|
30
|
+
* @beta
|
|
31
|
+
*/
|
|
32
|
+
_editTxn;
|
|
33
|
+
/** The [[EditTxn]] used for write operations on the target iModel.
|
|
34
|
+
* @beta
|
|
35
|
+
*/
|
|
36
|
+
get editTxn() {
|
|
37
|
+
return this._editTxn;
|
|
38
|
+
}
|
|
28
39
|
/** resolved initialization options for the importer
|
|
29
40
|
* @beta
|
|
30
41
|
*/
|
|
@@ -71,11 +82,12 @@ class IModelImporter {
|
|
|
71
82
|
"geometryGuid", // cannot compare GeometricModel.GeometryGuid values across iModels
|
|
72
83
|
]);
|
|
73
84
|
/** Construct a new IModelImporter
|
|
74
|
-
* @param
|
|
85
|
+
* @param editTxn The [[EditTxn]] to use for write operations on the target iModel. The target db is derived from `editTxn.iModel`.
|
|
75
86
|
* @param options The options that specify how the import should be done.
|
|
76
87
|
*/
|
|
77
|
-
constructor(
|
|
78
|
-
this.targetDb =
|
|
88
|
+
constructor(editTxn, options) {
|
|
89
|
+
this.targetDb = editTxn.iModel;
|
|
90
|
+
this._editTxn = editTxn;
|
|
79
91
|
this.options = {
|
|
80
92
|
autoExtendProjectExtents: options?.autoExtendProjectExtents ?? true,
|
|
81
93
|
preserveElementIdsForFiltering: options?.preserveElementIdsForFiltering ?? false,
|
|
@@ -105,7 +117,7 @@ class IModelImporter {
|
|
|
105
117
|
this._elementsToUpdateDuringPreserveIds.add(elementId);
|
|
106
118
|
}
|
|
107
119
|
/** Import the specified ModelProps (either as an insert or an update) into the target iModel. */
|
|
108
|
-
importModel(modelProps) {
|
|
120
|
+
async importModel(modelProps) {
|
|
109
121
|
if (undefined === modelProps.id || !core_bentley_1.Id64.isValidId64(modelProps.id))
|
|
110
122
|
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.InvalidId, "Model Id not provided, should be the same as the ModeledElementId");
|
|
111
123
|
if (this.doNotUpdateElement(modelProps.id)) {
|
|
@@ -115,14 +127,14 @@ class IModelImporter {
|
|
|
115
127
|
try {
|
|
116
128
|
const model = this.targetDb.models.getModel(modelProps.id); // throws IModelError.NotFound if model does not exist
|
|
117
129
|
if (hasEntityChanged(model, modelProps, this._modelPropertiesToIgnore)) {
|
|
118
|
-
this.onUpdateModel(modelProps);
|
|
130
|
+
await this.onUpdateModel(modelProps);
|
|
119
131
|
}
|
|
120
132
|
}
|
|
121
133
|
catch (error) {
|
|
122
134
|
// catch NotFound error and insertModel
|
|
123
135
|
if (error instanceof core_common_1.IModelError &&
|
|
124
136
|
error.errorNumber === core_bentley_1.IModelStatus.NotFound) {
|
|
125
|
-
this.onInsertModel(modelProps);
|
|
137
|
+
await this.onInsertModel(modelProps);
|
|
126
138
|
return;
|
|
127
139
|
}
|
|
128
140
|
throw error;
|
|
@@ -131,11 +143,11 @@ class IModelImporter {
|
|
|
131
143
|
/** Create a new Model from the specified ModelProps and insert it into the target iModel.
|
|
132
144
|
* @note A subclass may override this method to customize insert behavior but should call `super.onInsertModel`.
|
|
133
145
|
*/
|
|
134
|
-
onInsertModel(modelProps) {
|
|
146
|
+
async onInsertModel(modelProps) {
|
|
135
147
|
try {
|
|
136
|
-
const modelId = this.
|
|
148
|
+
const modelId = this._editTxn.insertModel(modelProps);
|
|
137
149
|
core_bentley_1.Logger.logInfo(loggerCategory, `Inserted ${this.formatModelForLogger(modelProps)}`);
|
|
138
|
-
this.trackProgress();
|
|
150
|
+
await this.trackProgress();
|
|
139
151
|
return modelId;
|
|
140
152
|
}
|
|
141
153
|
catch (error) {
|
|
@@ -150,30 +162,32 @@ class IModelImporter {
|
|
|
150
162
|
/** Update an existing Model in the target iModel from the specified ModelProps.
|
|
151
163
|
* @note A subclass may override this method to customize update behavior but should call `super.onUpdateModel`.
|
|
152
164
|
*/
|
|
153
|
-
onUpdateModel(modelProps) {
|
|
154
|
-
this.
|
|
165
|
+
async onUpdateModel(modelProps) {
|
|
166
|
+
this._editTxn.updateModel(modelProps);
|
|
155
167
|
core_bentley_1.Logger.logInfo(loggerCategory, `Updated ${this.formatModelForLogger(modelProps)}`);
|
|
156
|
-
this.trackProgress();
|
|
168
|
+
await this.trackProgress();
|
|
157
169
|
}
|
|
158
170
|
/** Format a Model for the Logger. */
|
|
159
171
|
formatModelForLogger(modelProps) {
|
|
172
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
160
173
|
return `${modelProps.classFullName} [${modelProps.id}]`;
|
|
161
174
|
}
|
|
162
175
|
/**
|
|
163
176
|
* Tries to update an element with the specified element properties.
|
|
164
177
|
* If a duplicate code error occurs, it assigns a new unique code value and retries the update
|
|
165
178
|
*/
|
|
166
|
-
tryUpdateElement(elemProps) {
|
|
179
|
+
async tryUpdateElement(elemProps) {
|
|
167
180
|
try {
|
|
168
|
-
this.onUpdateElement(elemProps);
|
|
181
|
+
await this.onUpdateElement(elemProps);
|
|
169
182
|
}
|
|
170
183
|
catch (err) {
|
|
171
184
|
if (err.errorNumber === core_bentley_1.IModelStatus.DuplicateCode) {
|
|
172
185
|
assert(elemProps.code.value !== undefined, "NULL code values are always considered unique and cannot clash");
|
|
186
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
173
187
|
this._duplicateCodeValueMap.set(elemProps.id, elemProps.code.value);
|
|
174
188
|
// Using NULL code values as an alternative is not valid because definition elements cannot have NULL code values.
|
|
175
189
|
elemProps.code.value = core_bentley_1.Guid.createValue();
|
|
176
|
-
this.onUpdateElement(elemProps);
|
|
190
|
+
await this.onUpdateElement(elemProps);
|
|
177
191
|
}
|
|
178
192
|
else {
|
|
179
193
|
throw err;
|
|
@@ -181,7 +195,7 @@ class IModelImporter {
|
|
|
181
195
|
}
|
|
182
196
|
}
|
|
183
197
|
/** Import the specified ElementProps (either as an insert or an update) into the target iModel. */
|
|
184
|
-
importElement(elementProps) {
|
|
198
|
+
async importElement(elementProps) {
|
|
185
199
|
if (undefined !== elementProps.id &&
|
|
186
200
|
this.doNotUpdateElement(elementProps.id)) {
|
|
187
201
|
core_bentley_1.Logger.logInfo(loggerCategory, `Do not update target element ${elementProps.id}`);
|
|
@@ -197,24 +211,24 @@ class IModelImporter {
|
|
|
197
211
|
// Always present elements (0xe, 0x1, 0x10) also will be updated to prevent duplicate inserts.
|
|
198
212
|
if ((isSubCategory(elementProps) && isDefaultSubCategory(elementProps)) ||
|
|
199
213
|
this._rootElementIds.has(elementProps.id)) {
|
|
200
|
-
this.onUpdateElement(elementProps);
|
|
214
|
+
await this.onUpdateElement(elementProps);
|
|
201
215
|
}
|
|
202
216
|
else {
|
|
203
217
|
if (this._elementsToUpdateDuringPreserveIds.has(elementProps.id)) {
|
|
204
|
-
this.tryUpdateElement(elementProps);
|
|
218
|
+
await this.tryUpdateElement(elementProps);
|
|
205
219
|
this._elementsToUpdateDuringPreserveIds.delete(elementProps.id);
|
|
206
220
|
}
|
|
207
221
|
else {
|
|
208
|
-
this.onInsertElement(elementProps);
|
|
222
|
+
await this.onInsertElement(elementProps);
|
|
209
223
|
}
|
|
210
224
|
}
|
|
211
225
|
}
|
|
212
226
|
else {
|
|
213
227
|
if (undefined !== elementProps.id) {
|
|
214
|
-
this.tryUpdateElement(elementProps);
|
|
228
|
+
await this.tryUpdateElement(elementProps);
|
|
215
229
|
}
|
|
216
230
|
else {
|
|
217
|
-
this.onInsertElement(elementProps); // targetElementProps.id assigned by insertElement
|
|
231
|
+
elementProps.id = await this.onInsertElement(elementProps); // targetElementProps.id assigned by insertElement
|
|
218
232
|
}
|
|
219
233
|
}
|
|
220
234
|
return elementProps.id;
|
|
@@ -223,16 +237,15 @@ class IModelImporter {
|
|
|
223
237
|
* @returns The Id of the newly inserted Element.
|
|
224
238
|
* @note A subclass may override this method to customize insert behavior but should call `super.onInsertElement`.
|
|
225
239
|
*/
|
|
226
|
-
onInsertElement(elementProps) {
|
|
227
|
-
/* eslint-disable deprecation/deprecation */
|
|
240
|
+
async onInsertElement(elementProps) {
|
|
228
241
|
try {
|
|
229
|
-
const elementId = this.
|
|
242
|
+
const elementId = this._editTxn.insertElement(elementProps, {
|
|
230
243
|
forceUseId: this.options.preserveElementIdsForFiltering,
|
|
231
244
|
});
|
|
232
245
|
// set the id like [IModelDb.insertElement]($backend), does, the raw nativeDb method does not
|
|
233
246
|
elementProps.id = elementId;
|
|
234
247
|
core_bentley_1.Logger.logInfo(loggerCategory, `Inserted ${this.formatElementForLogger(elementProps)}`);
|
|
235
|
-
this.trackProgress();
|
|
248
|
+
await this.trackProgress();
|
|
236
249
|
if (this.options.simplifyElementGeometry) {
|
|
237
250
|
this.targetDb.simplifyElementGeometry({
|
|
238
251
|
id: elementId,
|
|
@@ -250,20 +263,18 @@ class IModelImporter {
|
|
|
250
263
|
}
|
|
251
264
|
throw error; // throw original error
|
|
252
265
|
}
|
|
253
|
-
/* eslint-enable deprecation/deprecation */
|
|
254
266
|
}
|
|
255
267
|
/** Update an existing Element in the target iModel from the specified ElementProps.
|
|
256
268
|
* @note A subclass may override this method to customize update behavior but should call `super.onUpdateElement`.
|
|
257
269
|
*/
|
|
258
|
-
onUpdateElement(elementProps) {
|
|
270
|
+
async onUpdateElement(elementProps) {
|
|
259
271
|
if (!elementProps.id) {
|
|
260
272
|
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.InvalidId, "ElementId not provided");
|
|
261
273
|
}
|
|
262
|
-
this.
|
|
274
|
+
this._editTxn.updateElement(elementProps);
|
|
263
275
|
core_bentley_1.Logger.logInfo(loggerCategory, `Updated ${this.formatElementForLogger(elementProps)}`);
|
|
264
|
-
this.trackProgress();
|
|
276
|
+
await this.trackProgress();
|
|
265
277
|
if (this.options.simplifyElementGeometry) {
|
|
266
|
-
/* eslint-disable-next-line deprecation/deprecation */
|
|
267
278
|
this.targetDb.simplifyElementGeometry({
|
|
268
279
|
id: elementProps.id,
|
|
269
280
|
convertBReps: true,
|
|
@@ -275,30 +286,30 @@ class IModelImporter {
|
|
|
275
286
|
* Will delete special elements like definition elements and subjects.
|
|
276
287
|
* @note A subclass may override this method to customize delete behavior but should call `super.onDeleteElement`.
|
|
277
288
|
*/
|
|
278
|
-
onDeleteElement(elementId) {
|
|
279
|
-
(0, ElementCascadingDeleter_1.deleteElementTreeCascade)(this.
|
|
289
|
+
async onDeleteElement(elementId) {
|
|
290
|
+
(0, ElementCascadingDeleter_1.deleteElementTreeCascade)(this._editTxn, elementId);
|
|
280
291
|
core_bentley_1.Logger.logInfo(loggerCategory, `Deleted element ${elementId} and its descendants`);
|
|
281
|
-
this.trackProgress();
|
|
292
|
+
await this.trackProgress();
|
|
282
293
|
}
|
|
283
294
|
/** Delete the specified Element from the target iModel. */
|
|
284
|
-
deleteElement(elementId) {
|
|
295
|
+
async deleteElement(elementId) {
|
|
285
296
|
if (this.doNotUpdateElement(elementId)) {
|
|
286
297
|
core_bentley_1.Logger.logInfo(loggerCategory, `Do not delete target element ${elementId}`);
|
|
287
298
|
return;
|
|
288
299
|
}
|
|
289
|
-
this.onDeleteElement(elementId);
|
|
300
|
+
await this.onDeleteElement(elementId);
|
|
290
301
|
}
|
|
291
302
|
/** Delete the specified Model from the target iModel.
|
|
292
303
|
* @note A subclass may override this method to customize delete behavior but should call `super.onDeleteModel`.
|
|
293
304
|
*/
|
|
294
|
-
onDeleteModel(modelId) {
|
|
295
|
-
this.
|
|
305
|
+
async onDeleteModel(modelId) {
|
|
306
|
+
this._editTxn.deleteModel(modelId);
|
|
296
307
|
core_bentley_1.Logger.logInfo(loggerCategory, `Deleted model ${modelId}`);
|
|
297
|
-
this.trackProgress();
|
|
308
|
+
await this.trackProgress();
|
|
298
309
|
}
|
|
299
310
|
/** Delete the specified Model from the target iModel. */
|
|
300
|
-
deleteModel(modelId) {
|
|
301
|
-
this.onDeleteModel(modelId);
|
|
311
|
+
async deleteModel(modelId) {
|
|
312
|
+
await this.onDeleteModel(modelId);
|
|
302
313
|
}
|
|
303
314
|
/** Format an Element for the Logger. */
|
|
304
315
|
formatElementForLogger(elementProps) {
|
|
@@ -310,14 +321,14 @@ class IModelImporter {
|
|
|
310
321
|
return `${elementProps.classFullName} ${namePiece}[${elementProps.id}]`;
|
|
311
322
|
}
|
|
312
323
|
/** Import an ElementUniqueAspect into the target iModel. */
|
|
313
|
-
importElementUniqueAspect(aspectProps) {
|
|
324
|
+
async importElementUniqueAspect(aspectProps) {
|
|
314
325
|
const aspects = this.targetDb.elements.getAspects(aspectProps.element.id, aspectProps.classFullName);
|
|
315
326
|
if (aspects.length === 0) {
|
|
316
327
|
return this.onInsertElementAspect(aspectProps);
|
|
317
328
|
}
|
|
318
329
|
else if (hasEntityChanged(aspects[0], aspectProps)) {
|
|
319
330
|
aspectProps.id = aspects[0].id;
|
|
320
|
-
this.onUpdateElementAspect(aspectProps);
|
|
331
|
+
await this.onUpdateElementAspect(aspectProps);
|
|
321
332
|
}
|
|
322
333
|
return aspects[0].id;
|
|
323
334
|
}
|
|
@@ -327,7 +338,7 @@ class IModelImporter {
|
|
|
327
338
|
* @note For insert vs. update reasons, it is important to process all ElementMultiAspects owned by an Element at once since we don't have aspect-specific provenance.
|
|
328
339
|
* @returns the array of ids of the resulting ElementMultiAspects, in the same order of the aspectPropsArray parameter
|
|
329
340
|
*/
|
|
330
|
-
importElementMultiAspects(aspectPropsArray,
|
|
341
|
+
async importElementMultiAspects(aspectPropsArray,
|
|
331
342
|
/** caller must use this to enforce any aspects added by IModelTransformer are not considered for update */
|
|
332
343
|
filterFunc = () => true) {
|
|
333
344
|
const result = new Array(aspectPropsArray.length).fill(undefined);
|
|
@@ -341,7 +352,7 @@ class IModelImporter {
|
|
|
341
352
|
aspectClassFullNames.add(aspectsProps.classFullName);
|
|
342
353
|
});
|
|
343
354
|
// Handle ElementMultiAspects in groups by class
|
|
344
|
-
|
|
355
|
+
for (const aspectClassFullName of aspectClassFullNames) {
|
|
345
356
|
const proposedAspects = aspectPropsArray
|
|
346
357
|
.map((props, index) => ({ props, index }))
|
|
347
358
|
.filter(({ props }) => aspectClassFullName === props.classFullName);
|
|
@@ -350,50 +361,52 @@ class IModelImporter {
|
|
|
350
361
|
.map((props, index) => ({ props, index }))
|
|
351
362
|
.filter(({ props }) => filterFunc(props));
|
|
352
363
|
if (proposedAspects.length >= currentAspects.length) {
|
|
353
|
-
|
|
364
|
+
for (let index = 0; index < proposedAspects.length; index++) {
|
|
365
|
+
const { props, index: resultIndex } = proposedAspects[index];
|
|
354
366
|
let id;
|
|
355
367
|
if (index < currentAspects.length) {
|
|
356
368
|
id = currentAspects[index].props.id;
|
|
357
369
|
props.id = id;
|
|
358
370
|
if (hasEntityChanged(currentAspects[index].props, props)) {
|
|
359
|
-
this.onUpdateElementAspect(props);
|
|
371
|
+
await this.onUpdateElementAspect(props);
|
|
360
372
|
}
|
|
361
373
|
id = props.id;
|
|
362
374
|
}
|
|
363
375
|
else {
|
|
364
|
-
id = this.onInsertElementAspect(props);
|
|
376
|
+
id = await this.onInsertElementAspect(props);
|
|
365
377
|
}
|
|
366
378
|
result[resultIndex] = id;
|
|
367
|
-
}
|
|
379
|
+
}
|
|
368
380
|
}
|
|
369
381
|
else {
|
|
370
|
-
|
|
382
|
+
for (let index = 0; index < currentAspects.length; index++) {
|
|
383
|
+
const { props, index: resultIndex } = currentAspects[index];
|
|
371
384
|
let id;
|
|
372
385
|
if (index < proposedAspects.length) {
|
|
373
386
|
id = props.id;
|
|
374
387
|
proposedAspects[index].props.id = id;
|
|
375
388
|
if (hasEntityChanged(props, proposedAspects[index].props)) {
|
|
376
|
-
this.onUpdateElementAspect(proposedAspects[index].props);
|
|
389
|
+
await this.onUpdateElementAspect(proposedAspects[index].props);
|
|
377
390
|
}
|
|
378
391
|
result[resultIndex] = id;
|
|
379
392
|
}
|
|
380
393
|
else {
|
|
381
|
-
this.onDeleteElementAspect(props);
|
|
394
|
+
await this.onDeleteElementAspect(props);
|
|
382
395
|
}
|
|
383
|
-
}
|
|
396
|
+
}
|
|
384
397
|
}
|
|
385
|
-
}
|
|
398
|
+
}
|
|
386
399
|
assert(result.every((r) => typeof r !== undefined));
|
|
387
400
|
return result;
|
|
388
401
|
}
|
|
389
402
|
/** Insert the ElementAspect into the target iModel.
|
|
390
403
|
* @note A subclass may override this method to customize insert behavior but should call `super.onInsertElementAspect`.
|
|
391
404
|
*/
|
|
392
|
-
onInsertElementAspect(aspectProps) {
|
|
405
|
+
async onInsertElementAspect(aspectProps) {
|
|
393
406
|
try {
|
|
394
|
-
const id = this.
|
|
407
|
+
const id = this._editTxn.insertAspect(aspectProps);
|
|
395
408
|
core_bentley_1.Logger.logInfo(loggerCategory, `Inserted ${this.formatElementAspectForLogger(aspectProps)}`);
|
|
396
|
-
this.trackProgress();
|
|
409
|
+
await this.trackProgress();
|
|
397
410
|
return id;
|
|
398
411
|
}
|
|
399
412
|
catch (error) {
|
|
@@ -408,18 +421,18 @@ class IModelImporter {
|
|
|
408
421
|
/** Update the ElementAspect within the target iModel.
|
|
409
422
|
* @note A subclass may override this method to customize update behavior but should call `super.onUpdateElementAspect`.
|
|
410
423
|
*/
|
|
411
|
-
onUpdateElementAspect(aspectProps) {
|
|
412
|
-
this.
|
|
424
|
+
async onUpdateElementAspect(aspectProps) {
|
|
425
|
+
this._editTxn.updateAspect(aspectProps);
|
|
413
426
|
core_bentley_1.Logger.logInfo(loggerCategory, `Updated ${this.formatElementAspectForLogger(aspectProps)}`);
|
|
414
|
-
this.trackProgress();
|
|
427
|
+
await this.trackProgress();
|
|
415
428
|
}
|
|
416
429
|
/** Delete the specified ElementAspect from the target iModel.
|
|
417
430
|
* @note A subclass may override this method to customize delete behavior but should call `super.onDeleteElementAspect`.
|
|
418
431
|
*/
|
|
419
|
-
onDeleteElementAspect(targetElementAspect) {
|
|
420
|
-
this.
|
|
432
|
+
async onDeleteElementAspect(targetElementAspect) {
|
|
433
|
+
this._editTxn.deleteAspect(targetElementAspect.id);
|
|
421
434
|
core_bentley_1.Logger.logInfo(loggerCategory, `Deleted ${this.formatElementAspectForLogger(targetElementAspect)}`);
|
|
422
|
-
this.trackProgress();
|
|
435
|
+
await this.trackProgress();
|
|
423
436
|
}
|
|
424
437
|
/** Format an ElementAspect for the Logger. */
|
|
425
438
|
formatElementAspectForLogger(elementAspectProps) {
|
|
@@ -428,7 +441,7 @@ class IModelImporter {
|
|
|
428
441
|
/** Import the specified RelationshipProps (either as an insert or an update) into the target iModel.
|
|
429
442
|
* @returns The instance Id of the inserted or updated Relationship.
|
|
430
443
|
*/
|
|
431
|
-
importRelationship(relationshipProps) {
|
|
444
|
+
async importRelationship(relationshipProps) {
|
|
432
445
|
if (undefined === relationshipProps.sourceId ||
|
|
433
446
|
!core_bentley_1.Id64.isValidId64(relationshipProps.sourceId)) {
|
|
434
447
|
core_bentley_1.Logger.logInfo(loggerCategory, `Ignoring ${relationshipProps.classFullName} instance because of invalid RelationshipProps.sourceId`);
|
|
@@ -449,7 +462,7 @@ class IModelImporter {
|
|
|
449
462
|
// if relationship found, update it
|
|
450
463
|
relationshipProps.id = relationship.id;
|
|
451
464
|
if (hasEntityChanged(relationship, relationshipProps)) {
|
|
452
|
-
this.onUpdateRelationship(relationshipProps);
|
|
465
|
+
await this.onUpdateRelationship(relationshipProps);
|
|
453
466
|
}
|
|
454
467
|
return relationshipProps.id;
|
|
455
468
|
}
|
|
@@ -461,11 +474,11 @@ class IModelImporter {
|
|
|
461
474
|
* @returns The instance Id of the newly inserted relationship.
|
|
462
475
|
* @note A subclass may override this method to customize insert behavior but should call `super.onInsertRelationship`.
|
|
463
476
|
*/
|
|
464
|
-
onInsertRelationship(relationshipProps) {
|
|
477
|
+
async onInsertRelationship(relationshipProps) {
|
|
465
478
|
try {
|
|
466
|
-
const targetRelInstanceId = this.
|
|
479
|
+
const targetRelInstanceId = this._editTxn.insertRelationship(relationshipProps);
|
|
467
480
|
core_bentley_1.Logger.logInfo(loggerCategory, `Inserted ${this.formatRelationshipForLogger(relationshipProps)}`);
|
|
468
|
-
this.trackProgress();
|
|
481
|
+
await this.trackProgress();
|
|
469
482
|
return targetRelInstanceId;
|
|
470
483
|
}
|
|
471
484
|
catch (error) {
|
|
@@ -480,43 +493,43 @@ class IModelImporter {
|
|
|
480
493
|
/** Update an existing Relationship in the target iModel from the specified RelationshipProps.
|
|
481
494
|
* @note A subclass may override this method to customize update behavior but should call `super.onUpdateRelationship`.
|
|
482
495
|
*/
|
|
483
|
-
onUpdateRelationship(relationshipProps) {
|
|
496
|
+
async onUpdateRelationship(relationshipProps) {
|
|
484
497
|
if (!relationshipProps.id) {
|
|
485
498
|
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.InvalidId, "Relationship instance Id not provided");
|
|
486
499
|
}
|
|
487
|
-
this.
|
|
500
|
+
this._editTxn.updateRelationship(relationshipProps);
|
|
488
501
|
core_bentley_1.Logger.logInfo(loggerCategory, `Updated ${this.formatRelationshipForLogger(relationshipProps)}`);
|
|
489
|
-
this.trackProgress();
|
|
502
|
+
await this.trackProgress();
|
|
490
503
|
}
|
|
491
504
|
/** Delete the specified Relationship from the target iModel. */
|
|
492
|
-
onDeleteRelationship(relationshipProps) {
|
|
505
|
+
async onDeleteRelationship(relationshipProps) {
|
|
493
506
|
// Only passing in what deleteInstance actually uses, full relationshipProps is not necessary.
|
|
494
|
-
this.
|
|
507
|
+
this._editTxn.deleteRelationship({
|
|
495
508
|
id: relationshipProps.id,
|
|
496
509
|
classFullName: relationshipProps.classFullName,
|
|
497
510
|
});
|
|
498
511
|
core_bentley_1.Logger.logInfo(loggerCategory, `Deleted relationship ${relationshipProps.classFullName} id=${relationshipProps.id}`);
|
|
499
|
-
this.trackProgress();
|
|
512
|
+
await this.trackProgress();
|
|
500
513
|
}
|
|
501
514
|
/** Delete the specified Relationship from the target iModel. */
|
|
502
|
-
deleteRelationship(relationshipProps) {
|
|
503
|
-
this.onDeleteRelationship(relationshipProps);
|
|
515
|
+
async deleteRelationship(relationshipProps) {
|
|
516
|
+
await this.onDeleteRelationship(relationshipProps);
|
|
504
517
|
}
|
|
505
518
|
/** Format a Relationship for the Logger. */
|
|
506
519
|
formatRelationshipForLogger(relProps) {
|
|
507
520
|
return `${relProps.classFullName} sourceId=[${relProps.sourceId}] targetId=[${relProps.targetId}]`;
|
|
508
521
|
}
|
|
509
522
|
/** Tracks incremental progress */
|
|
510
|
-
trackProgress() {
|
|
523
|
+
async trackProgress() {
|
|
511
524
|
this._progressCounter++;
|
|
512
525
|
if (0 === this._progressCounter % this.progressInterval) {
|
|
513
|
-
this.onProgress();
|
|
526
|
+
await this.onProgress();
|
|
514
527
|
}
|
|
515
528
|
}
|
|
516
529
|
/** This method is called when IModelImporter has made incremental progress based on the [[progressInterval]] setting.
|
|
517
530
|
* @note A subclass may override this method to report custom progress but should call `super.onProgress`.
|
|
518
531
|
*/
|
|
519
|
-
onProgress() { }
|
|
532
|
+
async onProgress() { }
|
|
520
533
|
/** Optionally compute the projectExtents for the target iModel depending on the options for this IModelImporter.
|
|
521
534
|
* @note This method is automatically called from [IModelTransformer.process]($transformer).
|
|
522
535
|
* @see [IModelDb.computeProjectExtents]($backend), [[autoExtendProjectExtents]]
|
|
@@ -533,11 +546,15 @@ class IModelImporter {
|
|
|
533
546
|
const excludeOutliers = typeof this.options.autoExtendProjectExtents === "object"
|
|
534
547
|
? this.options.autoExtendProjectExtents.excludeOutliers
|
|
535
548
|
: false;
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
549
|
+
// If excludeOutliers is true, use the extents without outliers.
|
|
550
|
+
// Otherwise prefer extentsWithOutliers, but fall back to extents if it's undefined or a null range.
|
|
551
|
+
const extentsWithOutliers = computedProjectExtents.extentsWithOutliers;
|
|
552
|
+
const useExtentsWithOutliers = !excludeOutliers && extentsWithOutliers && !extentsWithOutliers.isNull;
|
|
553
|
+
const newProjectExtents = useExtentsWithOutliers
|
|
554
|
+
? extentsWithOutliers
|
|
555
|
+
: computedProjectExtents.extents;
|
|
539
556
|
if (!newProjectExtents.isAlmostEqual(this.targetDb.projectExtents)) {
|
|
540
|
-
this.
|
|
557
|
+
this._editTxn.updateProjectExtents(newProjectExtents);
|
|
541
558
|
core_bentley_1.Logger.logInfo(loggerCategory, `Updated projectExtents=${JSON.stringify(this.targetDb.projectExtents)}`);
|
|
542
559
|
}
|
|
543
560
|
if (!excludeOutliers &&
|
|
@@ -562,7 +579,6 @@ class IModelImporter {
|
|
|
562
579
|
*/
|
|
563
580
|
optimizeGeometry(options) {
|
|
564
581
|
if (options.inlineUniqueGeometryParts) {
|
|
565
|
-
/* eslint-disable-next-line deprecation/deprecation */
|
|
566
582
|
const result = this.targetDb.inlineGeometryParts();
|
|
567
583
|
core_bentley_1.Logger.logInfo(loggerCategory, `Inlined ${result.numRefsInlined} references to ${result.numCandidateParts} geometry parts and deleted ${result.numPartsDeleted} parts.`);
|
|
568
584
|
}
|
|
@@ -571,7 +587,7 @@ class IModelImporter {
|
|
|
571
587
|
for (const [elementId, codeValue] of this._duplicateCodeValueMap) {
|
|
572
588
|
const element = this.targetDb.elements.getElement(elementId);
|
|
573
589
|
element.code.value = codeValue;
|
|
574
|
-
element.
|
|
590
|
+
this._editTxn.updateElement(element.toJSON());
|
|
575
591
|
}
|
|
576
592
|
this._duplicateCodeValueMap.clear();
|
|
577
593
|
}
|
|
@@ -594,19 +610,20 @@ exports.IModelImporter = IModelImporter;
|
|
|
594
610
|
*/
|
|
595
611
|
function hasEntityChanged(entity, entityProps, namesToIgnore) {
|
|
596
612
|
let changed = false;
|
|
597
|
-
|
|
613
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
614
|
+
entity.forEach((propertyName, property) => {
|
|
598
615
|
if (!changed) {
|
|
599
616
|
if (namesToIgnore && namesToIgnore.has(propertyName)) {
|
|
600
617
|
// skip
|
|
601
618
|
}
|
|
602
|
-
else if (
|
|
603
|
-
changed = hasBinaryValueChanged(entity.asAny[propertyName], entityProps[propertyName]);
|
|
619
|
+
else if (ecschema_metadata_1.PropertyType.Binary === property.propertyType) {
|
|
620
|
+
changed = hasBinaryValueChanged(entity.asAny[core_common_1.ECJsNames.toJsName(propertyName)], entityProps[core_common_1.ECJsNames.toJsName(propertyName)]);
|
|
604
621
|
}
|
|
605
|
-
else if (
|
|
606
|
-
changed = hasNavigationValueChanged(entity.asAny[propertyName], entityProps[propertyName]);
|
|
622
|
+
else if (property.isNavigation()) {
|
|
623
|
+
changed = hasNavigationValueChanged(entity.asAny[core_common_1.ECJsNames.toJsName(propertyName)], entityProps[core_common_1.ECJsNames.toJsName(propertyName)]);
|
|
607
624
|
}
|
|
608
625
|
else {
|
|
609
|
-
changed = hasValueChanged(entity.asAny[propertyName], entityProps[propertyName]);
|
|
626
|
+
changed = hasValueChanged(entity.asAny[core_common_1.ECJsNames.toJsName(propertyName)], entityProps[core_common_1.ECJsNames.toJsName(propertyName)]);
|
|
610
627
|
}
|
|
611
628
|
}
|
|
612
629
|
});
|