@itwin/imodel-transformer 2.0.0-dev.5 → 2.0.0-dev.6

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 (31) hide show
  1. package/lib/cjs/BranchProvenanceInitializer.d.ts.map +1 -1
  2. package/lib/cjs/BranchProvenanceInitializer.js +1 -3
  3. package/lib/cjs/BranchProvenanceInitializer.js.map +1 -1
  4. package/lib/cjs/DetachedExportElementAspectsStrategy.d.ts.map +1 -1
  5. package/lib/cjs/DetachedExportElementAspectsStrategy.js +2 -2
  6. package/lib/cjs/DetachedExportElementAspectsStrategy.js.map +1 -1
  7. package/lib/cjs/ECReferenceTypesCache.d.ts.map +1 -1
  8. package/lib/cjs/ECReferenceTypesCache.js +4 -3
  9. package/lib/cjs/ECReferenceTypesCache.js.map +1 -1
  10. package/lib/cjs/ExportElementAspectsStrategy.d.ts +2 -2
  11. package/lib/cjs/ExportElementAspectsStrategy.d.ts.map +1 -1
  12. package/lib/cjs/ExportElementAspectsStrategy.js.map +1 -1
  13. package/lib/cjs/ExportElementAspectsWithElementsStrategy.js +2 -2
  14. package/lib/cjs/ExportElementAspectsWithElementsStrategy.js.map +1 -1
  15. package/lib/cjs/IModelCloneContext.d.ts +2 -2
  16. package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
  17. package/lib/cjs/IModelCloneContext.js +38 -37
  18. package/lib/cjs/IModelCloneContext.js.map +1 -1
  19. package/lib/cjs/IModelExporter.d.ts +16 -7
  20. package/lib/cjs/IModelExporter.d.ts.map +1 -1
  21. package/lib/cjs/IModelExporter.js +78 -83
  22. package/lib/cjs/IModelExporter.js.map +1 -1
  23. package/lib/cjs/IModelImporter.d.ts +2 -2
  24. package/lib/cjs/IModelImporter.d.ts.map +1 -1
  25. package/lib/cjs/IModelImporter.js +10 -13
  26. package/lib/cjs/IModelImporter.js.map +1 -1
  27. package/lib/cjs/IModelTransformer.d.ts +13 -13
  28. package/lib/cjs/IModelTransformer.d.ts.map +1 -1
  29. package/lib/cjs/IModelTransformer.js +243 -265
  30. package/lib/cjs/IModelTransformer.js.map +1 -1
  31. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"IModelCloneContext.js","sourceRoot":"","sources":["../../src/IModelCloneContext.ts"],"names":[],"mappings":";;;AAAA;;;gGAGgG;AAChG;;GAEG;AACH,iCAAiC;AACjC,sDAAyE;AACzE,oDAa4B;AAC5B,sDAO6B;AAC7B,mEAAgE;AAChE,mDAAgD;AAChD,2EAAwE;AAExE,MAAM,cAAc,GAAW,qDAAyB,CAAC,kBAAkB,CAAC;AAE5E;;GAEG;AACH,MAAa,kBAAmB,SAAQ,wCAAyB;IACvD,cAAc,GAAG,IAAI,6CAAqB,EAAE,CAAC;IAC7C,iBAAiB,GAAG,IAAI,GAAG,EAA0B,CAAC;IAE9D,0HAA0H;IAC1G,KAAK,CAAC,UAAU;QAC9B,MAAM,IAAI,CAAC,cAAc,CAAC,sBAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACa,YAAY,CAC1B,aAAsB,EACtB,YAAiD;QAEjD,MAAM,kBAAkB,GAAiB,IAAI,CAC3C,gBAAgB,CACjB,CAAC,YAAY,CAAC,aAAa,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;QAC/C,iJAAiJ;QACjJ,aAAa,CAAC,eAAe,CAC3B,CAAC,YAAoB,EAAE,IAAsB,EAAE,EAAE;YAC/C,IACE,IAAI,CAAC,YAAY;gBACjB,SAAS,KAAM,aAAqB,CAAC,YAAY,CAAC,EAClD,CAAC;gBACA,kBAA0B,CAAC,YAAY,CAAC,GAAG,4BAAc,CAAC,IAAI,CAAC;YAClE,CAAC;QACH,CAAC,EACD,KAAK,CACN,CAAC,CAAC,sDAAsD;QACzD,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC1B,kHAAkH;YAClH,kBAAkB,CAAC,cAAc,GAAG,aAAa,CAAC,cAAc,CAA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;QACH,OAAO,wBAAwB,CAAC;IAClC,CAAC;CACF;AAlQD,gDAkQC","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/** @packageDocumentation\n * @module iModels\n */\nimport * as assert from \"assert\";\nimport { DbResult, Id64, Id64String, Logger } from \"@itwin/core-bentley\";\nimport {\n Code,\n CodeScopeSpec,\n ConcreteEntityTypes,\n ElementAspectProps,\n ElementProps,\n EntityReference,\n IModel,\n IModelError,\n PrimitiveTypeCode,\n PropertyMetaData,\n RelatedElement,\n RelatedElementProps,\n} from \"@itwin/core-common\";\nimport {\n // eslint-disable-next-line @typescript-eslint/no-redeclare\n Element,\n ElementAspect,\n EntityReferences,\n IModelElementCloneContext,\n IModelJsNative,\n} from \"@itwin/core-backend\";\nimport { ECReferenceTypesCache } from \"./ECReferenceTypesCache\";\nimport { EntityUnifier } from \"./EntityUnifier\";\nimport { TransformerLoggerCategory } from \"./TransformerLoggerCategory\";\n\nconst loggerCategory: string = TransformerLoggerCategory.IModelCloneContext;\n\n/** The context for transforming a *source* Element to a *target* Element and remapping internal identifiers to the target iModel.\n * @beta\n */\nexport class IModelCloneContext extends IModelElementCloneContext {\n private _refTypesCache = new ECReferenceTypesCache();\n private _aspectRemapTable = new Map<Id64String, Id64String>();\n\n /** perform necessary initialization to use a clone context, namely caching the reference types in the source's schemas */\n public override async initialize() {\n await this._refTypesCache.initAllSchemasInIModel(this.sourceDb);\n }\n\n /** Clone the specified source Element into ElementProps for the target iModel.\n * @internal\n */\n public override cloneElement(\n sourceElement: Element,\n cloneOptions?: IModelJsNative.CloneElementOptions\n ): ElementProps {\n const targetElementProps: ElementProps = this[\n \"_nativeContext\"\n ].cloneElement(sourceElement.id, cloneOptions);\n // Ensure that all NavigationProperties in targetElementProps have a defined value so \"clearing\" changes will be part of the JSON used for update\n sourceElement.forEachProperty(\n (propertyName: string, meta: PropertyMetaData) => {\n if (\n meta.isNavigation &&\n undefined === (sourceElement as any)[propertyName]\n ) {\n (targetElementProps as any)[propertyName] = RelatedElement.none;\n }\n },\n false\n ); // exclude custom because C++ has already handled them\n if (this.isBetweenIModels) {\n // The native C++ cloneElement strips off federationGuid, want to put it back if transformation is between iModels\n targetElementProps.federationGuid = sourceElement.federationGuid;\n const targetElementCodeScopeType = this.targetDb.codeSpecs.getById(\n targetElementProps.code.spec\n ).scopeType;\n if (\n CodeScopeSpec.Type.Repository === targetElementCodeScopeType &&\n targetElementProps.code.scope !== IModel.rootSubjectId\n ) {\n Logger.logWarning(\n loggerCategory,\n `Incorrect CodeScope '${targetElementCodeScopeType}' is set for target element ${targetElementProps.id}`\n );\n }\n }\n // unlike other references, code cannot be null. If it is null, use an empty code instead\n // this will be updated back later as the transformer resolves references\n if (\n targetElementProps.code.scope === Id64.invalid ||\n targetElementProps.code.spec === Id64.invalid\n ) {\n targetElementProps.code = Code.createEmpty();\n }\n const jsClass = this.sourceDb.getJsClass<typeof Element>(\n sourceElement.classFullName\n );\n jsClass[\"onCloned\"](this, sourceElement.toJSON(), targetElementProps);\n return targetElementProps;\n }\n\n /** Add a rule that remaps the specified source ElementAspect to the specified target ElementAspect. */\n public remapElementAspect(\n aspectSourceId: Id64String,\n aspectTargetId: Id64String\n ): void {\n this._aspectRemapTable.set(aspectSourceId, aspectTargetId);\n }\n\n /** Remove a rule that remaps the specified source ElementAspect */\n public removeElementAspect(aspectSourceId: Id64String): void {\n this._aspectRemapTable.delete(aspectSourceId);\n }\n\n /** Look up a target AspectId from the source AspectId.\n * @returns the target AspectId or [Id64.invalid]($bentley) if a mapping not found.\n */\n public findTargetAspectId(sourceAspectId: Id64String): Id64String {\n return this._aspectRemapTable.get(sourceAspectId) ?? Id64.invalid;\n }\n\n /** Look up a target [EntityReference]($bentley) from a source [EntityReference]($bentley)\n * @returns the target CodeSpecId or a [EntityReference]($bentley) containing [Id64.invalid]($bentley) if a mapping is not found.\n */\n public findTargetEntityId(sourceEntityId: EntityReference): EntityReference {\n const [type, rawId] = EntityReferences.split(sourceEntityId);\n if (Id64.isValid(rawId)) {\n switch (type) {\n case ConcreteEntityTypes.Model: {\n let targetId;\n /**\n * The repository model is a singleton container which exists in all iModels which has a modelId of 0x1.\n * It is possible to remap the root subject (id 0x1) to some other non root subject, but this is not possible for the repository model.\n * The RepositoryModel only contains bis:Subject elements and bis:InformationpartitionElement instances (https://www.itwinjs.org/bis/domains/biscore.ecschema/#repositorymodel)\n * The system handler for both bis:InformationPartitionElement and bis:Subject will only permit instances to be inserted into the RepositoryModel.\n * https://www.itwinjs.org/bis/domains/biscore.ecschema/#informationpartitionelement\n * https://www.itwinjs.org/bis/domains/biscore.ecschema/#subject\n * Since there is a chance that the root subject is remapped to some other subject which has the same id as the repositoryModel, we need to ignore the remapping for the repository model.\n */\n if (rawId === IModel.repositoryModelId) {\n targetId = `m${IModel.repositoryModelId}` as const;\n } else {\n targetId = `m${this.findTargetElementId(rawId)}` as const;\n }\n // Check if the model exists, `findTargetElementId` may have worked because the element exists when the model doesn't.\n // That can occur in the transformer since a submodeled element is imported before its submodel.\n if (\n EntityUnifier.exists(this.targetDb, { entityReference: targetId })\n )\n return targetId;\n break;\n }\n case ConcreteEntityTypes.Element:\n return `e${this.findTargetElementId(rawId)}`;\n case ConcreteEntityTypes.ElementAspect:\n return `a${this.findTargetAspectId(rawId)}`;\n case ConcreteEntityTypes.Relationship: {\n const makeGetConcreteEntityTypeSql = (property: string) => `\n CASE\n WHEN [${property}] IS (BisCore.ElementUniqueAspect) OR [${property}] IS (BisCore.ElementMultiAspect)\n THEN 'a'\n WHEN [${property}] IS (BisCore.Element)\n THEN 'e'\n WHEN [${property}] IS (BisCore.Model)\n THEN 'm'\n WHEN [${property}] IS (BisCore.CodeSpec)\n THEN 'c'\n WHEN [${property}] IS (BisCore.ElementRefersToElements) -- TODO: ElementDrivesElement still not handled by the transformer\n THEN 'r'\n ELSE 'error'\n END\n `;\n // eslint-disable-next-line @itwin/no-internal, @typescript-eslint/no-deprecated\n const relInSource = this.sourceDb.withPreparedStatement(\n `\n SELECT\n SourceECInstanceId,\n TargetECInstanceId,\n (${makeGetConcreteEntityTypeSql(\n \"SourceECClassId\"\n )}) AS SourceType,\n (${makeGetConcreteEntityTypeSql(\"TargetECClassId\")}) AS TargetType\n FROM BisCore:ElementRefersToElements\n WHERE ECInstanceId=?\n `,\n (stmt) => {\n stmt.bindId(1, rawId);\n let status: DbResult;\n while ((status = stmt.step()) === DbResult.BE_SQLITE_ROW) {\n const sourceId = stmt.getValue(0).getId();\n const targetId = stmt.getValue(1).getId();\n const sourceType = stmt.getValue(2).getString() as\n | ConcreteEntityTypes\n | \"error\";\n const targetType = stmt.getValue(3).getString() as\n | ConcreteEntityTypes\n | \"error\";\n if (sourceType === \"error\" || targetType === \"error\")\n throw Error(\"relationship end had unknown root class\");\n return {\n sourceId: `${sourceType}${sourceId}`,\n targetId: `${targetType}${targetId}`,\n } as const;\n }\n if (status !== DbResult.BE_SQLITE_DONE)\n throw new IModelError(status, \"unexpected query failure\");\n return undefined;\n }\n );\n if (relInSource === undefined) break;\n // just in case prevent recursion\n if (\n relInSource.sourceId === sourceEntityId ||\n relInSource.targetId === sourceEntityId\n )\n throw Error(\n \"link table relationship end was resolved to itself. This should be impossible\"\n );\n const relInTarget = {\n sourceId: this.findTargetEntityId(relInSource.sourceId),\n targetId: this.findTargetEntityId(relInSource.targetId),\n };\n // return a null\n if (\n !EntityReferences.isValid(relInTarget.sourceId) ||\n !EntityReferences.isValid(relInTarget.targetId)\n )\n break;\n // eslint-disable-next-line @itwin/no-internal, @typescript-eslint/no-deprecated\n const relInTargetId = this.targetDb.withPreparedStatement(\n `\n SELECT ECInstanceId\n FROM BisCore:ElementRefersToElements\n WHERE SourceECInstanceId=?\n AND TargetECInstanceId=?\n `,\n (stmt) => {\n stmt.bindId(1, EntityReferences.toId64(relInTarget.sourceId));\n stmt.bindId(2, EntityReferences.toId64(relInTarget.targetId));\n const status: DbResult = stmt.step();\n if (status === DbResult.BE_SQLITE_ROW)\n return stmt.getValue(0).getId();\n if (status !== DbResult.BE_SQLITE_DONE)\n throw new IModelError(status, \"unexpected query failure\");\n return Id64.invalid;\n }\n );\n return `r${relInTargetId}`;\n }\n }\n }\n return `${type}${Id64.invalid}`;\n }\n\n /** Clone the specified source Element into ElementProps for the target iModel.\n * @internal\n */\n public cloneElementAspect(\n sourceElementAspect: ElementAspect\n ): ElementAspectProps {\n const targetElementAspectProps: ElementAspectProps =\n sourceElementAspect.toJSON();\n targetElementAspectProps.id = undefined;\n sourceElementAspect.forEachProperty((propertyName, propertyMetaData) => {\n if (propertyMetaData.isNavigation) {\n const sourceNavProp: RelatedElementProps | undefined =\n sourceElementAspect.asAny[propertyName];\n if (sourceNavProp?.id) {\n const navPropRefType = this._refTypesCache.getNavPropRefType(\n sourceElementAspect.schemaName,\n sourceElementAspect.className,\n propertyName\n );\n assert(\n navPropRefType !== undefined,\n `nav prop ref type for '${propertyName}' was not in the cache, this is a bug.`\n );\n const targetEntityReference = this.findTargetEntityId(\n EntityReferences.fromEntityType(sourceNavProp.id, navPropRefType)\n );\n const targetEntityId = EntityReferences.toId64(targetEntityReference);\n // spread the property in case toJSON did not deep-clone\n (targetElementAspectProps as any)[propertyName] = {\n ...(targetElementAspectProps as any)[propertyName],\n id: targetEntityId,\n };\n }\n } else if (\n PrimitiveTypeCode.Long === propertyMetaData.primitiveType &&\n \"Id\" === propertyMetaData.extendedType\n ) {\n (targetElementAspectProps as any)[propertyName] =\n this.findTargetElementId(sourceElementAspect.asAny[propertyName]);\n }\n });\n return targetElementAspectProps;\n }\n}\n"]}
