@itwin/imodel-transformer 0.1.14-fedguidopt.2 → 0.1.15
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/ECReferenceTypesCache.js +1 -1
- package/lib/cjs/ECReferenceTypesCache.js.map +1 -1
- package/lib/cjs/EntityUnifier.js +1 -1
- package/lib/cjs/EntityUnifier.js.map +1 -1
- package/lib/cjs/IModelCloneContext.js +2 -2
- package/lib/cjs/IModelCloneContext.js.map +1 -1
- package/lib/cjs/IModelExporter.d.ts +9 -31
- package/lib/cjs/IModelExporter.d.ts.map +1 -1
- package/lib/cjs/IModelExporter.js +24 -44
- package/lib/cjs/IModelExporter.js.map +1 -1
- package/lib/cjs/IModelImporter.js +1 -1
- package/lib/cjs/IModelImporter.js.map +1 -1
- package/lib/cjs/IModelTransformer.d.ts +29 -148
- package/lib/cjs/IModelTransformer.d.ts.map +1 -1
- package/lib/cjs/IModelTransformer.js +208 -859
- package/lib/cjs/IModelTransformer.js.map +1 -1
- package/lib/cjs/PendingReferenceMap.js +1 -1
- package/lib/cjs/PendingReferenceMap.js.map +1 -1
- package/lib/cjs/TransformerLoggerCategory.js +1 -1
- package/lib/cjs/TransformerLoggerCategory.js.map +1 -1
- package/package.json +1 -1
- package/lib/cjs/Algo.d.ts +0 -7
- package/lib/cjs/Algo.d.ts.map +0 -1
- package/lib/cjs/Algo.js +0 -50
- package/lib/cjs/Algo.js.map +0 -1
|
@@ -163,6 +163,7 @@ class ECReferenceTypesCache {
|
|
|
163
163
|
this._propQualifierToRefType.clear();
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
+
exports.ECReferenceTypesCache = ECReferenceTypesCache;
|
|
166
167
|
ECReferenceTypesCache.bisRootClassToRefType = {
|
|
167
168
|
/* eslint-disable quote-props, @typescript-eslint/naming-convention */
|
|
168
169
|
"Element": core_common_1.ConcreteEntityTypes.Element,
|
|
@@ -174,5 +175,4 @@ ECReferenceTypesCache.bisRootClassToRefType = {
|
|
|
174
175
|
// see [ConcreteEntityTypes]($common)
|
|
175
176
|
/* eslint-enable quote-props, @typescript-eslint/naming-convention */
|
|
176
177
|
};
|
|
177
|
-
exports.ECReferenceTypesCache = ECReferenceTypesCache;
|
|
178
178
|
//# sourceMappingURL=ECReferenceTypesCache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ECReferenceTypesCache.js","sourceRoot":"","sources":["../../src/ECReferenceTypesCache.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA8D;AAC9D,oDAAmF;AACnF,gEAAyJ;AACzJ,iCAAiC;AAGjC;;GAEG;AACH,MAAa,mBAAoB,SAAQ,KAAK;IAC5C,gBAAuB,KAAK,CAAC,iDAAiD,CAAC,CAAC,CAAC,CAAC;CACnF;AAFD,kDAEC;AAED;;;;;;;GAOG;AACH,MAAa,qBAAqB;IAAlC;QACE,uGAAuG;QAC/F,4BAAuB,GAAG,IAAI,4BAAa,EAAiD,CAAC;QAC7F,+BAA0B,GAAG,IAAI,4BAAa,EAAiC,CAAC;QAChF,mBAAc,GAAG,IAAI,GAAG,EAAqB,CAAC;IAyJxD,CAAC;IA3IS,KAAK,CAAC,eAAe,CAAC,OAAgB;QAC5C,IAAI,oBAAoB,GAAY,OAAO,CAAC;QAC5C,MAAM,OAAO,CAAC,mBAAmB,CAAC,CAAC,SAAS,EAAE,EAAE;YAC9C,2GAA2G;YAC3G,+GAA+G;YAC/G,iEAAiE;YACjE,MAAM,WAAW,GAAG,oBAAoB,KAAK,OAAO,CAAC;YACrD,MAAM,yBAAyB,GAAG,SAAS,CAAC,IAAI,KAAK,oBAAoB,CAAC,SAAS,EAAE,IAAI,CAAC;YAC1F,MAAM,uBAAuB,GAAG,WAAW,IAAI,CAAC,yBAAyB,CAAC;YAC1E,IAAI,CAAC,uBAAuB;gBAC1B,OAAO,IAAI,CAAC,CAAC,uBAAuB;YACtC,oBAAoB,GAAG,S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,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC;YACzC,UAAU,CAAC,WAAW,EAAE;YACxB,SAAS,CAAC,WAAW,EAAE;SACxB,CAAC,CAAC;IACL,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;QAC5B,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,CAAC;IACvC,CAAC;;AAtJc,2CAAqB,GAAoD;IACtF,sEAAsE;IACtE,SAAS,EAAE,iCAAmB,CAAC,OAAO;IACtC,OAAO,EAAE,iCAAmB,CAAC,KAAK;IAClC,eAAe,EAAE,iCAAmB,CAAC,aAAa;IAClD,yBAAyB,EAAE,iCAAmB,CAAC,YAAY;IAC3D,sBAAsB,EAAE,iCAAmB,CAAC,YAAY;IACxD,8EAA8E;IAC9E,qCAAqC;IACrC,qEAAqE;CACtE,AAVmC,CAUlC;AAhBS,sDAAqB","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 */\n\nimport { DbResult, TupleKeyedMap } from \"@itwin/core-bentley\";\nimport { ConcreteEntityTypes, IModelError, RelTypeInfo } from \"@itwin/core-common\";\nimport { ECClass, Mixin, RelationshipClass, RelationshipConstraint, Schema, SchemaKey, SchemaLoader, StrengthDirection } from \"@itwin/ecschema-metadata\";\nimport * as assert from \"assert\";\nimport { IModelDb } from \"@itwin/core-backend\";\n\n/** The context for transforming a *source* Element to a *target* Element and remapping internal identifiers to the target iModel.\n * @internal\n */\nexport class SchemaNotInCacheErr extends Error {\n public constructor() { super(\"Schema was not in cache, initialize that schema\"); }\n}\n\n/**\n * A cache of the entity types referenced by navprops in ecchemas, as well as the source and target entity types of\n * The transformer needs the referenced type to determine how to resolve references.\n *\n * Using multiple of these usually performs redundant computation, for static schemas at least. A possible future optimization\n * would be to seed the computation from a global cache of non-dynamic schemas, but dynamic schemas can collide willy-nilly\n * @internal\n */\nexport class ECReferenceTypesCache {\n /** nesting based tuple map keyed by qualified property path tuple [schemaName, className, propName] */\n private _propQualifierToRefType = new TupleKeyedMap<[string, string, string], ConcreteEntityTypes>();\n private _relClassNameEndToRefTypes = new TupleKeyedMap<[string, string], RelTypeInfo>();\n private _initedSchemas = new Map<string, SchemaKey>();\n\n private static bisRootClassToRefType: Record<string, ConcreteEntityTypes | undefined> = {\n /* eslint-disable quote-props, @typescript-eslint/naming-convention */\n \"Element\": ConcreteEntityTypes.Element,\n \"Model\": ConcreteEntityTypes.Model,\n \"ElementAspect\": ConcreteEntityTypes.ElementAspect,\n \"ElementRefersToElements\": ConcreteEntityTypes.Relationship,\n \"ElementDrivesElement\": ConcreteEntityTypes.Relationship,\n // code spec is technically a potential root class but it is ignored currently\n // see [ConcreteEntityTypes]($common)\n /* eslint-enable quote-props, @typescript-eslint/naming-convention */\n };\n\n private async getRootBisClass(ecclass: ECClass) {\n let bisRootForConstraint: ECClass = ecclass;\n await ecclass.traverseBaseClasses((baseClass) => {\n // The depth first traversal will descend all the way to the root class before making any lateral traversal\n // of mixin hierarchies, (or if the constraint is a mixin, it will traverse to the root of the mixin hierarchy)\n // Once we see that we've moved laterally, we can terminate early\n const isFirstTest = bisRootForConstraint === ecclass;\n const traversalSwitchedRootPath = baseClass.name !== bisRootForConstraint.baseClass?.name;\n const stillTraversingRootPath = isFirstTest || !traversalSwitchedRootPath;\n if (!stillTraversingRootPath)\n return true; // stop traversal early\n bisRootForConstraint = baseClass;\n return false;\n });\n // if the root class of the constraint was a mixin, use its AppliesToEntityClass\n if (bisRootForConstraint instanceof Mixin) {\n assert(bisRootForConstraint.appliesTo !== undefined, \"The referenced AppliesToEntityClass could not be found, how did it pass schema validation?\");\n bisRootForConstraint = await this.getRootBisClass(await bisRootForConstraint.appliesTo);\n }\n return bisRootForConstraint;\n }\n\n private async getAbstractConstraintClass(constraint: RelationshipConstraint): Promise<ECClass> {\n // constraint classes must share a base so we can get the root from any of them, just use the first\n const ecclass = await (constraint.constraintClasses?.[0] || constraint.abstractConstraint);\n assert(ecclass !== undefined, \"At least one constraint class or an abstract constraint must have been defined, the constraint is not valid\");\n return ecclass;\n }\n\n /** initialize from an imodel with metadata */\n public async initAllSchemasInIModel(imodel: IModelDb): Promise<void> {\n const schemaLoader = new SchemaLoader((name: string) => imodel.getSchemaProps(name));\n await imodel.withPreparedStatement(`\n WITH RECURSIVE refs(SchemaId) AS (\n SELECT ECInstanceId FROM ECDbMeta.ECSchemaDef WHERE Name='BisCore'\n UNION ALL\n SELECT sr.SourceECInstanceId\n FROM ECDbMeta.SchemaHasSchemaReferences sr\n JOIN refs ON sr.TargetECInstanceId = refs.SchemaId\n )\n SELECT s.Name\n FROM refs\n JOIN ECDbMeta.ECSchemaDef s ON refs.SchemaId=s.ECInstanceId\n -- ensure schema dependency order\n ORDER BY ECInstanceId\n `, async (stmt) => {\n let status: DbResult;\n while ((status = stmt.step()) === DbResult.BE_SQLITE_ROW) {\n const schemaName = stmt.getValue(0).getString();\n const schema = schemaLoader.getSchema(schemaName);\n await this.considerInitSchema(schema);\n }\n if (status !== DbResult.BE_SQLITE_DONE)\n throw new IModelError(status, \"unexpected query failure\");\n });\n }\n\n private async considerInitSchema(schema: Schema): Promise<void> {\n if (this._initedSchemas.has(schema.name)) {\n const cachedSchemaKey = this._initedSchemas.get(schema.name);\n assert(cachedSchemaKey !== undefined);\n const incomingSchemaIsEqualOrOlder = schema.schemaKey.compareByVersion(cachedSchemaKey) <= 0;\n if (incomingSchemaIsEqualOrOlder) {\n return;\n }\n }\n return this.initSchema(schema);\n }\n\n private async initSchema(schema: Schema): Promise<void> {\n for (const ecclass of schema.getClasses()) {\n for (const prop of await ecclass.getProperties()) {\n if (!prop.isNavigation())\n continue;\n const relClass = await prop.relationshipClass;\n const relInfo = await this.relInfoFromRelClass(relClass);\n if (relInfo === undefined)\n continue;\n const navPropRefType = prop.direction === StrengthDirection.Forward ? relInfo.target : relInfo.source;\n this._propQualifierToRefType.set([schema.name.toLowerCase(), ecclass.name.toLowerCase(), prop.name.toLowerCase()], navPropRefType);\n }\n\n if (ecclass instanceof RelationshipClass) {\n const relInfo = await this.relInfoFromRelClass(ecclass);\n if (relInfo)\n this._relClassNameEndToRefTypes.set([schema.name.toLowerCase(), ecclass.name.toLowerCase()], relInfo);\n }\n }\n\n this._initedSchemas.set(schema.name, schema.schemaKey);\n }\n\n private async relInfoFromRelClass(ecclass: RelationshipClass): Promise<RelTypeInfo | undefined> {\n assert(ecclass.source.constraintClasses !== undefined);\n assert(ecclass.target.constraintClasses !== undefined);\n const [[sourceClass, sourceRootBisClass], [targetClass, targetRootBisClass]] = await Promise.all([\n this.getAbstractConstraintClass(ecclass.source)\n .then(async (constraintClass) => [constraintClass, await this.getRootBisClass(constraintClass)]),\n this.getAbstractConstraintClass(ecclass.target)\n .then(async (constraintClass) => [constraintClass, await this.getRootBisClass(constraintClass)]),\n ]);\n\n if (sourceRootBisClass.name === \"CodeSpec\" || targetRootBisClass.name === \"CodeSpec\")\n return undefined;\n const sourceType = ECReferenceTypesCache.bisRootClassToRefType[sourceRootBisClass.name];\n const targetType = ECReferenceTypesCache.bisRootClassToRefType[targetRootBisClass.name];\n const makeAssertMsg = (root: ECClass, cls: ECClass) => [\n `An unknown root class '${root.fullName}' was encountered while populating`,\n `the nav prop reference type cache for ${cls.fullName}.`,\n \"This is a bug.\",\n ].join(\"\\n\");\n assert(sourceType !== undefined, makeAssertMsg(sourceRootBisClass, sourceClass));\n assert(targetType !== undefined, makeAssertMsg(targetRootBisClass, targetClass));\n return { source: sourceType, target: targetType };\n }\n\n public getNavPropRefType(schemaName: string, className: string, propName: string): undefined | ConcreteEntityTypes {\n if (!this._initedSchemas.has(schemaName))\n throw new SchemaNotInCacheErr();\n return this._propQualifierToRefType.get([\n schemaName.toLowerCase(),\n className.toLowerCase(),\n propName.toLowerCase(),\n ]);\n }\n\n public getRelationshipEndType(schemaName: string, className: string): undefined | RelTypeInfo {\n if (!this._initedSchemas.has(schemaName))\n throw new SchemaNotInCacheErr();\n return this._relClassNameEndToRefTypes.get([\n schemaName.toLowerCase(),\n className.toLowerCase(),\n ]);\n }\n\n public clear() {\n this._initedSchemas.clear();\n this._propQualifierToRefType.clear();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ECReferenceTypesCache.js","sourceRoot":"","sources":["../../src/ECReferenceTypesCache.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA8D;AAC9D,oDAAmF;AACnF,gEAAyJ;AACzJ,iCAAiC;AAGjC;;GAEG;AACH,MAAa,mBAAoB,SAAQ,KAAK;IAC5C,gBAAuB,KAAK,CAAC,iDAAiD,CAAC,CAAC,CAAC,CAAC;CACnF;AAFD,kDAEC;AAED;;;;;;;GAOG;AACH,MAAa,qBAAqB;IAAlC;QACE,uGAAuG;QAC/F,4BAAuB,GAAG,IAAI,4BAAa,EAAiD,CAAC;QAC7F,+BAA0B,GAAG,IAAI,4BAAa,EAAiC,CAAC;QAChF,mBAAc,GAAG,IAAI,GAAG,EAAqB,CAAC;IAyJxD,CAAC;IA3IS,KAAK,CAAC,eAAe,CAAC,OAAgB;QAC5C,IAAI,oBAAoB,GAAY,OAAO,CAAC;QAC5C,MAAM,OAAO,CAAC,mBAAmB,CAAC,CAAC,SAAS,EAAE,EAAE;YAC9C,2GAA2G;YAC3G,+GAA+G;YAC/G,iEAAiE;YACjE,MAAM,WAAW,GAAG,oBAAoB,KAAK,OAAO,CAAC;YACrD,MAAM,yBAAyB,GAAG,SAAS,CAAC,IAAI,KAAK,oBAAoB,CAAC,SAAS,EAAE,IAAI,CAAC;YAC1F,MAAM,uBAAuB,GAAG,WAAW,IAAI,CAAC,yBAAyB,CAAC;YAC1E,IAAI,CAAC,uBAAuB;gBAC1B,OAAO,IAAI,CAAC,CAAC,uBAAuB;YACtC,oBAAoB,GAAG,SAAS,CAAC;YACjC,OAAO,K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AC,GAAG,CAAC;YACzC,UAAU,CAAC,WAAW,EAAE;YACxB,SAAS,CAAC,WAAW,EAAE;SACxB,CAAC,CAAC;IACL,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;QAC5B,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,CAAC;IACvC,CAAC;;AA5JH,sDA6JC;AAvJgB,2CAAqB,GAAoD;IACtF,sEAAsE;IACtE,SAAS,EAAE,iCAAmB,CAAC,OAAO;IACtC,OAAO,EAAE,iCAAmB,CAAC,KAAK;IAClC,eAAe,EAAE,iCAAmB,CAAC,aAAa;IAClD,yBAAyB,EAAE,iCAAmB,CAAC,YAAY;IAC3D,sBAAsB,EAAE,iCAAmB,CAAC,YAAY;IACxD,8EAA8E;IAC9E,qCAAqC;IACrC,qEAAqE;CACtE,AAVmC,CAUlC","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 */\n\nimport { DbResult, TupleKeyedMap } from \"@itwin/core-bentley\";\nimport { ConcreteEntityTypes, IModelError, RelTypeInfo } from \"@itwin/core-common\";\nimport { ECClass, Mixin, RelationshipClass, RelationshipConstraint, Schema, SchemaKey, SchemaLoader, StrengthDirection } from \"@itwin/ecschema-metadata\";\nimport * as assert from \"assert\";\nimport { IModelDb } from \"@itwin/core-backend\";\n\n/** The context for transforming a *source* Element to a *target* Element and remapping internal identifiers to the target iModel.\n * @internal\n */\nexport class SchemaNotInCacheErr extends Error {\n public constructor() { super(\"Schema was not in cache, initialize that schema\"); }\n}\n\n/**\n * A cache of the entity types referenced by navprops in ecchemas, as well as the source and target entity types of\n * The transformer needs the referenced type to determine how to resolve references.\n *\n * Using multiple of these usually performs redundant computation, for static schemas at least. A possible future optimization\n * would be to seed the computation from a global cache of non-dynamic schemas, but dynamic schemas can collide willy-nilly\n * @internal\n */\nexport class ECReferenceTypesCache {\n /** nesting based tuple map keyed by qualified property path tuple [schemaName, className, propName] */\n private _propQualifierToRefType = new TupleKeyedMap<[string, string, string], ConcreteEntityTypes>();\n private _relClassNameEndToRefTypes = new TupleKeyedMap<[string, string], RelTypeInfo>();\n private _initedSchemas = new Map<string, SchemaKey>();\n\n private static bisRootClassToRefType: Record<string, ConcreteEntityTypes | undefined> = {\n /* eslint-disable quote-props, @typescript-eslint/naming-convention */\n \"Element\": ConcreteEntityTypes.Element,\n \"Model\": ConcreteEntityTypes.Model,\n \"ElementAspect\": ConcreteEntityTypes.ElementAspect,\n \"ElementRefersToElements\": ConcreteEntityTypes.Relationship,\n \"ElementDrivesElement\": ConcreteEntityTypes.Relationship,\n // code spec is technically a potential root class but it is ignored currently\n // see [ConcreteEntityTypes]($common)\n /* eslint-enable quote-props, @typescript-eslint/naming-convention */\n };\n\n private async getRootBisClass(ecclass: ECClass) {\n let bisRootForConstraint: ECClass = ecclass;\n await ecclass.traverseBaseClasses((baseClass) => {\n // The depth first traversal will descend all the way to the root class before making any lateral traversal\n // of mixin hierarchies, (or if the constraint is a mixin, it will traverse to the root of the mixin hierarchy)\n // Once we see that we've moved laterally, we can terminate early\n const isFirstTest = bisRootForConstraint === ecclass;\n const traversalSwitchedRootPath = baseClass.name !== bisRootForConstraint.baseClass?.name;\n const stillTraversingRootPath = isFirstTest || !traversalSwitchedRootPath;\n if (!stillTraversingRootPath)\n return true; // stop traversal early\n bisRootForConstraint = baseClass;\n return false;\n });\n // if the root class of the constraint was a mixin, use its AppliesToEntityClass\n if (bisRootForConstraint instanceof Mixin) {\n assert(bisRootForConstraint.appliesTo !== undefined, \"The referenced AppliesToEntityClass could not be found, how did it pass schema validation?\");\n bisRootForConstraint = await this.getRootBisClass(await bisRootForConstraint.appliesTo);\n }\n return bisRootForConstraint;\n }\n\n private async getAbstractConstraintClass(constraint: RelationshipConstraint): Promise<ECClass> {\n // constraint classes must share a base so we can get the root from any of them, just use the first\n const ecclass = await (constraint.constraintClasses?.[0] || constraint.abstractConstraint);\n assert(ecclass !== undefined, \"At least one constraint class or an abstract constraint must have been defined, the constraint is not valid\");\n return ecclass;\n }\n\n /** initialize from an imodel with metadata */\n public async initAllSchemasInIModel(imodel: IModelDb): Promise<void> {\n const schemaLoader = new SchemaLoader((name: string) => imodel.getSchemaProps(name));\n await imodel.withPreparedStatement(`\n WITH RECURSIVE refs(SchemaId) AS (\n SELECT ECInstanceId FROM ECDbMeta.ECSchemaDef WHERE Name='BisCore'\n UNION ALL\n SELECT sr.SourceECInstanceId\n FROM ECDbMeta.SchemaHasSchemaReferences sr\n JOIN refs ON sr.TargetECInstanceId = refs.SchemaId\n )\n SELECT s.Name\n FROM refs\n JOIN ECDbMeta.ECSchemaDef s ON refs.SchemaId=s.ECInstanceId\n -- ensure schema dependency order\n ORDER BY ECInstanceId\n `, async (stmt) => {\n let status: DbResult;\n while ((status = stmt.step()) === DbResult.BE_SQLITE_ROW) {\n const schemaName = stmt.getValue(0).getString();\n const schema = schemaLoader.getSchema(schemaName);\n await this.considerInitSchema(schema);\n }\n if (status !== DbResult.BE_SQLITE_DONE)\n throw new IModelError(status, \"unexpected query failure\");\n });\n }\n\n private async considerInitSchema(schema: Schema): Promise<void> {\n if (this._initedSchemas.has(schema.name)) {\n const cachedSchemaKey = this._initedSchemas.get(schema.name);\n assert(cachedSchemaKey !== undefined);\n const incomingSchemaIsEqualOrOlder = schema.schemaKey.compareByVersion(cachedSchemaKey) <= 0;\n if (incomingSchemaIsEqualOrOlder) {\n return;\n }\n }\n return this.initSchema(schema);\n }\n\n private async initSchema(schema: Schema): Promise<void> {\n for (const ecclass of schema.getClasses()) {\n for (const prop of await ecclass.getProperties()) {\n if (!prop.isNavigation())\n continue;\n const relClass = await prop.relationshipClass;\n const relInfo = await this.relInfoFromRelClass(relClass);\n if (relInfo === undefined)\n continue;\n const navPropRefType = prop.direction === StrengthDirection.Forward ? relInfo.target : relInfo.source;\n this._propQualifierToRefType.set([schema.name.toLowerCase(), ecclass.name.toLowerCase(), prop.name.toLowerCase()], navPropRefType);\n }\n\n if (ecclass instanceof RelationshipClass) {\n const relInfo = await this.relInfoFromRelClass(ecclass);\n if (relInfo)\n this._relClassNameEndToRefTypes.set([schema.name.toLowerCase(), ecclass.name.toLowerCase()], relInfo);\n }\n }\n\n this._initedSchemas.set(schema.name, schema.schemaKey);\n }\n\n private async relInfoFromRelClass(ecclass: RelationshipClass): Promise<RelTypeInfo | undefined> {\n assert(ecclass.source.constraintClasses !== undefined);\n assert(ecclass.target.constraintClasses !== undefined);\n const [[sourceClass, sourceRootBisClass], [targetClass, targetRootBisClass]] = await Promise.all([\n this.getAbstractConstraintClass(ecclass.source)\n .then(async (constraintClass) => [constraintClass, await this.getRootBisClass(constraintClass)]),\n this.getAbstractConstraintClass(ecclass.target)\n .then(async (constraintClass) => [constraintClass, await this.getRootBisClass(constraintClass)]),\n ]);\n\n if (sourceRootBisClass.name === \"CodeSpec\" || targetRootBisClass.name === \"CodeSpec\")\n return undefined;\n const sourceType = ECReferenceTypesCache.bisRootClassToRefType[sourceRootBisClass.name];\n const targetType = ECReferenceTypesCache.bisRootClassToRefType[targetRootBisClass.name];\n const makeAssertMsg = (root: ECClass, cls: ECClass) => [\n `An unknown root class '${root.fullName}' was encountered while populating`,\n `the nav prop reference type cache for ${cls.fullName}.`,\n \"This is a bug.\",\n ].join(\"\\n\");\n assert(sourceType !== undefined, makeAssertMsg(sourceRootBisClass, sourceClass));\n assert(targetType !== undefined, makeAssertMsg(targetRootBisClass, targetClass));\n return { source: sourceType, target: targetType };\n }\n\n public getNavPropRefType(schemaName: string, className: string, propName: string): undefined | ConcreteEntityTypes {\n if (!this._initedSchemas.has(schemaName))\n throw new SchemaNotInCacheErr();\n return this._propQualifierToRefType.get([\n schemaName.toLowerCase(),\n className.toLowerCase(),\n propName.toLowerCase(),\n ]);\n }\n\n public getRelationshipEndType(schemaName: string, className: string): undefined | RelTypeInfo {\n if (!this._initedSchemas.has(schemaName))\n throw new SchemaNotInCacheErr();\n return this._relClassNameEndToRefTypes.get([\n schemaName.toLowerCase(),\n className.toLowerCase(),\n ]);\n }\n\n public clear() {\n this._initedSchemas.clear();\n this._propQualifierToRefType.clear();\n }\n}\n"]}
|
package/lib/cjs/EntityUnifier.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityUnifier.js","sourceRoot":"","sources":["../../src/EntityUnifier.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F;;;;GAIG;AACH,iCAAiC;AACjC,oDAAkG;AAClG,sDAA4I;AAC5I,sDAA2C;AAE3C,gBAAgB;AAChB,IAAiB,aAAa,CA0D7B;AA1DD,WAAiB,aAAa;IAC5B,SAAgB,eAAe,CAAC,MAAsB;QACpD,IAAI,MAAM,YAAY,sBAAO;YAC3B,OAAO,SAAS,CAAC;aACd,IAAI,MAAM,YAAY,4BAAa;YACtC,OAAO,gBAAgB,CAAC;aACrB,IAAI,MAAM,YAAY,2BAAY;YACrC,OAAO,cAAc,CAAC;;YAEtB,OAAO,qBAAqB,CAAC;IACjC,CAAC;IATe,6BAAe,kBAS9B,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,CAAC,EAAE,CAAC,aAAa,CAAkB,CAAC;aAC5E,IAAI,MAAM,YAAY,4BAAa;YACtC,OAAO,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAkB,CAAC;;YAEnE,MAAM,CAAC,KAAK,EAAE,4BAA4B,MAAM,CAAC,WA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OAAO,EAAE,CAAC,qBAAqB,CAAC,kBAAkB,GAAG,CAAC,MAAM,CAAC,UAAU,MAAM,GAAG,CAAC,MAAM,CAAC,SAAS,wBAAwB,EAAE,CAAC,IAAI,EAAE,EAAE;gBAClI,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBAC9B,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;gBAClC,IAAI,aAAa,KAAK,sBAAQ,CAAC,aAAa;oBAC1C,OAAO,IAAI,CAAC;gBACd,IAAI,aAAa,KAAK,sBAAQ,CAAC,cAAc;oBAC3C,OAAO,KAAK,CAAC;;oBAEb,MAAM,IAAI,yBAAW,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;YACzD,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IA/Be,oBAAM,SA+BrB,CAAA;AACH,CAAC,EA1DgB,aAAa,6BAAb,aAAa,QA0D7B","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 */\nimport * as assert from \"assert\";\nimport { ConcreteEntityTypes, DbResult, EntityReference, IModelError } from \"@itwin/core-common\";\nimport { ConcreteEntity, ConcreteEntityProps, Element, ElementAspect, EntityReferences, IModelDb, Relationship } 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)\n return \"element\";\n else if (entity instanceof ElementAspect)\n return \"element aspect\";\n else if (entity instanceof Relationship)\n return \"relationship\";\n else\n 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(db.relationships) as EntityUpdater;\n else if (entity instanceof ElementAspect)\n return db.elements.updateAspect.bind(db.elements) as EntityUpdater;\n else\n assert(false, `unreachable; entity was '${entity.constructor.name}' not an Element, Relationship, or ElementAspect`);\n }\n\n export function exists(db: IModelDb, arg: { entity: ConcreteEntity } | { entityReference: EntityReference }) {\n if (\"entityReference\" in arg) {\n const [type, id] = EntityReferences.split(arg.entityReference);\n // FIXME: add a test with a deleted reference that triggers this\n if (id === undefined || Id64.isInvalid(id))\n return false;\n const bisCoreRootClassName = ConcreteEntityTypes.toBisCoreRootClassFullName(type);\n return db.withPreparedStatement(`SELECT 1 FROM ${bisCoreRootClassName} WHERE ECInstanceId=?`, (stmt) => {\n stmt.bindId(1, id);\n const matchesResult = stmt.step();\n if (matchesResult === DbResult.BE_SQLITE_ROW)\n return true;\n if (matchesResult === DbResult.BE_SQLITE_DONE)\n return false;\n else\n throw new IModelError(matchesResult, \"query failed\");\n });\n } else {\n if (arg.entity.id === undefined || Id64.isInvalid(arg.entity.id))\n return false;\n return db.withPreparedStatement(`SELECT 1 FROM [${arg.entity.schemaName}].[${arg.entity.className}] WHERE ECInstanceId=?`, (stmt) => {\n stmt.bindId(1, arg.entity.id);\n const matchesResult = stmt.step();\n if (matchesResult === DbResult.BE_SQLITE_ROW)\n return true;\n if (matchesResult === DbResult.BE_SQLITE_DONE)\n return false;\n else\n throw new IModelError(matchesResult, \"query failed\");\n });\n }\n }\n}\n"]}
|
|
@@ -145,7 +145,7 @@ class IModelCloneContext extends core_backend_1.IModelElementCloneContext {
|
|
|
145
145
|
targetId: this.findTargetEntityId(relInSource.targetId),
|
|
146
146
|
};
|
|
147
147
|
// return a null
|
|
148
|
-
if (
|
|
148
|
+
if (!core_backend_1.EntityReferences.isValid(relInTarget.sourceId) || !core_backend_1.EntityReferences.isValid(relInTarget.targetId))
|
|
149
149
|
break;
|
|
150
150
|
const relInTargetId = this.sourceDb.withPreparedStatement(`
|
|
151
151
|
SELECT ECInstanceId
|
|
@@ -221,6 +221,6 @@ class IModelCloneContext extends core_backend_1.IModelElementCloneContext {
|
|
|
221
221
|
});
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
-
IModelCloneContext.aspectRemapTableName = "AspectIdRemaps";
|
|
225
224
|
exports.IModelCloneContext = IModelCloneContext;
|
|
225
|
+
IModelCloneContext.aspectRemapTableName = "AspectIdRemaps";
|
|
226
226
|
//# sourceMappingURL=IModelCloneContext.js.map
|
|
@@ -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;IAwNhE,CAAC;IAtNC,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,2DAA2D;QAC3D,MAAM,kBAAkB,GAAiB,IAAI,CAAC,gBAAgB,CAAC,CAAC,YAAY,CAAC,aAAa,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;QAC7G,iJAAiJ;QACjJ,aAAa,C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G,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;;AAlCc,uCAAoB,GAAG,gBAAgB,AAAnB,CAAoB;AAxL5C,gDAAkB","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 // eslint-disable-next-line @typescript-eslint/dot-notation\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 // eslint-disable-next-line @typescript-eslint/dot-notation\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 (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"]}
|
|
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;IAwNhE,CAAC;IAtNC,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,2DAA2D;QAC3D,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,CAAC,SAAS,KAAM,aAAqB,CAAC,YAAY,CAAC,CAAC,EAAE;gBAC9E,kBAA0B,CAAC,YAAY,CAAC,GAAG,4BAAc,CAAC,IAAI,CAAC;aACjE;QACH,CAAC,EAA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YACD,MAAM,CAAC,MAAM,KAAK,uBAAQ,CAAC,cAAc,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;IACL,CAAC;;AA1NH,gDA2NC;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 // eslint-disable-next-line @typescript-eslint/dot-notation\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 // eslint-disable-next-line @typescript-eslint/dot-notation\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.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"]}
|
|
@@ -3,26 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { BriefcaseDb, Element, ElementAspect, ElementMultiAspect, ElementUniqueAspect, IModelDb, IModelJsNative, Model, Relationship } from "@itwin/core-backend";
|
|
5
5
|
import { AccessToken, CompressedId64Set, Id64String } from "@itwin/core-bentley";
|
|
6
|
-
import {
|
|
6
|
+
import { CodeSpec, FontProps } from "@itwin/core-common";
|
|
7
7
|
import { Schema, SchemaKey } from "@itwin/ecschema-metadata";
|
|
8
|
-
import type { InitArgs } from "./IModelTransformer";
|
|
9
|
-
export interface ExportChangesArgs extends InitArgs {
|
|
10
|
-
accessToken?: AccessToken;
|
|
11
|
-
/**
|
|
12
|
-
* A changeset id or index signifiying the inclusive start of changes
|
|
13
|
-
* to include. The end is implicitly the changeset of the source iModel
|
|
14
|
-
* @note mutually exclusive with @see changesetRanges
|
|
15
|
-
*/
|
|
16
|
-
startChangeset?: ChangesetIndexOrId;
|
|
17
|
-
/**
|
|
18
|
-
* An array of changeset index ranges, e.g. [[2,2], [4,5]] is [2,4,5]
|
|
19
|
-
* @note mutually exclusive with @see startChangeset
|
|
20
|
-
*/
|
|
21
|
-
changesetRanges?: [number, number][];
|
|
22
|
-
}
|
|
23
|
-
export interface ChangedInstanceIdsInitOptions extends ExportChangesArgs {
|
|
24
|
-
iModel: BriefcaseDb;
|
|
25
|
-
}
|
|
26
8
|
/**
|
|
27
9
|
* @beta
|
|
28
10
|
* The (optional) result of [[IModelExportHandler.onExportSchema]]
|
|
@@ -210,18 +192,12 @@ export declare class IModelExporter {
|
|
|
210
192
|
*/
|
|
211
193
|
exportAll(): Promise<void>;
|
|
212
194
|
/** Export changes from the source iModel.
|
|
213
|
-
*
|
|
214
|
-
* @param accessToken A valid access token string
|
|
195
|
+
* @param user The user
|
|
215
196
|
* @param startChangesetId Include changes from this changeset up through and including the current changeset.
|
|
216
197
|
* If this parameter is not provided, then just the current changeset will be exported.
|
|
217
|
-
* @note To form a range of versions to
|
|
218
|
-
* range and open the source iModel as of the end (inclusive) of the desired range.
|
|
219
|
-
*/
|
|
220
|
-
exportChanges(options: ExportChangesArgs): Promise<void>;
|
|
221
|
-
/**
|
|
222
|
-
* @deprecated in 0.1.x.
|
|
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.
|
|
223
199
|
*/
|
|
224
|
-
exportChanges(
|
|
200
|
+
exportChanges(user?: AccessToken, startChangesetId?: string): Promise<void>;
|
|
225
201
|
/** Export schemas from the source iModel.
|
|
226
202
|
* @note This must be called separately from [[exportAll]] or [[exportChanges]].
|
|
227
203
|
*/
|
|
@@ -367,9 +343,11 @@ export declare class ChangedInstanceIds {
|
|
|
367
343
|
private constructor();
|
|
368
344
|
/**
|
|
369
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.
|
|
370
350
|
*/
|
|
371
|
-
static initialize(
|
|
372
|
-
/** @deprecated in 0.1.x. Pass a [[ChangedInstanceIdsInitOptions]] object instead of a changeset id */
|
|
373
|
-
static initialize(accessToken: AccessToken | undefined, iModel: BriefcaseDb, startChangesetId: string): Promise<ChangedInstanceIds>;
|
|
351
|
+
static initialize(accessToken: AccessToken | undefined, iModel: BriefcaseDb, firstChangesetId: string): Promise<ChangedInstanceIds>;
|
|
374
352
|
}
|
|
375
353
|
//# sourceMappingURL=IModelExporter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelExporter.d.ts","sourceRoot":"","sources":["../../src/IModelExporter.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACL,WAAW,EAAqD,OAAO,EAAE,aAAa,EACtF,kBAAkB,EAA2B,mBAAmB,EA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ClC,SAAS,cAAyB;IAEzC,0EAA0E;IACnE,WAAW,CAAC,GAAG,EAAE,cAAc,CAAC,uBAAuB,GAAG,SAAS,GAAG,IAAI;CAYlF;AAED;;;GAGG;AACH,qBAAa,kBAAkB;IACtB,QAAQ,qBAA4B;IACpC,KAAK,qBAA4B;IACjC,OAAO,qBAA4B;IACnC,MAAM,qBAA4B;IAClC,YAAY,qBAA4B;IACxC,IAAI,qBAA4B;IACvC,OAAO;IAEP;;;;;;OAMG;WACiB,UAAU,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAsBjJ"}
|
|
@@ -13,7 +13,6 @@ const core_bentley_1 = require("@itwin/core-bentley");
|
|
|
13
13
|
const core_common_1 = require("@itwin/core-common");
|
|
14
14
|
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
15
15
|
const TransformerLoggerCategory_1 = require("./TransformerLoggerCategory");
|
|
16
|
-
const nodeAssert = require("assert");
|
|
17
16
|
const loggerCategory = TransformerLoggerCategory_1.TransformerLoggerCategory.IModelExporter;
|
|
18
17
|
/** Handles the events generated by IModelExporter.
|
|
19
18
|
* @note Change information is available when `IModelExportHandler` methods are invoked via [IModelExporter.exportChanges]($transformer), but not available when invoked via [IModelExporter.exportAll]($transformer).
|
|
@@ -218,15 +217,13 @@ class IModelExporter {
|
|
|
218
217
|
await this.exportModel(core_common_1.IModel.repositoryModelId);
|
|
219
218
|
await this.exportRelationships(core_backend_1.ElementRefersToElements.classFullName);
|
|
220
219
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
: optionsOrAccessToken;
|
|
220
|
+
/** Export changes from the source iModel.
|
|
221
|
+
* @param user The user
|
|
222
|
+
* @param startChangesetId Include changes from this changeset up through and including the current changeset.
|
|
223
|
+
* If this parameter is not provided, then just the current changeset will be exported.
|
|
224
|
+
* @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.
|
|
225
|
+
*/
|
|
226
|
+
async exportChanges(user, startChangesetId) {
|
|
230
227
|
if (!this.sourceDb.isBriefcaseDb()) {
|
|
231
228
|
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadRequest, "Must be a briefcase to export changes");
|
|
232
229
|
}
|
|
@@ -234,7 +231,10 @@ class IModelExporter {
|
|
|
234
231
|
await this.exportAll(); // no changesets, so revert to exportAll
|
|
235
232
|
return;
|
|
236
233
|
}
|
|
237
|
-
|
|
234
|
+
if (undefined === startChangesetId) {
|
|
235
|
+
startChangesetId = this.sourceDb.changeset.id;
|
|
236
|
+
}
|
|
237
|
+
this._sourceDbChanges = await ChangedInstanceIds.initialize(user, this.sourceDb, startChangesetId);
|
|
238
238
|
await this.exportCodeSpecs();
|
|
239
239
|
await this.exportFonts();
|
|
240
240
|
await this.exportModelContents(core_common_1.IModel.repositoryModelId);
|
|
@@ -773,41 +773,21 @@ class ChangedInstanceIds {
|
|
|
773
773
|
this.relationship = new ChangedInstanceOps();
|
|
774
774
|
this.font = new ChangedInstanceOps();
|
|
775
775
|
}
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
const
|
|
786
|
-
const
|
|
787
|
-
const
|
|
788
|
-
?? [[
|
|
789
|
-
opts.startChangeset.index
|
|
790
|
-
?? (await core_backend_1.IModelHost.hubAccess.queryChangeset({
|
|
791
|
-
iModelId,
|
|
792
|
-
changeset: { id: opts.startChangeset.id },
|
|
793
|
-
accessToken,
|
|
794
|
-
})).index,
|
|
795
|
-
opts.iModel.changeset.index
|
|
796
|
-
?? (await core_backend_1.IModelHost.hubAccess.queryChangeset({
|
|
797
|
-
iModelId,
|
|
798
|
-
changeset: { id: opts.iModel.changeset.id },
|
|
799
|
-
accessToken,
|
|
800
|
-
})).index,
|
|
801
|
-
]];
|
|
802
|
-
core_bentley_1.Logger.logTrace(loggerCategory, `ChangedInstanceIds.initialize ranges: ${changesetRanges.join("|")}`);
|
|
803
|
-
const changesets = (await Promise.all(changesetRanges.map(async ([first, end]) => core_backend_1.IModelHost.hubAccess.downloadChangesets({
|
|
804
|
-
accessToken,
|
|
805
|
-
iModelId, range: { first, end },
|
|
806
|
-
targetDir: core_backend_1.BriefcaseManager.getChangeSetsPath(iModelId),
|
|
807
|
-
})))).flat();
|
|
776
|
+
/**
|
|
777
|
+
* Initializes a new ChangedInstanceIds object with information taken from a range of changesets.
|
|
778
|
+
* @param accessToken Access token.
|
|
779
|
+
* @param iModel IModel briefcase whose changesets will be queried.
|
|
780
|
+
* @param firstChangesetId Changeset id.
|
|
781
|
+
* @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.
|
|
782
|
+
*/
|
|
783
|
+
static async initialize(accessToken, iModel, firstChangesetId) {
|
|
784
|
+
const iModelId = iModel.iModelId;
|
|
785
|
+
const first = (await core_backend_1.IModelHost.hubAccess.queryChangeset({ iModelId, changeset: { id: firstChangesetId }, accessToken })).index;
|
|
786
|
+
const end = (await core_backend_1.IModelHost.hubAccess.queryChangeset({ iModelId, changeset: { id: iModel.changeset.id }, accessToken })).index;
|
|
787
|
+
const changesets = await core_backend_1.IModelHost.hubAccess.downloadChangesets({ accessToken, iModelId, range: { first, end }, targetDir: core_backend_1.BriefcaseManager.getChangeSetsPath(iModelId) });
|
|
808
788
|
const changedInstanceIds = new ChangedInstanceIds();
|
|
809
789
|
const changesetFiles = changesets.map((c) => c.pathname);
|
|
810
|
-
const statusOrResult =
|
|
790
|
+
const statusOrResult = iModel.nativeDb.extractChangedInstanceIdsFromChangeSets(changesetFiles);
|
|
811
791
|
if (statusOrResult.error) {
|
|
812
792
|
throw new core_common_1.IModelError(statusOrResult.error.status, "Error processing changeset");
|
|
813
793
|
}
|