@itwin/imodel-transformer 2.0.0-dev.12 → 2.0.0-dev.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/BranchProvenanceInitializer.js +3 -3
- package/lib/cjs/BranchProvenanceInitializer.js.map +1 -1
- package/lib/cjs/ElementCascadingDeleter.js +1 -1
- package/lib/cjs/ElementCascadingDeleter.js.map +1 -1
- package/lib/cjs/EntityUnifier.d.ts.map +1 -1
- package/lib/cjs/EntityUnifier.js +4 -1
- package/lib/cjs/EntityUnifier.js.map +1 -1
- package/lib/cjs/IModelImporter.d.ts.map +1 -1
- package/lib/cjs/IModelImporter.js.map +1 -1
- package/lib/cjs/IModelTransformer.d.ts +26 -135
- package/lib/cjs/IModelTransformer.d.ts.map +1 -1
- package/lib/cjs/IModelTransformer.js +87 -742
- package/lib/cjs/IModelTransformer.js.map +1 -1
- package/lib/cjs/ProvenanceManager.d.ts +159 -0
- package/lib/cjs/ProvenanceManager.d.ts.map +1 -0
- package/lib/cjs/ProvenanceManager.js +677 -0
- package/lib/cjs/ProvenanceManager.js.map +1 -0
- package/lib/cjs/SyncTypeResolver.d.ts +34 -0
- package/lib/cjs/SyncTypeResolver.d.ts.map +1 -0
- package/lib/cjs/SyncTypeResolver.js +84 -0
- package/lib/cjs/SyncTypeResolver.js.map +1 -0
- package/package.json +15 -15
|
@@ -9,7 +9,7 @@ const core_backend_1 = require("@itwin/core-backend");
|
|
|
9
9
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
10
10
|
const core_common_1 = require("@itwin/core-common");
|
|
11
11
|
const assert = require("assert");
|
|
12
|
-
const
|
|
12
|
+
const ProvenanceManager_1 = require("./ProvenanceManager");
|
|
13
13
|
const url_1 = require("url");
|
|
14
14
|
/**
|
|
15
15
|
* @alpha
|
|
@@ -88,7 +88,7 @@ async function initializeBranchProvenance(args) {
|
|
|
88
88
|
const elemReader = args.branch.createQueryReader(fedGuidlessElemsSql, undefined, { usePrimaryConn: true });
|
|
89
89
|
for await (const row of elemReader) {
|
|
90
90
|
const id = row.id;
|
|
91
|
-
const aspectProps =
|
|
91
|
+
const aspectProps = ProvenanceManager_1.ProvenanceManager.initElementProvenanceOptions(id, id, {
|
|
92
92
|
isReverseSynchronization: false,
|
|
93
93
|
targetScopeElementId: masterExternalSourceId,
|
|
94
94
|
sourceDb: args.master,
|
|
@@ -108,7 +108,7 @@ async function initializeBranchProvenance(args) {
|
|
|
108
108
|
const relReader = args.branch.createQueryReader(fedGuidlessRelsSql, undefined, { usePrimaryConn: true });
|
|
109
109
|
for await (const row of relReader) {
|
|
110
110
|
const id = row.id;
|
|
111
|
-
const aspectProps = await
|
|
111
|
+
const aspectProps = await ProvenanceManager_1.ProvenanceManager.initRelationshipProvenanceOptions(id, id, {
|
|
112
112
|
isReverseSynchronization: false,
|
|
113
113
|
targetScopeElementId: masterExternalSourceId,
|
|
114
114
|
sourceDb: args.master,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BranchProvenanceInitializer.js","sourceRoot":"","sources":["../../src/BranchProvenanceInitializer.ts"],"names":[],"mappings":";;AA2DA,gEAmJC;AA9MD;;;gGAGgG;AAChG,sDAO6B;AAC7B,sDAA6E;AAC7E,oDAI4B;AAC5B,iCAAiC;AACjC,2DAAwD;AACxD,6BAAoC;AAoCpC;;GAEG;AACI,KAAK,UAAU,0BAA0B,CAC9C,IAAwB;IAExB,IAAI,IAAI,CAAC,uBAAuB,EAAE,CAAC;QACjC,sHAAsH;QACtH,wEAAwE;QACxE,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAC7B;;;;OAIC;QACD,8CAA8C;QAC9C,CAAC,CAAC,EAAE,EAAE,CACJ,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,uBAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAC3E,CAAC;QACF,MAAM,UAAU,GAAG,IAAI,CAAC,MAA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I,EAAE,CAAC;QAC1C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED,OAAO;QACL,oBAAoB,EAAE,sBAAsB;QAC5C,sBAAsB;QACtB,sBAAsB,EAAE,gBAAgB;KACzC,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,EAAY;IAClC,MAAM,YAAY,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,uBAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,uBAAQ,CAAC,SAAS,CAAC;IAC5E,MAAM,MAAM,GAAG,EAAE,CAAC,QAAQ,CAAC;IAC3B,IAAI,QAA2D,CAAC;IAChE,IAAI,EAAE,YAAY,0BAAW;QAC3B,QAAQ,GAAG,KAAK,EAAE,IAAI,GAAG,YAAY,EAAE,EAAE,CACvC,0BAAW,CAAC,IAAI,CAAC;YACf,QAAQ,EAAE,MAAM;YAChB,QAAQ,EAAE,IAAI,KAAK,uBAAQ,CAAC,QAAQ;SACrC,CAAC,CAAC;SACF,IAAI,EAAE,YAAY,2BAAY;QACjC,QAAQ,GAAG,CAAC,IAAI,GAAG,YAAY,EAAE,EAAE,CAAC,2BAAY,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;;QACrE,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,CAAC,WAAW,CAAC,IAAI,iBAAiB,CAAC,CAAC;IACrE,OAAO,QAAQ,CAAC;AAClB,CAAC","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 *--------------------------------------------------------------------------------------------*/\nimport {\n BriefcaseDb,\n ExternalSource,\n ExternalSourceIsInRepository,\n IModelDb,\n RepositoryLink,\n StandaloneDb,\n} from \"@itwin/core-backend\";\nimport { DbResult, Id64String, Logger, OpenMode } from \"@itwin/core-bentley\";\nimport {\n Code,\n ExternalSourceProps,\n RepositoryLinkProps,\n} from \"@itwin/core-common\";\nimport * as assert from \"assert\";\nimport { IModelTransformer } from \"./IModelTransformer\";\nimport { pathToFileURL } from \"url\";\n/**\n * @alpha\n */\nexport interface ProvenanceInitArgs {\n /** the master iModel which is the source of the provenance */\n master: IModelDb;\n /** the canonical url of the master iModel */\n masterUrl?: string;\n /** the description of the master iModel */\n masterDescription?: string;\n /**\n * @param {IModelDb} branchDb - the branch iModel which is the container of the provenance\n * Must be opened Read/Write\n */\n branch: IModelDb;\n /**\n * insert Federation Guids in all lacking elements in the master database, which will prevent\n * needing to insert External Source Aspects for provenance tracking\n * @note requires a read/write master\n * @note closes both the master and branch iModels to reset caches, so you must reopen them.\n * If you pass `\"keep-reopened-db\"`, this object's `master` and `branch` properties will\n * be set to new, open databases.\n */\n createFedGuidsForMaster?: true | false | \"keep-reopened-db\";\n}\n\n/**\n * @alpha\n */\nexport interface ProvenanceInitResult {\n targetScopeElementId: Id64String;\n masterExternalSourceId: Id64String;\n masterRepositoryLinkId: Id64String;\n}\n\n/**\n * @alpha\n */\nexport async function initializeBranchProvenance(\n args: ProvenanceInitArgs\n): Promise<ProvenanceInitResult> {\n if (args.createFedGuidsForMaster) {\n // FIXME<LOW>: Consider enforcing that the master and branch dbs passed as part of ProvenanceInitArgs to this function\n // are identical. https://github.com/iTwin/imodel-transformer/issues/138\n args.master.withSqliteStatement(\n `\n UPDATE bis_Element\n SET FederationGuid=randomblob(16)\n WHERE FederationGuid IS NULL\n `,\n // eslint-disable-next-line @itwin/no-internal\n (s) =>\n assert(s.step() === DbResult.BE_SQLITE_DONE, args.branch.getLastError())\n );\n const masterPath = args.master.pathName;\n const reopenMaster = makeDbReopener(args.master);\n args.master.close(); // prevent busy\n args.branch.withSqliteStatement(\n `ATTACH DATABASE '${pathToFileURL(`${masterPath}`)}?mode=ro' AS master`,\n // eslint-disable-next-line @itwin/no-internal\n (s) =>\n assert(s.step() === DbResult.BE_SQLITE_DONE, args.branch.getLastError())\n );\n args.branch.withSqliteStatement(\n `\n UPDATE main.bis_Element\n SET FederationGuid = (\n SELECT m.FederationGuid\n FROM master.bis_Element m\n WHERE m.Id=main.bis_Element.Id\n )`,\n\n // eslint-disable-next-line @itwin/no-internal\n (s) =>\n assert(s.step() === DbResult.BE_SQLITE_DONE, args.branch.getLastError())\n );\n args.branch.clearCaches(); // statements write lock attached db (clearing statement cache does not fix this)\n args.branch.saveChanges();\n args.branch.withSqliteStatement(\"DETACH DATABASE master\", (s) => {\n const res = s.step();\n if (res !== DbResult.BE_SQLITE_DONE)\n Logger.logTrace(\n \"initializeBranchProvenance\",\n `Error detaching db (we will close anyway): ${args.branch.getLastError()}`\n );\n // this is the case until native side changes\n // eslint-disable-next-line @itwin/no-internal\n assert(res === DbResult.BE_SQLITE_ERROR, args.branch.getLastError());\n });\n args.branch.performCheckpoint();\n\n const reopenBranch = makeDbReopener(args.branch);\n // close dbs because element cache could be invalid\n args.branch.close();\n [args.master, args.branch] = await Promise.all([\n reopenMaster(),\n reopenBranch(),\n ]);\n }\n\n // create an external source and owning repository link to use as our *Target Scope Element* for future synchronizations\n const masterRepoLinkId = args.branch.elements.insertElement({\n classFullName: RepositoryLink.classFullName,\n code: RepositoryLink.createCode(\n args.branch,\n IModelDb.repositoryModelId,\n \"example-code-value\"\n ),\n model: IModelDb.repositoryModelId,\n url: args.masterUrl,\n format: \"iModel\",\n repositoryGuid: args.master.iModelId,\n description: args.masterDescription,\n } as RepositoryLinkProps);\n\n const masterExternalSourceId = args.branch.elements.insertElement({\n classFullName: ExternalSource.classFullName,\n model: IModelDb.rootSubjectId,\n code: Code.createEmpty(),\n repository: new ExternalSourceIsInRepository(masterRepoLinkId),\n /* eslint-disable @typescript-eslint/no-require-imports */\n connectorName: require(\"../../package.json\").name,\n connectorVersion: require(\"../../package.json\").version,\n /* eslint-enable @typescript-eslint/no-require-imports */\n } as ExternalSourceProps);\n\n const fedGuidlessElemsSql = `\n SELECT ECInstanceId AS id\n FROM Bis.Element\n WHERE FederationGuid IS NULL\n AND ECInstanceId NOT IN (0x1, 0xe, 0x10) /* ignore special elems */\n `;\n const elemReader = args.branch.createQueryReader(\n fedGuidlessElemsSql,\n undefined,\n { usePrimaryConn: true }\n );\n for await (const row of elemReader) {\n const id: string = row.id;\n const aspectProps = IModelTransformer.initElementProvenanceOptions(id, id, {\n isReverseSynchronization: false,\n targetScopeElementId: masterExternalSourceId,\n sourceDb: args.master,\n targetDb: args.branch,\n });\n args.branch.elements.insertAspect(aspectProps);\n }\n\n const fedGuidlessRelsSql = `\n SELECT erte.ECInstanceId as id\n FROM Bis.ElementRefersToElements erte\n JOIN bis.Element se\n ON se.ECInstanceId=erte.SourceECInstanceId\n JOIN bis.Element te\n ON te.ECInstanceId=erte.TargetECInstanceId\n WHERE se.FederationGuid IS NULL\n OR te.FederationGuid IS NULL`;\n const relReader = args.branch.createQueryReader(\n fedGuidlessRelsSql,\n undefined,\n { usePrimaryConn: true }\n );\n for await (const row of relReader) {\n const id: string = row.id;\n const aspectProps =\n await IModelTransformer.initRelationshipProvenanceOptions(id, id, {\n isReverseSynchronization: false,\n targetScopeElementId: masterExternalSourceId,\n sourceDb: args.master,\n targetDb: args.branch,\n forceOldRelationshipProvenanceMethod: false,\n });\n args.branch.elements.insertAspect(aspectProps);\n }\n\n if (args.createFedGuidsForMaster === true) {\n args.master.close();\n args.branch.close();\n }\n\n return {\n targetScopeElementId: masterExternalSourceId,\n masterExternalSourceId,\n masterRepositoryLinkId: masterRepoLinkId,\n };\n}\n\nfunction makeDbReopener(db: IModelDb) {\n const originalMode = db.isReadonly ? OpenMode.Readonly : OpenMode.ReadWrite;\n const dbPath = db.pathName;\n let reopenDb: (mode?: OpenMode) => IModelDb | Promise<IModelDb>;\n if (db instanceof BriefcaseDb)\n reopenDb = async (mode = originalMode) =>\n BriefcaseDb.open({\n fileName: dbPath,\n readonly: mode === OpenMode.Readonly,\n });\n else if (db instanceof StandaloneDb)\n reopenDb = (mode = originalMode) => StandaloneDb.openFile(dbPath, mode);\n else assert(false, `db type '${db.constructor.name}' not supported`);\n return reopenDb;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BranchProvenanceInitializer.js","sourceRoot":"","sources":["../../src/BranchProvenanceInitializer.ts"],"names":[],"mappings":";;AA2DA,gEAmJC;AA9MD;;;gGAGgG;AAChG,sDAO6B;AAC7B,sDAA6E;AAC7E,oDAI4B;AAC5B,iCAAiC;AACjC,2DAAwD;AACxD,6BAAoC;AAoCpC;;GAEG;AACI,KAAK,UAAU,0BAA0B,CAC9C,IAAwB;IAExB,IAAI,IAAI,CAAC,uBAAuB,EAAE,CAAC;QACjC,sHAAsH;QACtH,wEAAwE;QACxE,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAC7B;;;;OAIC;QACD,8CAA8C;QAC9C,CAAC,CAAC,EAAE,EAAE,CACJ,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,uBAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAC3E,CAAC;QACF,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;QACxC,MAAM,YAAY,GAAG,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,eAAe;QACpC,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAC7B,oBAAoB,IAAA,mBAAa,EAAC,GAAG,UAAU,EAAE,CAAC,qBAAqB;QACvE,8CAA8C;QAC9C,CAAC,CAAC,EAAE,EAAE,CACJ,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,uBAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAC3E,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAC7B;;;;;;QAME;QAEF,8CAA8C;QAC9C,CAAC,CAAC,EAAE,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E,IAAI,GAAG,YAAY,EAAE,EAAE,CACvC,0BAAW,CAAC,IAAI,CAAC;YACf,QAAQ,EAAE,MAAM;YAChB,QAAQ,EAAE,IAAI,KAAK,uBAAQ,CAAC,QAAQ;SACrC,CAAC,CAAC;SACF,IAAI,EAAE,YAAY,2BAAY;QACjC,QAAQ,GAAG,CAAC,IAAI,GAAG,YAAY,EAAE,EAAE,CAAC,2BAAY,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;;QACrE,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,CAAC,WAAW,CAAC,IAAI,iBAAiB,CAAC,CAAC;IACrE,OAAO,QAAQ,CAAC;AAClB,CAAC","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 *--------------------------------------------------------------------------------------------*/\nimport {\n BriefcaseDb,\n ExternalSource,\n ExternalSourceIsInRepository,\n IModelDb,\n RepositoryLink,\n StandaloneDb,\n} from \"@itwin/core-backend\";\nimport { DbResult, Id64String, Logger, OpenMode } from \"@itwin/core-bentley\";\nimport {\n Code,\n ExternalSourceProps,\n RepositoryLinkProps,\n} from \"@itwin/core-common\";\nimport * as assert from \"assert\";\nimport { ProvenanceManager } from \"./ProvenanceManager\";\nimport { pathToFileURL } from \"url\";\n/**\n * @alpha\n */\nexport interface ProvenanceInitArgs {\n /** the master iModel which is the source of the provenance */\n master: IModelDb;\n /** the canonical url of the master iModel */\n masterUrl?: string;\n /** the description of the master iModel */\n masterDescription?: string;\n /**\n * @param {IModelDb} branchDb - the branch iModel which is the container of the provenance\n * Must be opened Read/Write\n */\n branch: IModelDb;\n /**\n * insert Federation Guids in all lacking elements in the master database, which will prevent\n * needing to insert External Source Aspects for provenance tracking\n * @note requires a read/write master\n * @note closes both the master and branch iModels to reset caches, so you must reopen them.\n * If you pass `\"keep-reopened-db\"`, this object's `master` and `branch` properties will\n * be set to new, open databases.\n */\n createFedGuidsForMaster?: true | false | \"keep-reopened-db\";\n}\n\n/**\n * @alpha\n */\nexport interface ProvenanceInitResult {\n targetScopeElementId: Id64String;\n masterExternalSourceId: Id64String;\n masterRepositoryLinkId: Id64String;\n}\n\n/**\n * @alpha\n */\nexport async function initializeBranchProvenance(\n args: ProvenanceInitArgs\n): Promise<ProvenanceInitResult> {\n if (args.createFedGuidsForMaster) {\n // FIXME<LOW>: Consider enforcing that the master and branch dbs passed as part of ProvenanceInitArgs to this function\n // are identical. https://github.com/iTwin/imodel-transformer/issues/138\n args.master.withSqliteStatement(\n `\n UPDATE bis_Element\n SET FederationGuid=randomblob(16)\n WHERE FederationGuid IS NULL\n `,\n // eslint-disable-next-line @itwin/no-internal\n (s) =>\n assert(s.step() === DbResult.BE_SQLITE_DONE, args.branch.getLastError())\n );\n const masterPath = args.master.pathName;\n const reopenMaster = makeDbReopener(args.master);\n args.master.close(); // prevent busy\n args.branch.withSqliteStatement(\n `ATTACH DATABASE '${pathToFileURL(`${masterPath}`)}?mode=ro' AS master`,\n // eslint-disable-next-line @itwin/no-internal\n (s) =>\n assert(s.step() === DbResult.BE_SQLITE_DONE, args.branch.getLastError())\n );\n args.branch.withSqliteStatement(\n `\n UPDATE main.bis_Element\n SET FederationGuid = (\n SELECT m.FederationGuid\n FROM master.bis_Element m\n WHERE m.Id=main.bis_Element.Id\n )`,\n\n // eslint-disable-next-line @itwin/no-internal\n (s) =>\n assert(s.step() === DbResult.BE_SQLITE_DONE, args.branch.getLastError())\n );\n args.branch.clearCaches(); // statements write lock attached db (clearing statement cache does not fix this)\n args.branch.saveChanges();\n args.branch.withSqliteStatement(\"DETACH DATABASE master\", (s) => {\n const res = s.step();\n if (res !== DbResult.BE_SQLITE_DONE)\n Logger.logTrace(\n \"initializeBranchProvenance\",\n `Error detaching db (we will close anyway): ${args.branch.getLastError()}`\n );\n // this is the case until native side changes\n // eslint-disable-next-line @itwin/no-internal\n assert(res === DbResult.BE_SQLITE_ERROR, args.branch.getLastError());\n });\n args.branch.performCheckpoint();\n\n const reopenBranch = makeDbReopener(args.branch);\n // close dbs because element cache could be invalid\n args.branch.close();\n [args.master, args.branch] = await Promise.all([\n reopenMaster(),\n reopenBranch(),\n ]);\n }\n\n // create an external source and owning repository link to use as our *Target Scope Element* for future synchronizations\n const masterRepoLinkId = args.branch.elements.insertElement({\n classFullName: RepositoryLink.classFullName,\n code: RepositoryLink.createCode(\n args.branch,\n IModelDb.repositoryModelId,\n \"example-code-value\"\n ),\n model: IModelDb.repositoryModelId,\n url: args.masterUrl,\n format: \"iModel\",\n repositoryGuid: args.master.iModelId,\n description: args.masterDescription,\n } as RepositoryLinkProps);\n\n const masterExternalSourceId = args.branch.elements.insertElement({\n classFullName: ExternalSource.classFullName,\n model: IModelDb.rootSubjectId,\n code: Code.createEmpty(),\n repository: new ExternalSourceIsInRepository(masterRepoLinkId),\n /* eslint-disable @typescript-eslint/no-require-imports */\n connectorName: require(\"../../package.json\").name,\n connectorVersion: require(\"../../package.json\").version,\n /* eslint-enable @typescript-eslint/no-require-imports */\n } as ExternalSourceProps);\n\n const fedGuidlessElemsSql = `\n SELECT ECInstanceId AS id\n FROM Bis.Element\n WHERE FederationGuid IS NULL\n AND ECInstanceId NOT IN (0x1, 0xe, 0x10) /* ignore special elems */\n `;\n const elemReader = args.branch.createQueryReader(\n fedGuidlessElemsSql,\n undefined,\n { usePrimaryConn: true }\n );\n for await (const row of elemReader) {\n const id: string = row.id;\n const aspectProps = ProvenanceManager.initElementProvenanceOptions(id, id, {\n isReverseSynchronization: false,\n targetScopeElementId: masterExternalSourceId,\n sourceDb: args.master,\n targetDb: args.branch,\n });\n args.branch.elements.insertAspect(aspectProps);\n }\n\n const fedGuidlessRelsSql = `\n SELECT erte.ECInstanceId as id\n FROM Bis.ElementRefersToElements erte\n JOIN bis.Element se\n ON se.ECInstanceId=erte.SourceECInstanceId\n JOIN bis.Element te\n ON te.ECInstanceId=erte.TargetECInstanceId\n WHERE se.FederationGuid IS NULL\n OR te.FederationGuid IS NULL`;\n const relReader = args.branch.createQueryReader(\n fedGuidlessRelsSql,\n undefined,\n { usePrimaryConn: true }\n );\n for await (const row of relReader) {\n const id: string = row.id;\n const aspectProps =\n await ProvenanceManager.initRelationshipProvenanceOptions(id, id, {\n isReverseSynchronization: false,\n targetScopeElementId: masterExternalSourceId,\n sourceDb: args.master,\n targetDb: args.branch,\n forceOldRelationshipProvenanceMethod: false,\n });\n args.branch.elements.insertAspect(aspectProps);\n }\n\n if (args.createFedGuidsForMaster === true) {\n args.master.close();\n args.branch.close();\n }\n\n return {\n targetScopeElementId: masterExternalSourceId,\n masterExternalSourceId,\n masterRepositoryLinkId: masterRepoLinkId,\n };\n}\n\nfunction makeDbReopener(db: IModelDb) {\n const originalMode = db.isReadonly ? OpenMode.Readonly : OpenMode.ReadWrite;\n const dbPath = db.pathName;\n let reopenDb: (mode?: OpenMode) => IModelDb | Promise<IModelDb>;\n if (db instanceof BriefcaseDb)\n reopenDb = async (mode = originalMode) =>\n BriefcaseDb.open({\n fileName: dbPath,\n readonly: mode === OpenMode.Readonly,\n });\n else if (db instanceof StandaloneDb)\n reopenDb = (mode = originalMode) => StandaloneDb.openFile(dbPath, mode);\n else assert(false, `db type '${db.constructor.name}' not supported`);\n return reopenDb;\n}\n"]}
|
|
@@ -45,7 +45,7 @@ class ElementCascadingDeleter extends core_backend_1.ElementTreeDeleter {
|
|
|
45
45
|
AND Parent.id IS NULL
|
|
46
46
|
`;
|
|
47
47
|
const params = new core_common_1.QueryBinder().bindId("scopeId", element);
|
|
48
|
-
this.
|
|
48
|
+
this.txn.iModel.withQueryReader(query, (reader) => {
|
|
49
49
|
for (const row of reader) {
|
|
50
50
|
const elementId = row[0];
|
|
51
51
|
this.processElementTree(elementId, newScope);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElementCascadingDeleter.js","sourceRoot":"","sources":["../../src/ElementCascadingDeleter.ts"],"names":[],"mappings":";;;AAmBA,4DAOC;AA1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GAAG,IAAI,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAChD,GAAG,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;IACrC,GAAG,CAAC,qBAAqB,EAAE,CAAC;AAC9B,CAAC;AAED;;;GAGG;AACH,MAAa,uBAAwB,SAAQ,iCAAkB;IACnD,qBAAqB,CAC7B,UAAsB,EACtB,MAA8B;QAE9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,qCAAqC;IAClB,kBAAkB,CACnC,OAAmB,EACnB,KAA6B;QAE7B,IAAI,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC;YAC/C,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC1C,CAAC;QACD,KAAK,CAAC,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IACD,oCAAoC;IAC5B,kBAAkB,CACxB,OAAmB,EACnB,KAA6B;QAE7B,MAAM,QAAQ,GAAG,IAAI,qCAAsB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC5D,MAAM,KAAK,GAAG;;;;;KAKb,CAAC;QAEF,MAAM,MAAM,GAAG,IAAI,yBAAW,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAE5D,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,CAC7B,KAAK,EACL,CAAC,MAAM,EAAE,EAAE;YACT,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;gBACzB,MAAM,SAAS,GAAG,GAAG,CAAC,CAAC,CAAe,CAAC;gBACvC,IAAI,CAAC,kBAAkB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC,EACD,MAAM,CACP,CAAC;IACJ,CAAC;CACF;AA5CD,0DA4CC","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 {\n ElementTreeDeleter,\n ElementTreeWalkerScope,\n IModelDb,\n} from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { QueryBinder } from \"@itwin/core-common\";\n\n/** Deletes an element tree and code scope references starting with the specified top element. The top element is also deleted. Uses ElementCascadeDeleter.\n * @param iModel The iModel\n * @param topElement The parent of the sub-tree\n */\nexport function deleteElementTreeCascade(\n iModel: IModelDb,\n topElement: Id64String\n): void {\n const del = new ElementCascadingDeleter(iModel);\n del.deleteNormalElements(topElement);\n del.deleteSpecialElements();\n}\n\n/** Deletes an entire element tree, including sub-models, child elements and code scope references.\n * Items are deleted in bottom-up order. Definitions and Subjects are deleted after normal elements.\n * Call deleteNormalElements on each tree. Then call deleteSpecialElements.\n */\nexport class ElementCascadingDeleter extends ElementTreeDeleter {\n protected shouldVisitCodeScopes(\n _elementId: Id64String,\n _scope: ElementTreeWalkerScope\n ) {\n return true;\n }\n\n /** The main tree-walking function */\n protected override processElementTree(\n element: Id64String,\n scope: ElementTreeWalkerScope\n ): void {\n if (this.shouldVisitCodeScopes(element, scope)) {\n this._processCodeScopes(element, scope);\n }\n super.processElementTree(element, scope);\n }\n /** Process code scope references */\n private _processCodeScopes(\n element: Id64String,\n scope: ElementTreeWalkerScope\n ) {\n const newScope = new ElementTreeWalkerScope(scope, element);\n const query = `\n SELECT ECInstanceId\n FROM bis.Element\n WHERE CodeScope.id=:scopeId\n AND Parent.id IS NULL\n `;\n\n const params = new QueryBinder().bindId(\"scopeId\", element);\n\n this.txn.iModel.withQueryReader(\n query,\n (reader) => {\n for (const row of reader) {\n const elementId = row[0] as Id64String;\n this.processElementTree(elementId, newScope);\n }\n },\n params\n );\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityUnifier.d.ts","sourceRoot":"","sources":["../../src/EntityUnifier.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AAGH,OAAO,EAEL,eAAe,EAEhB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,mBAAmB,EAKnB,QAAQ,EAET,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"EntityUnifier.d.ts","sourceRoot":"","sources":["../../src/EntityUnifier.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AAGH,OAAO,EAEL,eAAe,EAEhB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,mBAAmB,EAKnB,QAAQ,EAET,MAAM,qBAAqB,CAAC;AAG7B,gBAAgB;AAChB,yBAAiB,aAAa,CAAC;IAC7B,MAAM,UAAU,eAAe,CAAC,MAAM,EAAE,cAAc,yEAKrD;IAED,KAAK,aAAa,GAAG,CAAC,WAAW,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAEhE,2GAA2G;IAC3G,MAAM,UAAU,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,iBAc9D;IAED,gBAAsB,MAAM,CAC1B,EAAE,EAAE,QAAQ,EACZ,GAAG,EAAE;QAAE,MAAM,EAAE,cAAc,CAAA;KAAE,GAAG;QAAE,eAAe,EAAE,eAAe,CAAA;KAAE,oBAoBvE;;CACF"}
|
package/lib/cjs/EntityUnifier.js
CHANGED
|
@@ -52,7 +52,10 @@ var EntityUnifier;
|
|
|
52
52
|
return false;
|
|
53
53
|
const query = `SELECT 1 FROM ${classFullName} WHERE ECInstanceId=:id`;
|
|
54
54
|
const params = new core_common_1.QueryBinder().bindId("id", id);
|
|
55
|
-
|
|
55
|
+
const reader = db.createQueryReader(query, params, {
|
|
56
|
+
usePrimaryConn: true,
|
|
57
|
+
});
|
|
58
|
+
return reader.step();
|
|
56
59
|
}
|
|
57
60
|
EntityUnifier.exists = exists;
|
|
58
61
|
})(EntityUnifier || (exports.EntityUnifier = EntityUnifier = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityUnifier.js","sourceRoot":"","sources":["../../src/EntityUnifier.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;;;GAIG;;;AAEH,iCAAiC;AACjC,oDAI4B;AAC5B,sDAS6B;AAC7B,sDAA2C;
|
|
1
|
+
{"version":3,"file":"EntityUnifier.js","sourceRoot":"","sources":["../../src/EntityUnifier.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;;;GAIG;;;AAEH,iCAAiC;AACjC,oDAI4B;AAC5B,sDAS6B;AAC7B,sDAA2C;AAE3C,gBAAgB;AAChB,IAAiB,aAAa,CAkD7B;AAlDD,WAAiB,aAAa;IAC5B,SAAgB,eAAe,CAAC,MAAsB;QACpD,IAAI,MAAM,YAAY,sBAAO;YAAE,OAAO,SAAS,CAAC;aAC3C,IAAI,MAAM,YAAY,4BAAa;YAAE,OAAO,gBAAgB,CAAC;aAC7D,IAAI,MAAM,YAAY,2BAAY;YAAE,OAAO,cAAc,CAAC;;YAC1D,OAAO,qBAAqB,CAAC;IACpC,CAAC;IALe,6BAAe,kBAK9B,CAAA;IAID,2GAA2G;IAC3G,SAAgB,UAAU,CAAC,EAAY,EAAE,MAAsB;QAC7D,IAAI,MAAM,YAAY,sBAAO;YAC3B,OAAO,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAkB,CAAC;aACjE,IAAI,MAAM,YAAY,2BAAY;YACrC,OAAO,EAAE,CAAC,aAAa,CAAC,cAAc,CAAC,IAAI,CACzC,EAAE,CAAC,aAAa,CACA,CAAC;aAChB,IAAI,MAAM,YAAY,4BAAa;YACtC,OAAO,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAkB,CAAC;;YAEnE,MAAM,CACJ,KAAK,EACL,4BAA4B,MAAM,CAAC,WAAW,CAAC,IAAI,kDAAkD,CACtG,CAAC;IACN,CAAC;IAde,wBAAU,aAczB,CAAA;IAEM,KAAK,UAAU,MAAM,CAC1B,EAAY,EACZ,GAAsE;QAEtE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,GACd,iBAAiB,IAAI,GAAG;YACtB,CAAC,CAAC,+BAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC;YAC7C,CAAC,CAAC,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACjC,MAAM,aAAa,GACjB,iBAAiB,IAAI,GAAG;YACtB,CAAC,CAAC,wFAAwF;gBACxF,iCAAmB,CAAC,0BAA0B,CAAC,IAAK,CAAC;YACvD,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,UAAU,MAAM,GAAG,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC;QAE7D,IAAI,EAAE,KAAK,SAAS,IAAI,mBAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAAE,OAAO,KAAK,CAAC;QAEzD,MAAM,KAAK,GAAG,iBAAiB,aAAa,yBAAyB,CAAC;QACtE,MAAM,MAAM,GAAG,IAAI,yBAAW,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAClD,MAAM,MAAM,GAAG,EAAE,CAAC,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE;YACjD,cAAc,EAAE,IAAI;SACrB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACvB,CAAC;IAtBqB,oBAAM,SAsB3B,CAAA;AACH,CAAC,EAlDgB,aAAa,6BAAb,aAAa,QAkD7B","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 Utils\n * utilities that unify operations, especially CRUD operations, on entities\n * for entity-generic operations in the transformer\n */\n\nimport * as assert from \"assert\";\nimport {\n ConcreteEntityTypes,\n EntityReference,\n QueryBinder,\n} from \"@itwin/core-common\";\nimport {\n ConcreteEntity,\n ConcreteEntityProps,\n // eslint-disable-next-line @typescript-eslint/no-redeclare\n Element,\n ElementAspect,\n EntityReferences,\n IModelDb,\n Relationship,\n} from \"@itwin/core-backend\";\nimport { Id64 } from \"@itwin/core-bentley\";\n\n/** @internal */\nexport namespace EntityUnifier {\n export function getReadableType(entity: ConcreteEntity) {\n if (entity instanceof Element) return \"element\";\n else if (entity instanceof ElementAspect) return \"element aspect\";\n else if (entity instanceof Relationship) return \"relationship\";\n else return \"unknown entity type\";\n }\n\n type EntityUpdater = (entityProps: ConcreteEntityProps) => void;\n\n /** needs to return a widened type otherwise typescript complains when result is used with a narrow type */\n export function updaterFor(db: IModelDb, entity: ConcreteEntity) {\n if (entity instanceof Element)\n return db.elements.updateElement.bind(db.elements) as EntityUpdater;\n else if (entity instanceof Relationship)\n return db.relationships.updateInstance.bind(\n db.relationships\n ) as EntityUpdater;\n else if (entity instanceof ElementAspect)\n return db.elements.updateAspect.bind(db.elements) as EntityUpdater;\n else\n assert(\n false,\n `unreachable; entity was '${entity.constructor.name}' not an Element, Relationship, or ElementAspect`\n );\n }\n\n export async function exists(\n db: IModelDb,\n arg: { entity: ConcreteEntity } | { entityReference: EntityReference }\n ) {\n const [type, id] =\n \"entityReference\" in arg\n ? EntityReferences.split(arg.entityReference)\n : [undefined, arg.entity.id];\n const classFullName =\n \"entityReference\" in arg\n ? // eslint-disable-next-line @itwin/no-internal, @typescript-eslint/no-non-null-assertion\n ConcreteEntityTypes.toBisCoreRootClassFullName(type!)\n : `[${arg.entity.schemaName}].[${arg.entity.className}]`;\n\n if (id === undefined || Id64.isInvalid(id)) return false;\n\n const query = `SELECT 1 FROM ${classFullName} WHERE ECInstanceId=:id`;\n const params = new QueryBinder().bindId(\"id\", id);\n const reader = db.createQueryReader(query, params, {\n usePrimaryConn: true,\n });\n return reader.step();\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelImporter.d.ts","sourceRoot":"","sources":["../../src/IModelImporter.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,OAAO,EAGL,UAAU,EAGX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,
|
|
1
|
+
{"version":3,"file":"IModelImporter.d.ts","sourceRoot":"","sources":["../../src/IModelImporter.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,OAAO,EAGL,UAAU,EAGX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAGL,kBAAkB,EAClB,YAAY,EACZ,WAAW,EAGX,UAAU,EAGX,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,MAAM,EACN,QAAQ,EAER,iBAAiB,EAGlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAOtE;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,OAAO,GAAG;QAAE,eAAe,EAAE,OAAO,CAAA;KAAE,CAAC;IAClE,iDAAiD;IACjD,8BAA8B,CAAC,EAAE,OAAO,CAAC;IACzC;;OAEG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC;;;;OAIG;IACH,kCAAkC,CAAC,EAAE,OAAO,CAAC;CAC9C;AAED;;;;;GAKG;AACH,qBAAa,cAAc;IACzB,oCAAoC;IACpC,SAAgB,QAAQ,EAAE,QAAQ,CAAC;IAEnC;;OAEG;IACH,SAAgB,OAAO,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC;IAEvD,OAAO,CAAC,MAAM,CAAC,uCAAuC,CAAqB;IAE3E;;;;;;OAMG;IACH,OAAO,CAAC,sBAAsB,CAA0B;IAExD;;;;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AAyB,CAChC,mBAAwB,EACxB,mBAAwB;IAExB,MAAM,eAAe,GAAG,4BAAc,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;IACrE,MAAM,eAAe,GAAG,4BAAc,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;IACrE,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;IACpD,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;IACpD,OAAO,WAAW,KAAK,WAAW,CAAC;AACrC,CAAC;AAED,8EAA8E;AAC9E,SAAS,eAAe,CAAC,SAAc,EAAE,SAAc;IACrD,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AACjE,CAAC;AAED,+CAA+C;AAC/C,SAAS,aAAa,CAAC,KAAmB;IACxC,OAAO,KAAK,CAAC,aAAa,KAAK,0BAAW,CAAC,aAAa,CAAC;AAC3D,CAAC;AAED,2EAA2E;AAC3E,SAAS,oBAAoB,CAAC,KAAuB;IACnD,IAAI,KAAK,CAAC,EAAE,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAEzC,IAAI,CAAC,mBAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,yBAAW,CACnB,2BAAY,CAAC,UAAU,EACvB,4BAA4B,CAC7B,CAAC;IACJ,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE,KAAK,SAAS;QAChC,MAAM,IAAI,yBAAW,CACnB,2BAAY,CAAC,UAAU,EACvB,uBAAuB,KAAK,CAAC,EAAE,gBAAgB,CAChD,CAAC;IACJ,OAAO,KAAK,CAAC,EAAE,KAAK,uBAAQ,CAAC,uBAAuB,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACxE,CAAC","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 {\n Guid,\n Id64,\n Id64String,\n IModelStatus,\n Logger,\n} from \"@itwin/core-bentley\";\nimport {\n AxisAlignedBox3d,\n Base64EncodedString,\n ECJsNames,\n ElementAspectProps,\n ElementProps,\n EntityProps,\n IModel,\n IModelError,\n ModelProps,\n RelatedElement,\n SubCategoryProps,\n} from \"@itwin/core-common\";\nimport { TransformerLoggerCategory } from \"./TransformerLoggerCategory\";\nimport {\n ElementAspect,\n ElementMultiAspect,\n Entity,\n IModelDb,\n Relationship,\n RelationshipProps,\n SourceAndTarget,\n SubCategory,\n} from \"@itwin/core-backend\";\nimport type { RelationshipPropsForDelete } from \"./IModelTransformer\";\nimport * as assert from \"assert\";\nimport { deleteElementTreeCascade } from \"./ElementCascadingDeleter\";\nimport { Property, PropertyType } from \"@itwin/ecschema-metadata\";\n\nconst loggerCategory: string = TransformerLoggerCategory.IModelImporter;\n\n/** Options provided to [[IModelImporter.optimizeGeometry]] specifying post-processing optimizations to be applied to the iModel's geometry.\n * @beta\n */\nexport interface OptimizeGeometryOptions {\n /** If true, identify any [GeometryPart]($backend)s that are referenced exactly once. For each such part,\n * replace the reference in the element's geometry stream with the part's own geometry stream, then delete the part.\n */\n inlineUniqueGeometryParts?: boolean;\n}\n\n/** Options provided to the [[IModelImporter]] constructor.\n * @beta\n */\nexport interface IModelImportOptions {\n /** If `true` (the default), compute the projectExtents of the target iModel after elements are imported.\n * The computed projectExtents will either include or exclude *outliers* depending on the `excludeOutliers` flag that defaults to `false`.\n * @see [[IModelImporter.autoExtendProjectExtents]]\n * @see [IModelImporter Options]($docs/learning/transformer/index.md#IModelImporter)\n */\n autoExtendProjectExtents?: boolean | { excludeOutliers: boolean };\n /** See [IModelTransformOptions]($transformer) */\n preserveElementIdsForFiltering?: boolean;\n /** If `true`, simplify the element geometry for visualization purposes. For example, convert b-reps into meshes.\n * @default false\n */\n simplifyElementGeometry?: boolean;\n /**\n * Skip propagating changes made to the root subject, dictionaryModel and IModelImporter._realityDataSourceLinkPartitionStaticId (0xe)\n * If it is set to false, changes to root elements are propagated, the root subject name gets changed and leads to the iModelDb.name property being updated in .initializeiModelDb\n * @default true\n */\n skipPropagateChangesToRootElements?: boolean;\n}\n\n/** Base class for importing data into an iModel.\n * @see [iModel Transformation and Data Exchange]($docs/learning/transformer/index.md)\n * @see [IModelExporter]($transformer)\n * @see [IModelTransformer]($transformer)\n * @beta\n */\nexport class IModelImporter {\n /** The read/write target iModel. */\n public readonly targetDb: IModelDb;\n\n /** resolved initialization options for the importer\n * @beta\n */\n public readonly options: Required<IModelImportOptions>;\n\n private static _realityDataSourceLinkPartitionStaticId: Id64String = \"0xe\";\n\n /**\n * A map of conflicting element code values.\n * In cases where updating an element's code value results in a codeValue conflict, the element's code value will instead be updated to a random guid.\n * The actual codeValue will be stored in this ElementId->CodeValue map.\n * This is needed in cases where the duplicate target element is set to be deleted in the future, or when elements are switching code values with one another and we need a temporary code value.\n * To resolve code values to their intended values call [[IModelImporter.resolveDuplicateCodeValues]].\n */\n private _duplicateCodeValueMap: Map<Id64String, string>;\n\n /**\n * A set of elementIds that the transformer adds to while exporting elements to indicate that the element already exists in the target.\n * Defaults to an empty set.\n * @note\n *\n * This is used as an optimization when `[[IModelTransformOptions.preserveElementIdsForFiltering]]` is set to `true`\n * In normal cases where this option set to `false`,\n * the importer determines whether to insert or update based off of whether the ID is defined on the `elementProps` passed to `importElement`.\n * However, with `preserveElementIdsForFiltering` set to `true`, IDs are always set, so we can't determine insert/update like the normal case.\n * The transformer already knows if an element exists or not by the time `importElement` is called and pushes to this set with `markElementToUpdateForPreserveId`.\n * @note This set should stay small, as right after the transformer pushes to it, the importer will remove from the set.\n */\n private _elementsToUpdateDuringPreserveIds = new Set<Id64String>([]);\n\n /** The set of elements that should not be updated by this IModelImporter.\n * Defaults to an empty set.\n * @note Adding an element to this set is typically necessary when remapping a source element to one that already exists in the target and already has the desired properties.\n */\n public readonly doNotUpdateElementIds = new Set<Id64String>([]);\n\n /** This set is ONLY used for elements that are always present even in an \"empty\" iModel. We will use this set to filter out changes to root elements if [[IModelTransformOptions.skipPropagateChangesToRootElements]] is false. */\n private readonly _rootElementIds = new Set<Id64String>([\n IModel.rootSubjectId,\n IModel.dictionaryId,\n IModelImporter._realityDataSourceLinkPartitionStaticId,\n ]);\n\n /** The number of entity changes before incremental progress should be reported via the [[onProgress]] callback. */\n public progressInterval: number = 1000;\n /** Tracks the current total number of entity changes. */\n private _progressCounter: number = 0;\n /** */\n private _modelPropertiesToIgnore = new Set<string>([\n \"geometryGuid\", // cannot compare GeometricModel.GeometryGuid values across iModels\n ]);\n\n /** Construct a new IModelImporter\n * @param targetDb The target IModelDb\n * @param options The options that specify how the import should be done.\n */\n public constructor(targetDb: IModelDb, options?: IModelImportOptions) {\n this.targetDb = targetDb;\n this.options = {\n autoExtendProjectExtents: options?.autoExtendProjectExtents ?? true,\n preserveElementIdsForFiltering:\n options?.preserveElementIdsForFiltering ?? false,\n simplifyElementGeometry: options?.simplifyElementGeometry ?? false,\n skipPropagateChangesToRootElements:\n options?.skipPropagateChangesToRootElements ?? true,\n };\n this._duplicateCodeValueMap = new Map<Id64String, string>();\n }\n\n /**\n * Checks [[IModelImportOptions.skipPropagateChangesToRootElements]], [[IModelImporter.rootElementIds]], and [[IModelImporter.doNotUpdateElementIds]] and returns true for 'do not update', false for do 'update'.\n */\n private doNotUpdateElement(elementId: Id64String): boolean {\n if (\n this.options.skipPropagateChangesToRootElements &&\n this._rootElementIds.has(elementId)\n )\n return true;\n if (this.doNotUpdateElementIds.has(elementId)) return true;\n return false;\n }\n\n /**\n * Marks an element so that it can be updated during import when [[IModelTransformOptions.preserveElementIdsForFiltering]] is set to true.\n */\n public markElementToUpdateDuringPreserveIds(elementId: Id64String) {\n if (this._rootElementIds.has(elementId)) {\n return;\n }\n this._elementsToUpdateDuringPreserveIds.add(elementId);\n }\n\n /** Import the specified ModelProps (either as an insert or an update) into the target iModel. */\n public async importModel(modelProps: ModelProps): Promise<void> {\n if (undefined === modelProps.id || !Id64.isValidId64(modelProps.id))\n throw new IModelError(\n IModelStatus.InvalidId,\n \"Model Id not provided, should be the same as the ModeledElementId\"\n );\n\n if (this.doNotUpdateElement(modelProps.id)) {\n Logger.logInfo(\n loggerCategory,\n `Do not update target model ${modelProps.id}`\n );\n return;\n }\n try {\n const model = this.targetDb.models.getModel(modelProps.id); // throws IModelError.NotFound if model does not exist\n if (hasEntityChanged(model, modelProps, this._modelPropertiesToIgnore)) {\n await this.onUpdateModel(modelProps);\n }\n } catch (error) {\n // catch NotFound error and insertModel\n if (\n error instanceof IModelError &&\n error.errorNumber === IModelStatus.NotFound\n ) {\n await this.onInsertModel(modelProps);\n return;\n }\n throw error;\n }\n }\n\n /** Create a new Model from the specified ModelProps and insert it into the target iModel.\n * @note A subclass may override this method to customize insert behavior but should call `super.onInsertModel`.\n */\n protected async onInsertModel(modelProps: ModelProps): Promise<Id64String> {\n try {\n const modelId: Id64String = this.targetDb.models.insertModel(modelProps);\n Logger.logInfo(\n loggerCategory,\n `Inserted ${this.formatModelForLogger(modelProps)}`\n );\n await this.trackProgress();\n return modelId;\n } catch (error) {\n if (!this.targetDb.containsClass(modelProps.classFullName)) {\n // replace standard insert error with something more helpful\n const errorMessage = `Model class \"${modelProps.classFullName}\" not found in the target iModel. Was the latest version of the schema imported?`;\n throw new IModelError(IModelStatus.InvalidName, errorMessage);\n }\n throw error; // throw original error\n }\n }\n\n /** Update an existing Model in the target iModel from the specified ModelProps.\n * @note A subclass may override this method to customize update behavior but should call `super.onUpdateModel`.\n */\n protected async onUpdateModel(modelProps: ModelProps): Promise<void> {\n this.targetDb.models.updateModel(modelProps);\n Logger.logInfo(\n loggerCategory,\n `Updated ${this.formatModelForLogger(modelProps)}`\n );\n await this.trackProgress();\n }\n\n /** Format a Model for the Logger. */\n private formatModelForLogger(modelProps: ModelProps): string {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return `${modelProps.classFullName} [${modelProps.id!}]`;\n }\n\n /**\n * Tries to update an element with the specified element properties.\n * If a duplicate code error occurs, it assigns a new unique code value and retries the update\n */\n private async tryUpdateElement(elemProps: ElementProps) {\n try {\n await this.onUpdateElement(elemProps);\n } catch (err) {\n if ((err as IModelError).errorNumber === IModelStatus.DuplicateCode) {\n assert(\n elemProps.code.value !== undefined,\n \"NULL code values are always considered unique and cannot clash\"\n );\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._duplicateCodeValueMap.set(elemProps.id!, elemProps.code.value);\n // Using NULL code values as an alternative is not valid because definition elements cannot have NULL code values.\n elemProps.code.value = Guid.createValue();\n await this.onUpdateElement(elemProps);\n } else {\n throw err;\n }\n }\n }\n\n /** Import the specified ElementProps (either as an insert or an update) into the target iModel. */\n public async importElement(elementProps: ElementProps): Promise<Id64String> {\n if (\n undefined !== elementProps.id &&\n this.doNotUpdateElement(elementProps.id)\n ) {\n Logger.logInfo(\n loggerCategory,\n `Do not update target element ${elementProps.id}`\n );\n return elementProps.id;\n }\n\n if (this.options.preserveElementIdsForFiltering) {\n if (elementProps.id === undefined) {\n throw new IModelError(\n IModelStatus.BadElement,\n \"elementProps.id must be defined during a preserveIds operation\"\n );\n }\n\n // Categories are the only element that onInserted will immediately insert a new element (their default subcategory)\n // since default subcategories always exist and always will be inserted after their categories, we treat them as an update\n // to prevent duplicate inserts.\n // Always present elements (0xe, 0x1, 0x10) also will be updated to prevent duplicate inserts.\n if (\n (isSubCategory(elementProps) && isDefaultSubCategory(elementProps)) ||\n this._rootElementIds.has(elementProps.id)\n ) {\n await this.onUpdateElement(elementProps);\n } else {\n if (this._elementsToUpdateDuringPreserveIds.has(elementProps.id)) {\n await this.tryUpdateElement(elementProps);\n this._elementsToUpdateDuringPreserveIds.delete(elementProps.id);\n } else {\n await this.onInsertElement(elementProps);\n }\n }\n } else {\n if (undefined !== elementProps.id) {\n await this.tryUpdateElement(elementProps);\n } else {\n elementProps.id = await this.onInsertElement(elementProps); // targetElementProps.id assigned by insertElement\n }\n }\n return elementProps.id;\n }\n\n /** Create a new Element from the specified ElementProps and insert it into the target iModel.\n * @returns The Id of the newly inserted Element.\n * @note A subclass may override this method to customize insert behavior but should call `super.onInsertElement`.\n */\n protected async onInsertElement(\n elementProps: ElementProps\n ): Promise<Id64String> {\n try {\n const elementId = this.targetDb.elements.insertElement(elementProps, {\n forceUseId: this.options.preserveElementIdsForFiltering,\n });\n // set the id like [IModelDb.insertElement]($backend), does, the raw nativeDb method does not\n elementProps.id = elementId;\n Logger.logInfo(\n loggerCategory,\n `Inserted ${this.formatElementForLogger(elementProps)}`\n );\n await this.trackProgress();\n if (this.options.simplifyElementGeometry) {\n this.targetDb.simplifyElementGeometry({\n id: elementId,\n convertBReps: true,\n });\n Logger.logInfo(\n loggerCategory,\n `Simplified element geometry for ${this.formatElementForLogger(\n elementProps\n )}`\n );\n }\n return elementId;\n } catch (error) {\n if (!this.targetDb.containsClass(elementProps.classFullName)) {\n // replace standard insert error with something more helpful\n const errorMessage = `Element class \"${elementProps.classFullName}\" not found in the target iModel. Was the latest version of the schema imported?`;\n throw new IModelError(IModelStatus.InvalidName, errorMessage);\n }\n throw error; // throw original error\n }\n }\n\n /** Update an existing Element in the target iModel from the specified ElementProps.\n * @note A subclass may override this method to customize update behavior but should call `super.onUpdateElement`.\n */\n protected async onUpdateElement(elementProps: ElementProps): Promise<void> {\n if (!elementProps.id) {\n throw new IModelError(IModelStatus.InvalidId, \"ElementId not provided\");\n }\n this.targetDb.elements.updateElement(elementProps);\n Logger.logInfo(\n loggerCategory,\n `Updated ${this.formatElementForLogger(elementProps)}`\n );\n await this.trackProgress();\n if (this.options.simplifyElementGeometry) {\n this.targetDb.simplifyElementGeometry({\n id: elementProps.id,\n convertBReps: true,\n });\n Logger.logInfo(\n loggerCategory,\n `Simplified element geometry for ${this.formatElementForLogger(\n elementProps\n )}`\n );\n }\n }\n\n /** Delete the specified Element (and all its children) from the target iModel.\n * Will delete special elements like definition elements and subjects.\n * @note A subclass may override this method to customize delete behavior but should call `super.onDeleteElement`.\n */\n protected async onDeleteElement(elementId: Id64String): Promise<void> {\n deleteElementTreeCascade(this.targetDb, elementId);\n Logger.logInfo(\n loggerCategory,\n `Deleted element ${elementId} and its descendants`\n );\n await this.trackProgress();\n }\n\n /** Delete the specified Element from the target iModel. */\n public async deleteElement(elementId: Id64String): Promise<void> {\n if (this.doNotUpdateElement(elementId)) {\n Logger.logInfo(\n loggerCategory,\n `Do not delete target element ${elementId}`\n );\n return;\n }\n await this.onDeleteElement(elementId);\n }\n\n /** Delete the specified Model from the target iModel.\n * @note A subclass may override this method to customize delete behavior but should call `super.onDeleteModel`.\n */\n protected async onDeleteModel(modelId: Id64String): Promise<void> {\n this.targetDb.models.deleteModel(modelId);\n Logger.logInfo(loggerCategory, `Deleted model ${modelId}`);\n await this.trackProgress();\n }\n\n /** Delete the specified Model from the target iModel. */\n public async deleteModel(modelId: Id64String): Promise<void> {\n await this.onDeleteModel(modelId);\n }\n\n /** Format an Element for the Logger. */\n private formatElementForLogger(elementProps: ElementProps): string {\n const namePiece: string = elementProps.code.value\n ? `${elementProps.code.value} `\n : elementProps.userLabel\n ? `${elementProps.userLabel} `\n : \"\";\n return `${elementProps.classFullName} ${namePiece}[${elementProps.id}]`;\n }\n\n /** Import an ElementUniqueAspect into the target iModel. */\n public async importElementUniqueAspect(\n aspectProps: ElementAspectProps\n ): Promise<Id64String> {\n const aspects: ElementAspect[] = this.targetDb.elements.getAspects(\n aspectProps.element.id,\n aspectProps.classFullName\n );\n if (aspects.length === 0) {\n return this.onInsertElementAspect(aspectProps);\n } else if (hasEntityChanged(aspects[0], aspectProps)) {\n aspectProps.id = aspects[0].id;\n await this.onUpdateElementAspect(aspectProps);\n }\n return aspects[0].id;\n }\n\n /** Import the collection of ElementMultiAspects into the target iModel.\n * @param aspectPropsArray The ElementMultiAspects to import\n * @param filterFunc Optional filter func that is used to exclude target ElementMultiAspects that were added during iModel transformation from the update detection logic.\n * @note For insert vs. update reasons, it is important to process all ElementMultiAspects owned by an Element at once since we don't have aspect-specific provenance.\n * @returns the array of ids of the resulting ElementMultiAspects, in the same order of the aspectPropsArray parameter\n */\n public async importElementMultiAspects(\n aspectPropsArray: ElementAspectProps[],\n /** caller must use this to enforce any aspects added by IModelTransformer are not considered for update */\n filterFunc: (a: ElementMultiAspect) => boolean = () => true\n ): Promise<Id64String[]> {\n const result = new Array<Id64String | undefined>(\n aspectPropsArray.length\n ).fill(undefined);\n\n if (aspectPropsArray.length === 0) {\n return result as Id64String[];\n }\n\n const elementId: Id64String = aspectPropsArray[0].element.id;\n // Determine the set of ElementMultiAspect classes to consider\n const aspectClassFullNames = new Set<string>();\n aspectPropsArray.forEach((aspectsProps: ElementAspectProps): void => {\n aspectClassFullNames.add(aspectsProps.classFullName);\n });\n\n // Handle ElementMultiAspects in groups by class\n for (const aspectClassFullName of aspectClassFullNames) {\n const proposedAspects = aspectPropsArray\n .map((props, index) => ({ props, index }))\n .filter(({ props }) => aspectClassFullName === props.classFullName);\n\n const currentAspects = this.targetDb.elements\n .getAspects(elementId, aspectClassFullName)\n .map((props, index) => ({ props, index }) as const)\n .filter(({ props }) => filterFunc(props));\n\n if (proposedAspects.length >= currentAspects.length) {\n for (let index = 0; index < proposedAspects.length; index++) {\n const { props, index: resultIndex } = proposedAspects[index];\n let id: Id64String;\n if (index < currentAspects.length) {\n id = currentAspects[index].props.id;\n props.id = id;\n if (hasEntityChanged(currentAspects[index].props, props)) {\n await this.onUpdateElementAspect(props);\n }\n id = props.id;\n } else {\n id = await this.onInsertElementAspect(props);\n }\n result[resultIndex] = id;\n }\n } else {\n for (let index = 0; index < currentAspects.length; index++) {\n const { props, index: resultIndex } = currentAspects[index];\n let id: Id64String;\n if (index < proposedAspects.length) {\n id = props.id;\n proposedAspects[index].props.id = id;\n if (hasEntityChanged(props, proposedAspects[index].props)) {\n await this.onUpdateElementAspect(proposedAspects[index].props);\n }\n result[resultIndex] = id;\n } else {\n await this.onDeleteElementAspect(props);\n }\n }\n }\n }\n\n assert(result.every((r) => typeof r !== undefined));\n return result as Id64String[];\n }\n\n /** Insert the ElementAspect into the target iModel.\n * @note A subclass may override this method to customize insert behavior but should call `super.onInsertElementAspect`.\n */\n protected async onInsertElementAspect(\n aspectProps: ElementAspectProps\n ): Promise<Id64String> {\n try {\n const id = this.targetDb.elements.insertAspect(aspectProps);\n Logger.logInfo(\n loggerCategory,\n `Inserted ${this.formatElementAspectForLogger(aspectProps)}`\n );\n await this.trackProgress();\n return id;\n } catch (error) {\n if (!this.targetDb.containsClass(aspectProps.classFullName)) {\n // replace standard insert error with something more helpful\n const errorMessage = `ElementAspect class \"${aspectProps.classFullName}\" not found in the target iModel. Was the latest version of the schema imported?`;\n throw new IModelError(IModelStatus.InvalidName, errorMessage);\n }\n throw error; // throw original error\n }\n }\n\n /** Update the ElementAspect within the target iModel.\n * @note A subclass may override this method to customize update behavior but should call `super.onUpdateElementAspect`.\n */\n protected async onUpdateElementAspect(\n aspectProps: ElementAspectProps\n ): Promise<void> {\n this.targetDb.elements.updateAspect(aspectProps);\n Logger.logInfo(\n loggerCategory,\n `Updated ${this.formatElementAspectForLogger(aspectProps)}`\n );\n await this.trackProgress();\n }\n\n /** Delete the specified ElementAspect from the target iModel.\n * @note A subclass may override this method to customize delete behavior but should call `super.onDeleteElementAspect`.\n */\n protected async onDeleteElementAspect(\n targetElementAspect: ElementAspect\n ): Promise<void> {\n this.targetDb.elements.deleteAspect(targetElementAspect.id);\n Logger.logInfo(\n loggerCategory,\n `Deleted ${this.formatElementAspectForLogger(targetElementAspect)}`\n );\n await this.trackProgress();\n }\n\n /** Format an ElementAspect for the Logger. */\n private formatElementAspectForLogger(\n elementAspectProps: ElementAspectProps | ElementAspect\n ): string {\n return `${elementAspectProps.classFullName} elementId=[${elementAspectProps.element.id}]`;\n }\n\n /** Import the specified RelationshipProps (either as an insert or an update) into the target iModel.\n * @returns The instance Id of the inserted or updated Relationship.\n */\n public async importRelationship(\n relationshipProps: RelationshipProps\n ): Promise<Id64String> {\n if (\n undefined === relationshipProps.sourceId ||\n !Id64.isValidId64(relationshipProps.sourceId)\n ) {\n Logger.logInfo(\n loggerCategory,\n `Ignoring ${relationshipProps.classFullName} instance because of invalid RelationshipProps.sourceId`\n );\n return Id64.invalid;\n }\n if (\n undefined === relationshipProps.targetId ||\n !Id64.isValidId64(relationshipProps.targetId)\n ) {\n Logger.logInfo(\n loggerCategory,\n `Ignoring ${relationshipProps.classFullName} instance because of invalid RelationshipProps.targetId`\n );\n return Id64.invalid;\n }\n // check for an existing relationship\n const relSourceAndTarget: SourceAndTarget = {\n sourceId: relationshipProps.sourceId,\n targetId: relationshipProps.targetId,\n };\n const relationship: Relationship | undefined =\n this.targetDb.relationships.tryGetInstance(\n relationshipProps.classFullName,\n relSourceAndTarget\n );\n if (undefined !== relationship) {\n // if relationship found, update it\n relationshipProps.id = relationship.id;\n if (hasEntityChanged(relationship, relationshipProps)) {\n await this.onUpdateRelationship(relationshipProps);\n }\n return relationshipProps.id;\n } else {\n return this.onInsertRelationship(relationshipProps);\n }\n }\n\n /** Create a new Relationship from the specified RelationshipProps and insert it into the target iModel.\n * @returns The instance Id of the newly inserted relationship.\n * @note A subclass may override this method to customize insert behavior but should call `super.onInsertRelationship`.\n */\n protected async onInsertRelationship(\n relationshipProps: RelationshipProps\n ): Promise<Id64String> {\n try {\n const targetRelInstanceId: Id64String =\n this.targetDb.relationships.insertInstance(relationshipProps);\n Logger.logInfo(\n loggerCategory,\n `Inserted ${this.formatRelationshipForLogger(relationshipProps)}`\n );\n await this.trackProgress();\n return targetRelInstanceId;\n } catch (error) {\n if (!this.targetDb.containsClass(relationshipProps.classFullName)) {\n // replace standard insert error with something more helpful\n const errorMessage = `Relationship class \"${relationshipProps.classFullName}\" not found in the target iModel. Was the latest version of the schema imported?`;\n throw new IModelError(IModelStatus.InvalidName, errorMessage);\n }\n throw error; // throw original error\n }\n }\n\n /** Update an existing Relationship in the target iModel from the specified RelationshipProps.\n * @note A subclass may override this method to customize update behavior but should call `super.onUpdateRelationship`.\n */\n protected async onUpdateRelationship(\n relationshipProps: RelationshipProps\n ): Promise<void> {\n if (!relationshipProps.id) {\n throw new IModelError(\n IModelStatus.InvalidId,\n \"Relationship instance Id not provided\"\n );\n }\n this.targetDb.relationships.updateInstance(relationshipProps);\n Logger.logInfo(\n loggerCategory,\n `Updated ${this.formatRelationshipForLogger(relationshipProps)}`\n );\n await this.trackProgress();\n }\n\n /** Delete the specified Relationship from the target iModel. */\n protected async onDeleteRelationship(\n relationshipProps: RelationshipPropsForDelete\n ): Promise<void> {\n // Only passing in what deleteInstance actually uses, full relationshipProps is not necessary.\n this.targetDb.relationships.deleteInstance({\n id: relationshipProps.id,\n classFullName: relationshipProps.classFullName,\n } as RelationshipProps);\n Logger.logInfo(\n loggerCategory,\n `Deleted relationship ${relationshipProps.classFullName} id=${relationshipProps.id}`\n );\n await this.trackProgress();\n }\n\n /** Delete the specified Relationship from the target iModel. */\n public async deleteRelationship(\n relationshipProps: RelationshipPropsForDelete\n ): Promise<void> {\n await this.onDeleteRelationship(relationshipProps);\n }\n\n /** Format a Relationship for the Logger. */\n private formatRelationshipForLogger(relProps: RelationshipProps): string {\n return `${relProps.classFullName} sourceId=[${relProps.sourceId}] targetId=[${relProps.targetId}]`;\n }\n\n /** Tracks incremental progress */\n private async trackProgress(): Promise<void> {\n this._progressCounter++;\n if (0 === this._progressCounter % this.progressInterval) {\n await this.onProgress();\n }\n }\n\n /** This method is called when IModelImporter has made incremental progress based on the [[progressInterval]] setting.\n * @note A subclass may override this method to report custom progress but should call `super.onProgress`.\n */\n protected async onProgress(): Promise<void> {}\n\n /** Optionally compute the projectExtents for the target iModel depending on the options for this IModelImporter.\n * @note This method is automatically called from [IModelTransformer.process]($transformer).\n * @see [IModelDb.computeProjectExtents]($backend), [[autoExtendProjectExtents]]\n */\n public computeProjectExtents(): void {\n const computedProjectExtents = this.targetDb.computeProjectExtents({\n reportExtentsWithOutliers: true,\n reportOutliers: true,\n });\n Logger.logInfo(\n loggerCategory,\n `Current projectExtents=${JSON.stringify(this.targetDb.projectExtents)}`\n );\n Logger.logInfo(\n loggerCategory,\n `Computed projectExtents without outliers=${JSON.stringify(\n computedProjectExtents.extents\n )}`\n );\n Logger.logInfo(\n loggerCategory,\n `Computed projectExtents with outliers=${JSON.stringify(\n computedProjectExtents.extentsWithOutliers\n )}`\n );\n if (this.options.autoExtendProjectExtents) {\n const excludeOutliers: boolean =\n typeof this.options.autoExtendProjectExtents === \"object\"\n ? this.options.autoExtendProjectExtents.excludeOutliers\n : false;\n // If excludeOutliers is true, use the extents without outliers.\n // Otherwise prefer extentsWithOutliers, but fall back to extents if it's undefined or a null range.\n const extentsWithOutliers = computedProjectExtents.extentsWithOutliers;\n const useExtentsWithOutliers =\n !excludeOutliers && extentsWithOutliers && !extentsWithOutliers.isNull;\n const newProjectExtents = useExtentsWithOutliers\n ? extentsWithOutliers\n : computedProjectExtents.extents;\n if (!newProjectExtents.isAlmostEqual(this.targetDb.projectExtents)) {\n this.targetDb.updateProjectExtents(newProjectExtents);\n Logger.logInfo(\n loggerCategory,\n `Updated projectExtents=${JSON.stringify(\n this.targetDb.projectExtents\n )}`\n );\n }\n if (\n !excludeOutliers &&\n computedProjectExtents.outliers &&\n computedProjectExtents.outliers.length > 0\n ) {\n Logger.logInfo(\n loggerCategory,\n `${computedProjectExtents.outliers.length} outliers detected within projectExtents`\n );\n }\n } else {\n if (\n !this.targetDb.projectExtents.containsRange(\n computedProjectExtents.extents\n )\n ) {\n Logger.logWarning(\n loggerCategory,\n \"Current project extents may be too small\"\n );\n }\n if (\n computedProjectExtents.outliers &&\n computedProjectExtents.outliers.length > 0\n ) {\n Logger.logInfo(\n loggerCategory,\n `${computedProjectExtents.outliers.length} outliers detected within projectExtents`\n );\n }\n }\n }\n\n /** Examine the geometry streams of every [GeometricElement3d]($backend) in the target iModel and apply the specified optimizations.\n * @note This method is automatically called from [[IModelTransformer.process]] if\n * [[IModelTransformOptions.optimizeGeometry]] is defined.\n */\n public optimizeGeometry(options: OptimizeGeometryOptions): void {\n if (options.inlineUniqueGeometryParts) {\n const result = this.targetDb.inlineGeometryParts();\n Logger.logInfo(\n loggerCategory,\n `Inlined ${result.numRefsInlined} references to ${result.numCandidateParts} geometry parts and deleted ${result.numPartsDeleted} parts.`\n );\n }\n }\n\n private resolveDuplicateCodeValues(): void {\n for (const [elementId, codeValue] of this._duplicateCodeValueMap) {\n const element = this.targetDb.elements.getElement(elementId);\n element.code.value = codeValue;\n element.update();\n }\n this._duplicateCodeValueMap.clear();\n }\n\n /**\n * Needs to be called to perform necessary cleanup operations.\n * By not calling `finalize` there is a risk that data imported into targetDb will not be as expected.\n *\n * @note No need to call this If using [[IModelTransformer]] as it automatically invokes this method.\n */\n public finalize(): void {\n this.resolveDuplicateCodeValues();\n }\n}\n\n/** Returns true if a change within an Entity is detected.\n * @param entity The current persistent Entity.\n * @param entityProps The new EntityProps to compare against\n * @note This method should only be called if changeset information is not available.\n * @internal\n */\nexport function hasEntityChanged(\n entity: Entity,\n entityProps: EntityProps,\n namesToIgnore?: Set<string>\n): boolean {\n let changed: boolean = false;\n entity.forEach((propertyName: string, property: Property) => {\n if (!changed) {\n if (namesToIgnore && namesToIgnore.has(propertyName)) {\n // skip\n } else if (PropertyType.Binary === property.propertyType) {\n changed = hasBinaryValueChanged(\n entity.asAny[ECJsNames.toJsName(propertyName)],\n (entityProps as any)[ECJsNames.toJsName(propertyName)]\n );\n } else if (property.isNavigation()) {\n changed = hasNavigationValueChanged(\n entity.asAny[ECJsNames.toJsName(propertyName)],\n (entityProps as any)[ECJsNames.toJsName(propertyName)]\n );\n } else {\n changed = hasValueChanged(\n entity.asAny[ECJsNames.toJsName(propertyName)],\n (entityProps as any)[ECJsNames.toJsName(propertyName)]\n );\n }\n }\n });\n return changed;\n}\n\n/** Returns true if the specified binary values are different. */\nfunction hasBinaryValueChanged(\n binaryProperty1: any,\n binaryProperty2: any\n): boolean {\n const jsonString1 = JSON.stringify(\n binaryProperty1,\n Base64EncodedString.replacer\n );\n const jsonString2 = JSON.stringify(\n binaryProperty2,\n Base64EncodedString.replacer\n );\n return jsonString1 !== jsonString2;\n}\n\n/** Returns true if the specified navigation property values are different. */\nfunction hasNavigationValueChanged(\n navigationProperty1: any,\n navigationProperty2: any\n): boolean {\n const relatedElement1 = RelatedElement.fromJSON(navigationProperty1);\n const relatedElement2 = RelatedElement.fromJSON(navigationProperty2);\n const jsonString1 = JSON.stringify(relatedElement1);\n const jsonString2 = JSON.stringify(relatedElement2);\n return jsonString1 !== jsonString2;\n}\n\n/** Returns true if the specified navigation property values are different. */\nfunction hasValueChanged(property1: any, property2: any): boolean {\n return JSON.stringify(property1) !== JSON.stringify(property2);\n}\n\n/** check if element props are a subcategory */\nfunction isSubCategory(props: ElementProps): props is SubCategoryProps {\n return props.classFullName === SubCategory.classFullName;\n}\n\n/** check if element props are a subcategory without loading the element */\nfunction isDefaultSubCategory(props: SubCategoryProps): boolean {\n if (props.id === undefined) return false;\n\n if (!Id64.isId64(props.id))\n throw new IModelError(\n IModelStatus.BadElement,\n \"subcategory had invalid id\"\n );\n if (props.parent?.id === undefined)\n throw new IModelError(\n IModelStatus.BadElement,\n `subcategory with id ${props.id} had no parent`\n );\n return props.id === IModelDb.getDefaultSubCategoryId(props.parent.id);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"IModelImporter.js","sourceRoot":"","sources":["../../src/IModelImporter.ts"],"names":[],"mappings":";;;AAg1BA,4CA6BC;AA72BD;;;gGAGgG;AAChG;;GAEG;AACH,sDAM6B;AAC7B,oDAW4B;AAC5B,2EAAwE;AACxE,sDAS6B;AAE7B,iCAAiC;AACjC,uEAAqE;AACrE,gEAAkE;AAElE,MAAM,cAAc,GAAW,qDAAyB,CAAC,cAAc,CAAC;AAoCxE;;;;;GAKG;AACH,MAAa,cAAc;IACzB,oCAAoC;IACpB,QAAQ,CAAW;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I,CAAC,mBAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,yBAAW,CACnB,2BAAY,CAAC,UAAU,EACvB,4BAA4B,CAC7B,CAAC;IACJ,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE,KAAK,SAAS;QAChC,MAAM,IAAI,yBAAW,CACnB,2BAAY,CAAC,UAAU,EACvB,uBAAuB,KAAK,CAAC,EAAE,gBAAgB,CAChD,CAAC;IACJ,OAAO,KAAK,CAAC,EAAE,KAAK,uBAAQ,CAAC,uBAAuB,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACxE,CAAC","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 {\n Guid,\n Id64,\n Id64String,\n IModelStatus,\n Logger,\n} from \"@itwin/core-bentley\";\nimport {\n Base64EncodedString,\n ECJsNames,\n ElementAspectProps,\n ElementProps,\n EntityProps,\n IModel,\n IModelError,\n ModelProps,\n RelatedElement,\n SubCategoryProps,\n} from \"@itwin/core-common\";\nimport { TransformerLoggerCategory } from \"./TransformerLoggerCategory\";\nimport {\n ElementAspect,\n ElementMultiAspect,\n Entity,\n IModelDb,\n Relationship,\n RelationshipProps,\n SourceAndTarget,\n SubCategory,\n} from \"@itwin/core-backend\";\nimport type { RelationshipPropsForDelete } from \"./IModelTransformer\";\nimport * as assert from \"assert\";\nimport { deleteElementTreeCascade } from \"./ElementCascadingDeleter\";\nimport { Property, PropertyType } from \"@itwin/ecschema-metadata\";\n\nconst loggerCategory: string = TransformerLoggerCategory.IModelImporter;\n\n/** Options provided to [[IModelImporter.optimizeGeometry]] specifying post-processing optimizations to be applied to the iModel's geometry.\n * @beta\n */\nexport interface OptimizeGeometryOptions {\n /** If true, identify any [GeometryPart]($backend)s that are referenced exactly once. For each such part,\n * replace the reference in the element's geometry stream with the part's own geometry stream, then delete the part.\n */\n inlineUniqueGeometryParts?: boolean;\n}\n\n/** Options provided to the [[IModelImporter]] constructor.\n * @beta\n */\nexport interface IModelImportOptions {\n /** If `true` (the default), compute the projectExtents of the target iModel after elements are imported.\n * The computed projectExtents will either include or exclude *outliers* depending on the `excludeOutliers` flag that defaults to `false`.\n * @see [[IModelImporter.autoExtendProjectExtents]]\n * @see [IModelImporter Options]($docs/learning/transformer/index.md#IModelImporter)\n */\n autoExtendProjectExtents?: boolean | { excludeOutliers: boolean };\n /** See [IModelTransformOptions]($transformer) */\n preserveElementIdsForFiltering?: boolean;\n /** If `true`, simplify the element geometry for visualization purposes. For example, convert b-reps into meshes.\n * @default false\n */\n simplifyElementGeometry?: boolean;\n /**\n * Skip propagating changes made to the root subject, dictionaryModel and IModelImporter._realityDataSourceLinkPartitionStaticId (0xe)\n * If it is set to false, changes to root elements are propagated, the root subject name gets changed and leads to the iModelDb.name property being updated in .initializeiModelDb\n * @default true\n */\n skipPropagateChangesToRootElements?: boolean;\n}\n\n/** Base class for importing data into an iModel.\n * @see [iModel Transformation and Data Exchange]($docs/learning/transformer/index.md)\n * @see [IModelExporter]($transformer)\n * @see [IModelTransformer]($transformer)\n * @beta\n */\nexport class IModelImporter {\n /** The read/write target iModel. */\n public readonly targetDb: IModelDb;\n\n /** resolved initialization options for the importer\n * @beta\n */\n public readonly options: Required<IModelImportOptions>;\n\n private static _realityDataSourceLinkPartitionStaticId: Id64String = \"0xe\";\n\n /**\n * A map of conflicting element code values.\n * In cases where updating an element's code value results in a codeValue conflict, the element's code value will instead be updated to a random guid.\n * The actual codeValue will be stored in this ElementId->CodeValue map.\n * This is needed in cases where the duplicate target element is set to be deleted in the future, or when elements are switching code values with one another and we need a temporary code value.\n * To resolve code values to their intended values call [[IModelImporter.resolveDuplicateCodeValues]].\n */\n private _duplicateCodeValueMap: Map<Id64String, string>;\n\n /**\n * A set of elementIds that the transformer adds to while exporting elements to indicate that the element already exists in the target.\n * Defaults to an empty set.\n * @note\n *\n * This is used as an optimization when `[[IModelTransformOptions.preserveElementIdsForFiltering]]` is set to `true`\n * In normal cases where this option set to `false`,\n * the importer determines whether to insert or update based off of whether the ID is defined on the `elementProps` passed to `importElement`.\n * However, with `preserveElementIdsForFiltering` set to `true`, IDs are always set, so we can't determine insert/update like the normal case.\n * The transformer already knows if an element exists or not by the time `importElement` is called and pushes to this set with `markElementToUpdateForPreserveId`.\n * @note This set should stay small, as right after the transformer pushes to it, the importer will remove from the set.\n */\n private _elementsToUpdateDuringPreserveIds = new Set<Id64String>([]);\n\n /** The set of elements that should not be updated by this IModelImporter.\n * Defaults to an empty set.\n * @note Adding an element to this set is typically necessary when remapping a source element to one that already exists in the target and already has the desired properties.\n */\n public readonly doNotUpdateElementIds = new Set<Id64String>([]);\n\n /** This set is ONLY used for elements that are always present even in an \"empty\" iModel. We will use this set to filter out changes to root elements if [[IModelTransformOptions.skipPropagateChangesToRootElements]] is false. */\n private readonly _rootElementIds = new Set<Id64String>([\n IModel.rootSubjectId,\n IModel.dictionaryId,\n IModelImporter._realityDataSourceLinkPartitionStaticId,\n ]);\n\n /** The number of entity changes before incremental progress should be reported via the [[onProgress]] callback. */\n public progressInterval: number = 1000;\n /** Tracks the current total number of entity changes. */\n private _progressCounter: number = 0;\n /** */\n private _modelPropertiesToIgnore = new Set<string>([\n \"geometryGuid\", // cannot compare GeometricModel.GeometryGuid values across iModels\n ]);\n\n /** Construct a new IModelImporter\n * @param targetDb The target IModelDb\n * @param options The options that specify how the import should be done.\n */\n public constructor(targetDb: IModelDb, options?: IModelImportOptions) {\n this.targetDb = targetDb;\n this.options = {\n autoExtendProjectExtents: options?.autoExtendProjectExtents ?? true,\n preserveElementIdsForFiltering:\n options?.preserveElementIdsForFiltering ?? false,\n simplifyElementGeometry: options?.simplifyElementGeometry ?? false,\n skipPropagateChangesToRootElements:\n options?.skipPropagateChangesToRootElements ?? true,\n };\n this._duplicateCodeValueMap = new Map<Id64String, string>();\n }\n\n /**\n * Checks [[IModelImportOptions.skipPropagateChangesToRootElements]], [[IModelImporter.rootElementIds]], and [[IModelImporter.doNotUpdateElementIds]] and returns true for 'do not update', false for do 'update'.\n */\n private doNotUpdateElement(elementId: Id64String): boolean {\n if (\n this.options.skipPropagateChangesToRootElements &&\n this._rootElementIds.has(elementId)\n )\n return true;\n if (this.doNotUpdateElementIds.has(elementId)) return true;\n return false;\n }\n\n /**\n * Marks an element so that it can be updated during import when [[IModelTransformOptions.preserveElementIdsForFiltering]] is set to true.\n */\n public markElementToUpdateDuringPreserveIds(elementId: Id64String) {\n if (this._rootElementIds.has(elementId)) {\n return;\n }\n this._elementsToUpdateDuringPreserveIds.add(elementId);\n }\n\n /** Import the specified ModelProps (either as an insert or an update) into the target iModel. */\n public async importModel(modelProps: ModelProps): Promise<void> {\n if (undefined === modelProps.id || !Id64.isValidId64(modelProps.id))\n throw new IModelError(\n IModelStatus.InvalidId,\n \"Model Id not provided, should be the same as the ModeledElementId\"\n );\n\n if (this.doNotUpdateElement(modelProps.id)) {\n Logger.logInfo(\n loggerCategory,\n `Do not update target model ${modelProps.id}`\n );\n return;\n }\n try {\n const model = this.targetDb.models.getModel(modelProps.id); // throws IModelError.NotFound if model does not exist\n if (hasEntityChanged(model, modelProps, this._modelPropertiesToIgnore)) {\n await this.onUpdateModel(modelProps);\n }\n } catch (error) {\n // catch NotFound error and insertModel\n if (\n error instanceof IModelError &&\n error.errorNumber === IModelStatus.NotFound\n ) {\n await this.onInsertModel(modelProps);\n return;\n }\n throw error;\n }\n }\n\n /** Create a new Model from the specified ModelProps and insert it into the target iModel.\n * @note A subclass may override this method to customize insert behavior but should call `super.onInsertModel`.\n */\n protected async onInsertModel(modelProps: ModelProps): Promise<Id64String> {\n try {\n const modelId: Id64String = this.targetDb.models.insertModel(modelProps);\n Logger.logInfo(\n loggerCategory,\n `Inserted ${this.formatModelForLogger(modelProps)}`\n );\n await this.trackProgress();\n return modelId;\n } catch (error) {\n if (!this.targetDb.containsClass(modelProps.classFullName)) {\n // replace standard insert error with something more helpful\n const errorMessage = `Model class \"${modelProps.classFullName}\" not found in the target iModel. Was the latest version of the schema imported?`;\n throw new IModelError(IModelStatus.InvalidName, errorMessage);\n }\n throw error; // throw original error\n }\n }\n\n /** Update an existing Model in the target iModel from the specified ModelProps.\n * @note A subclass may override this method to customize update behavior but should call `super.onUpdateModel`.\n */\n protected async onUpdateModel(modelProps: ModelProps): Promise<void> {\n this.targetDb.models.updateModel(modelProps);\n Logger.logInfo(\n loggerCategory,\n `Updated ${this.formatModelForLogger(modelProps)}`\n );\n await this.trackProgress();\n }\n\n /** Format a Model for the Logger. */\n private formatModelForLogger(modelProps: ModelProps): string {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return `${modelProps.classFullName} [${modelProps.id!}]`;\n }\n\n /**\n * Tries to update an element with the specified element properties.\n * If a duplicate code error occurs, it assigns a new unique code value and retries the update\n */\n private async tryUpdateElement(elemProps: ElementProps) {\n try {\n await this.onUpdateElement(elemProps);\n } catch (err) {\n if ((err as IModelError).errorNumber === IModelStatus.DuplicateCode) {\n assert(\n elemProps.code.value !== undefined,\n \"NULL code values are always considered unique and cannot clash\"\n );\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._duplicateCodeValueMap.set(elemProps.id!, elemProps.code.value);\n // Using NULL code values as an alternative is not valid because definition elements cannot have NULL code values.\n elemProps.code.value = Guid.createValue();\n await this.onUpdateElement(elemProps);\n } else {\n throw err;\n }\n }\n }\n\n /** Import the specified ElementProps (either as an insert or an update) into the target iModel. */\n public async importElement(elementProps: ElementProps): Promise<Id64String> {\n if (\n undefined !== elementProps.id &&\n this.doNotUpdateElement(elementProps.id)\n ) {\n Logger.logInfo(\n loggerCategory,\n `Do not update target element ${elementProps.id}`\n );\n return elementProps.id;\n }\n\n if (this.options.preserveElementIdsForFiltering) {\n if (elementProps.id === undefined) {\n throw new IModelError(\n IModelStatus.BadElement,\n \"elementProps.id must be defined during a preserveIds operation\"\n );\n }\n\n // Categories are the only element that onInserted will immediately insert a new element (their default subcategory)\n // since default subcategories always exist and always will be inserted after their categories, we treat them as an update\n // to prevent duplicate inserts.\n // Always present elements (0xe, 0x1, 0x10) also will be updated to prevent duplicate inserts.\n if (\n (isSubCategory(elementProps) && isDefaultSubCategory(elementProps)) ||\n this._rootElementIds.has(elementProps.id)\n ) {\n await this.onUpdateElement(elementProps);\n } else {\n if (this._elementsToUpdateDuringPreserveIds.has(elementProps.id)) {\n await this.tryUpdateElement(elementProps);\n this._elementsToUpdateDuringPreserveIds.delete(elementProps.id);\n } else {\n await this.onInsertElement(elementProps);\n }\n }\n } else {\n if (undefined !== elementProps.id) {\n await this.tryUpdateElement(elementProps);\n } else {\n elementProps.id = await this.onInsertElement(elementProps); // targetElementProps.id assigned by insertElement\n }\n }\n return elementProps.id;\n }\n\n /** Create a new Element from the specified ElementProps and insert it into the target iModel.\n * @returns The Id of the newly inserted Element.\n * @note A subclass may override this method to customize insert behavior but should call `super.onInsertElement`.\n */\n protected async onInsertElement(\n elementProps: ElementProps\n ): Promise<Id64String> {\n try {\n const elementId = this.targetDb.elements.insertElement(elementProps, {\n forceUseId: this.options.preserveElementIdsForFiltering,\n });\n // set the id like [IModelDb.insertElement]($backend), does, the raw nativeDb method does not\n elementProps.id = elementId;\n Logger.logInfo(\n loggerCategory,\n `Inserted ${this.formatElementForLogger(elementProps)}`\n );\n await this.trackProgress();\n if (this.options.simplifyElementGeometry) {\n this.targetDb.simplifyElementGeometry({\n id: elementId,\n convertBReps: true,\n });\n Logger.logInfo(\n loggerCategory,\n `Simplified element geometry for ${this.formatElementForLogger(\n elementProps\n )}`\n );\n }\n return elementId;\n } catch (error) {\n if (!this.targetDb.containsClass(elementProps.classFullName)) {\n // replace standard insert error with something more helpful\n const errorMessage = `Element class \"${elementProps.classFullName}\" not found in the target iModel. Was the latest version of the schema imported?`;\n throw new IModelError(IModelStatus.InvalidName, errorMessage);\n }\n throw error; // throw original error\n }\n }\n\n /** Update an existing Element in the target iModel from the specified ElementProps.\n * @note A subclass may override this method to customize update behavior but should call `super.onUpdateElement`.\n */\n protected async onUpdateElement(elementProps: ElementProps): Promise<void> {\n if (!elementProps.id) {\n throw new IModelError(IModelStatus.InvalidId, \"ElementId not provided\");\n }\n this.targetDb.elements.updateElement(elementProps);\n Logger.logInfo(\n loggerCategory,\n `Updated ${this.formatElementForLogger(elementProps)}`\n );\n await this.trackProgress();\n if (this.options.simplifyElementGeometry) {\n this.targetDb.simplifyElementGeometry({\n id: elementProps.id,\n convertBReps: true,\n });\n Logger.logInfo(\n loggerCategory,\n `Simplified element geometry for ${this.formatElementForLogger(\n elementProps\n )}`\n );\n }\n }\n\n /** Delete the specified Element (and all its children) from the target iModel.\n * Will delete special elements like definition elements and subjects.\n * @note A subclass may override this method to customize delete behavior but should call `super.onDeleteElement`.\n */\n protected async onDeleteElement(elementId: Id64String): Promise<void> {\n deleteElementTreeCascade(this.targetDb, elementId);\n Logger.logInfo(\n loggerCategory,\n `Deleted element ${elementId} and its descendants`\n );\n await this.trackProgress();\n }\n\n /** Delete the specified Element from the target iModel. */\n public async deleteElement(elementId: Id64String): Promise<void> {\n if (this.doNotUpdateElement(elementId)) {\n Logger.logInfo(\n loggerCategory,\n `Do not delete target element ${elementId}`\n );\n return;\n }\n await this.onDeleteElement(elementId);\n }\n\n /** Delete the specified Model from the target iModel.\n * @note A subclass may override this method to customize delete behavior but should call `super.onDeleteModel`.\n */\n protected async onDeleteModel(modelId: Id64String): Promise<void> {\n this.targetDb.models.deleteModel(modelId);\n Logger.logInfo(loggerCategory, `Deleted model ${modelId}`);\n await this.trackProgress();\n }\n\n /** Delete the specified Model from the target iModel. */\n public async deleteModel(modelId: Id64String): Promise<void> {\n await this.onDeleteModel(modelId);\n }\n\n /** Format an Element for the Logger. */\n private formatElementForLogger(elementProps: ElementProps): string {\n const namePiece: string = elementProps.code.value\n ? `${elementProps.code.value} `\n : elementProps.userLabel\n ? `${elementProps.userLabel} `\n : \"\";\n return `${elementProps.classFullName} ${namePiece}[${elementProps.id}]`;\n }\n\n /** Import an ElementUniqueAspect into the target iModel. */\n public async importElementUniqueAspect(\n aspectProps: ElementAspectProps\n ): Promise<Id64String> {\n const aspects: ElementAspect[] = this.targetDb.elements.getAspects(\n aspectProps.element.id,\n aspectProps.classFullName\n );\n if (aspects.length === 0) {\n return this.onInsertElementAspect(aspectProps);\n } else if (hasEntityChanged(aspects[0], aspectProps)) {\n aspectProps.id = aspects[0].id;\n await this.onUpdateElementAspect(aspectProps);\n }\n return aspects[0].id;\n }\n\n /** Import the collection of ElementMultiAspects into the target iModel.\n * @param aspectPropsArray The ElementMultiAspects to import\n * @param filterFunc Optional filter func that is used to exclude target ElementMultiAspects that were added during iModel transformation from the update detection logic.\n * @note For insert vs. update reasons, it is important to process all ElementMultiAspects owned by an Element at once since we don't have aspect-specific provenance.\n * @returns the array of ids of the resulting ElementMultiAspects, in the same order of the aspectPropsArray parameter\n */\n public async importElementMultiAspects(\n aspectPropsArray: ElementAspectProps[],\n /** caller must use this to enforce any aspects added by IModelTransformer are not considered for update */\n filterFunc: (a: ElementMultiAspect) => boolean = () => true\n ): Promise<Id64String[]> {\n const result = new Array<Id64String | undefined>(\n aspectPropsArray.length\n ).fill(undefined);\n\n if (aspectPropsArray.length === 0) {\n return result as Id64String[];\n }\n\n const elementId: Id64String = aspectPropsArray[0].element.id;\n // Determine the set of ElementMultiAspect classes to consider\n const aspectClassFullNames = new Set<string>();\n aspectPropsArray.forEach((aspectsProps: ElementAspectProps): void => {\n aspectClassFullNames.add(aspectsProps.classFullName);\n });\n\n // Handle ElementMultiAspects in groups by class\n for (const aspectClassFullName of aspectClassFullNames) {\n const proposedAspects = aspectPropsArray\n .map((props, index) => ({ props, index }))\n .filter(({ props }) => aspectClassFullName === props.classFullName);\n\n const currentAspects = this.targetDb.elements\n .getAspects(elementId, aspectClassFullName)\n .map((props, index) => ({ props, index }) as const)\n .filter(({ props }) => filterFunc(props));\n\n if (proposedAspects.length >= currentAspects.length) {\n for (let index = 0; index < proposedAspects.length; index++) {\n const { props, index: resultIndex } = proposedAspects[index];\n let id: Id64String;\n if (index < currentAspects.length) {\n id = currentAspects[index].props.id;\n props.id = id;\n if (hasEntityChanged(currentAspects[index].props, props)) {\n await this.onUpdateElementAspect(props);\n }\n id = props.id;\n } else {\n id = await this.onInsertElementAspect(props);\n }\n result[resultIndex] = id;\n }\n } else {\n for (let index = 0; index < currentAspects.length; index++) {\n const { props, index: resultIndex } = currentAspects[index];\n let id: Id64String;\n if (index < proposedAspects.length) {\n id = props.id;\n proposedAspects[index].props.id = id;\n if (hasEntityChanged(props, proposedAspects[index].props)) {\n await this.onUpdateElementAspect(proposedAspects[index].props);\n }\n result[resultIndex] = id;\n } else {\n await this.onDeleteElementAspect(props);\n }\n }\n }\n }\n\n assert(result.every((r) => typeof r !== undefined));\n return result as Id64String[];\n }\n\n /** Insert the ElementAspect into the target iModel.\n * @note A subclass may override this method to customize insert behavior but should call `super.onInsertElementAspect`.\n */\n protected async onInsertElementAspect(\n aspectProps: ElementAspectProps\n ): Promise<Id64String> {\n try {\n const id = this.targetDb.elements.insertAspect(aspectProps);\n Logger.logInfo(\n loggerCategory,\n `Inserted ${this.formatElementAspectForLogger(aspectProps)}`\n );\n await this.trackProgress();\n return id;\n } catch (error) {\n if (!this.targetDb.containsClass(aspectProps.classFullName)) {\n // replace standard insert error with something more helpful\n const errorMessage = `ElementAspect class \"${aspectProps.classFullName}\" not found in the target iModel. Was the latest version of the schema imported?`;\n throw new IModelError(IModelStatus.InvalidName, errorMessage);\n }\n throw error; // throw original error\n }\n }\n\n /** Update the ElementAspect within the target iModel.\n * @note A subclass may override this method to customize update behavior but should call `super.onUpdateElementAspect`.\n */\n protected async onUpdateElementAspect(\n aspectProps: ElementAspectProps\n ): Promise<void> {\n this.targetDb.elements.updateAspect(aspectProps);\n Logger.logInfo(\n loggerCategory,\n `Updated ${this.formatElementAspectForLogger(aspectProps)}`\n );\n await this.trackProgress();\n }\n\n /** Delete the specified ElementAspect from the target iModel.\n * @note A subclass may override this method to customize delete behavior but should call `super.onDeleteElementAspect`.\n */\n protected async onDeleteElementAspect(\n targetElementAspect: ElementAspect\n ): Promise<void> {\n this.targetDb.elements.deleteAspect(targetElementAspect.id);\n Logger.logInfo(\n loggerCategory,\n `Deleted ${this.formatElementAspectForLogger(targetElementAspect)}`\n );\n await this.trackProgress();\n }\n\n /** Format an ElementAspect for the Logger. */\n private formatElementAspectForLogger(\n elementAspectProps: ElementAspectProps | ElementAspect\n ): string {\n return `${elementAspectProps.classFullName} elementId=[${elementAspectProps.element.id}]`;\n }\n\n /** Import the specified RelationshipProps (either as an insert or an update) into the target iModel.\n * @returns The instance Id of the inserted or updated Relationship.\n */\n public async importRelationship(\n relationshipProps: RelationshipProps\n ): Promise<Id64String> {\n if (\n undefined === relationshipProps.sourceId ||\n !Id64.isValidId64(relationshipProps.sourceId)\n ) {\n Logger.logInfo(\n loggerCategory,\n `Ignoring ${relationshipProps.classFullName} instance because of invalid RelationshipProps.sourceId`\n );\n return Id64.invalid;\n }\n if (\n undefined === relationshipProps.targetId ||\n !Id64.isValidId64(relationshipProps.targetId)\n ) {\n Logger.logInfo(\n loggerCategory,\n `Ignoring ${relationshipProps.classFullName} instance because of invalid RelationshipProps.targetId`\n );\n return Id64.invalid;\n }\n // check for an existing relationship\n const relSourceAndTarget: SourceAndTarget = {\n sourceId: relationshipProps.sourceId,\n targetId: relationshipProps.targetId,\n };\n const relationship: Relationship | undefined =\n this.targetDb.relationships.tryGetInstance(\n relationshipProps.classFullName,\n relSourceAndTarget\n );\n if (undefined !== relationship) {\n // if relationship found, update it\n relationshipProps.id = relationship.id;\n if (hasEntityChanged(relationship, relationshipProps)) {\n await this.onUpdateRelationship(relationshipProps);\n }\n return relationshipProps.id;\n } else {\n return this.onInsertRelationship(relationshipProps);\n }\n }\n\n /** Create a new Relationship from the specified RelationshipProps and insert it into the target iModel.\n * @returns The instance Id of the newly inserted relationship.\n * @note A subclass may override this method to customize insert behavior but should call `super.onInsertRelationship`.\n */\n protected async onInsertRelationship(\n relationshipProps: RelationshipProps\n ): Promise<Id64String> {\n try {\n const targetRelInstanceId: Id64String =\n this.targetDb.relationships.insertInstance(relationshipProps);\n Logger.logInfo(\n loggerCategory,\n `Inserted ${this.formatRelationshipForLogger(relationshipProps)}`\n );\n await this.trackProgress();\n return targetRelInstanceId;\n } catch (error) {\n if (!this.targetDb.containsClass(relationshipProps.classFullName)) {\n // replace standard insert error with something more helpful\n const errorMessage = `Relationship class \"${relationshipProps.classFullName}\" not found in the target iModel. Was the latest version of the schema imported?`;\n throw new IModelError(IModelStatus.InvalidName, errorMessage);\n }\n throw error; // throw original error\n }\n }\n\n /** Update an existing Relationship in the target iModel from the specified RelationshipProps.\n * @note A subclass may override this method to customize update behavior but should call `super.onUpdateRelationship`.\n */\n protected async onUpdateRelationship(\n relationshipProps: RelationshipProps\n ): Promise<void> {\n if (!relationshipProps.id) {\n throw new IModelError(\n IModelStatus.InvalidId,\n \"Relationship instance Id not provided\"\n );\n }\n this.targetDb.relationships.updateInstance(relationshipProps);\n Logger.logInfo(\n loggerCategory,\n `Updated ${this.formatRelationshipForLogger(relationshipProps)}`\n );\n await this.trackProgress();\n }\n\n /** Delete the specified Relationship from the target iModel. */\n protected async onDeleteRelationship(\n relationshipProps: RelationshipPropsForDelete\n ): Promise<void> {\n // Only passing in what deleteInstance actually uses, full relationshipProps is not necessary.\n this.targetDb.relationships.deleteInstance({\n id: relationshipProps.id,\n classFullName: relationshipProps.classFullName,\n } as RelationshipProps);\n Logger.logInfo(\n loggerCategory,\n `Deleted relationship ${relationshipProps.classFullName} id=${relationshipProps.id}`\n );\n await this.trackProgress();\n }\n\n /** Delete the specified Relationship from the target iModel. */\n public async deleteRelationship(\n relationshipProps: RelationshipPropsForDelete\n ): Promise<void> {\n await this.onDeleteRelationship(relationshipProps);\n }\n\n /** Format a Relationship for the Logger. */\n private formatRelationshipForLogger(relProps: RelationshipProps): string {\n return `${relProps.classFullName} sourceId=[${relProps.sourceId}] targetId=[${relProps.targetId}]`;\n }\n\n /** Tracks incremental progress */\n private async trackProgress(): Promise<void> {\n this._progressCounter++;\n if (0 === this._progressCounter % this.progressInterval) {\n await this.onProgress();\n }\n }\n\n /** This method is called when IModelImporter has made incremental progress based on the [[progressInterval]] setting.\n * @note A subclass may override this method to report custom progress but should call `super.onProgress`.\n */\n protected async onProgress(): Promise<void> {}\n\n /** Optionally compute the projectExtents for the target iModel depending on the options for this IModelImporter.\n * @note This method is automatically called from [IModelTransformer.process]($transformer).\n * @see [IModelDb.computeProjectExtents]($backend), [[autoExtendProjectExtents]]\n */\n public computeProjectExtents(): void {\n const computedProjectExtents = this.targetDb.computeProjectExtents({\n reportExtentsWithOutliers: true,\n reportOutliers: true,\n });\n Logger.logInfo(\n loggerCategory,\n `Current projectExtents=${JSON.stringify(this.targetDb.projectExtents)}`\n );\n Logger.logInfo(\n loggerCategory,\n `Computed projectExtents without outliers=${JSON.stringify(\n computedProjectExtents.extents\n )}`\n );\n Logger.logInfo(\n loggerCategory,\n `Computed projectExtents with outliers=${JSON.stringify(\n computedProjectExtents.extentsWithOutliers\n )}`\n );\n if (this.options.autoExtendProjectExtents) {\n const excludeOutliers: boolean =\n typeof this.options.autoExtendProjectExtents === \"object\"\n ? this.options.autoExtendProjectExtents.excludeOutliers\n : false;\n // If excludeOutliers is true, use the extents without outliers.\n // Otherwise prefer extentsWithOutliers, but fall back to extents if it's undefined or a null range.\n const extentsWithOutliers = computedProjectExtents.extentsWithOutliers;\n const useExtentsWithOutliers =\n !excludeOutliers && extentsWithOutliers && !extentsWithOutliers.isNull;\n const newProjectExtents = useExtentsWithOutliers\n ? extentsWithOutliers\n : computedProjectExtents.extents;\n if (!newProjectExtents.isAlmostEqual(this.targetDb.projectExtents)) {\n this.targetDb.updateProjectExtents(newProjectExtents);\n Logger.logInfo(\n loggerCategory,\n `Updated projectExtents=${JSON.stringify(\n this.targetDb.projectExtents\n )}`\n );\n }\n if (\n !excludeOutliers &&\n computedProjectExtents.outliers &&\n computedProjectExtents.outliers.length > 0\n ) {\n Logger.logInfo(\n loggerCategory,\n `${computedProjectExtents.outliers.length} outliers detected within projectExtents`\n );\n }\n } else {\n if (\n !this.targetDb.projectExtents.containsRange(\n computedProjectExtents.extents\n )\n ) {\n Logger.logWarning(\n loggerCategory,\n \"Current project extents may be too small\"\n );\n }\n if (\n computedProjectExtents.outliers &&\n computedProjectExtents.outliers.length > 0\n ) {\n Logger.logInfo(\n loggerCategory,\n `${computedProjectExtents.outliers.length} outliers detected within projectExtents`\n );\n }\n }\n }\n\n /** Examine the geometry streams of every [GeometricElement3d]($backend) in the target iModel and apply the specified optimizations.\n * @note This method is automatically called from [[IModelTransformer.process]] if\n * [[IModelTransformOptions.optimizeGeometry]] is defined.\n */\n public optimizeGeometry(options: OptimizeGeometryOptions): void {\n if (options.inlineUniqueGeometryParts) {\n const result = this.targetDb.inlineGeometryParts();\n Logger.logInfo(\n loggerCategory,\n `Inlined ${result.numRefsInlined} references to ${result.numCandidateParts} geometry parts and deleted ${result.numPartsDeleted} parts.`\n );\n }\n }\n\n private resolveDuplicateCodeValues(): void {\n for (const [elementId, codeValue] of this._duplicateCodeValueMap) {\n const element = this.targetDb.elements.getElement(elementId);\n element.code.value = codeValue;\n element.update();\n }\n this._duplicateCodeValueMap.clear();\n }\n\n /**\n * Needs to be called to perform necessary cleanup operations.\n * By not calling `finalize` there is a risk that data imported into targetDb will not be as expected.\n *\n * @note No need to call this If using [[IModelTransformer]] as it automatically invokes this method.\n */\n public finalize(): void {\n this.resolveDuplicateCodeValues();\n }\n}\n\n/** Returns true if a change within an Entity is detected.\n * @param entity The current persistent Entity.\n * @param entityProps The new EntityProps to compare against\n * @note This method should only be called if changeset information is not available.\n * @internal\n */\nexport function hasEntityChanged(\n entity: Entity,\n entityProps: EntityProps,\n namesToIgnore?: Set<string>\n): boolean {\n let changed: boolean = false;\n entity.forEach((propertyName: string, property: Property) => {\n if (!changed) {\n if (namesToIgnore && namesToIgnore.has(propertyName)) {\n // skip\n } else if (PropertyType.Binary === property.propertyType) {\n changed = hasBinaryValueChanged(\n entity.asAny[ECJsNames.toJsName(propertyName)],\n (entityProps as any)[ECJsNames.toJsName(propertyName)]\n );\n } else if (property.isNavigation()) {\n changed = hasNavigationValueChanged(\n entity.asAny[ECJsNames.toJsName(propertyName)],\n (entityProps as any)[ECJsNames.toJsName(propertyName)]\n );\n } else {\n changed = hasValueChanged(\n entity.asAny[ECJsNames.toJsName(propertyName)],\n (entityProps as any)[ECJsNames.toJsName(propertyName)]\n );\n }\n }\n });\n return changed;\n}\n\n/** Returns true if the specified binary values are different. */\nfunction hasBinaryValueChanged(\n binaryProperty1: any,\n binaryProperty2: any\n): boolean {\n const jsonString1 = JSON.stringify(\n binaryProperty1,\n Base64EncodedString.replacer\n );\n const jsonString2 = JSON.stringify(\n binaryProperty2,\n Base64EncodedString.replacer\n );\n return jsonString1 !== jsonString2;\n}\n\n/** Returns true if the specified navigation property values are different. */\nfunction hasNavigationValueChanged(\n navigationProperty1: any,\n navigationProperty2: any\n): boolean {\n const relatedElement1 = RelatedElement.fromJSON(navigationProperty1);\n const relatedElement2 = RelatedElement.fromJSON(navigationProperty2);\n const jsonString1 = JSON.stringify(relatedElement1);\n const jsonString2 = JSON.stringify(relatedElement2);\n return jsonString1 !== jsonString2;\n}\n\n/** Returns true if the specified navigation property values are different. */\nfunction hasValueChanged(property1: any, property2: any): boolean {\n return JSON.stringify(property1) !== JSON.stringify(property2);\n}\n\n/** check if element props are a subcategory */\nfunction isSubCategory(props: ElementProps): props is SubCategoryProps {\n return props.classFullName === SubCategory.classFullName;\n}\n\n/** check if element props are a subcategory without loading the element */\nfunction isDefaultSubCategory(props: SubCategoryProps): boolean {\n if (props.id === undefined) return false;\n\n if (!Id64.isId64(props.id))\n throw new IModelError(\n IModelStatus.BadElement,\n \"subcategory had invalid id\"\n );\n if (props.parent?.id === undefined)\n throw new IModelError(\n IModelStatus.BadElement,\n `subcategory with id ${props.id} had no parent`\n );\n return props.id === IModelDb.getDefaultSubCategoryId(props.parent.id);\n}\n"]}
|