@itwin/imodel-transformer 0.4.18-fedguidopt.6 → 1.0.1-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/Algo.d.ts.map +1 -1
- package/lib/cjs/Algo.js +3 -4
- package/lib/cjs/Algo.js.map +1 -1
- package/lib/cjs/BigMap.d.ts.map +1 -1
- package/lib/cjs/BigMap.js +1 -1
- package/lib/cjs/BigMap.js.map +1 -1
- package/lib/cjs/BranchProvenanceInitializer.d.ts.map +1 -1
- package/lib/cjs/BranchProvenanceInitializer.js +15 -4
- package/lib/cjs/BranchProvenanceInitializer.js.map +1 -1
- package/lib/cjs/DetachedExportElementAspectsStrategy.d.ts.map +1 -1
- package/lib/cjs/DetachedExportElementAspectsStrategy.js +12 -5
- package/lib/cjs/DetachedExportElementAspectsStrategy.js.map +1 -1
- package/lib/cjs/ECReferenceTypesCache.d.ts.map +1 -1
- package/lib/cjs/ECReferenceTypesCache.js +32 -18
- package/lib/cjs/ECReferenceTypesCache.js.map +1 -1
- package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.d.ts +1 -1
- package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.d.ts.map +1 -1
- package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.js +7 -5
- package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.js.map +1 -1
- package/lib/cjs/ElementCascadingDeleter.d.ts +3 -3
- package/lib/cjs/ElementCascadingDeleter.d.ts.map +1 -1
- package/lib/cjs/ElementCascadingDeleter.js +9 -7
- package/lib/cjs/ElementCascadingDeleter.js.map +1 -1
- package/lib/cjs/EntityMap.d.ts.map +1 -1
- package/lib/cjs/EntityMap.js.map +1 -1
- package/lib/cjs/EntityUnifier.d.ts +5 -0
- package/lib/cjs/EntityUnifier.d.ts.map +1 -1
- package/lib/cjs/EntityUnifier.js +22 -35
- package/lib/cjs/EntityUnifier.js.map +1 -1
- package/lib/cjs/ExportElementAspectsStrategy.d.ts.map +1 -1
- package/lib/cjs/ExportElementAspectsStrategy.js +5 -4
- package/lib/cjs/ExportElementAspectsStrategy.js.map +1 -1
- package/lib/cjs/ExportElementAspectsWithElementsStrategy.d.ts.map +1 -1
- package/lib/cjs/ExportElementAspectsWithElementsStrategy.js +9 -5
- package/lib/cjs/ExportElementAspectsWithElementsStrategy.js.map +1 -1
- package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
- package/lib/cjs/IModelCloneContext.js +23 -12
- package/lib/cjs/IModelCloneContext.js.map +1 -1
- package/lib/cjs/IModelExporter.d.ts +68 -25
- package/lib/cjs/IModelExporter.d.ts.map +1 -1
- package/lib/cjs/IModelExporter.js +241 -123
- package/lib/cjs/IModelExporter.js.map +1 -1
- package/lib/cjs/IModelImporter.d.ts +13 -22
- package/lib/cjs/IModelImporter.d.ts.map +1 -1
- package/lib/cjs/IModelImporter.js +80 -62
- package/lib/cjs/IModelImporter.js.map +1 -1
- package/lib/cjs/IModelTransformer.d.ts +126 -44
- package/lib/cjs/IModelTransformer.d.ts.map +1 -1
- package/lib/cjs/IModelTransformer.js +706 -535
- package/lib/cjs/IModelTransformer.js.map +1 -1
- package/lib/cjs/PendingReferenceMap.d.ts.map +1 -1
- package/lib/cjs/PendingReferenceMap.js +12 -6
- package/lib/cjs/PendingReferenceMap.js.map +1 -1
- package/lib/cjs/TransformerLoggerCategory.d.ts +2 -2
- package/lib/cjs/TransformerLoggerCategory.d.ts.map +1 -1
- package/lib/cjs/TransformerLoggerCategory.js +5 -5
- package/lib/cjs/TransformerLoggerCategory.js.map +1 -1
- package/lib/cjs/transformer.d.ts.map +1 -1
- package/lib/cjs/transformer.js +14 -10
- package/lib/cjs/transformer.js.map +1 -1
- package/package.json +20 -17
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ElementCascadingDeleter = exports.deleteElementTreeCascade = void 0;
|
|
4
4
|
/*---------------------------------------------------------------------------------------------
|
|
5
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
7
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
7
|
+
*--------------------------------------------------------------------------------------------*/
|
|
8
8
|
/** @packageDocumentation
|
|
9
9
|
* @module iModels
|
|
10
10
|
*/
|
|
@@ -21,11 +21,13 @@ function deleteElementTreeCascade(iModel, topElement) {
|
|
|
21
21
|
}
|
|
22
22
|
exports.deleteElementTreeCascade = deleteElementTreeCascade;
|
|
23
23
|
/** Deletes an entire element tree, including sub-models, child elements and code scope references.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
* Items are deleted in bottom-up order. Definitions and Subjects are deleted after normal elements.
|
|
25
|
+
* Call deleteNormalElements on each tree. Then call deleteSpecialElements.
|
|
26
|
+
*/
|
|
27
27
|
class ElementCascadingDeleter extends core_backend_1.ElementTreeDeleter {
|
|
28
|
-
shouldVisitCodeScopes(_elementId, _scope) {
|
|
28
|
+
shouldVisitCodeScopes(_elementId, _scope) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
29
31
|
/** The main tree-walking function */
|
|
30
32
|
processElementTree(element, scope) {
|
|
31
33
|
if (this.shouldVisitCodeScopes(element, scope)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElementCascadingDeleter.js","sourceRoot":"","sources":["../../src/ElementCascadingDeleter.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"ElementCascadingDeleter.js","sourceRoot":"","sources":["../../src/ElementCascadingDeleter.ts"],"names":[],"mappings":";;;AAAA;;;gGAGgG;AAChG;;GAEG;AACH,sDAI6B;AAC7B,sDAA2D;AAE3D;;;GAGG;AACH,SAAgB,wBAAwB,CACtC,MAAgB,EAChB,UAAsB;IAEtB,MAAM,GAAG,GAAG,IAAI,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAChD,GAAG,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;IACrC,GAAG,CAAC,qBAAqB,EAAE,CAAC;AAC9B,CAAC;AAPD,4DAOC;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;YAC9C,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;SACzC;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,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAChC;;;;;KAKD,EACC,CAAC,IAAI,EAAE,EAAE;YACP,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YACxB,OAAO,IAAI,CAAC,IAAI,EAAE,KAAK,uBAAQ,CAAC,aAAa,EAAE;gBAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;gBAC3C,IAAI,CAAC,kBAAkB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;aAC9C;QACH,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAxCD,0DAwCC","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 { DbResult, Id64String } from \"@itwin/core-bentley\";\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 this._iModel.withPreparedStatement(\n `\n SELECT ECInstanceId\n FROM bis.Element\n WHERE CodeScope.id=?\n AND Parent.id IS NULL\n `,\n (stmt) => {\n stmt.bindId(1, element);\n while (stmt.step() === DbResult.BE_SQLITE_ROW) {\n const elementId = stmt.getValue(0).getId();\n this.processElementTree(elementId, newScope);\n }\n }\n );\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityMap.d.ts","sourceRoot":"","sources":["../../src/EntityMap.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,OAAO,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AAC,MAAM,CAAC,QAAQ,CAAC;IAIxB,IAAW,IAAI,WAEd;CACF"}
|
package/lib/cjs/EntityMap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityMap.js","sourceRoot":"","sources":["../../src/EntityMap.ts"],"names":[],"mappings":";;;AAQA,sDAAuE;AACvE,qCAAkC;AAKlC,gBAAgB;AAChB,MAAa,SAAS;IAAtB;QACU,SAAI,GAAG,IAAI,eAAM,EAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"EntityMap.js","sourceRoot":"","sources":["../../src/EntityMap.ts"],"names":[],"mappings":";;;AAQA,sDAAuE;AACvE,qCAAkC;AAKlC,gBAAgB;AAChB,MAAa,SAAS;IAAtB;QACU,SAAI,GAAG,IAAI,eAAM,EAAK,CAAC;IA0DjC,CAAC;IAxDQ,MAAM,CAAC,OAAO,CAAC,MAAsB;QAC1C,OAAO,+BAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAEM,KAAK;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IAEM,GAAG,CAAC,MAAsB;QAC/B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,CAAC;IAEM,GAAG,CAAC,MAAsB,EAAE,GAAM;QACvC,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC;IACvD,CAAC;IAEM,QAAQ,CAAC,CAAY,EAAE,GAAM;QAClC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,GAAG,CAAC,MAAsB;QAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,CAAC;IAEM,QAAQ,CAAC,CAAY;QAC1B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;IAEM,MAAM,CAAC,MAAsB;QAClC,OAAO,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACrD,CAAC;IAEM,WAAW,CAAC,CAAY;QAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;IAEM,IAAI;QACT,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;IAEM,OAAO;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC;QACtB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IACtC,CAAC;IAED,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC;CACF;AA3DD,8BA2DC","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 */\nimport { EntityReference } from \"@itwin/core-common\";\nimport { ConcreteEntity, EntityReferences } from \"@itwin/core-backend\";\nimport { BigMap } from \"./BigMap\";\n\n/** @internal */\nexport type EntityKey = EntityReference;\n\n/** @internal */\nexport class EntityMap<V> {\n private _map = new BigMap<V>();\n\n public static makeKey(entity: ConcreteEntity): EntityKey {\n return EntityReferences.from(entity);\n }\n\n public clear(): void {\n return this._map.clear();\n }\n\n public has(entity: ConcreteEntity) {\n return this._map.has(EntityMap.makeKey(entity));\n }\n\n public set(entity: ConcreteEntity, val: V): EntityMap<V> {\n return this.setByKey(EntityMap.makeKey(entity), val);\n }\n\n public setByKey(k: EntityKey, val: V): EntityMap<V> {\n this._map.set(k, val);\n return this;\n }\n\n public get(entity: ConcreteEntity): V | undefined {\n return this.getByKey(EntityMap.makeKey(entity));\n }\n\n public getByKey(k: EntityKey): V | undefined {\n return this._map.get(k);\n }\n\n public delete(entity: ConcreteEntity): boolean {\n return this.deleteByKey(EntityMap.makeKey(entity));\n }\n\n public deleteByKey(k: EntityKey): boolean {\n return this._map.delete(k);\n }\n\n public keys() {\n return this._map.keys();\n }\n\n public values() {\n return this._map.values();\n }\n\n public entries() {\n return this._map.entries();\n }\n\n public [Symbol.iterator]() {\n return this._map[Symbol.iterator]();\n }\n\n public get size() {\n return this._map.size;\n }\n}\n"]}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Utils
|
|
3
|
+
* utilities that unify operations, especially CRUD operations, on entities
|
|
4
|
+
* for entity-generic operations in the transformer
|
|
5
|
+
*/
|
|
1
6
|
import { EntityReference } from "@itwin/core-common";
|
|
2
7
|
import { ConcreteEntity, ConcreteEntityProps, IModelDb } from "@itwin/core-backend";
|
|
3
8
|
/** @internal */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityUnifier.d.ts","sourceRoot":"","sources":["../../src/EntityUnifier.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EntityUnifier.d.ts","sourceRoot":"","sources":["../../src/EntityUnifier.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AAGH,OAAO,EAGL,eAAe,EAEhB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,mBAAmB,EAInB,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,MAAM,UAAU,MAAM,CACpB,EAAE,EAAE,QAAQ,EACZ,GAAG,EAAE;QAAE,MAAM,EAAE,cAAc,CAAA;KAAE,GAAG;QAAE,eAAe,EAAE,eAAe,CAAA;KAAE,WAuBvE;;CACF"}
|
package/lib/cjs/EntityUnifier.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EntityUnifier = void 0;
|
|
4
2
|
/*---------------------------------------------------------------------------------------------
|
|
5
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
7
|
-
*--------------------------------------------------------------------------------------------*/
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
8
6
|
/** @packageDocumentation
|
|
9
7
|
* @module Utils
|
|
10
8
|
* utilities that unify operations, especially CRUD operations, on entities
|
|
11
9
|
* for entity-generic operations in the transformer
|
|
12
10
|
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EntityUnifier = void 0;
|
|
13
13
|
const assert = require("assert");
|
|
14
14
|
const core_common_1 = require("@itwin/core-common");
|
|
15
15
|
const core_backend_1 = require("@itwin/core-backend");
|
|
@@ -41,37 +41,24 @@ var EntityUnifier;
|
|
|
41
41
|
}
|
|
42
42
|
EntityUnifier.updaterFor = updaterFor;
|
|
43
43
|
function exists(db, arg) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
throw new core_common_1.IModelError(matchesResult, "query failed");
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
if (arg.entity.id === undefined || core_bentley_1.Id64.isInvalid(arg.entity.id))
|
|
44
|
+
const [type, id] = "entityReference" in arg
|
|
45
|
+
? core_backend_1.EntityReferences.split(arg.entityReference)
|
|
46
|
+
: [undefined, arg.entity.id];
|
|
47
|
+
const classFullName = "entityReference" in arg
|
|
48
|
+
? core_common_1.ConcreteEntityTypes.toBisCoreRootClassFullName(type)
|
|
49
|
+
: `[${arg.entity.schemaName}].[${arg.entity.className}]`;
|
|
50
|
+
if (id === undefined || core_bentley_1.Id64.isInvalid(id))
|
|
51
|
+
return false;
|
|
52
|
+
return db.withPreparedStatement(`SELECT 1 FROM ${classFullName} WHERE ECInstanceId=?`, (stmt) => {
|
|
53
|
+
stmt.bindId(1, id);
|
|
54
|
+
const matchesResult = stmt.step();
|
|
55
|
+
if (matchesResult === core_common_1.DbResult.BE_SQLITE_ROW)
|
|
56
|
+
return true;
|
|
57
|
+
if (matchesResult === core_common_1.DbResult.BE_SQLITE_DONE)
|
|
63
58
|
return false;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (matchesResult === core_common_1.DbResult.BE_SQLITE_ROW)
|
|
68
|
-
return true;
|
|
69
|
-
if (matchesResult === core_common_1.DbResult.BE_SQLITE_DONE)
|
|
70
|
-
return false;
|
|
71
|
-
else
|
|
72
|
-
throw new core_common_1.IModelError(matchesResult, "query failed");
|
|
73
|
-
});
|
|
74
|
-
}
|
|
59
|
+
else
|
|
60
|
+
throw new core_common_1.IModelError(matchesResult, "query failed");
|
|
61
|
+
});
|
|
75
62
|
}
|
|
76
63
|
EntityUnifier.exists = exists;
|
|
77
64
|
})(EntityUnifier || (exports.EntityUnifier = EntityUnifier = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityUnifier.js","sourceRoot":"","sources":["../../src/EntityUnifier.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"EntityUnifier.js","sourceRoot":"","sources":["../../src/EntityUnifier.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;;;GAIG;;;AAEH,iCAAiC;AACjC,oDAK4B;AAC5B,sDAQ6B;AAC7B,sDAA2C;AAE3C,gBAAgB;AAChB,IAAiB,aAAa,CAqD7B;AArDD,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;IAED,SAAgB,MAAM,CACpB,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,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,OAAO,EAAE,CAAC,qBAAqB,CAC7B,iBAAiB,aAAa,uBAAuB,EACrD,CAAC,IAAI,EAAE,EAAE;YACP,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACnB,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YAClC,IAAI,aAAa,KAAK,sBAAQ,CAAC,aAAa;gBAAE,OAAO,IAAI,CAAC;YAC1D,IAAI,aAAa,KAAK,sBAAQ,CAAC,cAAc;gBAAE,OAAO,KAAK,CAAC;;gBACvD,MAAM,IAAI,yBAAW,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;QAC5D,CAAC,CACF,CAAC;IACJ,CAAC;IAzBe,oBAAM,SAyBrB,CAAA;AACH,CAAC,EArDgB,aAAa,6BAAb,aAAa,QAqD7B","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 DbResult,\n EntityReference,\n IModelError,\n} from \"@itwin/core-common\";\nimport {\n ConcreteEntity,\n ConcreteEntityProps,\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 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 ? ConcreteEntityTypes.toBisCoreRootClassFullName(type!)\n : `[${arg.entity.schemaName}].[${arg.entity.className}]`;\n\n if (id === undefined || Id64.isInvalid(id)) return false;\n\n return db.withPreparedStatement(\n `SELECT 1 FROM ${classFullName} WHERE ECInstanceId=?`,\n (stmt) => {\n stmt.bindId(1, id);\n const matchesResult = stmt.step();\n if (matchesResult === DbResult.BE_SQLITE_ROW) return true;\n if (matchesResult === DbResult.BE_SQLITE_DONE) return false;\n else throw new IModelError(matchesResult, \"query failed\");\n }\n );\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExportElementAspectsStrategy.d.ts","sourceRoot":"","sources":["../../src/ExportElementAspectsStrategy.ts"],"names":[],"mappings":"AAKA,OAAO,
|
|
1
|
+
{"version":3,"file":"ExportElementAspectsStrategy.d.ts","sourceRoot":"","sources":["../../src/ExportElementAspectsStrategy.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,QAAQ,EACT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAU,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAItD;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,yBAAyB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC;IAC1D,2BAA2B,CACzB,YAAY,EAAE,mBAAmB,EACjC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,GAC7B,IAAI,CAAC;IACR,2BAA2B,CAAC,YAAY,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC;IACtE,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAED;;;;GAIG;AACH,8BAAsB,4BAA4B;IAChD,6HAA6H;IAC7H,SAAS,CAAC,6BAA6B,4BAAmC;IAC1E,mHAAmH;IACnH,SAAgB,mCAAmC,cAAqB;IAExE,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAE7B,SAAS,CAAC,aAAa,EAAE,kBAAkB,GAAG,SAAS,CAAC;IAExD,SAAS,CAAC,OAAO,EAAE,qBAAqB,CAAC;gBAEtB,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,qBAAqB;aAKrD,8BAA8B,CAC5C,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,IAAI,CAAC;aACA,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC;IAExD,SAAS,CAAC,yBAAyB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO;IAe5D,gBAAgB,CAAC,aAAa,CAAC,EAAE,kBAAkB;IAInD,gCAAgC,CACrC,mCAAmC,EAAE,MAAM,EAAE,GAC5C,IAAI;IAWA,yBAAyB,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI;CAM9D"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.ExportElementAspectsStrategy = void 0;
|
|
8
8
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
@@ -23,7 +23,8 @@ class ExportElementAspectsStrategy {
|
|
|
23
23
|
this.handler = handler;
|
|
24
24
|
}
|
|
25
25
|
shouldExportElementAspect(aspect) {
|
|
26
|
-
for (const excludedElementAspectClass of this
|
|
26
|
+
for (const excludedElementAspectClass of this
|
|
27
|
+
._excludedElementAspectClasses) {
|
|
27
28
|
if (aspect instanceof excludedElementAspectClass) {
|
|
28
29
|
core_bentley_1.Logger.logInfo(loggerCategory, `Excluded ElementAspect by class: ${aspect.classFullName}`);
|
|
29
30
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExportElementAspectsStrategy.js","sourceRoot":"","sources":["../../src/ExportElementAspectsStrategy.ts"],"names":[],"mappings":";AAAA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qB;QACpD,IAAI,CAAC,mCAAmC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,gDAAgD;QAC7G,IAAI,CAAC,6BAA6B,CAAC,GAAG,CACpC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAuB,aAAa,CAAC,CAC9D,CAAC,CAAC,gDAAgD;IACrD,CAAC;CACF;AA5DD,oEA4DC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport {\n ElementAspect,\n ElementMultiAspect,\n ElementUniqueAspect,\n IModelDb,\n} from \"@itwin/core-backend\";\nimport { Id64String, Logger } from \"@itwin/core-bentley\";\nimport { TransformerLoggerCategory } from \"./TransformerLoggerCategory\";\nimport { ChangedInstanceOps } from \"./IModelExporter\";\n\nconst loggerCategory = TransformerLoggerCategory.IModelExporter;\n\n/**\n * Handler for [[ExportElementAspectsStrategy]]\n * @internal\n */\nexport interface ElementAspectsHandler {\n shouldExportElementAspect(aspect: ElementAspect): boolean;\n onExportElementUniqueAspect(\n uniqueAspect: ElementUniqueAspect,\n isUpdate?: boolean | undefined\n ): void;\n onExportElementMultiAspects(multiAspects: ElementMultiAspect[]): void;\n trackProgress: () => Promise<void>;\n}\n\n/**\n * Base ElementAspect export strategy. Base export strategy includes state saving and loading and\n * ElementAspect filtering.\n * @internal\n */\nexport abstract class ExportElementAspectsStrategy {\n /** The set of classes of ElementAspects that will be excluded (polymorphically) from transformation to the target iModel. */\n protected _excludedElementAspectClasses = new Set<typeof ElementAspect>();\n /** The set of classFullNames for ElementAspects that will be excluded from transformation to the target iModel. */\n public readonly excludedElementAspectClassFullNames = new Set<string>();\n\n protected sourceDb: IModelDb;\n\n protected aspectChanges: ChangedInstanceOps | undefined;\n\n protected handler: ElementAspectsHandler;\n\n public constructor(sourceDb: IModelDb, handler: ElementAspectsHandler) {\n this.sourceDb = sourceDb;\n this.handler = handler;\n }\n\n public abstract exportElementAspectsForElement(\n _elementId: Id64String\n ): Promise<void>;\n public abstract exportAllElementAspects(): Promise<void>;\n\n protected shouldExportElementAspect(aspect: ElementAspect): boolean {\n for (const excludedElementAspectClass of this\n ._excludedElementAspectClasses) {\n if (aspect instanceof excludedElementAspectClass) {\n Logger.logInfo(\n loggerCategory,\n `Excluded ElementAspect by class: ${aspect.classFullName}`\n );\n return false;\n }\n }\n // ElementAspect has passed standard exclusion rules, now give handler a chance to accept/reject\n return this.handler.shouldExportElementAspect(aspect);\n }\n\n public setAspectChanges(aspectChanges?: ChangedInstanceOps) {\n this.aspectChanges = aspectChanges;\n }\n\n public loadExcludedElementAspectClasses(\n excludedElementAspectClassFullNames: string[]\n ): void {\n (this.excludedElementAspectClassFullNames as any) = new Set(\n excludedElementAspectClassFullNames\n );\n this._excludedElementAspectClasses = new Set(\n excludedElementAspectClassFullNames.map((c) =>\n this.sourceDb.getJsClass(c)\n )\n );\n }\n\n public excludeElementAspectClass(classFullName: string): void {\n this.excludedElementAspectClassFullNames.add(classFullName); // allows non-polymorphic exclusion before query\n this._excludedElementAspectClasses.add(\n this.sourceDb.getJsClass<typeof ElementAspect>(classFullName)\n ); // allows polymorphic exclusion after query/load\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExportElementAspectsWithElementsStrategy.d.ts","sourceRoot":"","sources":["../../src/ExportElementAspectsWithElementsStrategy.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAE9E;;;;GAIG;AACH,qBAAa,wCAAyC,SAAQ,4BAA4B;IAClE,8BAA8B,
|
|
1
|
+
{"version":3,"file":"ExportElementAspectsWithElementsStrategy.d.ts","sourceRoot":"","sources":["../../src/ExportElementAspectsWithElementsStrategy.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAE9E;;;;GAIG;AACH,qBAAa,wCAAyC,SAAQ,4BAA4B;IAClE,8BAA8B,CAClD,SAAS,EAAE,UAAU,GACpB,OAAO,CAAC,IAAI,CAAC;IA6CM,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/D"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.ExportElementAspectsWithElementsStrategy = void 0;
|
|
8
8
|
const core_backend_1 = require("@itwin/core-backend");
|
|
@@ -20,9 +20,13 @@ class ExportElementAspectsWithElementsStrategy extends ExportElementAspectsStrat
|
|
|
20
20
|
.map(async (uniqueAspect) => {
|
|
21
21
|
const isInsertChange = this.aspectChanges?.insertIds.has(uniqueAspect.id) ?? false;
|
|
22
22
|
const isUpdateChange = this.aspectChanges?.updateIds.has(uniqueAspect.id) ?? false;
|
|
23
|
-
const doExport = this.aspectChanges === undefined ||
|
|
23
|
+
const doExport = this.aspectChanges === undefined ||
|
|
24
|
+
isInsertChange ||
|
|
25
|
+
isUpdateChange;
|
|
24
26
|
if (doExport) {
|
|
25
|
-
const isKnownUpdate = this.aspectChanges
|
|
27
|
+
const isKnownUpdate = this.aspectChanges
|
|
28
|
+
? isUpdateChange
|
|
29
|
+
: undefined;
|
|
26
30
|
this.handler.onExportElementUniqueAspect(uniqueAspect, isKnownUpdate);
|
|
27
31
|
await this.handler.trackProgress();
|
|
28
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExportElementAspectsWithElementsStrategy.js","sourceRoot":"","sources":["../../src/ExportElementAspectsWithElementsStrategy.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"ExportElementAspectsWithElementsStrategy.js","sourceRoot":"","sources":["../../src/ExportElementAspectsWithElementsStrategy.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,sDAA8E;AAE9E,iFAA8E;AAE9E;;;;GAIG;AACH,MAAa,wCAAyC,SAAQ,2DAA4B;IACxE,KAAK,CAAC,8BAA8B,CAClD,SAAqB;QAErB,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,GAAG,CACtC,IAAI,CAAC,QAAQ,CAAC,QAAQ;aACnB,aAAa,CACZ,SAAS,EACT,kCAAmB,CAAC,aAAa,EACjC,IAAI,CAAC,mCAAmC,CACzC;aACA,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC;aAChD,GAAG,CAAC,KAAK,EAAE,YAAiC,EAAE,EAAE;YAC/C,MAAM,cAAc,GAClB,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC;YAC9D,MAAM,cAAc,GAClB,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC;YAC9D,MAAM,QAAQ,GACZ,IAAI,CAAC,aAAa,KAAK,SAAS;gBAChC,cAAc;gBACd,cAAc,CAAC;YACjB,IAAI,QAAQ,EAAE;gBACZ,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa;oBACtC,CAAC,CAAC,cAAc;oBAChB,CAAC,CAAC,SAAS,CAAC;gBACd,IAAI,CAAC,OAAO,CAAC,2BAA2B,CACtC,YAAY,EACZ,aAAa,CACd,CAAC;gBACF,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;aACpC;QACH,CAAC,CAAC,CACL,CAAC;QAEF,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ;aACxC,aAAa,CACZ,SAAS,EACT,iCAAkB,CAAC,aAAa,EAChC,IAAI,CAAC,mCAAmC,CACzC;aACA,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,CAAC;QAEpD,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;YAC3B,IAAI,CAAC,OAAO,CAAC,2BAA2B,CAAC,YAAY,CAAC,CAAC;YACvD,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;SACrC;IACH,CAAC;IAEe,KAAK,CAAC,uBAAuB;QAC3C,gGAAgG;IAClG,CAAC;CACF;AAnDD,4FAmDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { ElementMultiAspect, ElementUniqueAspect } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { ExportElementAspectsStrategy } from \"./ExportElementAspectsStrategy\";\n\n/**\n * ElementAspect export strategy for [[IModelExporter]].\n * This strategy exports ElementAspects together with their Elements.\n * @internal\n */\nexport class ExportElementAspectsWithElementsStrategy extends ExportElementAspectsStrategy {\n public override async exportElementAspectsForElement(\n elementId: Id64String\n ): Promise<void> {\n const _uniqueAspects = await Promise.all(\n this.sourceDb.elements\n ._queryAspects(\n elementId,\n ElementUniqueAspect.classFullName,\n this.excludedElementAspectClassFullNames\n )\n .filter((a) => this.shouldExportElementAspect(a))\n .map(async (uniqueAspect: ElementUniqueAspect) => {\n const isInsertChange =\n this.aspectChanges?.insertIds.has(uniqueAspect.id) ?? false;\n const isUpdateChange =\n this.aspectChanges?.updateIds.has(uniqueAspect.id) ?? false;\n const doExport =\n this.aspectChanges === undefined ||\n isInsertChange ||\n isUpdateChange;\n if (doExport) {\n const isKnownUpdate = this.aspectChanges\n ? isUpdateChange\n : undefined;\n this.handler.onExportElementUniqueAspect(\n uniqueAspect,\n isKnownUpdate\n );\n await this.handler.trackProgress();\n }\n })\n );\n\n const multiAspects = this.sourceDb.elements\n ._queryAspects(\n elementId,\n ElementMultiAspect.classFullName,\n this.excludedElementAspectClassFullNames\n )\n .filter((a) => this.shouldExportElementAspect(a));\n\n if (multiAspects.length > 0) {\n this.handler.onExportElementMultiAspects(multiAspects);\n return this.handler.trackProgress();\n }\n }\n\n public override async exportAllElementAspects(): Promise<void> {\n // All aspects are exported with their owning elements and don't need to be exported separately.\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelCloneContext.d.ts","sourceRoot":"","sources":["../../src/IModelCloneContext.ts"],"names":[],"mappings":"AAQA,OAAO,EAAkB,UAAU,EAAU,MAAM,qBAAqB,CAAC;AACzE,OAAO,
|
|
1
|
+
{"version":3,"file":"IModelCloneContext.d.ts","sourceRoot":"","sources":["../../src/IModelCloneContext.ts"],"names":[],"mappings":"AAQA,OAAO,EAAkB,UAAU,EAAU,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAIL,kBAAkB,EAClB,YAAY,EACZ,eAAe,EAOhB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,OAAO,EACP,aAAa,EAEb,yBAAyB,EACzB,cAAc,EACd,QAAQ,EACT,MAAM,qBAAqB,CAAC;AAO7B;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,yBAAyB;IAC/D,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,iBAAiB,CAAqC;IAE9D,0HAA0H;IACpG,UAAU;IAIhC;;OAEG;IACa,YAAY,CAC1B,aAAa,EAAE,OAAO,EACtB,YAAY,CAAC,EAAE,cAAc,CAAC,mBAAmB,GAChD,YAAY;IA+Cf,uGAAuG;IAChG,kBAAkB,CACvB,cAAc,EAAE,UAAU,EAC1B,cAAc,EAAE,UAAU,GACzB,IAAI;IAIP,mEAAmE;IAC5D,mBAAmB,CAAC,cAAc,EAAE,UAAU,GAAG,IAAI;IAI5D;;OAEG;IACI,kBAAkB,CAAC,cAAc,EAAE,UAAU,GAAG,UAAU;IAIjE;;OAEG;IACI,kBAAkB,CAAC,cAAc,EAAE,eAAe,GAAG,eAAe;IAkH3E;;OAEG;IACI,kBAAkB,CACvB,mBAAmB,EAAE,aAAa,GACjC,kBAAkB;IAuCrB,OAAO,CAAC,MAAM,CAAC,oBAAoB,CAAoB;IAEvC,aAAa,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI;IA4BjC,eAAe,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI;CAgBpD"}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IModelCloneContext = void 0;
|
|
4
4
|
/*---------------------------------------------------------------------------------------------
|
|
5
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
7
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
7
|
+
*--------------------------------------------------------------------------------------------*/
|
|
8
8
|
/** @packageDocumentation
|
|
9
9
|
* @module iModels
|
|
10
10
|
*/
|
|
@@ -36,7 +36,8 @@ class IModelCloneContext extends core_backend_1.IModelElementCloneContext {
|
|
|
36
36
|
const targetElementProps = this["_nativeContext"].cloneElement(sourceElement.id, cloneOptions);
|
|
37
37
|
// Ensure that all NavigationProperties in targetElementProps have a defined value so "clearing" changes will be part of the JSON used for update
|
|
38
38
|
sourceElement.forEachProperty((propertyName, meta) => {
|
|
39
|
-
if (
|
|
39
|
+
if (meta.isNavigation &&
|
|
40
|
+
undefined === sourceElement[propertyName]) {
|
|
40
41
|
targetElementProps[propertyName] = core_common_1.RelatedElement.none;
|
|
41
42
|
}
|
|
42
43
|
}, false); // exclude custom because C++ has already handled them
|
|
@@ -44,13 +45,15 @@ class IModelCloneContext extends core_backend_1.IModelElementCloneContext {
|
|
|
44
45
|
// The native C++ cloneElement strips off federationGuid, want to put it back if transformation is between iModels
|
|
45
46
|
targetElementProps.federationGuid = sourceElement.federationGuid;
|
|
46
47
|
const targetElementCodeScopeType = this.targetDb.codeSpecs.getById(targetElementProps.code.spec).scopeType;
|
|
47
|
-
if (core_common_1.CodeScopeSpec.Type.Repository === targetElementCodeScopeType &&
|
|
48
|
+
if (core_common_1.CodeScopeSpec.Type.Repository === targetElementCodeScopeType &&
|
|
49
|
+
targetElementProps.code.scope !== core_common_1.IModel.rootSubjectId) {
|
|
48
50
|
core_bentley_1.Logger.logWarning(loggerCategory, `Incorrect CodeScope '${targetElementCodeScopeType}' is set for target element ${targetElementProps.id}`);
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
// unlike other references, code cannot be null. If it is null, use an empty code instead
|
|
52
54
|
// this will be updated back later as the transformer resolves references
|
|
53
|
-
if (targetElementProps.code.scope === core_bentley_1.Id64.invalid ||
|
|
55
|
+
if (targetElementProps.code.scope === core_bentley_1.Id64.invalid ||
|
|
56
|
+
targetElementProps.code.spec === core_bentley_1.Id64.invalid) {
|
|
54
57
|
targetElementProps.code = core_common_1.Code.createEmpty();
|
|
55
58
|
}
|
|
56
59
|
const jsClass = this.sourceDb.getJsClass(sourceElement.classFullName);
|
|
@@ -136,14 +139,16 @@ class IModelCloneContext extends core_backend_1.IModelElementCloneContext {
|
|
|
136
139
|
if (relInSource === undefined)
|
|
137
140
|
break;
|
|
138
141
|
// just in case prevent recursion
|
|
139
|
-
if (relInSource.sourceId === sourceEntityId ||
|
|
142
|
+
if (relInSource.sourceId === sourceEntityId ||
|
|
143
|
+
relInSource.targetId === sourceEntityId)
|
|
140
144
|
throw Error("link table relationship end was resolved to itself. This should be impossible");
|
|
141
145
|
const relInTarget = {
|
|
142
146
|
sourceId: this.findTargetEntityId(relInSource.sourceId),
|
|
143
147
|
targetId: this.findTargetEntityId(relInSource.targetId),
|
|
144
148
|
};
|
|
145
149
|
// return a null
|
|
146
|
-
if (!core_backend_1.EntityReferences.isValid(relInTarget.sourceId) ||
|
|
150
|
+
if (!core_backend_1.EntityReferences.isValid(relInTarget.sourceId) ||
|
|
151
|
+
!core_backend_1.EntityReferences.isValid(relInTarget.targetId))
|
|
147
152
|
break;
|
|
148
153
|
const relInTargetId = this.targetDb.withPreparedStatement(`
|
|
149
154
|
SELECT ECInstanceId
|
|
@@ -181,18 +186,24 @@ class IModelCloneContext extends core_backend_1.IModelElementCloneContext {
|
|
|
181
186
|
const targetEntityReference = this.findTargetEntityId(core_backend_1.EntityReferences.fromEntityType(sourceNavProp.id, navPropRefType));
|
|
182
187
|
const targetEntityId = core_backend_1.EntityReferences.toId64(targetEntityReference);
|
|
183
188
|
// spread the property in case toJSON did not deep-clone
|
|
184
|
-
targetElementAspectProps[propertyName] = {
|
|
189
|
+
targetElementAspectProps[propertyName] = {
|
|
190
|
+
...targetElementAspectProps[propertyName],
|
|
191
|
+
id: targetEntityId,
|
|
192
|
+
};
|
|
185
193
|
}
|
|
186
194
|
}
|
|
187
|
-
else if (
|
|
188
|
-
|
|
195
|
+
else if (core_common_1.PrimitiveTypeCode.Long === propertyMetaData.primitiveType &&
|
|
196
|
+
"Id" === propertyMetaData.extendedType) {
|
|
197
|
+
targetElementAspectProps[propertyName] =
|
|
198
|
+
this.findTargetElementId(sourceElementAspect.asAny[propertyName]);
|
|
189
199
|
}
|
|
190
200
|
});
|
|
191
201
|
return targetElementAspectProps;
|
|
192
202
|
}
|
|
193
203
|
saveStateToDb(db) {
|
|
194
204
|
super.saveStateToDb(db);
|
|
195
|
-
if (core_bentley_1.DbResult.BE_SQLITE_DONE !==
|
|
205
|
+
if (core_bentley_1.DbResult.BE_SQLITE_DONE !==
|
|
206
|
+
db.executeSQL(`CREATE TABLE ${IModelCloneContext.aspectRemapTableName} (Source INTEGER, Target INTEGER)`))
|
|
196
207
|
throw Error("Failed to create the aspect remap table in the state database");
|
|
197
208
|
db.saveChanges();
|
|
198
209
|
db.withPreparedSqliteStatement(`INSERT INTO ${IModelCloneContext.aspectRemapTableName} (Source, Target) VALUES (?, ?)`, (stmt) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelCloneContext.js","sourceRoot":"","sources":["../../src/IModelCloneContext.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,iCAAiC;AACjC,sDAAyE;AACzE,oDAK4B;AAC5B,sDAE6B;AAC7B,mEAAgE;AAChE,mDAAgD;AAChD,2EAAwE;AAExE,MAAM,cAAc,GAAW,qDAAyB,CAAC,kBAAkB,CAAC;AAE5E;;GAEG;AACH,MAAa,kBAAmB,SAAQ,wCAAyB;IAAjE;;QAEU,mBAAc,GAAG,IAAI,6CAAqB,EAAE,CAAC;QAC7C,sBAAiB,GAAG,IAAI,GAAG,EAA0B,CAAC;IAsNhE,CAAC;IApNC,0HAA0H;IAC1G,KAAK,CAAC,UAAU;QAC9B,MAAM,IAAI,CAAC,cAAc,CAAC,sBAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACa,YAAY,CAAC,aAAsB,EAAE,YAAiD;QACpG,MAAM,kBAAkB,GAAiB,IAAI,CAAC,gBAAgB,CAAC,CAAC,YAAY,CAAC,aAAa,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;QAC7G,iJAAiJ;QACjJ,aAAa,CAAC,eAAe,CAAC,CAAC,YAAoB,EAAE,IAAsB,EAAE,EAAE;YAC7E,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,C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AAC,CAAC,KAAK,EAAE,CAAC;gBACxC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;aAC5C;YACD,MAAM,CAAC,MAAM,KAAK,uBAAQ,CAAC,cAAc,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;IACL,CAAC;;AAxNH,gDAyNC;AAnCgB,uCAAoB,GAAG,gBAAgB,AAAnB,CAAoB","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module iModels\n */\nimport * as assert from \"assert\";\nimport { DbResult, Id64, Id64String, Logger } from \"@itwin/core-bentley\";\nimport {\n Code,\n CodeScopeSpec,\n ConcreteEntityTypes, ElementAspectProps, ElementProps, EntityReference, IModel, IModelError,\n PrimitiveTypeCode, PropertyMetaData, RelatedElement, RelatedElementProps,\n} from \"@itwin/core-common\";\nimport {\n Element, ElementAspect, EntityReferences, IModelElementCloneContext, IModelJsNative, SQLiteDb,\n} from \"@itwin/core-backend\";\nimport { ECReferenceTypesCache } from \"./ECReferenceTypesCache\";\nimport { EntityUnifier } from \"./EntityUnifier\";\nimport { TransformerLoggerCategory } from \"./TransformerLoggerCategory\";\n\nconst loggerCategory: string = TransformerLoggerCategory.IModelCloneContext;\n\n/** The context for transforming a *source* Element to a *target* Element and remapping internal identifiers to the target iModel.\n * @beta\n */\nexport class IModelCloneContext extends IModelElementCloneContext {\n\n private _refTypesCache = new ECReferenceTypesCache();\n private _aspectRemapTable = new Map<Id64String, Id64String>();\n\n /** perform necessary initialization to use a clone context, namely caching the reference types in the source's schemas */\n public override async initialize() {\n await this._refTypesCache.initAllSchemasInIModel(this.sourceDb);\n }\n\n /** Clone the specified source Element into ElementProps for the target iModel.\n * @internal\n */\n public override cloneElement(sourceElement: Element, cloneOptions?: IModelJsNative.CloneElementOptions): ElementProps {\n const targetElementProps: ElementProps = this[\"_nativeContext\"].cloneElement(sourceElement.id, cloneOptions);\n // Ensure that all NavigationProperties in targetElementProps have a defined value so \"clearing\" changes will be part of the JSON used for update\n sourceElement.forEachProperty((propertyName: string, meta: PropertyMetaData) => {\n if ((meta.isNavigation) && (undefined === (sourceElement as any)[propertyName])) {\n (targetElementProps as any)[propertyName] = RelatedElement.none;\n }\n }, false); // exclude custom because C++ has already handled them\n if (this.isBetweenIModels) {\n // The native C++ cloneElement strips off federationGuid, want to put it back if transformation is between iModels\n targetElementProps.federationGuid = sourceElement.federationGuid;\n const targetElementCodeScopeType = this.targetDb.codeSpecs.getById(targetElementProps.code.spec).scopeType;\n if (CodeScopeSpec.Type.Repository === targetElementCodeScopeType && targetElementProps.code.scope !== IModel.rootSubjectId) {\n Logger.logWarning(loggerCategory, `Incorrect CodeScope '${targetElementCodeScopeType}' is set for target element ${targetElementProps.id}`);\n }\n }\n // unlike other references, code cannot be null. If it is null, use an empty code instead\n // this will be updated back later as the transformer resolves references\n if (targetElementProps.code.scope === Id64.invalid || targetElementProps.code.spec === Id64.invalid) {\n targetElementProps.code = Code.createEmpty();\n }\n const jsClass = this.sourceDb.getJsClass<typeof Element>(sourceElement.classFullName);\n jsClass[\"onCloned\"](this, sourceElement.toJSON(), targetElementProps);\n return targetElementProps;\n }\n\n /** Add a rule that remaps the specified source ElementAspect to the specified target ElementAspect. */\n public remapElementAspect(aspectSourceId: Id64String, aspectTargetId: Id64String): void {\n this._aspectRemapTable.set(aspectSourceId, aspectTargetId);\n }\n\n /** Remove a rule that remaps the specified source ElementAspect */\n public removeElementAspect(aspectSourceId: Id64String): void {\n this._aspectRemapTable.delete(aspectSourceId);\n }\n\n /** Look up a target AspectId from the source AspectId.\n * @returns the target AspectId or [Id64.invalid]($bentley) if a mapping not found.\n */\n public findTargetAspectId(sourceAspectId: Id64String): Id64String {\n return this._aspectRemapTable.get(sourceAspectId) ?? Id64.invalid;\n }\n\n /** Look up a target [EntityReference]($bentley) from a source [EntityReference]($bentley)\n * @returns the target CodeSpecId or a [EntityReference]($bentley) containing [Id64.invalid]($bentley) if a mapping is not found.\n */\n public findTargetEntityId(sourceEntityId: EntityReference): EntityReference {\n const [type, rawId] = EntityReferences.split(sourceEntityId);\n if (Id64.isValid(rawId)) {\n switch (type) {\n case ConcreteEntityTypes.Model: {\n const targetId = `m${this.findTargetElementId(rawId)}` as const;\n // Check if the model exists, `findTargetElementId` may have worked because the element exists when the model doesn't.\n // That can occur in the transformer since a submodeled element is imported before its submodel.\n if (EntityUnifier.exists(this.targetDb, { entityReference: targetId }))\n return targetId;\n break;\n }\n case ConcreteEntityTypes.Element:\n return `e${this.findTargetElementId(rawId)}`;\n case ConcreteEntityTypes.ElementAspect:\n return `a${this.findTargetAspectId(rawId)}`;\n case ConcreteEntityTypes.Relationship: {\n const makeGetConcreteEntityTypeSql = (property: string) => `\n CASE\n WHEN [${property}] IS (BisCore.ElementUniqueAspect) OR [${property}] IS (BisCore.ElementMultiAspect)\n THEN 'a'\n WHEN [${property}] IS (BisCore.Element)\n THEN 'e'\n WHEN [${property}] IS (BisCore.Model)\n THEN 'm'\n WHEN [${property}] IS (BisCore.CodeSpec)\n THEN 'c'\n WHEN [${property}] IS (BisCore.ElementRefersToElements) -- TODO: ElementDrivesElement still not handled by the transformer\n THEN 'r'\n ELSE 'error'\n END\n `;\n const relInSource = this.sourceDb.withPreparedStatement(\n `\n SELECT\n SourceECInstanceId,\n TargetECInstanceId,\n (${makeGetConcreteEntityTypeSql(\"SourceECClassId\")}) AS SourceType,\n (${makeGetConcreteEntityTypeSql(\"TargetECClassId\")}) AS TargetType\n FROM BisCore:ElementRefersToElements\n WHERE ECInstanceId=?\n `, (stmt) => {\n stmt.bindId(1, rawId);\n let status: DbResult;\n while ((status = stmt.step()) === DbResult.BE_SQLITE_ROW) {\n const sourceId = stmt.getValue(0).getId();\n const targetId = stmt.getValue(1).getId();\n const sourceType = stmt.getValue(2).getString() as ConcreteEntityTypes | \"error\";\n const targetType = stmt.getValue(3).getString() as ConcreteEntityTypes | \"error\";\n if (sourceType === \"error\" || targetType === \"error\")\n throw Error(\"relationship end had unknown root class\");\n return {\n sourceId: `${sourceType}${sourceId}`,\n targetId: `${targetType}${targetId}`,\n } as const;\n }\n if (status !== DbResult.BE_SQLITE_DONE)\n throw new IModelError(status, \"unexpected query failure\");\n return undefined;\n });\n if (relInSource === undefined)\n break;\n // just in case prevent recursion\n if (relInSource.sourceId === sourceEntityId || relInSource.targetId === sourceEntityId)\n throw Error(\"link table relationship end was resolved to itself. This should be impossible\");\n const relInTarget = {\n sourceId: this.findTargetEntityId(relInSource.sourceId),\n targetId: this.findTargetEntityId(relInSource.targetId),\n };\n // return a null\n if (!EntityReferences.isValid(relInTarget.sourceId) || !EntityReferences.isValid(relInTarget.targetId))\n break;\n const relInTargetId = this.targetDb.withPreparedStatement(\n `\n SELECT ECInstanceId\n FROM BisCore:ElementRefersToElements\n WHERE SourceECInstanceId=?\n AND TargetECInstanceId=?\n `, (stmt) => {\n stmt.bindId(1, EntityReferences.toId64(relInTarget.sourceId));\n stmt.bindId(2, EntityReferences.toId64(relInTarget.targetId));\n const status: DbResult = stmt.step();\n if (status === DbResult.BE_SQLITE_ROW)\n return stmt.getValue(0).getId();\n if (status !== DbResult.BE_SQLITE_DONE)\n throw new IModelError(status, \"unexpected query failure\");\n return Id64.invalid;\n });\n return `r${relInTargetId}`;\n }\n }\n }\n return `${type}${Id64.invalid}`;\n }\n\n /** Clone the specified source Element into ElementProps for the target iModel.\n * @internal\n */\n public cloneElementAspect(sourceElementAspect: ElementAspect): ElementAspectProps {\n const targetElementAspectProps: ElementAspectProps = sourceElementAspect.toJSON();\n targetElementAspectProps.id = undefined;\n sourceElementAspect.forEachProperty((propertyName, propertyMetaData) => {\n if (propertyMetaData.isNavigation) {\n const sourceNavProp: RelatedElementProps | undefined = sourceElementAspect.asAny[propertyName];\n if (sourceNavProp?.id) {\n const navPropRefType = this._refTypesCache.getNavPropRefType(\n sourceElementAspect.schemaName,\n sourceElementAspect.className,\n propertyName\n );\n assert(navPropRefType !== undefined,`nav prop ref type for '${propertyName}' was not in the cache, this is a bug.`);\n const targetEntityReference = this.findTargetEntityId(EntityReferences.fromEntityType(sourceNavProp.id, navPropRefType));\n const targetEntityId = EntityReferences.toId64(targetEntityReference);\n // spread the property in case toJSON did not deep-clone\n (targetElementAspectProps as any)[propertyName] = { ...(targetElementAspectProps as any)[propertyName], id: targetEntityId };\n }\n } else if ((PrimitiveTypeCode.Long === propertyMetaData.primitiveType) && (\"Id\" === propertyMetaData.extendedType)) {\n (targetElementAspectProps as any)[propertyName] = this.findTargetElementId(sourceElementAspect.asAny[propertyName]);\n }\n });\n return targetElementAspectProps;\n }\n\n private static aspectRemapTableName = \"AspectIdRemaps\";\n\n public override saveStateToDb(db: SQLiteDb): void {\n super.saveStateToDb(db);\n if (DbResult.BE_SQLITE_DONE !== db.executeSQL(\n `CREATE TABLE ${IModelCloneContext.aspectRemapTableName} (Source INTEGER, Target INTEGER)`\n ))\n throw Error(\"Failed to create the aspect remap table in the state database\");\n db.saveChanges();\n db.withPreparedSqliteStatement(\n `INSERT INTO ${IModelCloneContext.aspectRemapTableName} (Source, Target) VALUES (?, ?)`,\n (stmt) => {\n for (const [source, target] of this._aspectRemapTable) {\n stmt.reset();\n stmt.bindId(1, source);\n stmt.bindId(2, target);\n if (DbResult.BE_SQLITE_DONE !== stmt.step())\n throw Error(\"Failed to insert aspect remapping into the state database\");\n }\n });\n }\n\n public override loadStateFromDb(db: SQLiteDb): void {\n super.loadStateFromDb(db);\n // FIXME: test this\n db.withSqliteStatement(`SELECT Source, Target FROM ${IModelCloneContext.aspectRemapTableName}`, (stmt) => {\n let status = DbResult.BE_SQLITE_ERROR;\n while ((status = stmt.step()) === DbResult.BE_SQLITE_ROW) {\n const source = stmt.getValue(0).getId();\n const target = stmt.getValue(1).getId();\n this._aspectRemapTable.set(source, target);\n }\n assert(status === DbResult.BE_SQLITE_DONE);\n });\n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,IAAI,IAAI,CAAC,iBAAiB,EAAE;gBACrD,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;gBACvB,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;gBACvB,IAAI,uBAAQ,CAAC,cAAc,KAAK,IAAI,CAAC,IAAI,EAAE;oBACzC,MAAM,KAAK,CACT,2DAA2D,CAC5D,CAAC;aACL;QACH,CAAC,CACF,CAAC;IACJ,CAAC;IAEe,eAAe,CAAC,EAAY;QAC1C,KAAK,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;QAC1B,mBAAmB;QACnB,EAAE,CAAC,mBAAmB,CACpB,8BAA8B,kBAAkB,CAAC,oBAAoB,EAAE,EACvE,CAAC,IAAI,EAAE,EAAE;YACP,IAAI,MAAM,GAAG,uBAAQ,CAAC,eAAe,CAAC;YACtC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,uBAAQ,CAAC,aAAa,EAAE;gBACxD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;gBACxC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;gBACxC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;aAC5C;YACD,MAAM,CAAC,MAAM,KAAK,uBAAQ,CAAC,cAAc,CAAC,CAAC;QAC7C,CAAC,CACF,CAAC;IACJ,CAAC;;AAhSH,gDAiSC;AA9CgB,uCAAoB,GAAG,gBAAgB,AAAnB,CAAoB","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module iModels\n */\nimport * as assert from \"assert\";\nimport { DbResult, Id64, Id64String, Logger } from \"@itwin/core-bentley\";\nimport {\n Code,\n CodeScopeSpec,\n ConcreteEntityTypes,\n ElementAspectProps,\n ElementProps,\n EntityReference,\n IModel,\n IModelError,\n PrimitiveTypeCode,\n PropertyMetaData,\n RelatedElement,\n RelatedElementProps,\n} from \"@itwin/core-common\";\nimport {\n Element,\n ElementAspect,\n EntityReferences,\n IModelElementCloneContext,\n IModelJsNative,\n SQLiteDb,\n} from \"@itwin/core-backend\";\nimport { ECReferenceTypesCache } from \"./ECReferenceTypesCache\";\nimport { EntityUnifier } from \"./EntityUnifier\";\nimport { TransformerLoggerCategory } from \"./TransformerLoggerCategory\";\n\nconst loggerCategory: string = TransformerLoggerCategory.IModelCloneContext;\n\n/** The context for transforming a *source* Element to a *target* Element and remapping internal identifiers to the target iModel.\n * @beta\n */\nexport class IModelCloneContext extends IModelElementCloneContext {\n private _refTypesCache = new ECReferenceTypesCache();\n private _aspectRemapTable = new Map<Id64String, Id64String>();\n\n /** perform necessary initialization to use a clone context, namely caching the reference types in the source's schemas */\n public override async initialize() {\n await this._refTypesCache.initAllSchemasInIModel(this.sourceDb);\n }\n\n /** Clone the specified source Element into ElementProps for the target iModel.\n * @internal\n */\n public override cloneElement(\n sourceElement: Element,\n cloneOptions?: IModelJsNative.CloneElementOptions\n ): ElementProps {\n const targetElementProps: ElementProps = this[\n \"_nativeContext\"\n ].cloneElement(sourceElement.id, cloneOptions);\n // Ensure that all NavigationProperties in targetElementProps have a defined value so \"clearing\" changes will be part of the JSON used for update\n sourceElement.forEachProperty(\n (propertyName: string, meta: PropertyMetaData) => {\n if (\n meta.isNavigation &&\n undefined === (sourceElement as any)[propertyName]\n ) {\n (targetElementProps as any)[propertyName] = RelatedElement.none;\n }\n },\n false\n ); // exclude custom because C++ has already handled them\n if (this.isBetweenIModels) {\n // The native C++ cloneElement strips off federationGuid, want to put it back if transformation is between iModels\n targetElementProps.federationGuid = sourceElement.federationGuid;\n const targetElementCodeScopeType = this.targetDb.codeSpecs.getById(\n targetElementProps.code.spec\n ).scopeType;\n if (\n CodeScopeSpec.Type.Repository === targetElementCodeScopeType &&\n targetElementProps.code.scope !== IModel.rootSubjectId\n ) {\n Logger.logWarning(\n loggerCategory,\n `Incorrect CodeScope '${targetElementCodeScopeType}' is set for target element ${targetElementProps.id}`\n );\n }\n }\n // unlike other references, code cannot be null. If it is null, use an empty code instead\n // this will be updated back later as the transformer resolves references\n if (\n targetElementProps.code.scope === Id64.invalid ||\n targetElementProps.code.spec === Id64.invalid\n ) {\n targetElementProps.code = Code.createEmpty();\n }\n const jsClass = this.sourceDb.getJsClass<typeof Element>(\n sourceElement.classFullName\n );\n jsClass[\"onCloned\"](this, sourceElement.toJSON(), targetElementProps);\n return targetElementProps;\n }\n\n /** Add a rule that remaps the specified source ElementAspect to the specified target ElementAspect. */\n public remapElementAspect(\n aspectSourceId: Id64String,\n aspectTargetId: Id64String\n ): void {\n this._aspectRemapTable.set(aspectSourceId, aspectTargetId);\n }\n\n /** Remove a rule that remaps the specified source ElementAspect */\n public removeElementAspect(aspectSourceId: Id64String): void {\n this._aspectRemapTable.delete(aspectSourceId);\n }\n\n /** Look up a target AspectId from the source AspectId.\n * @returns the target AspectId or [Id64.invalid]($bentley) if a mapping not found.\n */\n public findTargetAspectId(sourceAspectId: Id64String): Id64String {\n return this._aspectRemapTable.get(sourceAspectId) ?? Id64.invalid;\n }\n\n /** Look up a target [EntityReference]($bentley) from a source [EntityReference]($bentley)\n * @returns the target CodeSpecId or a [EntityReference]($bentley) containing [Id64.invalid]($bentley) if a mapping is not found.\n */\n public findTargetEntityId(sourceEntityId: EntityReference): EntityReference {\n const [type, rawId] = EntityReferences.split(sourceEntityId);\n if (Id64.isValid(rawId)) {\n switch (type) {\n case ConcreteEntityTypes.Model: {\n const targetId = `m${this.findTargetElementId(rawId)}` as const;\n // Check if the model exists, `findTargetElementId` may have worked because the element exists when the model doesn't.\n // That can occur in the transformer since a submodeled element is imported before its submodel.\n if (\n EntityUnifier.exists(this.targetDb, { entityReference: targetId })\n )\n return targetId;\n break;\n }\n case ConcreteEntityTypes.Element:\n return `e${this.findTargetElementId(rawId)}`;\n case ConcreteEntityTypes.ElementAspect:\n return `a${this.findTargetAspectId(rawId)}`;\n case ConcreteEntityTypes.Relationship: {\n const makeGetConcreteEntityTypeSql = (property: string) => `\n CASE\n WHEN [${property}] IS (BisCore.ElementUniqueAspect) OR [${property}] IS (BisCore.ElementMultiAspect)\n THEN 'a'\n WHEN [${property}] IS (BisCore.Element)\n THEN 'e'\n WHEN [${property}] IS (BisCore.Model)\n THEN 'm'\n WHEN [${property}] IS (BisCore.CodeSpec)\n THEN 'c'\n WHEN [${property}] IS (BisCore.ElementRefersToElements) -- TODO: ElementDrivesElement still not handled by the transformer\n THEN 'r'\n ELSE 'error'\n END\n `;\n const relInSource = this.sourceDb.withPreparedStatement(\n `\n SELECT\n SourceECInstanceId,\n TargetECInstanceId,\n (${makeGetConcreteEntityTypeSql(\n \"SourceECClassId\"\n )}) AS SourceType,\n (${makeGetConcreteEntityTypeSql(\"TargetECClassId\")}) AS TargetType\n FROM BisCore:ElementRefersToElements\n WHERE ECInstanceId=?\n `,\n (stmt) => {\n stmt.bindId(1, rawId);\n let status: DbResult;\n while ((status = stmt.step()) === DbResult.BE_SQLITE_ROW) {\n const sourceId = stmt.getValue(0).getId();\n const targetId = stmt.getValue(1).getId();\n const sourceType = stmt.getValue(2).getString() as\n | ConcreteEntityTypes\n | \"error\";\n const targetType = stmt.getValue(3).getString() as\n | ConcreteEntityTypes\n | \"error\";\n if (sourceType === \"error\" || targetType === \"error\")\n throw Error(\"relationship end had unknown root class\");\n return {\n sourceId: `${sourceType}${sourceId}`,\n targetId: `${targetType}${targetId}`,\n } as const;\n }\n if (status !== DbResult.BE_SQLITE_DONE)\n throw new IModelError(status, \"unexpected query failure\");\n return undefined;\n }\n );\n if (relInSource === undefined) break;\n // just in case prevent recursion\n if (\n relInSource.sourceId === sourceEntityId ||\n relInSource.targetId === sourceEntityId\n )\n throw Error(\n \"link table relationship end was resolved to itself. This should be impossible\"\n );\n const relInTarget = {\n sourceId: this.findTargetEntityId(relInSource.sourceId),\n targetId: this.findTargetEntityId(relInSource.targetId),\n };\n // return a null\n if (\n !EntityReferences.isValid(relInTarget.sourceId) ||\n !EntityReferences.isValid(relInTarget.targetId)\n )\n break;\n const relInTargetId = this.targetDb.withPreparedStatement(\n `\n SELECT ECInstanceId\n FROM BisCore:ElementRefersToElements\n WHERE SourceECInstanceId=?\n AND TargetECInstanceId=?\n `,\n (stmt) => {\n stmt.bindId(1, EntityReferences.toId64(relInTarget.sourceId));\n stmt.bindId(2, EntityReferences.toId64(relInTarget.targetId));\n const status: DbResult = stmt.step();\n if (status === DbResult.BE_SQLITE_ROW)\n return stmt.getValue(0).getId();\n if (status !== DbResult.BE_SQLITE_DONE)\n throw new IModelError(status, \"unexpected query failure\");\n return Id64.invalid;\n }\n );\n return `r${relInTargetId}`;\n }\n }\n }\n return `${type}${Id64.invalid}`;\n }\n\n /** Clone the specified source Element into ElementProps for the target iModel.\n * @internal\n */\n public cloneElementAspect(\n sourceElementAspect: ElementAspect\n ): ElementAspectProps {\n const targetElementAspectProps: ElementAspectProps =\n sourceElementAspect.toJSON();\n targetElementAspectProps.id = undefined;\n sourceElementAspect.forEachProperty((propertyName, propertyMetaData) => {\n if (propertyMetaData.isNavigation) {\n const sourceNavProp: RelatedElementProps | undefined =\n sourceElementAspect.asAny[propertyName];\n if (sourceNavProp?.id) {\n const navPropRefType = this._refTypesCache.getNavPropRefType(\n sourceElementAspect.schemaName,\n sourceElementAspect.className,\n propertyName\n );\n assert(\n navPropRefType !== undefined,\n `nav prop ref type for '${propertyName}' was not in the cache, this is a bug.`\n );\n const targetEntityReference = this.findTargetEntityId(\n EntityReferences.fromEntityType(sourceNavProp.id, navPropRefType)\n );\n const targetEntityId = EntityReferences.toId64(targetEntityReference);\n // spread the property in case toJSON did not deep-clone\n (targetElementAspectProps as any)[propertyName] = {\n ...(targetElementAspectProps as any)[propertyName],\n id: targetEntityId,\n };\n }\n } else if (\n PrimitiveTypeCode.Long === propertyMetaData.primitiveType &&\n \"Id\" === propertyMetaData.extendedType\n ) {\n (targetElementAspectProps as any)[propertyName] =\n this.findTargetElementId(sourceElementAspect.asAny[propertyName]);\n }\n });\n return targetElementAspectProps;\n }\n\n private static aspectRemapTableName = \"AspectIdRemaps\";\n\n public override saveStateToDb(db: SQLiteDb): void {\n super.saveStateToDb(db);\n if (\n DbResult.BE_SQLITE_DONE !==\n db.executeSQL(\n `CREATE TABLE ${IModelCloneContext.aspectRemapTableName} (Source INTEGER, Target INTEGER)`\n )\n )\n throw Error(\n \"Failed to create the aspect remap table in the state database\"\n );\n db.saveChanges();\n db.withPreparedSqliteStatement(\n `INSERT INTO ${IModelCloneContext.aspectRemapTableName} (Source, Target) VALUES (?, ?)`,\n (stmt) => {\n for (const [source, target] of this._aspectRemapTable) {\n stmt.reset();\n stmt.bindId(1, source);\n stmt.bindId(2, target);\n if (DbResult.BE_SQLITE_DONE !== stmt.step())\n throw Error(\n \"Failed to insert aspect remapping into the state database\"\n );\n }\n }\n );\n }\n\n public override loadStateFromDb(db: SQLiteDb): void {\n super.loadStateFromDb(db);\n // FIXME: test this\n db.withSqliteStatement(\n `SELECT Source, Target FROM ${IModelCloneContext.aspectRemapTableName}`,\n (stmt) => {\n let status = DbResult.BE_SQLITE_ERROR;\n while ((status = stmt.step()) === DbResult.BE_SQLITE_ROW) {\n const source = stmt.getValue(0).getId();\n const target = stmt.getValue(1).getId();\n this._aspectRemapTable.set(source, target);\n }\n assert(status === DbResult.BE_SQLITE_DONE);\n }\n );\n }\n}\n"]}
|