@itwin/imodel-transformer 0.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.
Files changed (43) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +33 -0
  3. package/lib/cjs/ECReferenceTypesCache.d.ts +37 -0
  4. package/lib/cjs/ECReferenceTypesCache.d.ts.map +1 -0
  5. package/lib/cjs/ECReferenceTypesCache.js +180 -0
  6. package/lib/cjs/ECReferenceTypesCache.js.map +1 -0
  7. package/lib/cjs/EntityMap.d.ts +26 -0
  8. package/lib/cjs/EntityMap.d.ts.map +1 -0
  9. package/lib/cjs/EntityMap.js +55 -0
  10. package/lib/cjs/EntityMap.js.map +1 -0
  11. package/lib/cjs/EntityUnifier.d.ts +16 -0
  12. package/lib/cjs/EntityUnifier.d.ts.map +1 -0
  13. package/lib/cjs/EntityUnifier.js +72 -0
  14. package/lib/cjs/EntityUnifier.js.map +1 -0
  15. package/lib/cjs/IModelCloneContext.d.ts +32 -0
  16. package/lib/cjs/IModelCloneContext.d.ts.map +1 -0
  17. package/lib/cjs/IModelCloneContext.js +195 -0
  18. package/lib/cjs/IModelCloneContext.js.map +1 -0
  19. package/lib/cjs/IModelExporter.d.ts +353 -0
  20. package/lib/cjs/IModelExporter.d.ts.map +1 -0
  21. package/lib/cjs/IModelExporter.js +804 -0
  22. package/lib/cjs/IModelExporter.js.map +1 -0
  23. package/lib/cjs/IModelImporter.d.ts +230 -0
  24. package/lib/cjs/IModelImporter.d.ts.map +1 -0
  25. package/lib/cjs/IModelImporter.js +591 -0
  26. package/lib/cjs/IModelImporter.js.map +1 -0
  27. package/lib/cjs/IModelTransformer.d.ts +499 -0
  28. package/lib/cjs/IModelTransformer.d.ts.map +1 -0
  29. package/lib/cjs/IModelTransformer.js +1357 -0
  30. package/lib/cjs/IModelTransformer.js.map +1 -0
  31. package/lib/cjs/PendingReferenceMap.d.ts +35 -0
  32. package/lib/cjs/PendingReferenceMap.d.ts.map +1 -0
  33. package/lib/cjs/PendingReferenceMap.js +81 -0
  34. package/lib/cjs/PendingReferenceMap.js.map +1 -0
  35. package/lib/cjs/TransformerLoggerCategory.d.ts +23 -0
  36. package/lib/cjs/TransformerLoggerCategory.d.ts.map +1 -0
  37. package/lib/cjs/TransformerLoggerCategory.js +31 -0
  38. package/lib/cjs/TransformerLoggerCategory.js.map +1 -0
  39. package/lib/cjs/transformer.d.ts +25 -0
  40. package/lib/cjs/transformer.d.ts.map +1 -0
  41. package/lib/cjs/transformer.js +77 -0
  42. package/lib/cjs/transformer.js.map +1 -0
  43. package/package.json +120 -0
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IModelCloneContext = void 0;
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
+ *--------------------------------------------------------------------------------------------*/
8
+ /** @packageDocumentation
9
+ * @module iModels
10
+ */
11
+ const assert = require("assert");
12
+ const core_bentley_1 = require("@itwin/core-bentley");
13
+ const core_common_1 = require("@itwin/core-common");
14
+ const core_backend_1 = require("@itwin/core-backend");
15
+ const ECReferenceTypesCache_1 = require("./ECReferenceTypesCache");
16
+ const EntityUnifier_1 = require("./EntityUnifier");
17
+ /** The context for transforming a *source* Element to a *target* Element and remapping internal identifiers to the target iModel.
18
+ * @beta
19
+ */
20
+ class IModelCloneContext extends core_backend_1.IModelElementCloneContext {
21
+ constructor() {
22
+ super(...arguments);
23
+ this._refTypesCache = new ECReferenceTypesCache_1.ECReferenceTypesCache();
24
+ this._aspectRemapTable = new Map();
25
+ }
26
+ /** perform necessary initialization to use a clone context, namely caching the reference types in the source's schemas */
27
+ async initialize() {
28
+ await this._refTypesCache.initAllSchemasInIModel(this.sourceDb);
29
+ }
30
+ /** Add a rule that remaps the specified source ElementAspect to the specified target ElementAspect. */
31
+ remapElementAspect(aspectSourceId, aspectTargetId) {
32
+ this._aspectRemapTable.set(aspectSourceId, aspectTargetId);
33
+ }
34
+ /** Remove a rule that remaps the specified source ElementAspect */
35
+ removeElementAspect(aspectSourceId) {
36
+ this._aspectRemapTable.delete(aspectSourceId);
37
+ }
38
+ /** Look up a target AspectId from the source AspectId.
39
+ * @returns the target AspectId or [Id64.invalid]($bentley) if a mapping not found.
40
+ */
41
+ findTargetAspectId(sourceAspectId) {
42
+ var _a;
43
+ return (_a = this._aspectRemapTable.get(sourceAspectId)) !== null && _a !== void 0 ? _a : core_bentley_1.Id64.invalid;
44
+ }
45
+ /** Look up a target [EntityReference]($bentley) from a source [EntityReference]($bentley)
46
+ * @returns the target CodeSpecId or a [EntityReference]($bentley) containing [Id64.invalid]($bentley) if a mapping is not found.
47
+ */
48
+ findTargetEntityId(sourceEntityId) {
49
+ const [type, rawId] = core_backend_1.EntityReferences.split(sourceEntityId);
50
+ if (core_bentley_1.Id64.isValid(rawId)) {
51
+ switch (type) {
52
+ case core_common_1.ConcreteEntityTypes.Model: {
53
+ const targetId = `m${this.findTargetElementId(rawId)}`;
54
+ // Check if the model exists, `findTargetElementId` may have worked because the element exists when the model doesn't.
55
+ // That can occur in the transformer since a submodeled element is imported before its submodel.
56
+ if (EntityUnifier_1.EntityUnifier.exists(this.targetDb, { entityReference: targetId }))
57
+ return targetId;
58
+ break;
59
+ }
60
+ case core_common_1.ConcreteEntityTypes.Element:
61
+ return `e${this.findTargetElementId(rawId)}`;
62
+ case core_common_1.ConcreteEntityTypes.ElementAspect:
63
+ return `a${this.findTargetAspectId(rawId)}`;
64
+ case core_common_1.ConcreteEntityTypes.Relationship: {
65
+ const makeGetConcreteEntityTypeSql = (property) => `
66
+ CASE
67
+ WHEN [${property}] IS (BisCore.ElementUniqueAspect) OR [${property}] IS (BisCore.ElementMultiAspect)
68
+ THEN 'a'
69
+ WHEN [${property}] IS (BisCore.Element)
70
+ THEN 'e'
71
+ WHEN [${property}] IS (BisCore.Model)
72
+ THEN 'm'
73
+ WHEN [${property}] IS (BisCore.CodeSpec)
74
+ THEN 'c'
75
+ WHEN [${property}] IS (BisCore.ElementRefersToElements) -- TODO: ElementDrivesElement still not handled by the transformer
76
+ THEN 'r'
77
+ ELSE 'error'
78
+ END
79
+ `;
80
+ const relInSource = this.sourceDb.withPreparedStatement(`
81
+ SELECT
82
+ SourceECInstanceId,
83
+ TargetECInstanceId,
84
+ (${makeGetConcreteEntityTypeSql("SourceECClassId")}) AS SourceType,
85
+ (${makeGetConcreteEntityTypeSql("TargetECClassId")}) AS TargetType
86
+ FROM BisCore:ElementRefersToElements
87
+ WHERE ECInstanceId=?
88
+ `, (stmt) => {
89
+ stmt.bindId(1, rawId);
90
+ let status;
91
+ while ((status = stmt.step()) === core_bentley_1.DbResult.BE_SQLITE_ROW) {
92
+ const sourceId = stmt.getValue(0).getId();
93
+ const targetId = stmt.getValue(1).getId();
94
+ const sourceType = stmt.getValue(2).getString();
95
+ const targetType = stmt.getValue(3).getString();
96
+ if (sourceType === "error" || targetType === "error")
97
+ throw Error("relationship end had unknown root class");
98
+ return {
99
+ sourceId: `${sourceType}${sourceId}`,
100
+ targetId: `${targetType}${targetId}`,
101
+ };
102
+ }
103
+ if (status !== core_bentley_1.DbResult.BE_SQLITE_DONE)
104
+ throw new core_common_1.IModelError(status, "unexpected query failure");
105
+ return undefined;
106
+ });
107
+ if (relInSource === undefined)
108
+ break;
109
+ // just in case prevent recursion
110
+ if (relInSource.sourceId === sourceEntityId || relInSource.targetId === sourceEntityId)
111
+ throw Error("link table relationship end was resolved to itself. This should be impossible");
112
+ const relInTarget = {
113
+ sourceId: this.findTargetEntityId(relInSource.sourceId),
114
+ targetId: this.findTargetEntityId(relInSource.targetId),
115
+ };
116
+ // return a null
117
+ if (core_bentley_1.Id64.isInvalid(relInTarget.sourceId) || core_bentley_1.Id64.isInvalid(relInTarget.targetId))
118
+ break;
119
+ const relInTargetId = this.sourceDb.withPreparedStatement(`
120
+ SELECT ECInstanceId
121
+ FROM BisCore:ElementRefersToElements
122
+ WHERE SourceECInstanceId=?
123
+ AND TargetECInstanceId=?
124
+ `, (stmt) => {
125
+ stmt.bindId(1, core_backend_1.EntityReferences.toId64(relInTarget.sourceId));
126
+ stmt.bindId(2, core_backend_1.EntityReferences.toId64(relInTarget.targetId));
127
+ let status;
128
+ if ((status = stmt.step()) === core_bentley_1.DbResult.BE_SQLITE_ROW)
129
+ return stmt.getValue(0).getId();
130
+ if (status !== core_bentley_1.DbResult.BE_SQLITE_DONE)
131
+ throw new core_common_1.IModelError(status, "unexpected query failure");
132
+ return core_bentley_1.Id64.invalid;
133
+ });
134
+ return `r${relInTargetId}`;
135
+ }
136
+ }
137
+ }
138
+ return `${type}${core_bentley_1.Id64.invalid}`;
139
+ }
140
+ /** Clone the specified source Element into ElementProps for the target iModel.
141
+ * @internal
142
+ */
143
+ cloneElementAspect(sourceElementAspect) {
144
+ const targetElementAspectProps = sourceElementAspect.toJSON();
145
+ targetElementAspectProps.id = undefined;
146
+ sourceElementAspect.forEachProperty((propertyName, propertyMetaData) => {
147
+ if (propertyMetaData.isNavigation) {
148
+ const sourceNavProp = sourceElementAspect.asAny[propertyName];
149
+ if (sourceNavProp === null || sourceNavProp === void 0 ? void 0 : sourceNavProp.id) {
150
+ const navPropRefType = this._refTypesCache.getNavPropRefType(sourceElementAspect.schemaName, sourceElementAspect.className, propertyName);
151
+ assert(navPropRefType !== undefined, `nav prop ref type for '${propertyName}' was not in the cache, this is a bug.`);
152
+ const targetEntityReference = this.findTargetEntityId(core_backend_1.EntityReferences.fromEntityType(sourceNavProp.id, navPropRefType));
153
+ const targetEntityId = core_backend_1.EntityReferences.toId64(targetEntityReference);
154
+ // spread the property in case toJSON did not deep-clone
155
+ targetElementAspectProps[propertyName] = { ...targetElementAspectProps[propertyName], id: targetEntityId };
156
+ }
157
+ }
158
+ else if ((core_common_1.PrimitiveTypeCode.Long === propertyMetaData.primitiveType) && ("Id" === propertyMetaData.extendedType)) {
159
+ targetElementAspectProps[propertyName] = this.findTargetElementId(sourceElementAspect.asAny[propertyName]);
160
+ }
161
+ });
162
+ return targetElementAspectProps;
163
+ }
164
+ saveStateToDb(db) {
165
+ super.saveStateToDb(db);
166
+ if (core_bentley_1.DbResult.BE_SQLITE_DONE !== db.executeSQL(`CREATE TABLE ${IModelCloneContext.aspectRemapTableName} (Source INTEGER, Target INTEGER)`))
167
+ throw Error("Failed to create the aspect remap table in the state database");
168
+ db.saveChanges();
169
+ db.withPreparedSqliteStatement(`INSERT INTO ${IModelCloneContext.aspectRemapTableName} (Source, Target) VALUES (?, ?)`, (stmt) => {
170
+ for (const [source, target] of this._aspectRemapTable) {
171
+ stmt.reset();
172
+ stmt.bindId(1, source);
173
+ stmt.bindId(2, target);
174
+ if (core_bentley_1.DbResult.BE_SQLITE_DONE !== stmt.step())
175
+ throw Error("Failed to insert aspect remapping into the state database");
176
+ }
177
+ });
178
+ }
179
+ loadStateFromDb(db) {
180
+ super.loadStateFromDb(db);
181
+ // FIXME: test this
182
+ db.withSqliteStatement(`SELECT Source, Target FROM ${IModelCloneContext.aspectRemapTableName}`, (stmt) => {
183
+ let status = core_bentley_1.DbResult.BE_SQLITE_ERROR;
184
+ while ((status = stmt.step()) === core_bentley_1.DbResult.BE_SQLITE_ROW) {
185
+ const source = stmt.getValue(0).getId();
186
+ const target = stmt.getValue(1).getId();
187
+ this._aspectRemapTable.set(source, target);
188
+ }
189
+ assert(status === core_bentley_1.DbResult.BE_SQLITE_DONE);
190
+ });
191
+ }
192
+ }
193
+ exports.IModelCloneContext = IModelCloneContext;
194
+ IModelCloneContext.aspectRemapTableName = "AspectIdRemaps";
195
+ //# sourceMappingURL=IModelCloneContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IModelCloneContext.js","sourceRoot":"","sources":["../../src/IModelCloneContext.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,iCAAiC;AACjC,sDAAiE;AACjE,oDAG4B;AAC5B,sDAE6B;AAC7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AY;QAC1C,KAAK,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;QAC1B,mBAAmB;QACnB,EAAE,CAAC,mBAAmB,CAAC,8BAA8B,kBAAkB,CAAC,oBAAoB,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;YACvG,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,CAAC,CAAC;IACL,CAAC;;AA5LH,gDA6LC;AAnCgB,uCAAoB,GAAG,gBAAgB,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 * as assert from \"assert\";\nimport { DbResult, Id64, Id64String } from \"@itwin/core-bentley\";\nimport {\n ConcreteEntityTypes, ElementAspectProps, EntityReference, IModelError,\n PrimitiveTypeCode, RelatedElementProps,\n} from \"@itwin/core-common\";\nimport {\n ElementAspect, EntityReferences, IModelElementCloneContext, SQLiteDb,\n} from \"@itwin/core-backend\";\nimport { ECReferenceTypesCache } from \"./ECReferenceTypesCache\";\nimport { EntityUnifier } from \"./EntityUnifier\";\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\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 private _aspectRemapTable = new Map<Id64String, Id64String>();\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 (Id64.isInvalid(relInTarget.sourceId) || Id64.isInvalid(relInTarget.targetId))\n break;\n const relInTargetId = this.sourceDb.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 let status: DbResult;\n if ((status = stmt.step()) === 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 }\n}\n"]}
@@ -0,0 +1,353 @@
1
+ /** @packageDocumentation
2
+ * @module iModels
3
+ */
4
+ import { AccessToken, CompressedId64Set, Id64String } from "@itwin/core-bentley";
5
+ import { Schema, SchemaKey } from "@itwin/ecschema-metadata";
6
+ import { CodeSpec, FontProps } from "@itwin/core-common";
7
+ import { BriefcaseDb, Element, ElementAspect, ElementMultiAspect, ElementUniqueAspect, IModelDb, IModelJsNative, Model, Relationship } from "@itwin/core-backend";
8
+ /**
9
+ * @beta
10
+ * The (optional) result of [[IModelExportHandler.onExportSchema]]
11
+ */
12
+ export interface ExportSchemaResult {
13
+ /** set this property to notify subclasses where you wrote a schema for later import */
14
+ schemaPath?: string;
15
+ }
16
+ /** Handles the events generated by IModelExporter.
17
+ * @note Change information is available when `IModelExportHandler` methods are invoked via [IModelExporter.exportChanges]($transformer), but not available when invoked via [IModelExporter.exportAll]($transformer).
18
+ * @note The handler is intended to be owned by (registered with) and called from the IModelExporter exclusively
19
+ * @see [iModel Transformation and Data Exchange]($docs/learning/transformer/index.md), [IModelExporter]($transformer)
20
+ * @beta
21
+ */
22
+ export declare abstract class IModelExportHandler {
23
+ /** If `true` is returned, then the CodeSpec will be exported.
24
+ * @note This method can optionally be overridden to exclude an individual CodeSpec from the export. The base implementation always returns `true`.
25
+ */
26
+ shouldExportCodeSpec(_codeSpec: CodeSpec): boolean;
27
+ /** Called when a CodeSpec should be exported.
28
+ * @param codeSpec The CodeSpec to export
29
+ * @param isUpdate If defined, then `true` indicates an UPDATE operation while `false` indicates an INSERT operation. If not defined, then INSERT vs. UPDATE is not known.
30
+ * @note This should be overridden to actually do the export.
31
+ */
32
+ onExportCodeSpec(_codeSpec: CodeSpec, _isUpdate: boolean | undefined): void;
33
+ /** Called when a font should be exported.
34
+ * @param font The font to export
35
+ * @param isUpdate If defined, then `true` indicates an UPDATE operation while `false` indicates an INSERT operation. If not defined, then INSERT vs. UPDATE is not known.
36
+ * @note This should be overridden to actually do the export.
37
+ */
38
+ onExportFont(_font: FontProps, _isUpdate: boolean | undefined): void;
39
+ /** Called when a model should be exported.
40
+ * @param model The model to export
41
+ * @param isUpdate If defined, then `true` indicates an UPDATE operation while `false` indicates an INSERT operation. If not defined, then INSERT vs. UPDATE is not known.
42
+ * @note This should be overridden to actually do the export.
43
+ */
44
+ onExportModel(_model: Model, _isUpdate: boolean | undefined): void;
45
+ /** Called when a model should be deleted. */
46
+ onDeleteModel(_modelId: Id64String): void;
47
+ /** If `true` is returned, then the element will be exported.
48
+ * @note This method can optionally be overridden to exclude an individual Element (and its children and ElementAspects) from the export. The base implementation always returns `true`.
49
+ */
50
+ shouldExportElement(_element: Element): boolean;
51
+ /** Called when an element should be exported.
52
+ * @param element The element to export
53
+ * @param isUpdate If defined, then `true` indicates an UPDATE operation while `false` indicates an INSERT operation. If not defined, then INSERT vs. UPDATE is not known.
54
+ * @note This should be overridden to actually do the export.
55
+ */
56
+ onExportElement(_element: Element, _isUpdate: boolean | undefined): void;
57
+ /**
58
+ * Do any asynchronous actions before exporting an element
59
+ * @note Do not implement this handler manually, it is internal, it will be removed.
60
+ * This will become a part of onExportElement once that becomes async
61
+ * @internal
62
+ */
63
+ preExportElement(_element: Element): Promise<void>;
64
+ /** Called when an element should be deleted. */
65
+ onDeleteElement(_elementId: Id64String): void;
66
+ /** If `true` is returned, then the ElementAspect will be exported.
67
+ * @note This method can optionally be overridden to exclude an individual ElementAspect from the export. The base implementation always returns `true`.
68
+ */
69
+ shouldExportElementAspect(_aspect: ElementAspect): boolean;
70
+ /** Called when an ElementUniqueAspect should be exported.
71
+ * @param aspect The ElementUniqueAspect to export
72
+ * @param isUpdate If defined, then `true` indicates an UPDATE operation while `false` indicates an INSERT operation. If not defined, then INSERT vs. UPDATE is not known.
73
+ * @note This should be overridden to actually do the export.
74
+ */
75
+ onExportElementUniqueAspect(_aspect: ElementUniqueAspect, _isUpdate: boolean | undefined): void;
76
+ /** Called when ElementMultiAspects should be exported.
77
+ * @note This should be overridden to actually do the export.
78
+ */
79
+ onExportElementMultiAspects(_aspects: ElementMultiAspect[]): void;
80
+ /** If `true` is returned, then the relationship will be exported.
81
+ * @note This method can optionally be overridden to exclude an individual CodeSpec from the export. The base implementation always returns `true`.
82
+ */
83
+ shouldExportRelationship(_relationship: Relationship): boolean;
84
+ /** Called when a Relationship should be exported.
85
+ * @param relationship The Relationship to export
86
+ * @param isUpdate If defined, then `true` indicates an UPDATE operation while `false` indicates an INSERT operation. If not defined, then INSERT vs. UPDATE is not known.
87
+ * @note This should be overridden to actually do the export.
88
+ */
89
+ onExportRelationship(_relationship: Relationship, _isUpdate: boolean | undefined): void;
90
+ /** Called when a relationship should be deleted. */
91
+ onDeleteRelationship(_relInstanceId: Id64String): void;
92
+ /** If `true` is returned, then the schema will be exported.
93
+ * @note This method can optionally be overridden to exclude an individual schema from the export. The base implementation always returns `true`.
94
+ */
95
+ shouldExportSchema(_schemaKey: SchemaKey): boolean;
96
+ /** Called when a schema should be exported.
97
+ * @param schema The schema to export
98
+ * @note This should be overridden to actually do the export.
99
+ * @note return an [[ExportSchemaResult]] with a `schemaPath` property to notify overrides that call `super`
100
+ * where a schema was written for import.
101
+ */
102
+ onExportSchema(_schema: Schema): Promise<void | ExportSchemaResult>;
103
+ /** This method is called when IModelExporter has made incremental progress based on the [[IModelExporter.progressInterval]] setting.
104
+ * This method is `async` to make it easier to integrate with asynchronous status and health reporting services.
105
+ * @note A subclass may override this method to report custom progress. The base implementation does nothing.
106
+ */
107
+ onProgress(): Promise<void>;
108
+ }
109
+ /** Base class for exporting data from an iModel.
110
+ * @note Most uses cases will not require a custom subclass of `IModelExporter`. Instead, it is more typical to subclass/customize [IModelExportHandler]($transformer).
111
+ * @see [iModel Transformation and Data Exchange]($docs/learning/transformer/index.md), [[registerHandler]], [IModelTransformer]($transformer), [IModelImporter]($transformer)
112
+ * @beta
113
+ */
114
+ export declare class IModelExporter {
115
+ /** The read-only source iModel. */
116
+ readonly sourceDb: IModelDb;
117
+ /** A flag that indicates whether element GeometryStreams are loaded or not.
118
+ * @note As an optimization, exporters that don't need geometry can set this flag to `false`. The default is `true`.
119
+ * @note The transformer by default sets this to `false` as an optimization.
120
+ * @note This implies the `wantBRepData` option when loading elements.
121
+ * @see [ElementLoadProps.wantGeometry]($common)
122
+ */
123
+ wantGeometry: boolean;
124
+ /** A flag that indicates whether template models should be exported or not. The default is `true`.
125
+ * @note If only exporting *instances* then template models can be skipped since they are just definitions that are cloned to create new instances.
126
+ * @see [Model.isTemplate]($backend)
127
+ */
128
+ wantTemplateModels: boolean;
129
+ /** A flag that indicates whether *system* schemas should be exported or not. The default is `true` (previously false).
130
+ * This can be set to false for the legacy default behavior, but it may cause errors during schema processing in some cases.
131
+ * @see [[exportSchemas]]
132
+ */
133
+ wantSystemSchemas: boolean;
134
+ /** A flag that determines whether this IModelExporter should visit Elements or not. The default is `true`.
135
+ * @note This flag is available as an optimization when the exporter doesn't need to visit elements, so can skip loading them.
136
+ */
137
+ visitElements: boolean;
138
+ /** A flag that determines whether this IModelExporter should visit Relationships or not. The default is `true`.
139
+ * @note This flag is available as an optimization when the exporter doesn't need to visit relationships, so can skip loading them.
140
+ */
141
+ visitRelationships: boolean;
142
+ /** The number of entities exported before incremental progress should be reported via the [[onProgress]] callback. */
143
+ progressInterval: number;
144
+ /** Tracks the current total number of entities exported. */
145
+ private _progressCounter;
146
+ /** Optionally cached entity change information */
147
+ private _sourceDbChanges?;
148
+ /**
149
+ * Retrieve the cached entity change information.
150
+ * @note This will only be initialized after [IModelExporter.exportChanges] is invoked.
151
+ */
152
+ get sourceDbChanges(): ChangedInstanceIds | undefined;
153
+ /** The handler called by this IModelExporter. */
154
+ private _handler;
155
+ /** The handler called by this IModelExporter. */
156
+ protected get handler(): IModelExportHandler;
157
+ /** The set of CodeSpecs to exclude from the export. */
158
+ private _excludedCodeSpecNames;
159
+ /** The set of specific Elements to exclude from the export. */
160
+ private _excludedElementIds;
161
+ /** The set of Categories where Elements in that Category will be excluded from transformation to the target iModel. */
162
+ private _excludedElementCategoryIds;
163
+ /** The set of classes of Elements that will be excluded (polymorphically) from transformation to the target iModel. */
164
+ private _excludedElementClasses;
165
+ /** The set of classes of ElementAspects that will be excluded (polymorphically) from transformation to the target iModel. */
166
+ private _excludedElementAspectClasses;
167
+ /** The set of classFullNames for ElementAspects that will be excluded from transformation to the target iModel. */
168
+ private _excludedElementAspectClassFullNames;
169
+ /** The set of classes of Relationships that will be excluded (polymorphically) from transformation to the target iModel. */
170
+ private _excludedRelationshipClasses;
171
+ /** Construct a new IModelExporter
172
+ * @param sourceDb The source IModelDb
173
+ * @see registerHandler
174
+ */
175
+ constructor(sourceDb: IModelDb);
176
+ /** Register the handler that will be called by IModelExporter. */
177
+ registerHandler(handler: IModelExportHandler): void;
178
+ /** Add a rule to exclude a CodeSpec */
179
+ excludeCodeSpec(codeSpecName: string): void;
180
+ /** Add a rule to exclude a specific Element. */
181
+ excludeElement(elementId: Id64String): void;
182
+ /** Add a rule to exclude all Elements in a specified Category. */
183
+ excludeElementsInCategory(categoryId: Id64String): void;
184
+ /** Add a rule to exclude all Elements of a specified class. */
185
+ excludeElementClass(classFullName: string): void;
186
+ /** Add a rule to exclude all ElementAspects of a specified class. */
187
+ excludeElementAspectClass(classFullName: string): void;
188
+ /** Add a rule to exclude all Relationships of a specified class. */
189
+ excludeRelationshipClass(classFullName: string): void;
190
+ /** Export all entity instance types from the source iModel.
191
+ * @note [[exportSchemas]] must be called separately.
192
+ */
193
+ exportAll(): Promise<void>;
194
+ /** Export changes from the source iModel.
195
+ * @param user The user
196
+ * @param startChangesetId Include changes from this changeset up through and including the current changeset.
197
+ * If this parameter is not provided, then just the current changeset will be exported.
198
+ * @note To form a range of versions to export, set `startChangesetId` for the start (inclusive) of the desired range and open the source iModel as of the end (inclusive) of the desired range.
199
+ */
200
+ exportChanges(user?: AccessToken, startChangesetId?: string): Promise<void>;
201
+ /** Export schemas from the source iModel.
202
+ * @note This must be called separately from [[exportAll]] or [[exportChanges]].
203
+ */
204
+ exportSchemas(): Promise<void>;
205
+ /** For logging, indicate the change type if known. */
206
+ private getChangeOpSuffix;
207
+ /** Export all CodeSpecs from the source iModel.
208
+ * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
209
+ */
210
+ exportCodeSpecs(): Promise<void>;
211
+ /** Export a single CodeSpec from the source iModel.
212
+ * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
213
+ */
214
+ exportCodeSpecByName(codeSpecName: string): Promise<void>;
215
+ /** Export a single CodeSpec from the source iModel.
216
+ * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
217
+ */
218
+ exportCodeSpecById(codeSpecId: Id64String): Promise<void>;
219
+ /** Export all fonts from the source iModel.
220
+ * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
221
+ */
222
+ exportFonts(): Promise<void>;
223
+ /** Export a single font from the source iModel.
224
+ * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
225
+ */
226
+ exportFontByName(fontName: string): Promise<void>;
227
+ /** Export a single font from the source iModel.
228
+ * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
229
+ */
230
+ exportFontByNumber(fontNumber: number): Promise<void>;
231
+ /** Export the model container, contents, and sub-models from the source iModel.
232
+ * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
233
+ */
234
+ exportModel(modeledElementId: Id64String): Promise<void>;
235
+ /** Export the model (the container only) from the source iModel. */
236
+ private exportModelContainer;
237
+ private _yieldManager;
238
+ /** Export the model contents.
239
+ * @param modelId The only required parameter
240
+ * @param elementClassFullName Can be optionally specified if the goal is to export a subset of the model contents
241
+ * @param skipRootSubject Decides whether or not to export the root Subject. It is normally left undefined except for internal implementation purposes.
242
+ * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
243
+ */
244
+ exportModelContents(modelId: Id64String, elementClassFullName?: string, skipRootSubject?: boolean): Promise<void>;
245
+ /** Export the sub-models directly below the specified model.
246
+ * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
247
+ */
248
+ exportSubModels(parentModelId: Id64String): Promise<void>;
249
+ /** Returns true if the specified element should be exported.
250
+ * This considers the standard IModelExporter exclusion rules plus calls [IModelExportHandler.shouldExportElement]($transformer) for any custom exclusion rules.
251
+ * @note This method is called from within [[exportChanges]] and [[exportAll]], so usually does not need to be called directly.
252
+ */
253
+ shouldExportElement(element: Element): boolean;
254
+ /** Export the specified element, its child elements (if applicable), and any owned ElementAspects.
255
+ * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
256
+ */
257
+ exportElement(elementId: Id64String): Promise<void>;
258
+ /** Export the child elements of the specified element from the source iModel.
259
+ * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
260
+ */
261
+ exportChildElements(elementId: Id64String): Promise<void>;
262
+ /** Returns `true` if the specified ElementAspect should be exported or `false` if if should be excluded. */
263
+ private shouldExportElementAspect;
264
+ /** Export ElementAspects from the specified element from the source iModel. */
265
+ private exportElementAspects;
266
+ /** Exports all relationships that subclass from the specified base class.
267
+ * @note This method is called from [[exportChanges]] and [[exportAll]], so it only needs to be called directly when exporting a subset of an iModel.
268
+ */
269
+ exportRelationships(baseRelClassFullName: string): Promise<void>;
270
+ /** Export a relationship from the source iModel. */
271
+ exportRelationship(relClassFullName: string, relInstanceId: Id64String): Promise<void>;
272
+ /** Tracks incremental progress */
273
+ private trackProgress;
274
+ /**
275
+ * You may override this to store arbitrary json state in a exporter state dump, useful for some resumptions
276
+ * @see [[IModelTransformer.saveStateToFile]]
277
+ */
278
+ protected getAdditionalStateJson(): any;
279
+ /**
280
+ * You may override this to load arbitrary json state in a transformer state dump, useful for some resumptions
281
+ * @see [[IModelTransformer.loadStateFromFile]]
282
+ */
283
+ protected loadAdditionalStateJson(_additionalState: any): void;
284
+ /**
285
+ * Reload our state from a JSON object
286
+ * Intended for [[IModelTransformer.resumeTransformation]]
287
+ * @internal
288
+ * You can load custom json from the exporter save state for custom exporters by overriding [[IModelExporter.loadAdditionalStateJson]]
289
+ */
290
+ loadStateFromJson(state: IModelExporterState): void;
291
+ /**
292
+ * Serialize state to a JSON object
293
+ * Intended for [[IModelTransformer.resumeTransformation]]
294
+ * @internal
295
+ * You can add custom json to the exporter save state for custom exporters by overriding [[IModelExporter.getAdditionalStateJson]]
296
+ */
297
+ saveStateToJson(): IModelExporterState;
298
+ }
299
+ /**
300
+ * The JSON format of a serialized IModelExporter instance
301
+ * Used for starting an exporter in the middle of an export operation,
302
+ * such as resuming a crashed transformation
303
+ *
304
+ * @note Must be kept synchronized with IModelExporter
305
+ * @internal
306
+ */
307
+ export interface IModelExporterState {
308
+ exporterClass: string;
309
+ wantGeometry: boolean;
310
+ wantTemplateModels: boolean;
311
+ wantSystemSchemas: boolean;
312
+ visitElements: boolean;
313
+ visitRelationships: boolean;
314
+ excludedCodeSpecNames: string[];
315
+ excludedElementIds: CompressedId64Set;
316
+ excludedElementCategoryIds: CompressedId64Set;
317
+ excludedElementClassNames: string[];
318
+ excludedElementAspectClassFullNames: string[];
319
+ excludedRelationshipClassNames: string[];
320
+ additionalState?: any;
321
+ }
322
+ /** Class for holding change information.
323
+ * @beta
324
+ */
325
+ export declare class ChangedInstanceOps {
326
+ insertIds: Set<string>;
327
+ updateIds: Set<string>;
328
+ deleteIds: Set<string>;
329
+ /** Initializes the object from IModelJsNative.ChangedInstanceOpsProps. */
330
+ addFromJson(val: IModelJsNative.ChangedInstanceOpsProps | undefined): void;
331
+ }
332
+ /**
333
+ * Class for discovering modified elements between 2 versions of an iModel.
334
+ * @beta
335
+ */
336
+ export declare class ChangedInstanceIds {
337
+ codeSpec: ChangedInstanceOps;
338
+ model: ChangedInstanceOps;
339
+ element: ChangedInstanceOps;
340
+ aspect: ChangedInstanceOps;
341
+ relationship: ChangedInstanceOps;
342
+ font: ChangedInstanceOps;
343
+ private constructor();
344
+ /**
345
+ * Initializes a new ChangedInstanceIds object with information taken from a range of changesets.
346
+ * @param accessToken Access token.
347
+ * @param iModel IModel briefcase whose changesets will be queried.
348
+ * @param firstChangesetId Changeset id.
349
+ * @note Modified element information will be taken from a range of changesets. First changeset in a range will be the 'firstChangesetId', the last will be whichever changeset the 'iModel' briefcase is currently opened on.
350
+ */
351
+ static initialize(accessToken: AccessToken | undefined, iModel: BriefcaseDb, firstChangesetId: string): Promise<ChangedInstanceIds>;
352
+ }
353
+ //# sourceMappingURL=IModelExporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IModelExporter.d.ts","sourceRoot":"","sources":["../../src/IModelExporter.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAU,iBAAiB,EAAkB,UAAU,EAAsC,MAAM,qBAAqB,CAA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