@itwin/imodel-transformer 1.1.3-dev.0 → 1.1.4-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.
- package/CHANGELOG.md +9 -1
- package/lib/cjs/Algo.js +2 -3
- package/lib/cjs/Algo.js.map +1 -1
- package/lib/cjs/BigMap.d.ts +4 -4
- package/lib/cjs/BigMap.d.ts.map +1 -1
- package/lib/cjs/BigMap.js +2 -0
- package/lib/cjs/BigMap.js.map +1 -1
- package/lib/cjs/BranchProvenanceInitializer.d.ts.map +1 -1
- package/lib/cjs/BranchProvenanceInitializer.js +6 -7
- package/lib/cjs/BranchProvenanceInitializer.js.map +1 -1
- package/lib/cjs/ECReferenceTypesCache.d.ts.map +1 -1
- package/lib/cjs/ECReferenceTypesCache.js +22 -19
- package/lib/cjs/ECReferenceTypesCache.js.map +1 -1
- package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.js +3 -2
- package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.js.map +1 -1
- package/lib/cjs/ElementCascadingDeleter.js +2 -2
- package/lib/cjs/ElementCascadingDeleter.js.map +1 -1
- package/lib/cjs/EntityMap.d.ts +4 -4
- package/lib/cjs/EntityMap.js +1 -3
- package/lib/cjs/EntityMap.js.map +1 -1
- package/lib/cjs/EntityUnifier.d.ts.map +1 -1
- package/lib/cjs/EntityUnifier.js +2 -2
- package/lib/cjs/EntityUnifier.js.map +1 -1
- package/lib/cjs/ExportElementAspectsStrategy.js +7 -4
- package/lib/cjs/ExportElementAspectsStrategy.js.map +1 -1
- package/lib/cjs/IModelCloneContext.js +2 -5
- package/lib/cjs/IModelCloneContext.js.map +1 -1
- package/lib/cjs/IModelExporter.d.ts.map +1 -1
- package/lib/cjs/IModelExporter.js +69 -55
- package/lib/cjs/IModelExporter.js.map +1 -1
- package/lib/cjs/IModelImporter.js +53 -39
- package/lib/cjs/IModelImporter.js.map +1 -1
- package/lib/cjs/IModelTransformer.d.ts +0 -7
- package/lib/cjs/IModelTransformer.d.ts.map +1 -1
- package/lib/cjs/IModelTransformer.js +73 -65
- package/lib/cjs/IModelTransformer.js.map +1 -1
- package/package.json +19 -19
|
@@ -14,11 +14,14 @@ const loggerCategory = TransformerLoggerCategory_1.TransformerLoggerCategory.IMo
|
|
|
14
14
|
* @internal
|
|
15
15
|
*/
|
|
16
16
|
class ExportElementAspectsStrategy {
|
|
17
|
+
/** The set of classes of ElementAspects that will be excluded (polymorphically) from transformation to the target iModel. */
|
|
18
|
+
_excludedElementAspectClasses = new Set();
|
|
19
|
+
/** The set of classFullNames for ElementAspects that will be excluded from transformation to the target iModel. */
|
|
20
|
+
excludedElementAspectClassFullNames = new Set();
|
|
21
|
+
sourceDb;
|
|
22
|
+
aspectChanges;
|
|
23
|
+
handler;
|
|
17
24
|
constructor(sourceDb, handler) {
|
|
18
|
-
/** The set of classes of ElementAspects that will be excluded (polymorphically) from transformation to the target iModel. */
|
|
19
|
-
this._excludedElementAspectClasses = new Set();
|
|
20
|
-
/** The set of classFullNames for ElementAspects that will be excluded from transformation to the target iModel. */
|
|
21
|
-
this.excludedElementAspectClassFullNames = new Set();
|
|
22
25
|
this.sourceDb = sourceDb;
|
|
23
26
|
this.handler = handler;
|
|
24
27
|
}
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"ExportElementAspectsStrategy.js","sourceRoot":"","sources":["../../src/ExportElementAspectsStrategy.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAQhG,sDAAyD;AACzD,2EAAwE;AAGxE,MAAM,cAAc,GAAG,qDAAyB,C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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"]}
|
|
@@ -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
|
-
|
|
24
|
-
|
|
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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E,CAAC;QAC/B,wBAAwB,CAAC,EAAE,GAAG,SAAS,CAAC;QACxC,mBAAmB,CAAC,eAAe,CAAC,CAAC,YAAY,EAAE,gBAAgB,EAAE,EAAE;YACrE,IAAI,gBAAgB,CAAC,YAAY,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;IAC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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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelExporter.d.ts","sourceRoot":"","sources":["../../src/IModelExporter.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACL,WAAW,EAEX,iBAAiB,EAKjB,OAAO,EACP,aAAa,EACb,kBAAkB,EAElB,mBAAmB,EAEnB,QAAQ,EAER,cAAc,EACd,KAAK,EAGL,YAAY,EACZ,cAAc,EAEf,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"IModelExporter.d.ts","sourceRoot":"","sources":["../../src/IModelExporter.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACL,WAAW,EAEX,iBAAiB,EAKjB,OAAO,EACP,aAAa,EACb,kBAAkB,EAElB,mBAAmB,EAEnB,QAAQ,EAER,cAAc,EACd,KAAK,EAGL,YAAY,EACZ,cAAc,EAEf,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAIL,OAAO,EAEP,UAAU,EAIX,MAAM,qBAAqB,CAAC;AAC7B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AC,mBAAmB,CAAC,CAAc;IAC1C,OAAO,CAAC,kBAAkB,CAAC,CAAc;IACzC,OAAO,CAAC,wBAAwB,CAAC,CAAc;IAC/C,OAAO,CAAC,8BAA8B,CAAC,CAAc;IAErD,OAAO,CAAC,GAAG,CAAW;gBACH,EAAE,EAAE,QAAQ;YAIjB,eAAe;IAuC7B,OAAO,KAAK,sBAAsB,GASjC;IAED,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,SAAS;IAIjB;;OAEG;IACH,IAAW,UAAU,IAAI,OAAO,CAS/B;IAED;;;;;OAKG;IACU,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BhE;;;;;;;;;;;OAWG;IACU,sBAAsB,CACjC,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"}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.ChangedInstanceIds = exports.ChangedInstanceOps = exports.IModelExporter = exports.IModelExportHandler = void 0;
|
|
11
11
|
const core_backend_1 = require("@itwin/core-backend");
|
|
12
|
+
const Symbols_1 = require("@itwin/core-backend/lib/cjs/internal/Symbols");
|
|
12
13
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
13
14
|
const core_common_1 = require("@itwin/core-common");
|
|
14
15
|
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
@@ -130,6 +131,39 @@ exports.IModelExportHandler = IModelExportHandler;
|
|
|
130
131
|
* @beta
|
|
131
132
|
*/
|
|
132
133
|
class IModelExporter {
|
|
134
|
+
/** The read-only source iModel. */
|
|
135
|
+
sourceDb;
|
|
136
|
+
/** A flag that indicates whether element GeometryStreams are loaded or not.
|
|
137
|
+
* @note As an optimization, exporters that don't need geometry can set this flag to `false`. The default is `true`.
|
|
138
|
+
* @note The transformer by default sets this to `false` as an optimization.
|
|
139
|
+
* @note This implies the `wantBRepData` option when loading elements.
|
|
140
|
+
* @see [ElementLoadProps.wantGeometry]($common)
|
|
141
|
+
*/
|
|
142
|
+
wantGeometry = true;
|
|
143
|
+
/** A flag that indicates whether template models should be exported or not. The default is `true`.
|
|
144
|
+
* @note If only exporting *instances* then template models can be skipped since they are just definitions that are cloned to create new instances.
|
|
145
|
+
* @see [Model.isTemplate]($backend)
|
|
146
|
+
*/
|
|
147
|
+
wantTemplateModels = true;
|
|
148
|
+
/** A flag that indicates whether *system* schemas should be exported or not. The default is `true` (previously false).
|
|
149
|
+
* This can be set to false for the legacy default behavior, but it may cause errors during schema processing in some cases.
|
|
150
|
+
* @see [[exportSchemas]]
|
|
151
|
+
*/
|
|
152
|
+
wantSystemSchemas = true;
|
|
153
|
+
/** A flag that determines whether this IModelExporter should visit Elements or not. The default is `true`.
|
|
154
|
+
* @note This flag is available as an optimization when the exporter doesn't need to visit elements, so can skip loading them.
|
|
155
|
+
*/
|
|
156
|
+
visitElements = true;
|
|
157
|
+
/** A flag that determines whether this IModelExporter should visit Relationships or not. The default is `true`.
|
|
158
|
+
* @note This flag is available as an optimization when the exporter doesn't need to visit relationships, so can skip loading them.
|
|
159
|
+
*/
|
|
160
|
+
visitRelationships = true;
|
|
161
|
+
/** The number of entities exported before incremental progress should be reported via the [[onProgress]] callback. */
|
|
162
|
+
progressInterval = 1000;
|
|
163
|
+
/** Tracks the current total number of entities exported. */
|
|
164
|
+
_progressCounter = 0;
|
|
165
|
+
/** Optionally cached entity change information */
|
|
166
|
+
_sourceDbChanges;
|
|
133
167
|
/**
|
|
134
168
|
* Retrieve the cached entity change information.
|
|
135
169
|
* @note This will only be initialized after [IModelExporter.exportChanges] is invoked or [IModelExporter.initialize] is called.
|
|
@@ -138,58 +172,31 @@ class IModelExporter {
|
|
|
138
172
|
return this._sourceDbChanges;
|
|
139
173
|
}
|
|
140
174
|
/** The handler called by this IModelExporter. */
|
|
175
|
+
_handler;
|
|
176
|
+
/** The handler called by this IModelExporter. */
|
|
141
177
|
get handler() {
|
|
142
178
|
if (undefined === this._handler) {
|
|
143
179
|
throw new Error("IModelExportHandler not registered");
|
|
144
180
|
}
|
|
145
181
|
return this._handler;
|
|
146
182
|
}
|
|
183
|
+
/** The set of CodeSpecs to exclude from the export. */
|
|
184
|
+
_excludedCodeSpecNames = new Set();
|
|
185
|
+
/** The set of specific Elements to exclude from the export. */
|
|
186
|
+
_excludedElementIds = new Set();
|
|
187
|
+
/** The set of Categories where Elements in that Category will be excluded from transformation to the target iModel. */
|
|
188
|
+
_excludedElementCategoryIds = new Set();
|
|
189
|
+
/** The set of classes of Elements that will be excluded (polymorphically) from transformation to the target iModel. */
|
|
190
|
+
_excludedElementClasses = new Set();
|
|
191
|
+
/** The set of classes of Relationships that will be excluded (polymorphically) from transformation to the target iModel. */
|
|
192
|
+
_excludedRelationshipClasses = new Set();
|
|
193
|
+
/** Strategy for how ElementAspects are exported */
|
|
194
|
+
_exportElementAspectsStrategy;
|
|
147
195
|
/** Construct a new IModelExporter
|
|
148
196
|
* @param sourceDb The source IModelDb
|
|
149
197
|
* @see registerHandler
|
|
150
198
|
*/
|
|
151
199
|
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
200
|
this.sourceDb = sourceDb;
|
|
194
201
|
this._exportElementAspectsStrategy = new elementAspectsStrategy(this.sourceDb, {
|
|
195
202
|
onExportElementMultiAspects: (aspects) => this.handler.onExportElementMultiAspects(aspects),
|
|
@@ -324,6 +331,7 @@ class IModelExporter {
|
|
|
324
331
|
if (this._resetChangeDataOnExport)
|
|
325
332
|
this._sourceDbChanges = undefined;
|
|
326
333
|
}
|
|
334
|
+
_resetChangeDataOnExport = true;
|
|
327
335
|
/** Export schemas from the source iModel.
|
|
328
336
|
* @note This must be called separately from [[exportAll]] or [[exportChanges]].
|
|
329
337
|
*/
|
|
@@ -496,6 +504,7 @@ class IModelExporter {
|
|
|
496
504
|
this.handler.onExportModel(model, isUpdate);
|
|
497
505
|
return this.trackProgress();
|
|
498
506
|
}
|
|
507
|
+
_yieldManager = new core_bentley_1.YieldManager();
|
|
499
508
|
/** Export the model contents.
|
|
500
509
|
* @param modelId The only required parameter
|
|
501
510
|
* @param elementClassFullName Can be optionally specified if the goal is to export a subset of the model contents
|
|
@@ -735,11 +744,9 @@ exports.IModelExporter = IModelExporter;
|
|
|
735
744
|
* @public
|
|
736
745
|
*/
|
|
737
746
|
class ChangedInstanceOps {
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
this.deleteIds = new Set();
|
|
742
|
-
}
|
|
747
|
+
insertIds = new Set();
|
|
748
|
+
updateIds = new Set();
|
|
749
|
+
deleteIds = new Set();
|
|
743
750
|
/** Initializes the object from IModelJsNative.ChangedInstanceOpsProps. */
|
|
744
751
|
addFromJson(val) {
|
|
745
752
|
if (undefined !== val) {
|
|
@@ -767,13 +774,20 @@ exports.ChangedInstanceOps = ChangedInstanceOps;
|
|
|
767
774
|
* @public
|
|
768
775
|
*/
|
|
769
776
|
class ChangedInstanceIds {
|
|
777
|
+
codeSpec = new ChangedInstanceOps();
|
|
778
|
+
model = new ChangedInstanceOps();
|
|
779
|
+
element = new ChangedInstanceOps();
|
|
780
|
+
aspect = new ChangedInstanceOps();
|
|
781
|
+
relationship = new ChangedInstanceOps();
|
|
782
|
+
font = new ChangedInstanceOps();
|
|
783
|
+
_codeSpecSubclassIds;
|
|
784
|
+
_modelSubclassIds;
|
|
785
|
+
_elementSubclassIds;
|
|
786
|
+
_aspectSubclassIds;
|
|
787
|
+
_relationshipSubclassIds;
|
|
788
|
+
_relationshipSubclassIdsToSkip;
|
|
789
|
+
_db;
|
|
770
790
|
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
791
|
this._db = db;
|
|
778
792
|
}
|
|
779
793
|
async setupECClassIds() {
|
|
@@ -1018,14 +1032,14 @@ class ChangedInstanceIds {
|
|
|
1018
1032
|
? [
|
|
1019
1033
|
[
|
|
1020
1034
|
startChangeset.index ??
|
|
1021
|
-
(await core_backend_1.
|
|
1035
|
+
(await core_backend_1.BriefcaseManager.queryChangeset({
|
|
1022
1036
|
iModelId,
|
|
1023
1037
|
changeset: {
|
|
1024
1038
|
id: startChangeset.id ?? opts.iModel.changeset.id,
|
|
1025
1039
|
},
|
|
1026
1040
|
})).index,
|
|
1027
1041
|
opts.iModel.changeset.index ??
|
|
1028
|
-
(await core_backend_1.
|
|
1042
|
+
(await core_backend_1.BriefcaseManager.queryChangeset({
|
|
1029
1043
|
iModelId,
|
|
1030
1044
|
changeset: { id: opts.iModel.changeset.id },
|
|
1031
1045
|
})).index,
|
|
@@ -1035,7 +1049,7 @@ class ChangedInstanceIds {
|
|
|
1035
1049
|
? opts.changesetRanges
|
|
1036
1050
|
: undefined;
|
|
1037
1051
|
const csFileProps = changesetRanges !== undefined
|
|
1038
|
-
? (await Promise.all(changesetRanges.map(async ([first, end]) => core_backend_1.IModelHost.
|
|
1052
|
+
? (await Promise.all(changesetRanges.map(async ([first, end]) => core_backend_1.IModelHost[Symbols_1._hubAccess].downloadChangesets({
|
|
1039
1053
|
iModelId,
|
|
1040
1054
|
range: { first, end },
|
|
1041
1055
|
targetDir: core_backend_1.BriefcaseManager.getChangeSetsPath(iModelId),
|