@itwin/imodel-transformer 1.1.3 → 2.0.0-dev.0

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 (36) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/lib/cjs/Algo.js +2 -3
  3. package/lib/cjs/Algo.js.map +1 -1
  4. package/lib/cjs/BigMap.d.ts +4 -4
  5. package/lib/cjs/BigMap.d.ts.map +1 -1
  6. package/lib/cjs/BigMap.js +2 -0
  7. package/lib/cjs/BigMap.js.map +1 -1
  8. package/lib/cjs/BranchProvenanceInitializer.d.ts.map +1 -1
  9. package/lib/cjs/BranchProvenanceInitializer.js +6 -7
  10. package/lib/cjs/BranchProvenanceInitializer.js.map +1 -1
  11. package/lib/cjs/ECReferenceTypesCache.d.ts.map +1 -1
  12. package/lib/cjs/ECReferenceTypesCache.js +22 -19
  13. package/lib/cjs/ECReferenceTypesCache.js.map +1 -1
  14. package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.js +3 -2
  15. package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.js.map +1 -1
  16. package/lib/cjs/ElementCascadingDeleter.js +2 -2
  17. package/lib/cjs/ElementCascadingDeleter.js.map +1 -1
  18. package/lib/cjs/EntityMap.d.ts +4 -4
  19. package/lib/cjs/EntityMap.js +1 -3
  20. package/lib/cjs/EntityMap.js.map +1 -1
  21. package/lib/cjs/EntityUnifier.d.ts.map +1 -1
  22. package/lib/cjs/EntityUnifier.js +2 -2
  23. package/lib/cjs/EntityUnifier.js.map +1 -1
  24. package/lib/cjs/ExportElementAspectsStrategy.js +7 -4
  25. package/lib/cjs/ExportElementAspectsStrategy.js.map +1 -1
  26. package/lib/cjs/IModelCloneContext.js +2 -5
  27. package/lib/cjs/IModelCloneContext.js.map +1 -1
  28. package/lib/cjs/IModelExporter.js +68 -55
  29. package/lib/cjs/IModelExporter.js.map +1 -1
  30. package/lib/cjs/IModelImporter.js +53 -39
  31. package/lib/cjs/IModelImporter.js.map +1 -1
  32. package/lib/cjs/IModelTransformer.d.ts +0 -7
  33. package/lib/cjs/IModelTransformer.d.ts.map +1 -1
  34. package/lib/cjs/IModelTransformer.js +72 -65
  35. package/lib/cjs/IModelTransformer.js.map +1 -1
  36. package/package.json +19 -19
