@itwin/imodel-transformer 2.0.0-dev.5 → 2.0.0-dev.7
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/lib/cjs/BranchProvenanceInitializer.d.ts.map +1 -1
- package/lib/cjs/BranchProvenanceInitializer.js +9 -11
- package/lib/cjs/BranchProvenanceInitializer.js.map +1 -1
- package/lib/cjs/DetachedExportElementAspectsStrategy.d.ts.map +1 -1
- package/lib/cjs/DetachedExportElementAspectsStrategy.js +3 -3
- package/lib/cjs/DetachedExportElementAspectsStrategy.js.map +1 -1
- package/lib/cjs/ECReferenceTypesCache.d.ts.map +1 -1
- package/lib/cjs/ECReferenceTypesCache.js +4 -3
- package/lib/cjs/ECReferenceTypesCache.js.map +1 -1
- package/lib/cjs/EntityUnifier.d.ts +1 -1
- package/lib/cjs/EntityUnifier.d.ts.map +1 -1
- package/lib/cjs/EntityUnifier.js +5 -12
- package/lib/cjs/EntityUnifier.js.map +1 -1
- package/lib/cjs/ExportElementAspectsStrategy.d.ts +2 -2
- package/lib/cjs/ExportElementAspectsStrategy.d.ts.map +1 -1
- package/lib/cjs/ExportElementAspectsStrategy.js.map +1 -1
- package/lib/cjs/ExportElementAspectsWithElementsStrategy.js +2 -2
- package/lib/cjs/ExportElementAspectsWithElementsStrategy.js.map +1 -1
- package/lib/cjs/IModelCloneContext.d.ts +2 -2
- package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
- package/lib/cjs/IModelCloneContext.js +52 -50
- package/lib/cjs/IModelCloneContext.js.map +1 -1
- package/lib/cjs/IModelExporter.d.ts +16 -7
- package/lib/cjs/IModelExporter.d.ts.map +1 -1
- package/lib/cjs/IModelExporter.js +78 -83
- package/lib/cjs/IModelExporter.js.map +1 -1
- package/lib/cjs/IModelImporter.d.ts +2 -2
- package/lib/cjs/IModelImporter.d.ts.map +1 -1
- package/lib/cjs/IModelImporter.js +10 -13
- package/lib/cjs/IModelImporter.js.map +1 -1
- package/lib/cjs/IModelTransformer.d.ts +26 -28
- package/lib/cjs/IModelTransformer.d.ts.map +1 -1
- package/lib/cjs/IModelTransformer.js +387 -397
- package/lib/cjs/IModelTransformer.js.map +1 -1
- package/package.json +1 -1
|
@@ -48,7 +48,7 @@ class IModelExportHandler {
|
|
|
48
48
|
*/
|
|
49
49
|
onExportModel(_model, _isUpdate) { }
|
|
50
50
|
/** Called when a model should be deleted. */
|
|
51
|
-
onDeleteModel(_modelId) { }
|
|
51
|
+
async onDeleteModel(_modelId) { }
|
|
52
52
|
/** If `true` is returned, then the element will be exported.
|
|
53
53
|
* @note This method can optionally be overridden to exclude an individual Element (and its children and ElementAspects) from the export. The base implementation always returns `true`.
|
|
54
54
|
*/
|
|
@@ -64,7 +64,7 @@ class IModelExportHandler {
|
|
|
64
64
|
* @param isUpdate If defined, then `true` indicates an UPDATE operation while `false` indicates an INSERT operation. If not defined, then INSERT vs. UPDATE is not known.
|
|
65
65
|
* @note This should be overridden to actually do the export.
|
|
66
66
|
*/
|
|
67
|
-
onExportElement(_element, _isUpdate) { }
|
|
67
|
+
async onExportElement(_element, _isUpdate) { }
|
|
68
68
|
/**
|
|
69
69
|
* Do any asynchronous actions before exporting an element
|
|
70
70
|
* @note Do not implement this handler manually, it is internal, it will be removed.
|
|
@@ -85,11 +85,11 @@ class IModelExportHandler {
|
|
|
85
85
|
* @param isUpdate If defined, then `true` indicates an UPDATE operation while `false` indicates an INSERT operation. If not defined, then INSERT vs. UPDATE is not known.
|
|
86
86
|
* @note This should be overridden to actually do the export.
|
|
87
87
|
*/
|
|
88
|
-
onExportElementUniqueAspect(_aspect, _isUpdate) { }
|
|
88
|
+
async onExportElementUniqueAspect(_aspect, _isUpdate) { }
|
|
89
89
|
/** Called when ElementMultiAspects should be exported.
|
|
90
90
|
* @note This should be overridden to actually do the export.
|
|
91
91
|
*/
|
|
92
|
-
onExportElementMultiAspects(_aspects) { }
|
|
92
|
+
async onExportElementMultiAspects(_aspects) { }
|
|
93
93
|
/** If `true` is returned, then the relationship will be exported.
|
|
94
94
|
* @note This method can optionally be overridden to exclude an individual CodeSpec from the export. The base implementation always returns `true`.
|
|
95
95
|
*/
|
|
@@ -101,7 +101,7 @@ class IModelExportHandler {
|
|
|
101
101
|
* @param isUpdate If defined, then `true` indicates an UPDATE operation while `false` indicates an INSERT operation. If not defined, then INSERT vs. UPDATE is not known.
|
|
102
102
|
* @note This should be overridden to actually do the export.
|
|
103
103
|
*/
|
|
104
|
-
onExportRelationship(_relationship, _isUpdate) { }
|
|
104
|
+
async onExportRelationship(_relationship, _isUpdate) { }
|
|
105
105
|
/** Called when a relationship should be deleted. */
|
|
106
106
|
onDeleteRelationship(_relInstanceId) { }
|
|
107
107
|
/** If `true` is returned, then the schema will be exported.
|
|
@@ -198,8 +198,8 @@ class IModelExporter {
|
|
|
198
198
|
constructor(sourceDb, elementAspectsStrategy = ExportElementAspectsWithElementsStrategy_1.ExportElementAspectsWithElementsStrategy) {
|
|
199
199
|
this.sourceDb = sourceDb;
|
|
200
200
|
this._exportElementAspectsStrategy = new elementAspectsStrategy(this.sourceDb, {
|
|
201
|
-
onExportElementMultiAspects: (aspects) => this.handler.onExportElementMultiAspects(aspects),
|
|
202
|
-
onExportElementUniqueAspect: (aspect, isUpdate) => this.handler.onExportElementUniqueAspect(aspect, isUpdate),
|
|
201
|
+
onExportElementMultiAspects: async (aspects) => this.handler.onExportElementMultiAspects(aspects),
|
|
202
|
+
onExportElementUniqueAspect: async (aspect, isUpdate) => this.handler.onExportElementUniqueAspect(aspect, isUpdate),
|
|
203
203
|
shouldExportElementAspect: (aspect) => this.handler.shouldExportElementAspect(aspect),
|
|
204
204
|
trackProgress: async () => this.trackProgress(),
|
|
205
205
|
});
|
|
@@ -297,7 +297,7 @@ class IModelExporter {
|
|
|
297
297
|
if (this.visitElements) {
|
|
298
298
|
// must delete models first since they have a constraint on the submodeling element which may also be deleted
|
|
299
299
|
for (const modelId of this._sourceDbChanges.model.deleteIds) {
|
|
300
|
-
this.handler.onDeleteModel(modelId);
|
|
300
|
+
await this.handler.onDeleteModel(modelId);
|
|
301
301
|
}
|
|
302
302
|
for (const elementId of this._sourceDbChanges.element.deleteIds) {
|
|
303
303
|
// We don't know how the handler wants to handle deletions, and we don't have enough information
|
|
@@ -346,19 +346,16 @@ class IModelExporter {
|
|
|
346
346
|
ORDER BY ECInstanceId
|
|
347
347
|
`;
|
|
348
348
|
const schemaNamesToExport = [];
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
if (this.handler.shouldExportSchema(schemaKey)) {
|
|
358
|
-
schemaNamesToExport.push(schemaName);
|
|
359
|
-
}
|
|
349
|
+
for await (const row of this.sourceDb.createQueryReader(sql)) {
|
|
350
|
+
const schemaName = row[0];
|
|
351
|
+
const versionMajor = row[1];
|
|
352
|
+
const versionWrite = row[2];
|
|
353
|
+
const versionMinor = row[3];
|
|
354
|
+
const schemaKey = new ecschema_metadata_1.SchemaKey(schemaName, new ecschema_metadata_1.ECVersion(versionMajor, versionWrite, versionMinor));
|
|
355
|
+
if (this.handler.shouldExportSchema(schemaKey)) {
|
|
356
|
+
schemaNamesToExport.push(schemaName);
|
|
360
357
|
}
|
|
361
|
-
}
|
|
358
|
+
}
|
|
362
359
|
if (schemaNamesToExport.length === 0)
|
|
363
360
|
return;
|
|
364
361
|
const schemaLoader = new ecschema_metadata_1.SchemaLoader((name) => this.sourceDb.getSchemaProps(name));
|
|
@@ -378,15 +375,9 @@ class IModelExporter {
|
|
|
378
375
|
async exportCodeSpecs() {
|
|
379
376
|
core_bentley_1.Logger.logTrace(loggerCategory, "exportCodeSpecs()");
|
|
380
377
|
const sql = "SELECT Name FROM BisCore:CodeSpec ORDER BY ECInstanceId";
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
async (statement) => {
|
|
385
|
-
while (core_bentley_1.DbResult.BE_SQLITE_ROW === statement.step()) {
|
|
386
|
-
const codeSpecName = statement.getValue(0).getString();
|
|
387
|
-
await this.exportCodeSpecByName(codeSpecName);
|
|
388
|
-
}
|
|
389
|
-
});
|
|
378
|
+
for await (const row of this.sourceDb.createQueryReader(sql)) {
|
|
379
|
+
await this.exportCodeSpecByName(row.name);
|
|
380
|
+
}
|
|
390
381
|
}
|
|
391
382
|
/** Export a single CodeSpec from the source iModel.
|
|
392
383
|
* @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
|
|
@@ -430,18 +421,39 @@ class IModelExporter {
|
|
|
430
421
|
*/
|
|
431
422
|
async exportFonts() {
|
|
432
423
|
core_bentley_1.Logger.logTrace(loggerCategory, "exportFonts()");
|
|
433
|
-
for (const font of this.sourceDb.
|
|
434
|
-
await this.
|
|
424
|
+
for (const font of this.sourceDb.fonts.queryMappedFamilies()) {
|
|
425
|
+
await this.exportFontByFontProps(font);
|
|
435
426
|
}
|
|
436
427
|
}
|
|
437
428
|
/** Export a single font from the source iModel.
|
|
438
|
-
* @note
|
|
429
|
+
* @note multiple fonts can have the same font name, if a font with a specific type is needed use exportFontByFontFamilyDescriptor.
|
|
430
|
+
* If not this will only export the first font with this type in the db.
|
|
439
431
|
*/
|
|
440
432
|
async exportFontByName(fontName) {
|
|
441
433
|
core_bentley_1.Logger.logTrace(loggerCategory, `exportFontByName(${fontName})`);
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
|
|
434
|
+
const fontId = this.sourceDb.fonts.findId({
|
|
435
|
+
name: fontName,
|
|
436
|
+
});
|
|
437
|
+
if (undefined !== fontId) {
|
|
438
|
+
await this.exportFontByNumber(fontId);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
/** Export a single font from the source iModel.
|
|
442
|
+
* @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
|
|
443
|
+
*/
|
|
444
|
+
async exportFontByFontProps(fontProps) {
|
|
445
|
+
core_bentley_1.Logger.logTrace(loggerCategory, `exportFontByFamily(${fontProps.name}, ${fontProps.type})`);
|
|
446
|
+
this.handler.onExportFont(fontProps, true);
|
|
447
|
+
return this.trackProgress();
|
|
448
|
+
}
|
|
449
|
+
/** Export a single font from the source iModel.
|
|
450
|
+
* @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
|
|
451
|
+
*/
|
|
452
|
+
async exportFontByFontFamilyDescriptor(fontFamily) {
|
|
453
|
+
core_bentley_1.Logger.logTrace(loggerCategory, `exportFontByFamilyDescriptor(${fontFamily.name}, ${fontFamily.type})`);
|
|
454
|
+
const fontId = await this.sourceDb.fonts.acquireId(fontFamily);
|
|
455
|
+
if (undefined !== fontId) {
|
|
456
|
+
await this.exportFontByFontProps({ ...fontFamily, id: fontId });
|
|
445
457
|
}
|
|
446
458
|
}
|
|
447
459
|
/** Export a single font from the source iModel.
|
|
@@ -453,12 +465,10 @@ class IModelExporter {
|
|
|
453
465
|
* It is very rare and even problematic for the font table to reach a large size, so it is not a bottleneck in transforming changes.
|
|
454
466
|
* See https://github.com/iTwin/imodel-transformer/pull/135 for removed code.
|
|
455
467
|
*/
|
|
456
|
-
const isUpdate = true;
|
|
457
468
|
core_bentley_1.Logger.logTrace(loggerCategory, `exportFontById(${fontNumber})`);
|
|
458
|
-
const font = this.sourceDb.
|
|
469
|
+
const font = this.sourceDb.fonts.findDescriptor(fontNumber);
|
|
459
470
|
if (undefined !== font) {
|
|
460
|
-
this.
|
|
461
|
-
return this.trackProgress();
|
|
471
|
+
await this.exportFontByFontFamilyDescriptor(font);
|
|
462
472
|
}
|
|
463
473
|
}
|
|
464
474
|
/** Export the model container, contents, and sub-models from the source iModel.
|
|
@@ -533,19 +543,16 @@ class IModelExporter {
|
|
|
533
543
|
else {
|
|
534
544
|
sql = `SELECT ECInstanceId FROM ${elementClassFullName} WHERE Parent.Id IS NULL AND Model.Id=:modelId ORDER BY ECInstanceId`;
|
|
535
545
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
await this._yieldManager.allowYield();
|
|
547
|
-
}
|
|
548
|
-
});
|
|
546
|
+
const params = new core_common_1.QueryBinder().bindId("modelId", modelId);
|
|
547
|
+
if (skipRootSubject) {
|
|
548
|
+
params.bindId("rootSubjectId", core_common_1.IModel.rootSubjectId);
|
|
549
|
+
}
|
|
550
|
+
for await (const row of this.sourceDb.createQueryReader(sql, params, {
|
|
551
|
+
usePrimaryConn: true,
|
|
552
|
+
})) {
|
|
553
|
+
await this.exportElement(row.id);
|
|
554
|
+
await this._yieldManager.allowYield();
|
|
555
|
+
}
|
|
549
556
|
}
|
|
550
557
|
/** Export the sub-models directly below the specified model.
|
|
551
558
|
* @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
|
|
@@ -555,22 +562,17 @@ class IModelExporter {
|
|
|
555
562
|
const definitionModelIds = [];
|
|
556
563
|
const otherModelIds = [];
|
|
557
564
|
const sql = `SELECT ECInstanceId FROM ${core_backend_1.Model.classFullName} WHERE ParentModel.Id=:parentModelId ORDER BY ECInstanceId`;
|
|
558
|
-
|
|
559
|
-
this.sourceDb.
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
const modelId = statement.getValue(0).getId();
|
|
565
|
-
const model = this.sourceDb.models.getModel(modelId);
|
|
566
|
-
if (model instanceof core_backend_1.DefinitionModel) {
|
|
567
|
-
definitionModelIds.push(modelId);
|
|
568
|
-
}
|
|
569
|
-
else {
|
|
570
|
-
otherModelIds.push(modelId);
|
|
571
|
-
}
|
|
565
|
+
const params = new core_common_1.QueryBinder().bindId("parentModelId", parentModelId);
|
|
566
|
+
for await (const row of this.sourceDb.createQueryReader(sql, params)) {
|
|
567
|
+
const modelId = row.ecinstanceid;
|
|
568
|
+
const model = this.sourceDb.models.getModel(modelId);
|
|
569
|
+
if (model instanceof core_backend_1.DefinitionModel) {
|
|
570
|
+
definitionModelIds.push(modelId);
|
|
572
571
|
}
|
|
573
|
-
|
|
572
|
+
else {
|
|
573
|
+
otherModelIds.push(modelId);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
574
576
|
// export DefinitionModels before other types of Models
|
|
575
577
|
for (const definitionModelId of definitionModelIds) {
|
|
576
578
|
await this.exportModel(definitionModelId);
|
|
@@ -637,7 +639,7 @@ class IModelExporter {
|
|
|
637
639
|
// the order and `await`ing of calls beyond here is depended upon by the IModelTransformer for a current bug workaround
|
|
638
640
|
if (this.shouldExportElement(element)) {
|
|
639
641
|
await this.handler.preExportElement(element);
|
|
640
|
-
this.handler.onExportElement(element, isUpdate);
|
|
642
|
+
await this.handler.onExportElement(element, isUpdate);
|
|
641
643
|
await this.trackProgress();
|
|
642
644
|
await this._exportElementAspectsStrategy.exportElementAspectsForElement(elementId);
|
|
643
645
|
return this.exportChildElements(elementId);
|
|
@@ -676,23 +678,16 @@ class IModelExporter {
|
|
|
676
678
|
return;
|
|
677
679
|
}
|
|
678
680
|
core_bentley_1.Logger.logTrace(loggerCategory, `exportRelationships(${baseRelClassFullName})`);
|
|
679
|
-
const sql = `SELECT r.ECInstanceId, r.ECClassId FROM ${baseRelClassFullName} r
|
|
681
|
+
const sql = `SELECT r.ECInstanceId, ec_className(r.ECClassId, 's.c') as ClassName FROM ${baseRelClassFullName} r
|
|
680
682
|
JOIN bis.Element s ON s.ECInstanceId = r.SourceECInstanceId
|
|
681
683
|
JOIN bis.Element t ON t.ECInstanceId = r.TargetECInstanceId
|
|
682
684
|
WHERE s.ECInstanceId IS NOT NULL AND t.ECInstanceId IS NOT NULL`;
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
const relationshipClass = statement
|
|
690
|
-
.getValue(1)
|
|
691
|
-
.getClassNameForClassId();
|
|
692
|
-
await this.exportRelationship(relationshipClass, relationshipId); // must call exportRelationship using the actual classFullName, not baseRelClassFullName
|
|
693
|
-
await this._yieldManager.allowYield();
|
|
694
|
-
}
|
|
695
|
-
});
|
|
685
|
+
for await (const row of this.sourceDb.createQueryReader(sql)) {
|
|
686
|
+
const relationshipId = row.ecinstanceid;
|
|
687
|
+
const relationshipClass = row.classname;
|
|
688
|
+
await this.exportRelationship(relationshipClass, relationshipId); // must call exportRelationship using the actual classFullName, not baseRelClassFullName
|
|
689
|
+
await this._yieldManager.allowYield();
|
|
690
|
+
}
|
|
696
691
|
}
|
|
697
692
|
/** Export a relationship from the source iModel. */
|
|
698
693
|
async exportRelationship(relClassFullName, relInstanceId) {
|
|
@@ -724,7 +719,7 @@ class IModelExporter {
|
|
|
724
719
|
}
|
|
725
720
|
// relationship has passed standard exclusion rules, now give handler a chance to accept/reject export
|
|
726
721
|
if (this.handler.shouldExportRelationship(relationship)) {
|
|
727
|
-
this.handler.onExportRelationship(relationship, isUpdate);
|
|
722
|
+
await this.handler.onExportRelationship(relationship, isUpdate);
|
|
728
723
|
await this.trackProgress();
|
|
729
724
|
}
|
|
730
725
|
}
|