1
+ {"version":3,"file":"IModelCloneContext.js","sourceRoot":"","sources":["../../src/IModelCloneContext.ts"],"names":[],"mappings":";;;AAAA;;;gGAGgG;AAChG;;GAEG;AACH,iCAAiC;AACjC,sDAAyE;AACzE,oDAa4B;AAC5B,sDAO6B;AAC7B,mEAAgE;AAChE,mDAAgD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,CAAC;QACnC,OAAO,wBAAwB,CAAC;IAClC,CAAC;CACF;AAnQD,gDAmQC","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/** @packageDocumentation\n * @module iModels\n */\nimport * as assert from \"assert\";\nimport { DbResult, Id64, Id64String, Logger } from \"@itwin/core-bentley\";\nimport {\n Code,\n CodeScopeSpec,\n ConcreteEntityTypes,\n ECJsNames,\n ElementAspectProps,\n ElementProps,\n EntityReference,\n IModel,\n IModelError,\n QueryBinder,\n RelatedElement,\n RelatedElementProps,\n} from \"@itwin/core-common\";\nimport {\n // eslint-disable-next-line @typescript-eslint/no-redeclare\n Element,\n ElementAspect,\n EntityReferences,\n IModelElementCloneContext,\n IModelJsNative,\n} from \"@itwin/core-backend\";\nimport { ECReferenceTypesCache } from \"./ECReferenceTypesCache\";\nimport { EntityUnifier } from \"./EntityUnifier\";\nimport { TransformerLoggerCategory } from \"./TransformerLoggerCategory\";\nimport { parseClassModifier, Property } from \"@itwin/ecschema-metadata\";\n\nconst loggerCategory: string = TransformerLoggerCategory.IModelCloneContext;\n\n/** The context for transforming a *source* Element to a *target* Element and remapping internal identifiers to the target iModel.\n * @beta\n */\nexport class IModelCloneContext extends IModelElementCloneContext {\n private _refTypesCache = new ECReferenceTypesCache();\n private _aspectRemapTable = new Map<Id64String, Id64String>();\n\n /** perform necessary initialization to use a clone context, namely caching the reference types in the source's schemas */\n public override async initialize() {\n await this._refTypesCache.initAllSchemasInIModel(this.sourceDb);\n }\n\n /** Clone the specified source Element into ElementProps for the target iModel.\n * @internal\n */\n public override cloneElement(\n sourceElement: Element,\n cloneOptions?: IModelJsNative.CloneElementOptions\n ): ElementProps {\n const targetElementProps: ElementProps = this[\n \"_nativeContext\"\n ].cloneElement(sourceElement.id, cloneOptions);\n // Ensure that all NavigationProperties in targetElementProps have a defined value so \"clearing\" changes will be part of the JSON used for update\n sourceElement.forEach((name: string, property: Property) => {\n if (\n property.isNavigation() &&\n undefined === (sourceElement as any)[ECJsNames.toJsName(name)]\n ) {\n (targetElementProps as any)[ECJsNames.toJsName(name)] =\n RelatedElement.none;\n }\n }, false); // exclude custom because C++ has already handled them\n if (this.isBetweenIModels) {\n // The native C++ cloneElement strips off federationGuid, want to put it back if transformation is between iModels\n targetElementProps.federationGuid = sourceElement.federationGuid;\n const targetElementCodeScopeType = this.targetDb.codeSpecs.getById(\n targetElementProps.code.spec\n ).scopeType;\n if (\n CodeScopeSpec.Type.Repository === targetElementCodeScopeType &&\n targetElementProps.code.scope !== IModel.rootSubjectId\n ) {\n Logger.logWarning(\n loggerCategory,\n `Incorrect CodeScope '${targetElementCodeScopeType}' is set for target element ${targetElementProps.id}`\n );\n }\n }\n // unlike other references, code cannot be null. If it is null, use an empty code instead\n // this will be updated back later as the transformer resolves references\n if (\n targetElementProps.code.scope === Id64.invalid ||\n targetElementProps.code.spec === Id64.invalid\n ) {\n targetElementProps.code = Code.createEmpty();\n }\n const jsClass = this.sourceDb.getJsClass<typeof Element>(\n sourceElement.classFullName\n );\n jsClass[\"onCloned\"](this, sourceElement.toJSON(), targetElementProps);\n return targetElementProps;\n }\n\n /** Add a rule that remaps the specified source ElementAspect to the specified target ElementAspect. */\n public remapElementAspect(\n aspectSourceId: Id64String,\n aspectTargetId: Id64String\n ): void {\n this._aspectRemapTable.set(aspectSourceId, aspectTargetId);\n }\n\n /** Remove a rule that remaps the specified source ElementAspect */\n public removeElementAspect(aspectSourceId: Id64String): void {\n this._aspectRemapTable.delete(aspectSourceId);\n }\n\n /** Look up a target AspectId from the source AspectId.\n * @returns the target AspectId or [Id64.invalid]($bentley) if a mapping not found.\n */\n public findTargetAspectId(sourceAspectId: Id64String): Id64String {\n return this._aspectRemapTable.get(sourceAspectId) ?? Id64.invalid;\n }\n\n /** Look up a target [EntityReference]($bentley) from a source [EntityReference]($bentley)\n * @returns the target CodeSpecId or a [EntityReference]($bentley) containing [Id64.invalid]($bentley) if a mapping is not found.\n */\n public async findTargetEntityId(\n sourceEntityId: EntityReference\n ): Promise<EntityReference> {\n const [type, rawId] = EntityReferences.split(sourceEntityId);\n if (Id64.isValid(rawId)) {\n switch (type) {\n case ConcreteEntityTypes.Model: {\n let targetId;\n /**\n * The repository model is a singleton container which exists in all iModels which has a modelId of 0x1.\n * It is possible to remap the root subject (id 0x1) to some other non root subject, but this is not possible for the repository model.\n * The RepositoryModel only contains bis:Subject elements and bis:InformationpartitionElement instances (https://www.itwinjs.org/bis/domains/biscore.ecschema/#repositorymodel)\n * The system handler for both bis:InformationPartitionElement and bis:Subject will only permit instances to be inserted into the RepositoryModel.\n * https://www.itwinjs.org/bis/domains/biscore.ecschema/#informationpartitionelement\n * https://www.itwinjs.org/bis/domains/biscore.ecschema/#subject\n * Since there is a chance that the root subject is remapped to some other subject which has the same id as the repositoryModel, we need to ignore the remapping for the repository model.\n */\n if (rawId === IModel.repositoryModelId) {\n targetId = `m${IModel.repositoryModelId}` as const;\n } else {\n targetId = `m${this.findTargetElementId(rawId)}` as const;\n }\n // Check if the model exists, `findTargetElementId` may have worked because the element exists when the model doesn't.\n // That can occur in the transformer since a submodeled element is imported before its submodel.\n if (\n EntityUnifier.exists(this.targetDb, { entityReference: targetId })\n )\n return targetId;\n break;\n }\n case ConcreteEntityTypes.Element:\n return `e${this.findTargetElementId(rawId)}`;\n case ConcreteEntityTypes.ElementAspect:\n return `a${this.findTargetAspectId(rawId)}`;\n case ConcreteEntityTypes.Relationship: {\n const makeGetConcreteEntityTypeSql = (property: string) => `\n CASE\n WHEN [${property}] IS (BisCore.ElementUniqueAspect) OR [${property}] IS (BisCore.ElementMultiAspect)\n THEN 'a'\n WHEN [${property}] IS (BisCore.Element)\n THEN 'e'\n WHEN [${property}] IS (BisCore.Model)\n THEN 'm'\n WHEN [${property}] IS (BisCore.CodeSpec)\n THEN 'c'\n WHEN [${property}] IS (BisCore.ElementRefersToElements) -- TODO: ElementDrivesElement still not handled by the transformer\n THEN 'r'\n ELSE 'error'\n END\n `;\n const sql = `\n SELECT\n SourceECInstanceId,\n TargetECInstanceId,\n (${makeGetConcreteEntityTypeSql(\n \"SourceECClassId\"\n )}) AS SourceType,\n (${makeGetConcreteEntityTypeSql(\"TargetECClassId\")}) AS TargetType\n FROM BisCore:ElementRefersToElements\n WHERE ECInstanceId=?\n `;\n const params = new QueryBinder().bindId(1, rawId);\n const reader = this.sourceDb.createQueryReader(sql, params);\n const relInSource = await (async () => {\n if (await reader.step()) {\n const sourceId = reader.current[0];\n const targetId = reader.current[1];\n const sourceType = reader.current[2] as\n | ConcreteEntityTypes\n | \"error\";\n const targetType = reader.current[3] as\n | ConcreteEntityTypes\n | \"error\";\n if (sourceType === \"error\" || targetType === \"error\")\n throw Error(\"relationship end had unknown root class\");\n return {\n sourceId: `${sourceType}${sourceId}`,\n targetId: `${targetType}${targetId}`,\n } as const;\n }\n return undefined;\n })();\n if (relInSource === undefined) break;\n // just in case prevent recursion\n if (\n relInSource.sourceId === sourceEntityId ||\n relInSource.targetId === sourceEntityId\n )\n throw Error(\n \"link table relationship end was resolved to itself. This should be impossible\"\n );\n const relInTarget = {\n sourceId: await this.findTargetEntityId(relInSource.sourceId),\n targetId: await this.findTargetEntityId(relInSource.targetId),\n };\n // return a null\n if (\n !EntityReferences.isValid(relInTarget.sourceId) ||\n !EntityReferences.isValid(relInTarget.targetId)\n )\n break;\n // eslint-disable-next-line @itwin/no-internal, @typescript-eslint/no-deprecated\n const relInTargetId = this.targetDb.withPreparedStatement(\n `\n SELECT ECInstanceId\n FROM BisCore:ElementRefersToElements\n WHERE SourceECInstanceId=?\n AND TargetECInstanceId=?\n `,\n (stmt) => {\n stmt.bindId(1, EntityReferences.toId64(relInTarget.sourceId));\n stmt.bindId(2, EntityReferences.toId64(relInTarget.targetId));\n const status: DbResult = stmt.step();\n if (status === DbResult.BE_SQLITE_ROW)\n return stmt.getValue(0).getId();\n if (status !== DbResult.BE_SQLITE_DONE)\n throw new IModelError(status, \"unexpected query failure\");\n return Id64.invalid;\n }\n );\n return `r${relInTargetId}`;\n }\n }\n }\n return `${type}${Id64.invalid}`;\n }\n\n /** Clone the specified source Element into ElementProps for the target iModel.\n * @internal\n */\n public async cloneElementAspect(\n sourceElementAspect: ElementAspect\n ): Promise<ElementAspectProps> {\n const targetElementAspectProps: ElementAspectProps =\n sourceElementAspect.toJSON();\n targetElementAspectProps.id = undefined;\n const targetEntityIds: Promise<void>[] = [];\n sourceElementAspect.forEach((name, property) => {\n if (property.isNavigation()) {\n const sourceNavProp: RelatedElementProps | undefined =\n sourceElementAspect.asAny[ECJsNames.toJsName(name)];\n if (sourceNavProp?.id) {\n const navPropRefType = this._refTypesCache.getNavPropRefType(\n sourceElementAspect.schemaName,\n sourceElementAspect.className,\n ECJsNames.toJsName(name)\n );\n assert(\n navPropRefType !== undefined,\n `nav prop ref type for '${name}' was not in the cache, this is a bug.`\n );\n targetEntityIds.push(\n this.findTargetEntityId(\n EntityReferences.fromEntityType(sourceNavProp.id, navPropRefType)\n ).then((targetEntityReference) => {\n const targetEntityId = EntityReferences.toId64(\n targetEntityReference\n );\n // spread the property in case toJSON did not deep-clone\n (targetElementAspectProps as any)[ECJsNames.toJsName(name)] = {\n ...(targetElementAspectProps as any)[ECJsNames.toJsName(name)],\n id: targetEntityId,\n };\n })\n );\n }\n } else if (property.isPrimitive() && \"Id\" === property.extendedTypeName) {\n (targetElementAspectProps as any)[ECJsNames.toJsName(name)] =\n this.findTargetElementId(\n sourceElementAspect.asAny[ECJsNames.toJsName(name)]\n );\n }\n });\n await Promise.all(targetEntityIds);\n return targetElementAspectProps;\n }\n}\n"]}
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import { BriefcaseDb, ChangedECInstance, Element, ElementAspect, ElementMultiAspect, ElementUniqueAspect, IModelDb, IModelJsNative, Model, Relationship, SqliteChangeOp } from "@itwin/core-backend";
5
5
  import { Id64Arg, Id64String } from "@itwin/core-bentley";