@@ -1 +1 @@
1
- {"version":3,"file":"ExportElementAspectsStrategy.js","sourceRoot":"","sources":["../../src/ExportElementAspectsStrategy.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAQhG,sDAAyD;AACzD,2EAAwE;AAGxE,MAAM,cAAc,GAAG,qDAAyB,CAAC,cAAc,CAAC;AAgBhE;;;;GAIG;AACH,MAAsB,4BAA4B;IAYhD,YAAmB,QAAkB,EAAE,OAA8B;QAXrE,6HAA6H;QACnH,kCAA6B,GAAG,IAAI,GAAG,EAAwB,CAAC;QAC1E,mHAAmH;QACnG,wCAAmC,GAAG,IAAI,GAAG,EAAU,CAAC;QAStE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAOS,yBAAyB,CAAC,MAAqB;QACvD,KAAK,MAAM,0BAA0B,IAAI,IAAI;aAC1C,6BAA6B,EAAE,CAAC;YACjC,IAAI,MAAM,YAAY,0BAA0B,EAAE,CAAC;gBACjD,qBAAM,CAAC,OAAO,CACZ,cAAc,EACd,oCAAoC,MAAM,CAAC,aAAa,EAAE,CAC3D,CAAC;gBACF,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QACD,gGAAgG;QAChG,OAAO,IAAI,CAAC,OAAO,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC;IACxD,CAAC;IAEM,gBAAgB,CAAC,aAAkC;QACxD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAEM,gCAAgC,CACrC,mCAA6C;QAE5C,IAAI,CAAC,mCAA2C,GAAG,IAAI,GAAG,CACzD,mCAAmC,CACpC,CAAC;QACF,IAAI,CAAC,6BAA6B,GAAG,IAAI,GAAG,CAC1C,mCAAmC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAC5C,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAC5B,CACF,CAAC;IACJ,CAAC;IAEM,yBAAyB,CAAC,aAAqB;QACpD,IAAI,CAAC,mCAAmC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,gDAAgD;QAC7G,IAAI,CAAC,6BAA6B,CAAC,GAAG,CACpC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAuB,aAAa,CAAC,CAC9D,CAAC,CAAC,gDAAgD;IACrD,CAAC;CACF;AA5DD,oEA4DC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport {\n ElementAspect,\n ElementMultiAspect,\n ElementUniqueAspect,\n IModelDb,\n} from \"@itwin/core-backend\";\nimport { Id64String, Logger } from \"@itwin/core-bentley\";\nimport { TransformerLoggerCategory } from \"./TransformerLoggerCategory\";\nimport { ChangedInstanceOps } from \"./IModelExporter\";\n\nconst loggerCategory = TransformerLoggerCategory.IModelExporter;\n\n/**\n * Handler for [[ExportElementAspectsStrategy]]\n * @internal\n */\nexport interface ElementAspectsHandler {\n shouldExportElementAspect(aspect: ElementAspect): boolean;\n onExportElementUniqueAspect(\n uniqueAspect: ElementUniqueAspect,\n isUpdate?: boolean | undefined\n ): void;\n onExportElementMultiAspects(multiAspects: ElementMultiAspect[]): void;\n trackProgress: () => Promise<void>;\n}\n\n/**\n * Base ElementAspect export strategy. Base export strategy includes state saving and loading and\n * ElementAspect filtering.\n * @internal\n */\nexport abstract class ExportElementAspectsStrategy {\n /** The set of classes of ElementAspects that will be excluded (polymorphically) from transformation to the target iModel. */\n protected _excludedElementAspectClasses = new Set<typeof ElementAspect>();\n /** The set of classFullNames for ElementAspects that will be excluded from transformation to the target iModel. */\n public readonly excludedElementAspectClassFullNames = new Set<string>();\n\n protected sourceDb: IModelDb;\n\n protected aspectChanges: ChangedInstanceOps | undefined;\n\n protected handler: ElementAspectsHandler;\n\n public constructor(sourceDb: IModelDb, handler: ElementAspectsHandler) {\n this.sourceDb = sourceDb;\n this.handler = handler;\n }\n\n public abstract exportElementAspectsForElement(\n _elementId: Id64String\n ): Promise<void>;\n public abstract exportAllElementAspects(): Promise<void>;\n\n protected shouldExportElementAspect(aspect: ElementAspect): boolean {\n for (const excludedElementAspectClass of this\n ._excludedElementAspectClasses) {\n if (aspect instanceof excludedElementAspectClass) {\n Logger.logInfo(\n loggerCategory,\n `Excluded ElementAspect by class: ${aspect.classFullName}`\n );\n return false;\n }\n }\n // ElementAspect has passed standard exclusion rules, now give handler a chance to accept/reject\n return this.handler.shouldExportElementAspect(aspect);\n }\n\n public setAspectChanges(aspectChanges?: ChangedInstanceOps) {\n this.aspectChanges = aspectChanges;\n }\n\n public loadExcludedElementAspectClasses(\n excludedElementAspectClassFullNames: string[]\n ): void {\n (this.excludedElementAspectClassFullNames as any) = new Set(\n excludedElementAspectClassFullNames\n );\n this._excludedElementAspectClasses = new Set(\n excludedElementAspectClassFullNames.map((c) =>\n this.sourceDb.getJsClass(c)\n )\n );\n }\n\n public excludeElementAspectClass(classFullName: string): void {\n this.excludedElementAspectClassFullNames.add(classFullName); // allows non-polymorphic exclusion before query\n this._excludedElementAspectClasses.add(\n this.sourceDb.getJsClass<typeof ElementAspect>(classFullName)\n ); // allows polymorphic exclusion after query/load\n }\n}\n"]}
1
+ {"version":3,"file":"ExportElementAspectsStrategy.js","sourceRoot":"","sources":["../../src/ExportElementAspectsStrategy.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAQhG,sDAAyD;AACzD,2EAAwE;AAGxE,MAAM,cAAc,GAAG,qDAAyB,CAAC,cAAc,CAAC;AAgBhE;;;;GAIG;AACH,MAAsB,4BAA4B;IA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CAAuB,aAAa,CAAC,CAC9D,CAAC,CAAC,gDAAgD;IACrD,CAAC;CACF;AA5DD,oEA4DC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport {\n ElementAspect,\n ElementMultiAspect,\n ElementUniqueAspect,\n IModelDb,\n} from \"@itwin/core-backend\";\nimport { Id64String, Logger } from \"@itwin/core-bentley\";\nimport { TransformerLoggerCategory } from \"./TransformerLoggerCategory\";\nimport { ChangedInstanceOps } from \"./IModelExporter\";\n\nconst loggerCategory = TransformerLoggerCategory.IModelExporter;\n\n/**\n * Handler for [[ExportElementAspectsStrategy]]\n * @internal\n */\nexport interface ElementAspectsHandler {\n shouldExportElementAspect(aspect: ElementAspect): boolean;\n onExportElementUniqueAspect(\n uniqueAspect: ElementUniqueAspect,\n isUpdate?: boolean | undefined\n ): void;\n onExportElementMultiAspects(multiAspects: ElementMultiAspect[]): void;\n trackProgress: () => Promise<void>;\n}\n\n/**\n * Base ElementAspect export strategy. Base export strategy includes state saving and loading and\n * ElementAspect filtering.\n * @internal\n */\nexport abstract class ExportElementAspectsStrategy {\n /** The set of classes of ElementAspects that will be excluded (polymorphically) from transformation to the target iModel. */\n protected _excludedElementAspectClasses = new Set<typeof ElementAspect>();\n /** The set of classFullNames for ElementAspects that will be excluded from transformation to the target iModel. */\n public readonly excludedElementAspectClassFullNames = new Set<string>();\n\n protected sourceDb: IModelDb;\n\n protected aspectChanges: ChangedInstanceOps | undefined;\n\n protected handler: ElementAspectsHandler;\n\n public constructor(sourceDb: IModelDb, handler: ElementAspectsHandler) {\n this.sourceDb = sourceDb;\n this.handler = handler;\n }\n\n public abstract exportElementAspectsForElement(\n _elementId: Id64String\n ): Promise<void>;\n public abstract exportAllElementAspects(): Promise<void>;\n\n protected shouldExportElementAspect(aspect: ElementAspect): boolean {\n for (const excludedElementAspectClass of this\n ._excludedElementAspectClasses) {\n if (aspect instanceof excludedElementAspectClass) {\n Logger.logInfo(\n loggerCategory,\n `Excluded ElementAspect by class: ${aspect.classFullName}`\n );\n return false;\n }\n }\n // ElementAspect has passed standard exclusion rules, now give handler a chance to accept/reject\n return this.handler.shouldExportElementAspect(aspect);\n }\n\n public setAspectChanges(aspectChanges?: ChangedInstanceOps) {\n this.aspectChanges = aspectChanges;\n }\n\n public loadExcludedElementAspectClasses(\n excludedElementAspectClassFullNames: string[]\n ): void {\n (this.excludedElementAspectClassFullNames as any) = new Set(\n excludedElementAspectClassFullNames\n );\n this._excludedElementAspectClasses = new Set(\n excludedElementAspectClassFullNames.map((c) =>\n this.sourceDb.getJsClass(c)\n )\n );\n }\n\n public excludeElementAspectClass(classFullName: string): void {\n this.excludedElementAspectClassFullNames.add(classFullName); // allows non-polymorphic exclusion before query\n this._excludedElementAspectClasses.add(\n this.sourceDb.getJsClass<typeof ElementAspect>(classFullName)\n ); // allows polymorphic exclusion after query/load\n }\n}\n"]}
@@ -20,11 +20,8 @@ const loggerCategory = TransformerLoggerCategory_1.TransformerLoggerCategory.IMo
20
20
  * @beta
21
21
  */
22
22
  class IModelCloneContext extends core_backend_1.IModelElementCloneContext {
23
- constructor() {
24
- super(...arguments);
25
- this._refTypesCache = new ECReferenceTypesCache_1.ECReferenceTypesCache();
26
- this._aspectRemapTable = new Map();
27
- }
23
+ _refTypesCache = new ECReferenceTypesCache_1.ECReferenceTypesCache();
24
+ _aspectRemapTable = new Map();
28
25
  /** perform necessary initialization to use a clone context, namely caching the reference types in the source's schemas */
29
26
  async initialize() {
30
27
  await this._refTypesCache.initAllSchemasInIModel(this.sourceDb);
@@ -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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EAAE,CAAC;gBAClC,MAAM,aAAa,GACjB,mBAAmB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;gBAC1C,IAAI,aAAa,EAAE,EAAE,EAAE,CAAC;oBACtB,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAC1D,mBAAmB,CAAC,UAAU,EAC9B,mBAAmB,CAAC,SAAS,EAC7B,YAAY,CACb,CAAC;oBACF,MAAM,CACJ,cAAc,KAAK,SAAS,EAC5B,0BAA0B,YAAY,wCAAwC,CAC/E,CAAC;oBACF,MAAM,qBAAqB,GAAG,IAAI,CAAC,kBAAkB,CACnD,+BAAgB,CAAC,cAAc,CAAC,aAAa,CAAC,EAAE,EAAE,cAAc,CAAC,CAClE,CAAC;oBACF,MAAM,cAAc,GAAG,+BAAgB,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;oBACtE,wDAAwD;oBACvD,wBAAgC,CAAC,YAAY,CAAC,GAAG;wBAChD,GAAI,wBAAgC,CAAC,YAAY,CAAC;wBAClD,EAAE,EAAE,cAAc;qBACnB,CAAC;gBACJ,CAAC;YACH,CAAC;iBAAM,IACL,+BAAiB,CAAC,IAAI,KAAK,gBAAgB,CAAC,aAAa;gBACzD,IAAI,KAAK,gBAAgB,CAAC,YAAY,EACtC,CAAC;gBACA,wBAAgC,CAAC,YAAY,CAAC;oBAC7C,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;YACtE,CAAC;QACH,CAAC,CAAC,CAAC;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, deprecation/deprecation\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, deprecation/deprecation\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;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,CAA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CAAwC,CAC/E,CAAC;oBACF,MAAM,qBAAqB,GAAG,IAAI,CAAC,kBAAkB,CACnD,+BAAgB,CAAC,cAAc,CAAC,aAAa,CAAC,EAAE,EAAE,cAAc,CAAC,CAClE,CAAC;oBACF,MAAM,cAAc,GAAG,+BAAgB,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;oBACtE,wDAAwD;oBACvD,wBAAgC,CAAC,YAAY,CAAC,GAAG;wBAChD,GAAI,wBAAgC,CAAC,YAAY,CAAC;wBAClD,EAAE,EAAE,cAAc;qBACnB,CAAC;gBACJ,CAAC;YACH,CAAC;iBAAM,IACL,+BAAiB,CAAC,IAAI,KAAK,gBAAgB,CAAC,aAAa;gBACzD,IAAI,KAAK,gBAAgB,CAAC,YAAY,EACtC,CAAC;gBACA,wBAAgC,CAAC,YAAY,CAAC;oBAC7C,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;YACtE,CAAC;QACH,CAAC,CAAC,CAAC;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, deprecation/deprecation\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, deprecation/deprecation\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"]}
@@ -130,6 +130,39 @@ exports.IModelExportHandler = IModelExportHandler;
130
130
  * @beta
131
131
  */
132
132
  class IModelExporter {
133
+ /** The read-only source iModel. */
134
+ sourceDb;
135
+ /** A flag that indicates whether element GeometryStreams are loaded or not.
136
+ * @note As an optimization, exporters that don't need geometry can set this flag to `false`. The default is `true`.
137
+ * @note The transformer by default sets this to `false` as an optimization.
138
+ * @note This implies the `wantBRepData` option when loading elements.
139
+ * @see [ElementLoadProps.wantGeometry]($common)
140
+ */
141
+ wantGeometry = true;
142
+ /** A flag that indicates whether template models should be exported or not. The default is `true`.
143
+ * @note If only exporting *instances* then template models can be skipped since they are just definitions that are cloned to create new instances.
144
+ * @see [Model.isTemplate]($backend)
145
+ */
146
+ wantTemplateModels = true;
147
+ /** A flag that indicates whether *system* schemas should be exported or not. The default is `true` (previously false).
148
+ * This can be set to false for the legacy default behavior, but it may cause errors during schema processing in some cases.
149
+ * @see [[exportSchemas]]
150
+ */
151
+ wantSystemSchemas = true;
152
+ /** A flag that determines whether this IModelExporter should visit Elements or not. The default is `true`.
153
+ * @note This flag is available as an optimization when the exporter doesn't need to visit elements, so can skip loading them.
154
+ */
155
+ visitElements = true;
156
+ /** A flag that determines whether this IModelExporter should visit Relationships or not. The default is `true`.
157
+ * @note This flag is available as an optimization when the exporter doesn't need to visit relationships, so can skip loading them.
158
+ */
159
+ visitRelationships = true;
160
+ /** The number of entities exported before incremental progress should be reported via the [[onProgress]] callback. */
161
+ progressInterval = 1000;
162
+ /** Tracks the current total number of entities exported. */
163
+ _progressCounter = 0;
164
+ /** Optionally cached entity change information */
165
+ _sourceDbChanges;
133
166
  /**
134
167
  * Retrieve the cached entity change information.
135
168
  * @note This will only be initialized after [IModelExporter.exportChanges] is invoked or [IModelExporter.initialize] is called.
@@ -138,58 +171,31 @@ class IModelExporter {
138
171
  return this._sourceDbChanges;
139
172
  }
140
173
  /** The handler called by this IModelExporter. */
174
+ _handler;
175
+ /** The handler called by this IModelExporter. */
141
176
  get handler() {
142
177
  if (undefined === this._handler) {
143
178
  throw new Error("IModelExportHandler not registered");
144
179
  }
145
180
  return this._handler;
146
181
  }
182
+ /** The set of CodeSpecs to exclude from the export. */
183
+ _excludedCodeSpecNames = new Set();
184
+ /** The set of specific Elements to exclude from the export. */
185
+ _excludedElementIds = new Set();
186
+ /** The set of Categories where Elements in that Category will be excluded from transformation to the target iModel. */
187
+ _excludedElementCategoryIds = new Set();
188
+ /** The set of classes of Elements that will be excluded (polymorphically) from transformation to the target iModel. */
189
+ _excludedElementClasses = new Set();
190
+ /** The set of classes of Relationships that will be excluded (polymorphically) from transformation to the target iModel. */
191
+ _excludedRelationshipClasses = new Set();
192
+ /** Strategy for how ElementAspects are exported */
193
+ _exportElementAspectsStrategy;
147
194
  /** Construct a new IModelExporter
148
195
  * @param sourceDb The source IModelDb
149
196
  * @see registerHandler
150
197
  */
151
198
  constructor(sourceDb, elementAspectsStrategy = ExportElementAspectsWithElementsStrategy_1.ExportElementAspectsWithElementsStrategy) {
152
- /** A flag that indicates whether element GeometryStreams are loaded or not.
153
- * @note As an optimization, exporters that don't need geometry can set this flag to `false`. The default is `true`.
154
- * @note The transformer by default sets this to `false` as an optimization.
155
- * @note This implies the `wantBRepData` option when loading elements.
156
- * @see [ElementLoadProps.wantGeometry]($common)
157
- */
158
- this.wantGeometry = true;
159
- /** A flag that indicates whether template models should be exported or not. The default is `true`.
160
- * @note If only exporting *instances* then template models can be skipped since they are just definitions that are cloned to create new instances.
161
- * @see [Model.isTemplate]($backend)
162
- */
163
- this.wantTemplateModels = true;
164
- /** A flag that indicates whether *system* schemas should be exported or not. The default is `true` (previously false).
165
- * This can be set to false for the legacy default behavior, but it may cause errors during schema processing in some cases.
166
- * @see [[exportSchemas]]
167
- */
168
- this.wantSystemSchemas = true;
169
- /** A flag that determines whether this IModelExporter should visit Elements or not. The default is `true`.
170
- * @note This flag is available as an optimization when the exporter doesn't need to visit elements, so can skip loading them.
171
- */
172
- this.visitElements = true;
173
- /** A flag that determines whether this IModelExporter should visit Relationships or not. The default is `true`.
174
- * @note This flag is available as an optimization when the exporter doesn't need to visit relationships, so can skip loading them.
175
- */
176
- this.visitRelationships = true;
177
- /** The number of entities exported before incremental progress should be reported via the [[onProgress]] callback. */
178
- this.progressInterval = 1000;
179
- /** Tracks the current total number of entities exported. */
180
- this._progressCounter = 0;
181
- /** The set of CodeSpecs to exclude from the export. */
182
- this._excludedCodeSpecNames = new Set();
183
- /** The set of specific Elements to exclude from the export. */
184
- this._excludedElementIds = new Set();
185
- /** The set of Categories where Elements in that Category will be excluded from transformation to the target iModel. */
186
- this._excludedElementCategoryIds = new Set();
187
- /** The set of classes of Elements that will be excluded (polymorphically) from transformation to the target iModel. */
188
- this._excludedElementClasses = new Set();
189
- /** The set of classes of Relationships that will be excluded (polymorphically) from transformation to the target iModel. */
190
- this._excludedRelationshipClasses = new Set();
191
- this._resetChangeDataOnExport = true;
192
- this._yieldManager = new core_bentley_1.YieldManager();
193
199
  this.sourceDb = sourceDb;
194
200
  this._exportElementAspectsStrategy = new elementAspectsStrategy(this.sourceDb, {
195
201
  onExportElementMultiAspects: (aspects) => this.handler.onExportElementMultiAspects(aspects),
@@ -324,6 +330,7 @@ class IModelExporter {
324
330
  if (this._resetChangeDataOnExport)
325
331
  this._sourceDbChanges = undefined;
326
332
  }
333
+ _resetChangeDataOnExport = true;
327
334
  /** Export schemas from the source iModel.
328
335
  * @note This must be called separately from [[exportAll]] or [[exportChanges]].
329
336
  */
@@ -496,6 +503,7 @@ class IModelExporter {
496
503
  this.handler.onExportModel(model, isUpdate);
497
504
  return this.trackProgress();
498
505
  }
506
+ _yieldManager = new core_bentley_1.YieldManager();
499
507
  /** Export the model contents.
500
508
  * @param modelId The only required parameter
501
509
  * @param elementClassFullName Can be optionally specified if the goal is to export a subset of the model contents
@@ -735,11 +743,9 @@ exports.IModelExporter = IModelExporter;
735
743
  * @public
736
744
  */
737
745
  class ChangedInstanceOps {
738
- constructor() {
739
- this.insertIds = new Set();
740
- this.updateIds = new Set();
741
- this.deleteIds = new Set();
742
- }
746
+ insertIds = new Set();
747
+ updateIds = new Set();
748
+ deleteIds = new Set();
743
749
  /** Initializes the object from IModelJsNative.ChangedInstanceOpsProps. */
744
750
  addFromJson(val) {
745
751
  if (undefined !== val) {
@@ -767,13 +773,20 @@ exports.ChangedInstanceOps = ChangedInstanceOps;
767
773
  * @public
768
774
  */
769
775
  class ChangedInstanceIds {
776
+ codeSpec = new ChangedInstanceOps();
777
+ model = new ChangedInstanceOps();
778
+ element = new ChangedInstanceOps();
779
+ aspect = new ChangedInstanceOps();
780
+ relationship = new ChangedInstanceOps();
781
+ font = new ChangedInstanceOps();
782
+ _codeSpecSubclassIds;
783
+ _modelSubclassIds;
784
+ _elementSubclassIds;
785
+ _aspectSubclassIds;
786
+ _relationshipSubclassIds;
787
+ _relationshipSubclassIdsToSkip;
788
+ _db;
770
789
  constructor(db) {
771
- this.codeSpec = new ChangedInstanceOps();
772
- this.model = new ChangedInstanceOps();
773
- this.element = new ChangedInstanceOps();
774
- this.aspect = new ChangedInstanceOps();
775
- this.relationship = new ChangedInstanceOps();
776
- this.font = new ChangedInstanceOps();
777
790
  this._db = db;
778
791
  }
779
792
  async setupECClassIds() {
@@ -1018,14 +1031,14 @@ class ChangedInstanceIds {
1018
1031
  ? [
1019
1032
  [
1020
1033
  startChangeset.index ??
1021
- (await core_backend_1.IModelHost.hubAccess.queryChangeset({
1034
+ (await core_backend_1.BriefcaseManager.queryChangeset({
1022
1035
  iModelId,
1023
1036
  changeset: {
1024
1037
  id: startChangeset.id ?? opts.iModel.changeset.id,
1025
1038
  },
1026
1039
  })).index,
1027
1040
  opts.iModel.changeset.index ??
1028
- (await core_backend_1.IModelHost.hubAccess.queryChangeset({
1041
+ (await core_backend_1.BriefcaseManager.queryChangeset({
1029
1042
  iModelId,
1030
1043
  changeset: { id: opts.iModel.changeset.id },
1031
1044
  })).index,
@@ -1035,7 +1048,7 @@ class ChangedInstanceIds {
1035
1048
  ? opts.changesetRanges
1036
1049
  : undefined;
1037
1050
  const csFileProps = changesetRanges !== undefined
1038
- ? (await Promise.all(changesetRanges.map(async ([first, end]) => core_backend_1.IModelHost.hubAccess.downloadChangesets({
1051
+ ? (await Promise.all(changesetRanges.map(async ([first, end]) => core_backend_1.BriefcaseManager.downloadChangesets({
1039
1052
  iModelId,
1040
1053
  range: { first, end },
1041
1054
  targetDir: core_backend_1.BriefcaseManager.getChangeSetsPath(iModelId),