6
- import { ChangesetFileProps, CodeSpec, FontProps } from "@itwin/core-common";
6
+ import { ChangesetFileProps, CodeSpec, FontFamilyDescriptor, FontProps } from "@itwin/core-common";
7
7
  import { Schema, SchemaKey } from "@itwin/ecschema-metadata";
8
8
  import { ElementAspectsHandler, ExportElementAspectsStrategy } from "./ExportElementAspectsStrategy";
9
9
  /**
@@ -90,7 +90,7 @@ export declare abstract class IModelExportHandler {
90
90
  */
91
91
  onExportModel(_model: Model, _isUpdate: boolean | undefined): void;
92
92
  /** Called when a model should be deleted. */
93
- onDeleteModel(_modelId: Id64String): void;
93
+ onDeleteModel(_modelId: Id64String): Promise<void>;
94
94
  /** If `true` is returned, then the element will be exported.
95
95
  * @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`.
96
96
  */
@@ -104,7 +104,7 @@ export declare abstract class IModelExportHandler {
104
104
  * @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.
105
105
  * @note This should be overridden to actually do the export.
106
106
  */
107
- onExportElement(_element: Element, _isUpdate: boolean | undefined): void;
107
+ onExportElement(_element: Element, _isUpdate: boolean | undefined): Promise<void>;
108
108
  /**
109
109
  * Do any asynchronous actions before exporting an element
110
110
  * @note Do not implement this handler manually, it is internal, it will be removed.
@@ -123,11 +123,11 @@ export declare abstract class IModelExportHandler {
123
123
  * @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.
124
124
  * @note This should be overridden to actually do the export.
125
125
  */
126
- onExportElementUniqueAspect(_aspect: ElementUniqueAspect, _isUpdate: boolean | undefined): void;
126
+ onExportElementUniqueAspect(_aspect: ElementUniqueAspect, _isUpdate: boolean | undefined): Promise<void>;
127
127
  /** Called when ElementMultiAspects should be exported.
128
128
  * @note This should be overridden to actually do the export.
129
129
  */
130
- onExportElementMultiAspects(_aspects: ElementMultiAspect[]): void;
130
+ onExportElementMultiAspects(_aspects: ElementMultiAspect[]): Promise<void>;
131
131
  /** If `true` is returned, then the relationship will be exported.
132
132
  * @note This method can optionally be overridden to exclude an individual CodeSpec from the export. The base implementation always returns `true`.
133
133
  */
@@ -137,7 +137,7 @@ export declare abstract class IModelExportHandler {
137
137
  * @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.
138
138
  * @note This should be overridden to actually do the export.
139
139
  */
140
- onExportRelationship(_relationship: Relationship, _isUpdate: boolean | undefined): void;
140
+ onExportRelationship(_relationship: Relationship, _isUpdate: boolean | undefined): Promise<void>;
141
141
  /** Called when a relationship should be deleted. */
142
142
  onDeleteRelationship(_relInstanceId: Id64String): void;
143
143
  /** If `true` is returned, then the schema will be exported.
@@ -280,9 +280,18 @@ export declare class IModelExporter {
280
280
  */
281
281
  exportFonts(): Promise<void>;
282
282
  /** Export a single font from the source iModel.
283
- * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
283
+ * @note multiple fonts can have the same font name, if a font with a specific type is needed use exportFontByFontFamilyDescriptor.
284
+ * If not this will only export the first font with this type in the db.
284
285
  */
285
286
  exportFontByName(fontName: string): Promise<void>;
287
+ /** Export a single font from the source iModel.
288
+ * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
289
+ */
290
+ exportFontByFontProps(fontProps: FontProps): Promise<void>;
291
+ /** Export a single font from the source iModel.
292
+ * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
293
+ */
294
+ exportFontByFontFamilyDescriptor(fontFamily: FontFamilyDescriptor): Promise<void>;
286
295
  /** Export a single font from the source iModel.
287
296
  * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
288
297
  */
@@ -1 +1 @@
1
- {"version":3,"file":"IModelExporter.d.ts","sourceRoot":"","sources":["../../src/IModelExporter.ts"],"names":[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UAAU,EAAE,cAAc,EAC1B,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,IAAI,CAAC;IAkChB;;;;;;;;;;OAUG;IACU,oBAAoB,CAC/B,UAAU,EAAE,cAAc,EAC1B,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,IAAI,CAAC;IAQhB;;;;;;;;OAQG;IACI,qBAAqB,CAAC,UAAU,EAAE,cAAc,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI;IAM5E;;;OAGG;YACW,yBAAyB;YA4BzB,kCAAkC;YAgBlC,4BAA4B;IAc1C,OAAO,CAAC,YAAY;IAyBpB;;;OAGG;WACiB,UAAU,CAC5B,IAAI,EAAE,6BAA6B,GAClC,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC;CAyE3C"}
@@ -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
- // eslint-disable-next-line @itwin/no-internal, @typescript-eslint/no-deprecated
350
- this.sourceDb.withPreparedStatement(sql, (statement) => {
351
- while (core_bentley_1.DbResult.BE_SQLITE_ROW === statement.step()) {
352
- const schemaName = statement.getValue(0).getString();
353
- const versionMajor = statement.getValue(1).getInteger();
354
- const versionWrite = statement.getValue(2).getInteger();
355
- const versionMinor = statement.getValue(3).getInteger();
356
- const schemaKey = new ecschema_metadata_1.SchemaKey(schemaName, new ecschema_metadata_1.ECVersion(versionMajor, versionWrite, versionMinor));
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
- // eslint-disable-next-line @itwin/no-internal, @typescript-eslint/no-deprecated
382
- await this.sourceDb.withPreparedStatement(sql,
383
- // eslint-disable-next-line @itwin/no-internal, @typescript-eslint/no-deprecated
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.fontMap.fonts.values()) {
434
- await this.exportFontByNumber(font.id);
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 This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
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 font = this.sourceDb.fontMap.getFont(fontName);
443
- if (undefined !== font) {
444
- await this.exportFontByNumber(font.id);
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.fontMap.getFont(fontNumber);
469
+ const font = this.sourceDb.fonts.findDescriptor(fontNumber);
459
470
  if (undefined !== font) {
460
- this.handler.onExportFont(font, isUpdate);
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
- // eslint-disable-next-line @itwin/no-internal, @typescript-eslint/no-deprecated
537
- await this.sourceDb.withPreparedStatement(sql,
538
- // eslint-disable-next-line @itwin/no-internal, @typescript-eslint/no-deprecated
539
- async (statement) => {
540
- statement.bindId("modelId", modelId);
541
- if (skipRootSubject) {
542
- statement.bindId("rootSubjectId", core_common_1.IModel.rootSubjectId);
543
- }
544
- while (core_bentley_1.DbResult.BE_SQLITE_ROW === statement.step()) {
545
- await this.exportElement(statement.getValue(0).getId());
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
- // eslint-disable-next-line @itwin/no-internal, @typescript-eslint/no-deprecated
559
- this.sourceDb.withPreparedStatement(sql,
560
- // eslint-disable-next-line @itwin/no-internal, @typescript-eslint/no-deprecated
561
- (statement) => {
562
- statement.bindId("parentModelId", parentModelId);
563
- while (core_bentley_1.DbResult.BE_SQLITE_ROW === statement.step()) {
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
- // eslint-disable-next-line @itwin/no-internal, @typescript-eslint/no-deprecated
684
- await this.sourceDb.withPreparedStatement(sql,
685
- // eslint-disable-next-line @itwin/no-internal, @typescript-eslint/no-deprecated
686
- async (statement) => {
687
- while (core_bentley_1.DbResult.BE_SQLITE_ROW === statement.step()) {
688
- const relationshipId = statement.getValue(0).getId();
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
  }