@itwin/core-backend 4.1.0-dev.6 → 4.1.0-dev.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +74 -1
- package/lib/cjs/BlobContainerService.d.ts +38 -28
- package/lib/cjs/BlobContainerService.d.ts.map +1 -1
- package/lib/cjs/BlobContainerService.js.map +1 -1
- package/lib/cjs/BriefcaseManager.d.ts +8 -5
- package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
- package/lib/cjs/BriefcaseManager.js +8 -15
- package/lib/cjs/BriefcaseManager.js.map +1 -1
- package/lib/cjs/Category.d.ts +4 -16
- package/lib/cjs/Category.d.ts.map +1 -1
- package/lib/cjs/Category.js +0 -12
- package/lib/cjs/Category.js.map +1 -1
- package/lib/cjs/ChannelControl.d.ts +5 -1
- package/lib/cjs/ChannelControl.d.ts.map +1 -1
- package/lib/cjs/ChannelControl.js +10 -5
- package/lib/cjs/ChannelControl.js.map +1 -1
- package/lib/cjs/CheckpointManager.d.ts.map +1 -1
- package/lib/cjs/CheckpointManager.js +20 -9
- package/lib/cjs/CheckpointManager.js.map +1 -1
- package/lib/cjs/ClassRegistry.d.ts +3 -2
- package/lib/cjs/ClassRegistry.d.ts.map +1 -1
- package/lib/cjs/ClassRegistry.js +3 -2
- package/lib/cjs/ClassRegistry.js.map +1 -1
- package/lib/cjs/CloudSqlite.d.ts +57 -40
- package/lib/cjs/CloudSqlite.d.ts.map +1 -1
- package/lib/cjs/CloudSqlite.js +54 -39
- package/lib/cjs/CloudSqlite.js.map +1 -1
- package/lib/cjs/DisplayStyle.d.ts +2 -5
- package/lib/cjs/DisplayStyle.d.ts.map +1 -1
- package/lib/cjs/DisplayStyle.js +0 -3
- package/lib/cjs/DisplayStyle.js.map +1 -1
- package/lib/cjs/ECDb.d.ts +6 -0
- package/lib/cjs/ECDb.d.ts.map +1 -1
- package/lib/cjs/ECDb.js +6 -0
- package/lib/cjs/ECDb.js.map +1 -1
- package/lib/cjs/Element.d.ts +40 -97
- package/lib/cjs/Element.d.ts.map +1 -1
- package/lib/cjs/Element.js +0 -57
- package/lib/cjs/Element.js.map +1 -1
- package/lib/cjs/ElementAspect.d.ts +0 -2
- package/lib/cjs/ElementAspect.d.ts.map +1 -1
- package/lib/cjs/ElementAspect.js +0 -2
- package/lib/cjs/ElementAspect.js.map +1 -1
- package/lib/cjs/Entity.d.ts +5 -2
- package/lib/cjs/Entity.d.ts.map +1 -1
- package/lib/cjs/Entity.js +10 -2
- package/lib/cjs/Entity.js.map +1 -1
- package/lib/cjs/ExternalSource.d.ts +4 -11
- package/lib/cjs/ExternalSource.d.ts.map +1 -1
- package/lib/cjs/ExternalSource.js +0 -7
- package/lib/cjs/ExternalSource.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +62 -27
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +165 -84
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IModelHost.d.ts +1 -3
- package/lib/cjs/IModelHost.d.ts.map +1 -1
- package/lib/cjs/IModelHost.js +1 -3
- package/lib/cjs/IModelHost.js.map +1 -1
- package/lib/cjs/IpcHost.d.ts +8 -2
- package/lib/cjs/IpcHost.d.ts.map +1 -1
- package/lib/cjs/IpcHost.js +6 -6
- package/lib/cjs/IpcHost.js.map +1 -1
- package/lib/cjs/LocalhostIpcHost.d.ts.map +1 -1
- package/lib/cjs/LocalhostIpcHost.js +2 -3
- package/lib/cjs/LocalhostIpcHost.js.map +1 -1
- package/lib/cjs/Material.d.ts +0 -1
- package/lib/cjs/Material.d.ts.map +1 -1
- package/lib/cjs/Material.js +0 -1
- package/lib/cjs/Material.js.map +1 -1
- package/lib/cjs/Model.d.ts +4 -13
- package/lib/cjs/Model.d.ts.map +1 -1
- package/lib/cjs/Model.js +0 -9
- package/lib/cjs/Model.js.map +1 -1
- package/lib/cjs/NativeHost.d.ts.map +1 -1
- package/lib/cjs/NativeHost.js +2 -2
- package/lib/cjs/NativeHost.js.map +1 -1
- package/lib/cjs/PropertyStore.d.ts +3 -3
- package/lib/cjs/PropertyStore.d.ts.map +1 -1
- package/lib/cjs/PropertyStore.js +2 -5
- package/lib/cjs/PropertyStore.js.map +1 -1
- package/lib/cjs/Relationship.d.ts +2 -5
- package/lib/cjs/Relationship.d.ts.map +1 -1
- package/lib/cjs/Relationship.js +0 -3
- package/lib/cjs/Relationship.js.map +1 -1
- package/lib/cjs/SQLiteDb.d.ts +1 -1
- package/lib/cjs/SQLiteDb.d.ts.map +1 -1
- package/lib/cjs/SQLiteDb.js +1 -1
- package/lib/cjs/SQLiteDb.js.map +1 -1
- package/lib/cjs/Schema.d.ts +0 -1
- package/lib/cjs/Schema.d.ts.map +1 -1
- package/lib/cjs/Schema.js +0 -1
- package/lib/cjs/Schema.js.map +1 -1
- package/lib/cjs/SchemaUtils.d.ts +16 -0
- package/lib/cjs/SchemaUtils.d.ts.map +1 -0
- package/lib/cjs/SchemaUtils.js +42 -0
- package/lib/cjs/SchemaUtils.js.map +1 -0
- package/lib/cjs/SqliteStatement.d.ts +13 -1
- package/lib/cjs/SqliteStatement.d.ts.map +1 -1
- package/lib/cjs/SqliteStatement.js +23 -1
- package/lib/cjs/SqliteStatement.js.map +1 -1
- package/lib/cjs/Texture.d.ts +3 -4
- package/lib/cjs/Texture.d.ts.map +1 -1
- package/lib/cjs/Texture.js +1 -2
- package/lib/cjs/Texture.js.map +1 -1
- package/lib/cjs/TileStorage.d.ts +3 -0
- package/lib/cjs/TileStorage.d.ts.map +1 -1
- package/lib/cjs/TileStorage.js +9 -1
- package/lib/cjs/TileStorage.js.map +1 -1
- package/lib/cjs/ViewDefinition.d.ts +7 -28
- package/lib/cjs/ViewDefinition.d.ts.map +1 -1
- package/lib/cjs/ViewDefinition.js +0 -21
- package/lib/cjs/ViewDefinition.js.map +1 -1
- package/lib/cjs/ViewStore.d.ts +488 -0
- package/lib/cjs/ViewStore.d.ts.map +1 -0
- package/lib/cjs/ViewStore.js +1246 -0
- package/lib/cjs/ViewStore.js.map +1 -0
- package/lib/cjs/core-backend.d.ts +2 -0
- package/lib/cjs/core-backend.d.ts.map +1 -1
- package/lib/cjs/core-backend.js +2 -0
- package/lib/cjs/core-backend.js.map +1 -1
- package/lib/cjs/domains/FunctionalElements.d.ts +6 -12
- package/lib/cjs/domains/FunctionalElements.d.ts.map +1 -1
- package/lib/cjs/domains/FunctionalElements.js +0 -6
- package/lib/cjs/domains/FunctionalElements.js.map +1 -1
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +5 -3
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +53 -36
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +0 -2
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
- package/lib/cjs/workspace/Workspace.d.ts +1 -1
- package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
- package/lib/cjs/workspace/Workspace.js +4 -4
- package/lib/cjs/workspace/Workspace.js.map +1 -1
- package/package.json +20 -19
package/lib/cjs/Category.js
CHANGED
|
@@ -19,7 +19,6 @@ const NavigationRelationship_1 = require("./NavigationRelationship");
|
|
|
19
19
|
class SubCategory extends Element_1.DefinitionElement {
|
|
20
20
|
/** @internal */
|
|
21
21
|
static get className() { return "SubCategory"; }
|
|
22
|
-
/** @internal */
|
|
23
22
|
constructor(props, iModel) {
|
|
24
23
|
super(props, iModel);
|
|
25
24
|
this.appearance = new core_common_1.SubCategoryAppearance(props.appearance);
|
|
@@ -91,7 +90,6 @@ exports.SubCategory = SubCategory;
|
|
|
91
90
|
class Category extends Element_1.DefinitionElement {
|
|
92
91
|
/** @internal */
|
|
93
92
|
static get className() { return "Category"; }
|
|
94
|
-
/** @internal */
|
|
95
93
|
constructor(props, iModel) {
|
|
96
94
|
super(props, iModel);
|
|
97
95
|
this.rank = core_common_1.Rank.User;
|
|
@@ -124,11 +122,6 @@ exports.Category = Category;
|
|
|
124
122
|
class DrawingCategory extends Category {
|
|
125
123
|
/** @internal */
|
|
126
124
|
static get className() { return "DrawingCategory"; }
|
|
127
|
-
/** Construct a DrawingCategory
|
|
128
|
-
* @param opts The properties of the new DrawingCategory
|
|
129
|
-
* @param iModel The IModelDb where the DrawingCategory may be inserted.
|
|
130
|
-
* @internal
|
|
131
|
-
*/
|
|
132
125
|
constructor(opts, iModel) { super(opts, iModel); }
|
|
133
126
|
/** Get the name of the CodeSpec that is used by DrawingCategory objects. */
|
|
134
127
|
static getCodeSpecName() { return core_common_1.BisCodeSpec.drawingCategory; }
|
|
@@ -186,11 +179,6 @@ exports.DrawingCategory = DrawingCategory;
|
|
|
186
179
|
class SpatialCategory extends Category {
|
|
187
180
|
/** @internal */
|
|
188
181
|
static get className() { return "SpatialCategory"; }
|
|
189
|
-
/** Construct a SpatialCategory
|
|
190
|
-
* @param opts The properties of the new SpatialCategory
|
|
191
|
-
* @param iModel The IModelDb where the SpatialCategory may be inserted.
|
|
192
|
-
* @internal
|
|
193
|
-
*/
|
|
194
182
|
constructor(opts, iModel) { super(opts, iModel); }
|
|
195
183
|
/** Get the name of the CodeSpec that is used by SpatialCategory objects. */
|
|
196
184
|
static getCodeSpecName() { return core_common_1.BisCodeSpec.spatialCategory; }
|
package/lib/cjs/Category.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Category.js","sourceRoot":"","sources":["../../src/Category.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAkE;AAClE,oDAE4B;AAC5B,uCAA8C;AAC9C,yCAAsC;AACtC,qEAAqE;AAErE;;GAEG;AACH,MAAa,WAAY,SAAQ,2BAAiB;IAChD,gBAAgB;IACT,MAAM,KAAc,SAAS,KAAa,OAAO,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AE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAChF,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,QAAkB,EAAE,iBAA6B,EAAE,IAAY;QAClF,MAAM,aAAa,GAAkB;YACnC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,KAAK,EAAE,iBAAiB;YACxB,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAiB,EAAE,IAAI,CAAC;YACxD,SAAS,EAAE,KAAK;SACjB,CAAC;QACF,OAAO,IAAI,eAAe,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,MAAM,CAAC,QAAkB,EAAE,iBAA6B,EAAE,IAAY,EAAE,iBAAsE;QAC1J,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,iBAAiB,EAAE,IAAI,CAAC,CAAC;QAChE,QAAQ,CAAC,EAAE,GAAG,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;QACjE,QAAQ,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;QACjD,OAAO,QAAQ,CAAC,EAAE,CAAC;IACrB,CAAC;CACF;AA7DD,0CA6DC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Categories\r\n */\r\n\r\nimport { Id64, Id64String, JsonUtils } from \"@itwin/core-bentley\";\r\nimport {\r\n BisCodeSpec, CategoryProps, Code, CodeScopeProps, CodeSpec, ElementProps, Rank, SubCategoryAppearance, SubCategoryProps,\r\n} from \"@itwin/core-common\";\r\nimport { DefinitionElement } from \"./Element\";\r\nimport { IModelDb } from \"./IModelDb\";\r\nimport { CategoryOwnsSubCategories } from \"./NavigationRelationship\";\r\n\r\n/** Defines the appearance for graphics in Geometric elements\r\n * @public\r\n */\r\nexport class SubCategory extends DefinitionElement {\r\n /** @internal */\r\n public static override get className(): string { return \"SubCategory\"; }\r\n /** The Appearance parameters for this SubCategory */\r\n public appearance: SubCategoryAppearance;\r\n /** Optional description of this SubCategory. */\r\n public description?: string;\r\n\r\n /** @internal */\r\n public constructor(props: SubCategoryProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.appearance = new SubCategoryAppearance(props.appearance);\r\n this.description = JsonUtils.asString(props.description);\r\n }\r\n\r\n /** @internal */\r\n public override toJSON(): SubCategoryProps {\r\n const val = super.toJSON() as SubCategoryProps;\r\n val.appearance = this.appearance.toJSON();\r\n if (this.description && this.description.length > 0)\r\n val.description = this.description;\r\n return val;\r\n }\r\n\r\n /** Get the SubCategory's name (its Code value). */\r\n public getSubCategoryName(): string { return this.code.value; }\r\n /** Get the Id of the SubCategory. */\r\n public getSubCategoryId(): Id64String { return this.id; }\r\n /** Get the Id of this SubCategory's parent Category. */\r\n public getCategoryId(): Id64String { return this.parent ? this.parent.id : Id64.invalid; }\r\n /** Check if this is the default SubCategory of its parent Category. */\r\n public get isDefaultSubCategory(): boolean { return IModelDb.getDefaultSubCategoryId(this.getCategoryId()) === this.getSubCategoryId(); }\r\n\r\n /** Create a Code for a SubCategory given a name that is meant to be unique within the scope of the specified parent Category.\r\n * @param iModel The IModel\r\n * @param parentCategoryId The Id of the parent Category that owns the SubCategory and provides the scope for its name.\r\n * @param codeValue The name of the SubCategory\r\n */\r\n public static createCode(iModel: IModelDb, parentCategoryId: CodeScopeProps, codeValue: string): Code {\r\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(BisCodeSpec.subCategory);\r\n return new Code({ spec: codeSpec.id, scope: parentCategoryId, value: codeValue });\r\n }\r\n\r\n /** Create a new SubCategory\r\n * @param iModelDb The iModel\r\n * @param parentCategoryId Create the new SubCategory as a child of this [[Category]]\r\n * @param name The name of the SubCategory\r\n * @param appearance The appearance settings to use for this SubCategory\r\n * @returns The newly constructed SubCategory element.\r\n * @throws [[IModelError]] if unable to create the element.\r\n */\r\n public static create(iModelDb: IModelDb, parentCategoryId: Id64String, name: string, appearance: SubCategoryAppearance.Props | SubCategoryAppearance): SubCategory {\r\n if (appearance instanceof SubCategoryAppearance)\r\n appearance = appearance.toJSON();\r\n\r\n const parentCategory = iModelDb.elements.getElement<Category>(parentCategoryId);\r\n const subCategoryProps: SubCategoryProps = {\r\n classFullName: this.classFullName,\r\n model: parentCategory.model,\r\n parent: new CategoryOwnsSubCategories(parentCategoryId),\r\n code: this.createCode(iModelDb, parentCategoryId, name),\r\n appearance,\r\n };\r\n return new SubCategory(subCategoryProps, iModelDb);\r\n }\r\n\r\n /** Insert a new SubCategory\r\n * @param iModelDb Insert into this iModel\r\n * @param parentCategoryId Insert the new SubCategory as a child of this Category\r\n * @param name The name of the SubCategory\r\n * @param appearance The appearance settings to use for this SubCategory\r\n * @returns The Id of the newly inserted SubCategory element.\r\n * @throws [[IModelError]] if unable to insert the element.\r\n */\r\n public static insert(iModelDb: IModelDb, parentCategoryId: Id64String, name: string, appearance: SubCategoryAppearance.Props | SubCategoryAppearance): Id64String {\r\n const subCategory = this.create(iModelDb, parentCategoryId, name, appearance);\r\n return iModelDb.elements.insertElement(subCategory.toJSON());\r\n }\r\n}\r\n\r\n/** A Category element is the target of the `category` member of [[GeometricElement]].\r\n * @public\r\n */\r\nexport class Category extends DefinitionElement {\r\n /** @internal */\r\n public static override get className(): string { return \"Category\"; }\r\n public rank: Rank = Rank.User;\r\n public description?: string;\r\n\r\n /** @internal */\r\n public constructor(props: CategoryProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.rank = JsonUtils.asInt(props.rank);\r\n this.description = JsonUtils.asString(props.description);\r\n }\r\n\r\n /** @internal */\r\n public override toJSON(): CategoryProps {\r\n const val = super.toJSON() as CategoryProps;\r\n val.rank = this.rank;\r\n if (this.description && this.description.length > 0)\r\n val.description = this.description;\r\n return val;\r\n }\r\n\r\n /** Get the Id of the default SubCategory for this Category. */\r\n public myDefaultSubCategoryId(): Id64String { return IModelDb.getDefaultSubCategoryId(this.id); }\r\n\r\n /** Set the appearance of the default SubCategory for this Category */\r\n public setDefaultAppearance(props: SubCategoryAppearance.Props | SubCategoryAppearance): void {\r\n if (props instanceof SubCategoryAppearance)\r\n props = props.toJSON();\r\n\r\n const subCat = this.iModel.elements.getElement<SubCategory>(this.myDefaultSubCategoryId());\r\n subCat.appearance = new SubCategoryAppearance(props);\r\n this.iModel.elements.updateElement(subCat.toJSON());\r\n }\r\n}\r\n\r\n/** Categorizes 2d GeometricElements.\r\n * @public\r\n */\r\nexport class DrawingCategory extends Category {\r\n /** @internal */\r\n public static override get className(): string { return \"DrawingCategory\"; }\r\n\r\n /** Construct a DrawingCategory\r\n * @param opts The properties of the new DrawingCategory\r\n * @param iModel The IModelDb where the DrawingCategory may be inserted.\r\n * @internal\r\n */\r\n public constructor(opts: ElementProps, iModel: IModelDb) { super(opts, iModel); }\r\n\r\n /** Get the name of the CodeSpec that is used by DrawingCategory objects. */\r\n public static getCodeSpecName(): string { return BisCodeSpec.drawingCategory; }\r\n\r\n /** Looks up the CategoryId of a DrawingCategory by model and name */\r\n public static queryCategoryIdByName(iModel: IModelDb, scopeModelId: Id64String, categoryName: string): Id64String | undefined {\r\n const code: Code = DrawingCategory.createCode(iModel, scopeModelId, categoryName);\r\n return iModel.elements.queryElementIdByCode(code);\r\n }\r\n\r\n /** Create a Code for a DrawingCategory given a name that is meant to be unique within the scope of the specified DefinitionModel.\r\n * @param iModel The IModel\r\n * @param scopeModelId The Id of the DefinitionModel that contains the DrawingCategory and provides the scope for its name.\r\n * @param codeValue The name of the category\r\n * @return A drawing category Code\r\n */\r\n public static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, codeValue: string): Code {\r\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(DrawingCategory.getCodeSpecName());\r\n return new Code({ spec: codeSpec.id, scope: scopeModelId, value: codeValue });\r\n }\r\n\r\n /** Create a new DrawingCategory\r\n * @param iModelDb The iModel\r\n * @param definitionModelId The [[DefinitionModel]]\r\n * @param name The name of the DrawingCategory\r\n * @returns The newly constructed DrawingCategory element.\r\n * @throws [[IModelError]] if unable to create the element.\r\n */\r\n public static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string): DrawingCategory {\r\n const categoryProps: CategoryProps = {\r\n classFullName: this.classFullName,\r\n model: definitionModelId,\r\n code: this.createCode(iModelDb, definitionModelId, name),\r\n isPrivate: false,\r\n };\r\n return new DrawingCategory(categoryProps, iModelDb);\r\n }\r\n\r\n /** Insert a new DrawingCategory\r\n * @param iModelDb Insert into this iModel\r\n * @param definitionModelId Insert the new DrawingCategory into this [[DefinitionModel]]\r\n * @param name The name of the DrawingCategory\r\n * @param defaultAppearance The appearance settings to use for the default SubCategory of this DrawingCategory\r\n * @returns The Id of the newly inserted DrawingCategory element.\r\n * @throws [[IModelError]] if unable to insert the element.\r\n */\r\n public static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string, defaultAppearance: SubCategoryAppearance.Props | SubCategoryAppearance): Id64String {\r\n const category = this.create(iModelDb, definitionModelId, name);\r\n const elements = iModelDb.elements;\r\n category.id = elements.insertElement(category.toJSON());\r\n category.setDefaultAppearance(defaultAppearance);\r\n return category.id;\r\n }\r\n}\r\n\r\n/** Categorizes SpatialElements. See [how to create a SpatialCategory]($docs/learning/backend/CreateElements.md#SpatialCategory).\r\n * @public\r\n */\r\nexport class SpatialCategory extends Category {\r\n /** @internal */\r\n public static override get className(): string { return \"SpatialCategory\"; }\r\n /** Construct a SpatialCategory\r\n * @param opts The properties of the new SpatialCategory\r\n * @param iModel The IModelDb where the SpatialCategory may be inserted.\r\n * @internal\r\n */\r\n public constructor(opts: ElementProps, iModel: IModelDb) { super(opts, iModel); }\r\n\r\n /** Get the name of the CodeSpec that is used by SpatialCategory objects. */\r\n public static getCodeSpecName(): string { return BisCodeSpec.spatialCategory; }\r\n\r\n /** Looks up the CategoryId of a SpatialCategory by model and name */\r\n public static queryCategoryIdByName(iModel: IModelDb, scopeModelId: Id64String, categoryName: string): Id64String | undefined {\r\n const code: Code = SpatialCategory.createCode(iModel, scopeModelId, categoryName);\r\n return iModel.elements.queryElementIdByCode(code);\r\n }\r\n\r\n /** Create a Code for a SpatialCategory given a name that is meant to be unique within the scope of the specified DefinitionModel.\r\n * @param iModel The IModel\r\n * @param scopeModelId The Id of the DefinitionModel that contains the SpatialCategory and provides the scope for its name.\r\n * @param codeValue The name of the category\r\n * @return A spatial category Code\r\n */\r\n public static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, codeValue: string): Code {\r\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(SpatialCategory.getCodeSpecName());\r\n return new Code({ spec: codeSpec.id, scope: scopeModelId, value: codeValue });\r\n }\r\n\r\n /** Create a new SpatialCategory\r\n * @param iModelDb The iModel\r\n * @param definitionModelId The [[DefinitionModel]]\r\n * @param name The name/CodeValue of the SpatialCategory\r\n * @returns The newly constructed SpatialCategory element.\r\n * @throws [[IModelError]] if unable to create the element.\r\n */\r\n public static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string): SpatialCategory {\r\n const categoryProps: CategoryProps = {\r\n classFullName: this.classFullName,\r\n model: definitionModelId,\r\n code: this.createCode(iModelDb, definitionModelId, name),\r\n isPrivate: false,\r\n };\r\n return new SpatialCategory(categoryProps, iModelDb);\r\n }\r\n\r\n /** Insert a new SpatialCategory\r\n * @param iModelDb Insert into this iModel\r\n * @param definitionModelId Insert the new SpatialCategory into this DefinitionModel\r\n * @param name The name of the SpatialCategory\r\n * @param defaultAppearance The appearance settings to use for the default SubCategory of this SpatialCategory\r\n * @returns The Id of the newly inserted SpatialCategory element.\r\n * @throws [[IModelError]] if unable to insert the element.\r\n */\r\n public static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string, defaultAppearance: SubCategoryAppearance.Props | SubCategoryAppearance): Id64String {\r\n const category = this.create(iModelDb, definitionModelId, name);\r\n category.id = iModelDb.elements.insertElement(category.toJSON());\r\n category.setDefaultAppearance(defaultAppearance);\r\n return category.id;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Category.js","sourceRoot":"","sources":["../../src/Category.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAkE;AAClE,oDAE4B;AAC5B,uCAA8C;AAC9C,yCAAsC;AACtC,qEAAqE;AAErE;;GAEG;AACH,MAAa,WAAY,SAAQ,2BAAiB;IAChD,gBAAgB;IACT,MAAM,KAAc,SAAS,KAAa,OAAO,aAAa,CAAC,CAAC,CAAC;IAMxE,YAAsB,KAAuB,EAAE,MAAgB;QAC7D,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,IAAI,mCAAqB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC9D,IAAI,CAAC,WAAW,GAAG,wBAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC3D,CAAC;IAED,gBAAgB;IACA,MAAM;QACpB,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,EAAsB,CAAC;QAC/C,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;QAC1C,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC;YACjD,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACrC,OAAO,GAAG,CAAC;IACb,CAAC;IAED,mDAAmD;IAC5C,kBAAkB,KAAa,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/D,qCAAqC;IAC9B,gBAAgB,KAAiB,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC,CA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AC,EAAE,CAAC;IACrB,CAAC;CACF;AAxDD,0CAwDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Categories\r\n */\r\n\r\nimport { Id64, Id64String, JsonUtils } from \"@itwin/core-bentley\";\r\nimport {\r\n BisCodeSpec, CategoryProps, Code, CodeScopeProps, CodeSpec, ElementProps, Rank, SubCategoryAppearance, SubCategoryProps,\r\n} from \"@itwin/core-common\";\r\nimport { DefinitionElement } from \"./Element\";\r\nimport { IModelDb } from \"./IModelDb\";\r\nimport { CategoryOwnsSubCategories } from \"./NavigationRelationship\";\r\n\r\n/** Defines the appearance for graphics in Geometric elements\r\n * @public\r\n */\r\nexport class SubCategory extends DefinitionElement {\r\n /** @internal */\r\n public static override get className(): string { return \"SubCategory\"; }\r\n /** The Appearance parameters for this SubCategory */\r\n public appearance: SubCategoryAppearance;\r\n /** Optional description of this SubCategory. */\r\n public description?: string;\r\n\r\n protected constructor(props: SubCategoryProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.appearance = new SubCategoryAppearance(props.appearance);\r\n this.description = JsonUtils.asString(props.description);\r\n }\r\n\r\n /** @internal */\r\n public override toJSON(): SubCategoryProps {\r\n const val = super.toJSON() as SubCategoryProps;\r\n val.appearance = this.appearance.toJSON();\r\n if (this.description && this.description.length > 0)\r\n val.description = this.description;\r\n return val;\r\n }\r\n\r\n /** Get the SubCategory's name (its Code value). */\r\n public getSubCategoryName(): string { return this.code.value; }\r\n /** Get the Id of the SubCategory. */\r\n public getSubCategoryId(): Id64String { return this.id; }\r\n /** Get the Id of this SubCategory's parent Category. */\r\n public getCategoryId(): Id64String { return this.parent ? this.parent.id : Id64.invalid; }\r\n /** Check if this is the default SubCategory of its parent Category. */\r\n public get isDefaultSubCategory(): boolean { return IModelDb.getDefaultSubCategoryId(this.getCategoryId()) === this.getSubCategoryId(); }\r\n\r\n /** Create a Code for a SubCategory given a name that is meant to be unique within the scope of the specified parent Category.\r\n * @param iModel The IModel\r\n * @param parentCategoryId The Id of the parent Category that owns the SubCategory and provides the scope for its name.\r\n * @param codeValue The name of the SubCategory\r\n */\r\n public static createCode(iModel: IModelDb, parentCategoryId: CodeScopeProps, codeValue: string): Code {\r\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(BisCodeSpec.subCategory);\r\n return new Code({ spec: codeSpec.id, scope: parentCategoryId, value: codeValue });\r\n }\r\n\r\n /** Create a new SubCategory\r\n * @param iModelDb The iModel\r\n * @param parentCategoryId Create the new SubCategory as a child of this [[Category]]\r\n * @param name The name of the SubCategory\r\n * @param appearance The appearance settings to use for this SubCategory\r\n * @returns The newly constructed SubCategory element.\r\n * @throws [[IModelError]] if unable to create the element.\r\n */\r\n public static create(iModelDb: IModelDb, parentCategoryId: Id64String, name: string, appearance: SubCategoryAppearance.Props | SubCategoryAppearance): SubCategory {\r\n if (appearance instanceof SubCategoryAppearance)\r\n appearance = appearance.toJSON();\r\n\r\n const parentCategory = iModelDb.elements.getElement<Category>(parentCategoryId);\r\n const subCategoryProps: SubCategoryProps = {\r\n classFullName: this.classFullName,\r\n model: parentCategory.model,\r\n parent: new CategoryOwnsSubCategories(parentCategoryId),\r\n code: this.createCode(iModelDb, parentCategoryId, name),\r\n appearance,\r\n };\r\n return new SubCategory(subCategoryProps, iModelDb);\r\n }\r\n\r\n /** Insert a new SubCategory\r\n * @param iModelDb Insert into this iModel\r\n * @param parentCategoryId Insert the new SubCategory as a child of this Category\r\n * @param name The name of the SubCategory\r\n * @param appearance The appearance settings to use for this SubCategory\r\n * @returns The Id of the newly inserted SubCategory element.\r\n * @throws [[IModelError]] if unable to insert the element.\r\n */\r\n public static insert(iModelDb: IModelDb, parentCategoryId: Id64String, name: string, appearance: SubCategoryAppearance.Props | SubCategoryAppearance): Id64String {\r\n const subCategory = this.create(iModelDb, parentCategoryId, name, appearance);\r\n return iModelDb.elements.insertElement(subCategory.toJSON());\r\n }\r\n}\r\n\r\n/** A Category element is the target of the `category` member of [[GeometricElement]].\r\n * @public\r\n */\r\nexport class Category extends DefinitionElement {\r\n /** @internal */\r\n public static override get className(): string { return \"Category\"; }\r\n public rank: Rank = Rank.User;\r\n public description?: string;\r\n\r\n protected constructor(props: CategoryProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.rank = JsonUtils.asInt(props.rank);\r\n this.description = JsonUtils.asString(props.description);\r\n }\r\n\r\n /** @internal */\r\n public override toJSON(): CategoryProps {\r\n const val = super.toJSON() as CategoryProps;\r\n val.rank = this.rank;\r\n if (this.description && this.description.length > 0)\r\n val.description = this.description;\r\n return val;\r\n }\r\n\r\n /** Get the Id of the default SubCategory for this Category. */\r\n public myDefaultSubCategoryId(): Id64String { return IModelDb.getDefaultSubCategoryId(this.id); }\r\n\r\n /** Set the appearance of the default SubCategory for this Category */\r\n public setDefaultAppearance(props: SubCategoryAppearance.Props | SubCategoryAppearance): void {\r\n if (props instanceof SubCategoryAppearance)\r\n props = props.toJSON();\r\n\r\n const subCat = this.iModel.elements.getElement<SubCategory>(this.myDefaultSubCategoryId());\r\n subCat.appearance = new SubCategoryAppearance(props);\r\n this.iModel.elements.updateElement(subCat.toJSON());\r\n }\r\n}\r\n\r\n/** Categorizes 2d GeometricElements.\r\n * @public\r\n */\r\nexport class DrawingCategory extends Category {\r\n /** @internal */\r\n public static override get className(): string { return \"DrawingCategory\"; }\r\n\r\n protected constructor(opts: ElementProps, iModel: IModelDb) { super(opts, iModel); }\r\n\r\n /** Get the name of the CodeSpec that is used by DrawingCategory objects. */\r\n public static getCodeSpecName(): string { return BisCodeSpec.drawingCategory; }\r\n\r\n /** Looks up the CategoryId of a DrawingCategory by model and name */\r\n public static queryCategoryIdByName(iModel: IModelDb, scopeModelId: Id64String, categoryName: string): Id64String | undefined {\r\n const code: Code = DrawingCategory.createCode(iModel, scopeModelId, categoryName);\r\n return iModel.elements.queryElementIdByCode(code);\r\n }\r\n\r\n /** Create a Code for a DrawingCategory given a name that is meant to be unique within the scope of the specified DefinitionModel.\r\n * @param iModel The IModel\r\n * @param scopeModelId The Id of the DefinitionModel that contains the DrawingCategory and provides the scope for its name.\r\n * @param codeValue The name of the category\r\n * @return A drawing category Code\r\n */\r\n public static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, codeValue: string): Code {\r\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(DrawingCategory.getCodeSpecName());\r\n return new Code({ spec: codeSpec.id, scope: scopeModelId, value: codeValue });\r\n }\r\n\r\n /** Create a new DrawingCategory\r\n * @param iModelDb The iModel\r\n * @param definitionModelId The [[DefinitionModel]]\r\n * @param name The name of the DrawingCategory\r\n * @returns The newly constructed DrawingCategory element.\r\n * @throws [[IModelError]] if unable to create the element.\r\n */\r\n public static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string): DrawingCategory {\r\n const categoryProps: CategoryProps = {\r\n classFullName: this.classFullName,\r\n model: definitionModelId,\r\n code: this.createCode(iModelDb, definitionModelId, name),\r\n isPrivate: false,\r\n };\r\n return new DrawingCategory(categoryProps, iModelDb);\r\n }\r\n\r\n /** Insert a new DrawingCategory\r\n * @param iModelDb Insert into this iModel\r\n * @param definitionModelId Insert the new DrawingCategory into this [[DefinitionModel]]\r\n * @param name The name of the DrawingCategory\r\n * @param defaultAppearance The appearance settings to use for the default SubCategory of this DrawingCategory\r\n * @returns The Id of the newly inserted DrawingCategory element.\r\n * @throws [[IModelError]] if unable to insert the element.\r\n */\r\n public static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string, defaultAppearance: SubCategoryAppearance.Props | SubCategoryAppearance): Id64String {\r\n const category = this.create(iModelDb, definitionModelId, name);\r\n const elements = iModelDb.elements;\r\n category.id = elements.insertElement(category.toJSON());\r\n category.setDefaultAppearance(defaultAppearance);\r\n return category.id;\r\n }\r\n}\r\n\r\n/** Categorizes SpatialElements. See [how to create a SpatialCategory]($docs/learning/backend/CreateElements.md#SpatialCategory).\r\n * @public\r\n */\r\nexport class SpatialCategory extends Category {\r\n /** @internal */\r\n public static override get className(): string { return \"SpatialCategory\"; }\r\n protected constructor(opts: ElementProps, iModel: IModelDb) { super(opts, iModel); }\r\n\r\n /** Get the name of the CodeSpec that is used by SpatialCategory objects. */\r\n public static getCodeSpecName(): string { return BisCodeSpec.spatialCategory; }\r\n\r\n /** Looks up the CategoryId of a SpatialCategory by model and name */\r\n public static queryCategoryIdByName(iModel: IModelDb, scopeModelId: Id64String, categoryName: string): Id64String | undefined {\r\n const code: Code = SpatialCategory.createCode(iModel, scopeModelId, categoryName);\r\n return iModel.elements.queryElementIdByCode(code);\r\n }\r\n\r\n /** Create a Code for a SpatialCategory given a name that is meant to be unique within the scope of the specified DefinitionModel.\r\n * @param iModel The IModel\r\n * @param scopeModelId The Id of the DefinitionModel that contains the SpatialCategory and provides the scope for its name.\r\n * @param codeValue The name of the category\r\n * @return A spatial category Code\r\n */\r\n public static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, codeValue: string): Code {\r\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(SpatialCategory.getCodeSpecName());\r\n return new Code({ spec: codeSpec.id, scope: scopeModelId, value: codeValue });\r\n }\r\n\r\n /** Create a new SpatialCategory\r\n * @param iModelDb The iModel\r\n * @param definitionModelId The [[DefinitionModel]]\r\n * @param name The name/CodeValue of the SpatialCategory\r\n * @returns The newly constructed SpatialCategory element.\r\n * @throws [[IModelError]] if unable to create the element.\r\n */\r\n public static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string): SpatialCategory {\r\n const categoryProps: CategoryProps = {\r\n classFullName: this.classFullName,\r\n model: definitionModelId,\r\n code: this.createCode(iModelDb, definitionModelId, name),\r\n isPrivate: false,\r\n };\r\n return new SpatialCategory(categoryProps, iModelDb);\r\n }\r\n\r\n /** Insert a new SpatialCategory\r\n * @param iModelDb Insert into this iModel\r\n * @param definitionModelId Insert the new SpatialCategory into this DefinitionModel\r\n * @param name The name of the SpatialCategory\r\n * @param defaultAppearance The appearance settings to use for the default SubCategory of this SpatialCategory\r\n * @returns The Id of the newly inserted SpatialCategory element.\r\n * @throws [[IModelError]] if unable to insert the element.\r\n */\r\n public static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string, defaultAppearance: SubCategoryAppearance.Props | SubCategoryAppearance): Id64String {\r\n const category = this.create(iModelDb, definitionModelId, name);\r\n category.id = iModelDb.elements.insertElement(category.toJSON());\r\n category.setDefaultAppearance(defaultAppearance);\r\n return category.id;\r\n }\r\n}\r\n"]}
|
|
@@ -52,10 +52,14 @@ export interface ChannelControl {
|
|
|
52
52
|
/** @internal */
|
|
53
53
|
verifyChannel(modelId: Id64String): void;
|
|
54
54
|
}
|
|
55
|
+
/** @beta */
|
|
56
|
+
export declare namespace ChannelControl {
|
|
57
|
+
/** the name of the special "shared" channel holding information that is editable by any application. */
|
|
58
|
+
const sharedChannelName = "shared";
|
|
59
|
+
}
|
|
55
60
|
/** @internal */
|
|
56
61
|
export declare class ChannelAdmin implements ChannelControl {
|
|
57
62
|
private _iModel;
|
|
58
|
-
/** the name of the special "shared" channel holding information that is editable by any application. */
|
|
59
63
|
static readonly sharedChannel = "shared";
|
|
60
64
|
static readonly channelClassName = "bis:ChannelRootAspect";
|
|
61
65
|
private _allowedChannels;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChannelControl.d.ts","sourceRoot":"","sources":["../../src/ChannelControl.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAY,UAAU,EAAkC,MAAM,qBAAqB,CAAC;AAG3F,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,kEAAkE;IAClE,IAAI,WAAW,IAAI,OAAO,CAAC;IAC3B;;OAEG;IACH,iBAAiB,CAAC,UA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QAAC,UAAU,EAAE,UAAU,CAAC;QAAC,eAAe,CAAC,EAAE,UAAU,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,UAAU;CAKnJ"}
|
|
@@ -7,10 +7,16 @@
|
|
|
7
7
|
* @module Elements
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.ChannelAdmin = void 0;
|
|
10
|
+
exports.ChannelAdmin = exports.ChannelControl = void 0;
|
|
11
11
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
12
|
const core_common_1 = require("@itwin/core-common");
|
|
13
13
|
const Element_1 = require("./Element");
|
|
14
|
+
/** @beta */
|
|
15
|
+
var ChannelControl;
|
|
16
|
+
(function (ChannelControl) {
|
|
17
|
+
/** the name of the special "shared" channel holding information that is editable by any application. */
|
|
18
|
+
ChannelControl.sharedChannelName = "shared";
|
|
19
|
+
})(ChannelControl = exports.ChannelControl || (exports.ChannelControl = {}));
|
|
14
20
|
/** @internal */
|
|
15
21
|
class ChannelAdmin {
|
|
16
22
|
constructor(_iModel) {
|
|
@@ -18,7 +24,7 @@ class ChannelAdmin {
|
|
|
18
24
|
this._allowedChannels = new Set();
|
|
19
25
|
this._allowedModels = new Set();
|
|
20
26
|
this._deniedModels = new Map();
|
|
21
|
-
this._allowedChannels.add(
|
|
27
|
+
this._allowedChannels.add(ChannelControl.sharedChannelName);
|
|
22
28
|
}
|
|
23
29
|
addAllowedChannel(channelKey) {
|
|
24
30
|
this._allowedChannels.add(channelKey);
|
|
@@ -42,7 +48,7 @@ class ChannelAdmin {
|
|
|
42
48
|
}
|
|
43
49
|
getChannelKey(elementId) {
|
|
44
50
|
if (!this.hasChannels || elementId === core_common_1.IModel.rootSubjectId)
|
|
45
|
-
return
|
|
51
|
+
return ChannelControl.sharedChannelName;
|
|
46
52
|
const channel = this._iModel.withPreparedStatement(`SELECT Owner FROM ${ChannelAdmin.channelClassName} WHERE Element.Id=?`, (stmt) => {
|
|
47
53
|
stmt.bindId(1, elementId);
|
|
48
54
|
return core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getValue(0).getString() : undefined;
|
|
@@ -73,7 +79,7 @@ class ChannelAdmin {
|
|
|
73
79
|
return this.verifyChannel(modelId);
|
|
74
80
|
}
|
|
75
81
|
makeChannelRoot(args) {
|
|
76
|
-
if (
|
|
82
|
+
if (ChannelControl.sharedChannelName !== this.getChannelKey(args.elementId))
|
|
77
83
|
throw new Error("channels may not nest");
|
|
78
84
|
const props = { classFullName: ChannelAdmin.channelClassName, element: { id: args.elementId }, owner: args.channelKey };
|
|
79
85
|
this._iModel.elements.insertAspect(props);
|
|
@@ -85,7 +91,6 @@ class ChannelAdmin {
|
|
|
85
91
|
return elementId;
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
|
-
/** the name of the special "shared" channel holding information that is editable by any application. */
|
|
89
94
|
ChannelAdmin.sharedChannel = "shared";
|
|
90
95
|
ChannelAdmin.channelClassName = "bis:ChannelRootAspect";
|
|
91
96
|
exports.ChannelAdmin = ChannelAdmin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChannelControl.js","sourceRoot":"","sources":["../../src/ChannelControl.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA2F;AAC3F,oDAAiF;AACjF,uCAAoC;AAoDpC,gBAAgB;AAChB,MAAa,YAAY;IASvB,YAA2B,OAAiB;QAAjB,YAAO,GAAP,OAAO,CAAU;QALpC,qBAAgB,GAAG,IAAI,GAAG,EAAc,CAAC;QACzC,mBAAc,GAAG,IAAI,GAAG,EAAc,CAAC;QACvC,kBAAa,GAAG,IAAI,GAAG,EAA0B,CAAC;QAIxD,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;IACxD,CAAC;IACM,iBAAiB,CAAC,UAAsB;QAC7C,IAAI,CAAC,gBAAgB,CAAC,GA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AAa,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IACM,eAAe,CAAC,IAAuD;QAC5E,IAAI,YAAY,CAAC,aAAa,KAAK,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC;YACnE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAE3C,MAAM,KAAK,GAA2B,EAAE,aAAa,EAAE,YAAY,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;QAChJ,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IAC3B,CAAC;IACM,oBAAoB,CAAC,IAAyG;QACnI,MAAM,SAAS,GAAG,iBAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,IAAI,oBAAM,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACjI,IAAI,CAAC,eAAe,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QACjE,OAAO,SAAS,CAAC;IACnB,CAAC;;AA7ED,wGAAwG;AACjF,0BAAa,GAAG,QAAQ,AAAX,CAAY;AACzB,6BAAgB,GAAG,uBAAuB,AAA1B,CAA2B;AAHvD,oCAAY","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Elements\r\n */\r\n\r\nimport { DbResult, Id64String, IModelStatus, RepositoryStatus } from \"@itwin/core-bentley\";\r\nimport { ChannelRootAspectProps, IModel, IModelError } from \"@itwin/core-common\";\r\nimport { Subject } from \"./Element\";\r\nimport { IModelDb } from \"./IModelDb\";\r\n\r\n/** The key for a channel. Used for \"allowed channels\" in [[ChannelControl]]\r\n * @beta\r\n */\r\nexport type ChannelKey = string;\r\n\r\n/**\r\n * Controls which channels of an iModel are permitted for write operations. An implementation of this interface is\r\n * available via [[IModelDb.channels]].\r\n * @see [Working With Channels]($docs/learning/backend/Channel.md) for details\r\n * @beta\r\n */\r\nexport interface ChannelControl {\r\n /** Determine whether this [[IModelDb]] has any channels in it. */\r\n get hasChannels(): boolean;\r\n /** Add a new channel to the list of allowed channels of the [[IModelDb]] for this session.\r\n * @param channelKey The key for the channel to become editable in this session.\r\n */\r\n addAllowedChannel(channelKey: ChannelKey): void;\r\n /** Remove a channel from the list of allowed channels of the [[IModelDb]] for this session.\r\n * @param channelKey The key of the channel that should no longer be editable in this session.\r\n */\r\n removeAllowedChannel(channelKey: ChannelKey): void;\r\n /** Get the channelKey of the channel for an element by ElementId.\r\n * @throws if the element does not exist\r\n */\r\n getChannelKey(elementId: Id64String): ChannelKey;\r\n /** Make an existing element a new Channel root.\r\n * @note if the element is already in a channel, this will throw an error.\r\n */\r\n makeChannelRoot(args: { elementId: Id64String, channelKey: ChannelKey }): void;\r\n /** Insert a new Subject element that is a Channel root in this iModel.\r\n * @returns the ElementId of the new Subject element.\r\n * @note if the parentSubject element is already in a channel, this will add the Subject element and then throw an error without making it a Channel root.\r\n */\r\n insertChannelSubject(args: {\r\n /** The name of the new Subject element */\r\n subjectName: string;\r\n /** The channel key for the new [[Subject]]. This is the string to pass to [[addAllowedChannel]]*/\r\n channelKey: ChannelKey;\r\n /** the Id of the parent of the new Subject. Default is [[IModel.rootSubjectId]]. */\r\n parentSubjectId?: Id64String;\r\n /** Optional description for new Subject. */\r\n description?: string;\r\n }): Id64String;\r\n\r\n /** @internal */\r\n verifyChannel(modelId: Id64String): void;\r\n}\r\n\r\n/** @internal */\r\nexport class ChannelAdmin implements ChannelControl {\r\n /** the name of the special \"shared\" channel holding information that is editable by any application. */\r\n public static readonly sharedChannel = \"shared\";\r\n public static readonly channelClassName = \"bis:ChannelRootAspect\";\r\n private _allowedChannels = new Set<ChannelKey>();\r\n private _allowedModels = new Set<Id64String>();\r\n private _deniedModels = new Map<Id64String, ChannelKey>();\r\n private _hasChannels?: boolean;\r\n\r\n public constructor(private _iModel: IModelDb) {\r\n this._allowedChannels.add(ChannelAdmin.sharedChannel);\r\n }\r\n public addAllowedChannel(channelKey: ChannelKey) {\r\n this._allowedChannels.add(channelKey);\r\n this._deniedModels.clear();\r\n }\r\n public removeAllowedChannel(channelKey: ChannelKey) {\r\n this._allowedChannels.delete(channelKey);\r\n this._allowedModels.clear();\r\n }\r\n public get hasChannels(): boolean {\r\n if (undefined === this._hasChannels) {\r\n try {\r\n this._hasChannels = this._iModel.withStatement(`SELECT 1 FROM ${ChannelAdmin.channelClassName}`, (stmt) => stmt.step() === DbResult.BE_SQLITE_ROW, false);\r\n } catch (e) {\r\n // iModel doesn't have channel class in its BIS schema\r\n this._hasChannels = false;\r\n }\r\n }\r\n return this._hasChannels;\r\n }\r\n public getChannelKey(elementId: Id64String): ChannelKey {\r\n if (!this.hasChannels || elementId === IModel.rootSubjectId)\r\n return ChannelAdmin.sharedChannel;\r\n\r\n const channel = this._iModel.withPreparedStatement(`SELECT Owner FROM ${ChannelAdmin.channelClassName} WHERE Element.Id=?`, (stmt) => {\r\n stmt.bindId(1, elementId);\r\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getValue(0).getString() : undefined;\r\n });\r\n if (channel !== undefined)\r\n return channel;\r\n const parentId = this._iModel.withPreparedSqliteStatement(\"SELECT ParentId,ModelId FROM bis_Element WHERE id=?\", (stmt) => {\r\n stmt.bindId(1, elementId);\r\n if (DbResult.BE_SQLITE_ROW !== stmt.step())\r\n throw new IModelError(IModelStatus.NotFound, \"Element does not exist\");\r\n return stmt.getValueId(0) ?? stmt.getValueId(1); // if parent is undefined, use modelId\r\n });\r\n return this.getChannelKey(parentId);\r\n }\r\n public verifyChannel(modelId: Id64String): void {\r\n // Note: indirect changes are permitted to change any channel\r\n if (!this.hasChannels || this._allowedModels.has(modelId) || this._iModel.nativeDb.isIndirectChanges())\r\n return;\r\n\r\n const deniedChannel = this._deniedModels.get(modelId);\r\n if (undefined !== deniedChannel)\r\n throw new IModelError(RepositoryStatus.ChannelConstraintViolation, `channel \"${deniedChannel}\" is not allowed`);\r\n\r\n const channel = this.getChannelKey(modelId);\r\n if (this._allowedChannels.has(channel)) {\r\n this._allowedModels.add(modelId);\r\n return;\r\n }\r\n this._deniedModels.set(modelId, channel);\r\n return this.verifyChannel(modelId);\r\n }\r\n public makeChannelRoot(args: { elementId: Id64String, channelKey: ChannelKey }) {\r\n if (ChannelAdmin.sharedChannel !== this.getChannelKey(args.elementId))\r\n throw new Error(\"channels may not nest\");\r\n\r\n const props: ChannelRootAspectProps = { classFullName: ChannelAdmin.channelClassName, element: { id: args.elementId }, owner: args.channelKey };\r\n this._iModel.elements.insertAspect(props);\r\n this._hasChannels = true;\r\n }\r\n public insertChannelSubject(args: { subjectName: string, channelKey: ChannelKey, parentSubjectId?: Id64String, description?: string }): Id64String {\r\n const elementId = Subject.insert(this._iModel, args.parentSubjectId ?? IModel.rootSubjectId, args.subjectName, args.description);\r\n this.makeChannelRoot({ elementId, channelKey: args.channelKey });\r\n return elementId;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ChannelControl.js","sourceRoot":"","sources":["../../src/ChannelControl.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA2F;AAC3F,oDAAiF;AACjF,uCAAoC;AAoDpC,YAAY;AACZ,IAAiB,cAAc,CAG9B;AAHD,WAAiB,cAAc;IAC7B,wGAAwG;IAC3F,gCAAiB,GAAG,QAAQ,CAAC;AAC5C,CAAC,EAHgB,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAG9B;AAED,gBAAgB;AAChB,MAAa,YAAY;IAQvB,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B,GAAG,uBAAuB,AAA1B,CAA2B;AAFvD,oCAAY","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Elements\r\n */\r\n\r\nimport { DbResult, Id64String, IModelStatus, RepositoryStatus } from \"@itwin/core-bentley\";\r\nimport { ChannelRootAspectProps, IModel, IModelError } from \"@itwin/core-common\";\r\nimport { Subject } from \"./Element\";\r\nimport { IModelDb } from \"./IModelDb\";\r\n\r\n/** The key for a channel. Used for \"allowed channels\" in [[ChannelControl]]\r\n * @beta\r\n */\r\nexport type ChannelKey = string;\r\n\r\n/**\r\n * Controls which channels of an iModel are permitted for write operations. An implementation of this interface is\r\n * available via [[IModelDb.channels]].\r\n * @see [Working With Channels]($docs/learning/backend/Channel.md) for details\r\n * @beta\r\n */\r\nexport interface ChannelControl {\r\n /** Determine whether this [[IModelDb]] has any channels in it. */\r\n get hasChannels(): boolean;\r\n /** Add a new channel to the list of allowed channels of the [[IModelDb]] for this session.\r\n * @param channelKey The key for the channel to become editable in this session.\r\n */\r\n addAllowedChannel(channelKey: ChannelKey): void;\r\n /** Remove a channel from the list of allowed channels of the [[IModelDb]] for this session.\r\n * @param channelKey The key of the channel that should no longer be editable in this session.\r\n */\r\n removeAllowedChannel(channelKey: ChannelKey): void;\r\n /** Get the channelKey of the channel for an element by ElementId.\r\n * @throws if the element does not exist\r\n */\r\n getChannelKey(elementId: Id64String): ChannelKey;\r\n /** Make an existing element a new Channel root.\r\n * @note if the element is already in a channel, this will throw an error.\r\n */\r\n makeChannelRoot(args: { elementId: Id64String, channelKey: ChannelKey }): void;\r\n /** Insert a new Subject element that is a Channel root in this iModel.\r\n * @returns the ElementId of the new Subject element.\r\n * @note if the parentSubject element is already in a channel, this will add the Subject element and then throw an error without making it a Channel root.\r\n */\r\n insertChannelSubject(args: {\r\n /** The name of the new Subject element */\r\n subjectName: string;\r\n /** The channel key for the new [[Subject]]. This is the string to pass to [[addAllowedChannel]]*/\r\n channelKey: ChannelKey;\r\n /** the Id of the parent of the new Subject. Default is [[IModel.rootSubjectId]]. */\r\n parentSubjectId?: Id64String;\r\n /** Optional description for new Subject. */\r\n description?: string;\r\n }): Id64String;\r\n\r\n /** @internal */\r\n verifyChannel(modelId: Id64String): void;\r\n}\r\n\r\n/** @beta */\r\nexport namespace ChannelControl {\r\n /** the name of the special \"shared\" channel holding information that is editable by any application. */\r\n export const sharedChannelName = \"shared\";\r\n}\r\n\r\n/** @internal */\r\nexport class ChannelAdmin implements ChannelControl {\r\n public static readonly sharedChannel = \"shared\";\r\n public static readonly channelClassName = \"bis:ChannelRootAspect\";\r\n private _allowedChannels = new Set<ChannelKey>();\r\n private _allowedModels = new Set<Id64String>();\r\n private _deniedModels = new Map<Id64String, ChannelKey>();\r\n private _hasChannels?: boolean;\r\n\r\n public constructor(private _iModel: IModelDb) {\r\n this._allowedChannels.add(ChannelControl.sharedChannelName);\r\n }\r\n public addAllowedChannel(channelKey: ChannelKey) {\r\n this._allowedChannels.add(channelKey);\r\n this._deniedModels.clear();\r\n }\r\n public removeAllowedChannel(channelKey: ChannelKey) {\r\n this._allowedChannels.delete(channelKey);\r\n this._allowedModels.clear();\r\n }\r\n public get hasChannels(): boolean {\r\n if (undefined === this._hasChannels) {\r\n try {\r\n this._hasChannels = this._iModel.withStatement(`SELECT 1 FROM ${ChannelAdmin.channelClassName}`, (stmt) => stmt.step() === DbResult.BE_SQLITE_ROW, false);\r\n } catch (e) {\r\n // iModel doesn't have channel class in its BIS schema\r\n this._hasChannels = false;\r\n }\r\n }\r\n return this._hasChannels;\r\n }\r\n public getChannelKey(elementId: Id64String): ChannelKey {\r\n if (!this.hasChannels || elementId === IModel.rootSubjectId)\r\n return ChannelControl.sharedChannelName;\r\n\r\n const channel = this._iModel.withPreparedStatement(`SELECT Owner FROM ${ChannelAdmin.channelClassName} WHERE Element.Id=?`, (stmt) => {\r\n stmt.bindId(1, elementId);\r\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getValue(0).getString() : undefined;\r\n });\r\n if (channel !== undefined)\r\n return channel;\r\n const parentId = this._iModel.withPreparedSqliteStatement(\"SELECT ParentId,ModelId FROM bis_Element WHERE id=?\", (stmt) => {\r\n stmt.bindId(1, elementId);\r\n if (DbResult.BE_SQLITE_ROW !== stmt.step())\r\n throw new IModelError(IModelStatus.NotFound, \"Element does not exist\");\r\n return stmt.getValueId(0) ?? stmt.getValueId(1); // if parent is undefined, use modelId\r\n });\r\n return this.getChannelKey(parentId);\r\n }\r\n public verifyChannel(modelId: Id64String): void {\r\n // Note: indirect changes are permitted to change any channel\r\n if (!this.hasChannels || this._allowedModels.has(modelId) || this._iModel.nativeDb.isIndirectChanges())\r\n return;\r\n\r\n const deniedChannel = this._deniedModels.get(modelId);\r\n if (undefined !== deniedChannel)\r\n throw new IModelError(RepositoryStatus.ChannelConstraintViolation, `channel \"${deniedChannel}\" is not allowed`);\r\n\r\n const channel = this.getChannelKey(modelId);\r\n if (this._allowedChannels.has(channel)) {\r\n this._allowedModels.add(modelId);\r\n return;\r\n }\r\n this._deniedModels.set(modelId, channel);\r\n return this.verifyChannel(modelId);\r\n }\r\n public makeChannelRoot(args: { elementId: Id64String, channelKey: ChannelKey }) {\r\n if (ChannelControl.sharedChannelName !== this.getChannelKey(args.elementId))\r\n throw new Error(\"channels may not nest\");\r\n\r\n const props: ChannelRootAspectProps = { classFullName: ChannelAdmin.channelClassName, element: { id: args.elementId }, owner: args.channelKey };\r\n this._iModel.elements.insertAspect(props);\r\n this._hasChannels = true;\r\n }\r\n public insertChannelSubject(args: { subjectName: string, channelKey: ChannelKey, parentSubjectId?: Id64String, description?: string }): Id64String {\r\n const elementId = Subject.insert(this._iModel, args.parentSubjectId ?? IModel.rootSubjectId, args.subjectName, args.description);\r\n this.makeChannelRoot({ elementId, channelKey: args.channelKey });\r\n return elementId;\r\n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C;AAED,iBAAiB;AACjB,qBAAa,iBAAiB;IAC5B,gBAAuB,YAAY,gBAAqB,WAAW,KAAK,IAAI,EAAI;IAChF,gBAAuB,YAAY,gBAAqB,WAAW,KAAK,IAAI,EAAI;WAClE,MAAM,CAAC,UAAU,EAAE,eAAe;mBAE3B,UAAU;WAmBX,wBAAwB,CAAC,OAAO,EAAE,eAAe;IAkDrE,uGAAuG;WACnF,kBAAkB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB/E,6FAA6F;WAC/E,uBAAuB,CAAC,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU;IAyBzF,4DAA4D;WAC9C,gBAAgB,CAAC,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO;IAmB7F,uEAAuE;WACzD,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,UAAU,GAAG,SAAS;CAgBjF"}
|
|
@@ -112,7 +112,7 @@ class V2CheckpointManager {
|
|
|
112
112
|
let container = this.containers.get(v2Props.containerId);
|
|
113
113
|
if (!container) {
|
|
114
114
|
// note checkpoint tokens can't be auto-refreshed because they rely on user credentials supplied through RPC. They're refreshed in SnapshotDb._refreshSas.
|
|
115
|
-
container = CloudSqlite_1.CloudSqlite.createCloudContainer({ ...this.toCloudContainerProps(v2Props), tokenRefreshSeconds: -1 });
|
|
115
|
+
container = CloudSqlite_1.CloudSqlite.createCloudContainer({ ...this.toCloudContainerProps(v2Props), tokenRefreshSeconds: -1, logId: process.env.POD_NAME });
|
|
116
116
|
this.containers.set(v2Props.containerId, container);
|
|
117
117
|
}
|
|
118
118
|
return container;
|
|
@@ -133,15 +133,26 @@ class V2CheckpointManager {
|
|
|
133
133
|
if (!container.isConnected)
|
|
134
134
|
container.connect(this.cloudCache);
|
|
135
135
|
container.checkForChanges();
|
|
136
|
+
const dbStats = container.queryDatabase(dbName);
|
|
136
137
|
if (IModelHost_1.IModelHost.appWorkspace.settings.getBoolean("Checkpoints/prefetch", false)) {
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
138
|
+
const getPrefetchConfig = (name, defaultVal) => IModelHost_1.IModelHost.appWorkspace.settings.getNumber(`Checkpoints/prefetch/${name}`, defaultVal);
|
|
139
|
+
const minRequests = getPrefetchConfig("minRequests", 3);
|
|
140
|
+
const maxRequests = getPrefetchConfig("maxRequests", 6);
|
|
141
|
+
const timeout = getPrefetchConfig("timeout", 100);
|
|
142
|
+
const maxBlocks = getPrefetchConfig("maxBlocks", 500); // default size of 2GB. Assumes a checkpoint block size of 4MB.
|
|
143
|
+
if (dbStats?.totalBlocks !== undefined && dbStats.totalBlocks <= maxBlocks) {
|
|
144
|
+
const logPrefetch = async (prefetch) => {
|
|
145
|
+
const stopwatch = new core_bentley_1.StopWatch(`[${container.containerId}/${dbName}]`, true);
|
|
146
|
+
core_bentley_1.Logger.logInfo(loggerCategory, `Starting prefetch of ${stopwatch.description}`, { minRequests, maxRequests, timeout });
|
|
147
|
+
const done = await prefetch.promise;
|
|
148
|
+
core_bentley_1.Logger.logInfo(loggerCategory, `Prefetch of ${stopwatch.description} complete=${done} (${stopwatch.elapsedSeconds} seconds)`, { minRequests, maxRequests, timeout });
|
|
149
|
+
};
|
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
151
|
+
logPrefetch(CloudSqlite_1.CloudSqlite.startCloudPrefetch(container, dbName, { minRequests, nRequests: maxRequests, timeout }));
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
core_bentley_1.Logger.logInfo(loggerCategory, `Skipping prefetch due to size limits.`, { maxBlocks, totalBlocksInDb: dbStats?.totalBlocks, v2props });
|
|
155
|
+
}
|
|
145
156
|
}
|
|
146
157
|
return { dbName, container };
|
|
147
158
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckpointManager.js","sourceR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AK,CAAC;SACd;QAED,MAAM,OAAO,GAAG,UAAU,CAAC,QAAQ,KAAK,QAAQ,CAAC,WAAW,EAAE,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,KAAK,QAAQ,CAAC,mBAAmB,EAAE,CAAC,EAAE,CAAC;QAChI,QAAQ,CAAC,WAAW,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO;YACV,uBAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAElC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,uEAAuE;IAChE,MAAM,CAAC,gBAAgB,CAAC,OAAwB;QACrD,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACtC,IAAI,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC;YACtD,OAAO,qBAAU,CAAC,gBAAgB,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAEpE,iHAAiH;QACjH,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,UAAU,EAAE;gBACtC,IAAI,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE;oBAC5C,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;oBAC1B,OAAO,qBAAU,CAAC,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;iBACvD;aACF;SACF;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;;AAzJsB,8BAAY,GAAG,IAAI,sBAAO,EAA8B,CAAC;AACzD,8BAAY,GAAG,IAAI,sBAAO,EAA8B,CAAC;AAFrE,8CAAiB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module iModels\r\n */\r\n\r\n// cspell:ignore BLOCKCACHE\r\n\r\nimport * as path from \"path\";\r\nimport { NativeLoggerCategory } from \"@bentley/imodeljs-native\";\r\nimport { BeEvent, ChangeSetStatus, Guid, GuidString, IModelStatus, Logger, LogLevel, Mutable, OpenMode, StopWatch } from \"@itwin/core-bentley\";\r\nimport {\r\n BriefcaseIdValue, ChangesetId, ChangesetIdWithIndex, ChangesetIndexAndId, IModelError, IModelVersion, LocalDirName, LocalFileName,\r\n} from \"@itwin/core-common\";\r\nimport { V2CheckpointAccessProps } from \"./BackendHubAccess\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { BriefcaseManager } from \"./BriefcaseManager\";\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { SnapshotDb, TokenArg } from \"./IModelDb\";\r\n\r\nconst loggerCategory = BackendLoggerCategory.IModelDb;\r\n\r\n/**\r\n * Properties of a checkpoint\r\n * @public\r\n */\r\nexport interface CheckpointProps extends TokenArg {\r\n readonly expectV2?: boolean;\r\n\r\n /** iTwin that the iModel belongs to */\r\n readonly iTwinId: GuidString;\r\n\r\n /** Id of the iModel */\r\n readonly iModelId: GuidString;\r\n\r\n /** changeset for the checkpoint */\r\n readonly changeset: ChangesetIdWithIndex;\r\n\r\n /** If true, then the latest successful v2 checkpoint at or before the provided changeset will be returned when calling queryV2Checkpoint. */\r\n readonly allowPreceding?: boolean;\r\n\r\n /** The number of seconds before the current token expires to attempt to reacquire a new token. Default is 1 hour. */\r\n readonly reattachSafetySeconds?: number;\r\n}\r\n\r\n/** Return value from [[ProgressFunction]].\r\n * @public\r\n */\r\nexport enum ProgressStatus {\r\n /** Continue download. */\r\n Continue = 0,\r\n /** Abort download. */\r\n Abort = 1,\r\n}\r\n\r\n/** Called to show progress during a download. If this function returns non-zero, the download is aborted.\r\n * @public\r\n */\r\nexport type ProgressFunction = (loaded: number, total: number) => ProgressStatus;\r\n\r\n/** The parameters that specify a request to download a checkpoint file from iModelHub.\r\n * @internal\r\n */\r\nexport interface DownloadRequest {\r\n /** name of local file to hold the downloaded data. */\r\n localFile: LocalFileName;\r\n\r\n /** A list of full fileName paths to test before downloading. If a valid file exists by one of these names,\r\n * no download is performed and `localFile` is updated to reflect the fact that the file exists with that name.\r\n * This can be used, for example, to look for checkpoints from previous versions if the naming strategy changes.\r\n */\r\n readonly aliasFiles?: ReadonlyArray<string>;\r\n\r\n /** Properties of the checkpoint to be downloaded */\r\n readonly checkpoint: CheckpointProps;\r\n\r\n /** If present, this function will be called to indicate progress as the briefcase is downloaded. If this\r\n * function returns a non-zero value, the download is aborted.\r\n */\r\n readonly onProgress?: ProgressFunction;\r\n}\r\n\r\n/** @internal */\r\nexport interface DownloadJob {\r\n request: DownloadRequest;\r\n promise?: Promise<any>;\r\n}\r\n\r\n/** @internal */\r\nexport class Downloads {\r\n private static _active = new Map<string, DownloadJob>();\r\n\r\n private static async process<T>(job: DownloadJob, fn: (job: DownloadJob) => Promise<T>) {\r\n const jobName = job.request.localFile; // save this, it can change inside call to `fn`!\r\n this._active.set(jobName, job);\r\n try {\r\n return await fn(job);\r\n } finally {\r\n this._active.delete(jobName);\r\n }\r\n }\r\n\r\n public static isInProgress(pathName: LocalFileName): DownloadJob | undefined {\r\n return this._active.get(pathName);\r\n }\r\n\r\n public static async download<T>(request: DownloadRequest, downloadFn: (job: DownloadJob) => Promise<T>) {\r\n const pathName = request.localFile;\r\n let job = this.isInProgress(pathName);\r\n if (undefined !== job)\r\n return job.promise;\r\n\r\n IModelJsFs.recursiveMkDirSync(path.dirname(pathName));\r\n job = { request };\r\n return job.promise = this.process(job, downloadFn);\r\n }\r\n}\r\n\r\n/**\r\n * Utility class for opening V2 checkpoints from cloud containers, and also for downloading them.\r\n * @internal\r\n*/\r\nexport class V2CheckpointManager {\r\n public static readonly cloudCacheName = \"v2Checkpoints\";\r\n private static _cloudCache?: CloudSqlite.CloudCache;\r\n private static containers = new Map<string, CloudSqlite.CloudContainer>();\r\n\r\n public static getFolder(): LocalDirName {\r\n const cloudCachePath = path.join(BriefcaseManager.cacheDir, V2CheckpointManager.cloudCacheName);\r\n if (!(IModelJsFs.existsSync(cloudCachePath))) {\r\n IModelJsFs.recursiveMkDirSync(cloudCachePath);\r\n }\r\n return cloudCachePath;\r\n }\r\n\r\n /* only used by tests that reset the state of the v2CheckpointManager. all dbs should be closed before calling this function. */\r\n public static cleanup(): void {\r\n for (const [_, value] of this.containers.entries()) {\r\n if (value.isConnected)\r\n value.disconnect({ detach: true });\r\n }\r\n\r\n CloudSqlite.CloudCaches.dropCache(this.cloudCacheName)?.destroy();\r\n this._cloudCache = undefined;\r\n this.containers.clear();\r\n }\r\n\r\n public static getFileName(checkpoint: CheckpointProps): LocalFileName {\r\n const changesetId = checkpoint.changeset.id || \"first\";\r\n return path.join(this.getFolder(), `${changesetId}.bim`);\r\n }\r\n\r\n private static get cloudCache(): CloudSqlite.CloudCache {\r\n if (!this._cloudCache) {\r\n let cacheDir = process.env.CHECKPOINT_CACHE_DIR;\r\n if (!cacheDir) {\r\n cacheDir = this.getFolder();\r\n Logger.logWarning(loggerCategory, `No CHECKPOINT_CACHE_DIR found in process.env, using ${cacheDir} instead.`);\r\n } else {\r\n // Make sure the checkpoint_cache_dir has an iTwinDaemon specific file in it, otherwise fall back to other directory.\r\n if (!(IModelJsFs.existsSync(path.join(cacheDir, \"portnumber.bcv\")))) {\r\n cacheDir = this.getFolder();\r\n Logger.logWarning(loggerCategory, `No evidence of the iTwinDaemon in provided CHECKPOINT_CACHE_DIR: ${process.env.CHECKPOINT_CACHE_DIR}, using ${cacheDir} instead.`);\r\n }\r\n }\r\n\r\n this._cloudCache = CloudSqlite.CloudCaches.getCache({ cacheName: this.cloudCacheName, cacheDir });\r\n\r\n // Its fine if its not a daemon, but lets log an info message\r\n if (!this._cloudCache.isDaemon)\r\n Logger.logInfo(loggerCategory, \"V2Checkpoint manager running with no iTwinDaemon.\");\r\n }\r\n return this._cloudCache;\r\n }\r\n\r\n /** Member names differ slightly between the V2Checkpoint api and the CloudSqlite api. Add aliases `accessName` for `accountName` and `accessToken` for `sasToken` */\r\n private static toCloudContainerProps(from: V2CheckpointAccessProps): CloudSqlite.ContainerAccessProps {\r\n return { ...from, baseUri: `https://${from.accountName}.blob.core.windows.net`, accessToken: from.sasToken, storageType: \"azure\" };\r\n }\r\n\r\n private static getContainer(v2Props: V2CheckpointAccessProps) {\r\n let container = this.containers.get(v2Props.containerId);\r\n if (!container) {\r\n // note checkpoint tokens can't be auto-refreshed because they rely on user credentials supplied through RPC. They're refreshed in SnapshotDb._refreshSas.\r\n container = CloudSqlite.createCloudContainer({ ...this.toCloudContainerProps(v2Props), tokenRefreshSeconds: -1 });\r\n this.containers.set(v2Props.containerId, container);\r\n }\r\n return container;\r\n }\r\n\r\n public static async attach(checkpoint: CheckpointProps): Promise<{ dbName: string, container: CloudSqlite.CloudContainer }> {\r\n let v2props: V2CheckpointAccessProps | undefined;\r\n try {\r\n v2props = await IModelHost.hubAccess.queryV2Checkpoint(checkpoint);\r\n if (!v2props)\r\n throw new Error(\"no checkpoint\");\r\n } catch (err: any) {\r\n throw new IModelError(IModelStatus.NotFound, `V2 checkpoint not found: err: ${err.message}`);\r\n }\r\n\r\n try {\r\n const container = this.getContainer(v2props);\r\n const dbName = v2props.dbName;\r\n if (!container.isConnected)\r\n container.connect(this.cloudCache);\r\n container.checkForChanges();\r\n if (IModelHost.appWorkspace.settings.getBoolean(\"Checkpoints/prefetch\", false)) {\r\n const logPrefetch = async (prefetch: CloudSqlite.CloudPrefetch) => {\r\n const stopwatch = new StopWatch(`[${container.containerId}/${dbName}]`, true);\r\n Logger.logInfo(loggerCategory, `Starting prefetch of ${stopwatch.description}`);\r\n const done = await prefetch.promise;\r\n Logger.logInfo(loggerCategory, `Prefetch of ${stopwatch.description} complete=${done} (${stopwatch.elapsedSeconds} seconds)`);\r\n };\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n logPrefetch(CloudSqlite.startCloudPrefetch(container, dbName));\r\n }\r\n return { dbName, container };\r\n } catch (e: any) {\r\n const error = `Cloud cache connect failed: ${e.message}`;\r\n if (checkpoint.expectV2)\r\n Logger.logError(loggerCategory, error);\r\n\r\n throw new IModelError(e.errorNumber, error);\r\n }\r\n }\r\n\r\n private static async performDownload(job: DownloadJob): Promise<ChangesetId> {\r\n const request = job.request;\r\n const v2props: V2CheckpointAccessProps | undefined = await IModelHost.hubAccess.queryV2Checkpoint({ ...request.checkpoint, allowPreceding: true });\r\n if (!v2props)\r\n throw new IModelError(IModelStatus.NotFound, \"V2 checkpoint not found\");\r\n\r\n CheckpointManager.onDownloadV2.raiseEvent(job);\r\n const container = CloudSqlite.createCloudContainer(this.toCloudContainerProps(v2props));\r\n await CloudSqlite.transferDb(\"download\", container, { dbName: v2props.dbName, localFileName: request.localFile, onProgress: request.onProgress });\r\n return request.checkpoint.changeset.id;\r\n }\r\n\r\n /** Fully download a V2 checkpoint to a local file that can be used to create a briefcase or to work offline.\r\n * @returns a Promise that is resolved when the download completes with the changesetId of the downloaded checkpoint (which will\r\n * be the same as the requested changesetId or the most recent checkpoint before it.)\r\n */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<ChangesetId> {\r\n return Downloads.download(request, async (job: DownloadJob) => this.performDownload(job));\r\n }\r\n}\r\n\r\n/** Utility class to deal with downloading V1 checkpoints from iModelHub.\r\n * @internal\r\n */\r\nexport class V1CheckpointManager {\r\n public static getFolder(iModelId: GuidString): LocalDirName {\r\n return path.join(BriefcaseManager.getIModelPath(iModelId), \"checkpoints\");\r\n }\r\n\r\n public static getFileName(checkpoint: CheckpointProps): LocalFileName {\r\n const changesetId = checkpoint.changeset.id || \"first\";\r\n return path.join(this.getFolder(checkpoint.iModelId), `${changesetId}.bim`);\r\n }\r\n\r\n public static async getCheckpointDb(request: DownloadRequest): Promise<SnapshotDb> {\r\n const db = SnapshotDb.tryFindByKey(CheckpointManager.getKey(request.checkpoint));\r\n return (undefined !== db) ? db : Downloads.download(request, async (job: DownloadJob) => this.downloadAndOpen(job));\r\n }\r\n\r\n /** Download a V1 checkpoint */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<ChangesetId> {\r\n return Downloads.download(request, async (job: DownloadJob) => this.performDownload(job));\r\n }\r\n\r\n private static async downloadAndOpen(job: DownloadJob) {\r\n const db = CheckpointManager.tryOpenLocalFile(job.request);\r\n if (db)\r\n return db;\r\n await this.performDownload(job);\r\n await CheckpointManager.updateToRequestedVersion(job.request);\r\n return SnapshotDb.openCheckpointV1(job.request.localFile, job.request.checkpoint);\r\n }\r\n\r\n private static async performDownload(job: DownloadJob): Promise<ChangesetId> {\r\n CheckpointManager.onDownloadV1.raiseEvent(job);\r\n // eslint-disable-next-line deprecation/deprecation\r\n return (await IModelHost.hubAccess.downloadV1Checkpoint(job.request)).id;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class CheckpointManager {\r\n public static readonly onDownloadV1 = new BeEvent<(job: DownloadJob) => void>();\r\n public static readonly onDownloadV2 = new BeEvent<(job: DownloadJob) => void>();\r\n public static getKey(checkpoint: CheckpointProps) { return `${checkpoint.iModelId}:${checkpoint.changeset.id}`; }\r\n\r\n private static async doDownload(request: DownloadRequest): Promise<ChangesetId> {\r\n try {\r\n // first see if there's a V2 checkpoint available.\r\n const changesetId = await V2CheckpointManager.downloadCheckpoint(request);\r\n if (changesetId !== request.checkpoint.changeset.id)\r\n Logger.logInfo(loggerCategory, `Downloaded previous v2 checkpoint because requested checkpoint not found.`, { requestedChangesetId: request.checkpoint.changeset.id, iModelId: request.checkpoint.iModelId, changesetId, iTwinId: request.checkpoint.iTwinId });\r\n else\r\n Logger.logInfo(loggerCategory, `Downloaded v2 checkpoint.`, { iModelId: request.checkpoint.iModelId, changesetId: request.checkpoint.changeset.id, iTwinId: request.checkpoint.iTwinId });\r\n return changesetId;\r\n } catch (error: any) {\r\n if (error.errorNumber === IModelStatus.NotFound) { // No V2 checkpoint available, try a v1 checkpoint\r\n const changeset = await V1CheckpointManager.downloadCheckpoint(request);\r\n Logger.logWarning(loggerCategory, `Got an error downloading v2 checkpoint, but downloaded v1 checkpoint successfully!`, { error, iModelId: request.checkpoint.iModelId, iTwinId: request.checkpoint.iTwinId, requestedChangesetId: request.checkpoint.changeset.id, changesetId: changeset });\r\n return changeset;\r\n }\r\n throw error; // most likely, was aborted\r\n }\r\n }\r\n\r\n public static async updateToRequestedVersion(request: DownloadRequest) {\r\n const checkpoint = request.checkpoint;\r\n const targetFile = request.localFile;\r\n const traceInfo = { iTwinId: checkpoint.iTwinId, iModelId: checkpoint.iModelId, changeset: checkpoint.changeset };\r\n try {\r\n // Open checkpoint for write\r\n Logger.setLevel(NativeLoggerCategory.SQLite, LogLevel.None); // Ignores noisy error messages when applying changesets.\r\n const db = SnapshotDb.openForApplyChangesets(targetFile);\r\n const nativeDb = db.nativeDb;\r\n try {\r\n\r\n if (nativeDb.hasPendingTxns()) {\r\n Logger.logWarning(loggerCategory, \"Checkpoint with Txns found - deleting them\", () => traceInfo);\r\n nativeDb.deleteAllTxns();\r\n }\r\n\r\n if (nativeDb.getBriefcaseId() !== BriefcaseIdValue.Unassigned)\r\n nativeDb.resetBriefcaseId(BriefcaseIdValue.Unassigned);\r\n\r\n CheckpointManager.validateCheckpointGuids(checkpoint, db);\r\n // Apply change sets if necessary\r\n const currentChangeset: Mutable<ChangesetIndexAndId> = nativeDb.getCurrentChangeset();\r\n if (currentChangeset.id !== checkpoint.changeset.id) {\r\n const accessToken = checkpoint.accessToken;\r\n const toIndex = checkpoint.changeset.index ??\r\n (await IModelHost.hubAccess.getChangesetFromVersion({ accessToken, iModelId: checkpoint.iModelId, version: IModelVersion.asOfChangeSet(checkpoint.changeset.id) })).index;\r\n await BriefcaseManager.pullAndApplyChangesets(db, { accessToken, toIndex });\r\n } else {\r\n // make sure the parent changeset index is saved in the file - old versions didn't have it.\r\n currentChangeset.index = checkpoint.changeset.index!; // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n nativeDb.saveLocalValue(\"parentChangeSet\", JSON.stringify(currentChangeset));\r\n }\r\n } finally {\r\n Logger.setLevel(NativeLoggerCategory.SQLite, LogLevel.Error); // Turn logging back on after applying changesets.\r\n db.saveChanges();\r\n db.close();\r\n }\r\n } catch (error: any) {\r\n\r\n Logger.logError(loggerCategory, \"Error downloading checkpoint - deleting it\", () => traceInfo);\r\n IModelJsFs.removeSync(targetFile);\r\n\r\n if (error.errorNumber === ChangeSetStatus.CorruptedChangeStream || error.errorNumber === ChangeSetStatus.InvalidId || error.errorNumber === ChangeSetStatus.InvalidVersion) {\r\n Logger.logError(loggerCategory, \"Detected potential corruption of change sets. Deleting them to enable retries\", () => traceInfo);\r\n BriefcaseManager.deleteChangeSetsFromLocalDisk(checkpoint.iModelId);\r\n }\r\n throw error;\r\n }\r\n }\r\n\r\n /** Download a checkpoint file from iModelHub into a local file specified in the request parameters. */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<void> {\r\n if (this.verifyCheckpoint(request.checkpoint, request.localFile))\r\n return;\r\n\r\n if (request.aliasFiles) {\r\n for (const alias of request.aliasFiles) {\r\n if (this.verifyCheckpoint(request.checkpoint, alias)) {\r\n request.localFile = alias;\r\n return;\r\n }\r\n }\r\n }\r\n\r\n await this.doDownload(request);\r\n return this.updateToRequestedVersion(request);\r\n }\r\n\r\n /** checks a file's dbGuid & iTwinId for consistency, and updates the dbGuid when possible */\r\n public static validateCheckpointGuids(checkpoint: CheckpointProps, snapshotDb: SnapshotDb) {\r\n const traceInfo = { iTwinId: checkpoint.iTwinId, iModelId: checkpoint.iModelId };\r\n\r\n const nativeDb = snapshotDb.nativeDb;\r\n const dbChangeset = nativeDb.getCurrentChangeset();\r\n const iModelId = Guid.normalize(nativeDb.getIModelId());\r\n if (iModelId !== Guid.normalize(checkpoint.iModelId)) {\r\n if (nativeDb.isReadonly())\r\n throw new IModelError(IModelStatus.ValidationFailed, \"iModelId is not properly set up in the checkpoint\");\r\n\r\n Logger.logWarning(loggerCategory, \"iModelId is not properly set up in the checkpoint. Updated checkpoint to the correct iModelId.\", () => ({ ...traceInfo, dbGuid: iModelId }));\r\n const iModelIdNormalized = Guid.normalize(checkpoint.iModelId);\r\n nativeDb.setIModelId(iModelIdNormalized);\r\n (snapshotDb as any)._iModelId = iModelIdNormalized;\r\n // Required to reset the ChangeSetId because setDbGuid clears the value.\r\n nativeDb.saveLocalValue(\"ParentChangeSetId\", dbChangeset.id);\r\n if (undefined !== dbChangeset.index)\r\n nativeDb.saveLocalValue(\"parentChangeSet\", JSON.stringify(dbChangeset));\r\n }\r\n\r\n const iTwinId = Guid.normalize(nativeDb.getITwinId());\r\n if (iTwinId !== Guid.normalize(checkpoint.iTwinId))\r\n throw new IModelError(IModelStatus.ValidationFailed, \"iTwinId was not properly set up in the checkpoint\");\r\n }\r\n\r\n /** @returns true if the file is the checkpoint requested */\r\n public static verifyCheckpoint(checkpoint: CheckpointProps, fileName: LocalFileName): boolean {\r\n if (!IModelJsFs.existsSync(fileName))\r\n return false;\r\n\r\n const nativeDb = new IModelHost.platform.DgnDb();\r\n try {\r\n nativeDb.openIModel(fileName, OpenMode.Readonly);\r\n } catch (error) {\r\n return false;\r\n }\r\n\r\n const isValid = checkpoint.iModelId === nativeDb.getIModelId() && checkpoint.changeset.id === nativeDb.getCurrentChangeset().id;\r\n nativeDb.closeIModel();\r\n if (!isValid)\r\n IModelJsFs.removeSync(fileName);\r\n\r\n return isValid;\r\n }\r\n\r\n /** try to open an existing local file to satisfy a download request */\r\n public static tryOpenLocalFile(request: DownloadRequest): SnapshotDb | undefined {\r\n const checkpoint = request.checkpoint;\r\n if (this.verifyCheckpoint(checkpoint, request.localFile))\r\n return SnapshotDb.openCheckpointV1(request.localFile, checkpoint);\r\n\r\n // check a list of aliases for finding checkpoints downloaded to non-default locations (e.g. from older versions)\r\n if (request.aliasFiles) {\r\n for (const alias of request.aliasFiles) {\r\n if (this.verifyCheckpoint(checkpoint, alias)) {\r\n request.localFile = alias;\r\n return SnapshotDb.openCheckpointV1(alias, checkpoint);\r\n }\r\n }\r\n }\r\n return undefined;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"CheckpointManager.js","sourceRoot":"","sources":["../../src/CheckpointManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,2BAA2B;AAE3B,6BAA6B;AAC7B,8DAAgE;AAChE,sDAA+I;AAC/I,oDAE4B;AAE5B,mEAAgE;AAChE,yDAAsD;AACtD,+CAA4C;AAC5C,6CAA0C;AAC1C,6CAA0C;AAC1C,yCAAkD;AAElD,MAAM,cAAc,GAAG,6CAAqB,CAAC,QAAQ,CAAC;AAyBtD;;GAEG;AACH,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,yBAAyB;IACzB,2DAAY,CAAA;IACZ,sBAAsB;IACtB,qDAAS,CAAA;AACX,CAAC,EALW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAKzB;AAmCD,gBAAgB;AAChB,MAAa,SAAS;IAGZ,MAAM,CAAC,KAAK,CAAC,OAAO,CAAI,GAAgB,EAAE,EAAoC;QACpF,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,gDAAgD;QACvF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC/B,IAAI;YACF,OAAO,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;SACtB;gBAAS;YACR,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;SAC9B;IACH,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,QAAuB;QAChD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAI,OAAwB,EAAE,UAA4C;QACpG,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,GAAG,G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,CAAC,mBAAmB,EAAE,CAAC,EAAE,CAAC;QAChI,QAAQ,CAAC,WAAW,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO;YACV,uBAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAElC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,uEAAuE;IAChE,MAAM,CAAC,gBAAgB,CAAC,OAAwB;QACrD,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACtC,IAAI,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC;YACtD,OAAO,qBAAU,CAAC,gBAAgB,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAEpE,iHAAiH;QACjH,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,UAAU,EAAE;gBACtC,IAAI,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE;oBAC5C,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;oBAC1B,OAAO,qBAAU,CAAC,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;iBACvD;aACF;SACF;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;;AAzJsB,8BAAY,GAAG,IAAI,sBAAO,EAA8B,CAAC;AACzD,8BAAY,GAAG,IAAI,sBAAO,EAA8B,CAAC;AAFrE,8CAAiB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module iModels\r\n */\r\n\r\n// cspell:ignore BLOCKCACHE\r\n\r\nimport * as path from \"path\";\r\nimport { NativeLoggerCategory } from \"@bentley/imodeljs-native\";\r\nimport { BeEvent, ChangeSetStatus, Guid, GuidString, IModelStatus, Logger, LogLevel, Mutable, OpenMode, StopWatch } from \"@itwin/core-bentley\";\r\nimport {\r\n BriefcaseIdValue, ChangesetId, ChangesetIdWithIndex, ChangesetIndexAndId, IModelError, IModelVersion, LocalDirName, LocalFileName,\r\n} from \"@itwin/core-common\";\r\nimport { V2CheckpointAccessProps } from \"./BackendHubAccess\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { BriefcaseManager } from \"./BriefcaseManager\";\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { SnapshotDb, TokenArg } from \"./IModelDb\";\r\n\r\nconst loggerCategory = BackendLoggerCategory.IModelDb;\r\n\r\n/**\r\n * Properties of a checkpoint\r\n * @public\r\n */\r\nexport interface CheckpointProps extends TokenArg {\r\n readonly expectV2?: boolean;\r\n\r\n /** iTwin that the iModel belongs to */\r\n readonly iTwinId: GuidString;\r\n\r\n /** Id of the iModel */\r\n readonly iModelId: GuidString;\r\n\r\n /** changeset for the checkpoint */\r\n readonly changeset: ChangesetIdWithIndex;\r\n\r\n /** If true, then the latest successful v2 checkpoint at or before the provided changeset will be returned when calling queryV2Checkpoint. */\r\n readonly allowPreceding?: boolean;\r\n\r\n /** The number of seconds before the current token expires to attempt to reacquire a new token. Default is 1 hour. */\r\n readonly reattachSafetySeconds?: number;\r\n}\r\n\r\n/** Return value from [[ProgressFunction]].\r\n * @public\r\n */\r\nexport enum ProgressStatus {\r\n /** Continue download. */\r\n Continue = 0,\r\n /** Abort download. */\r\n Abort = 1,\r\n}\r\n\r\n/** Called to show progress during a download. If this function returns non-zero, the download is aborted.\r\n * @public\r\n */\r\nexport type ProgressFunction = (loaded: number, total: number) => ProgressStatus;\r\n\r\n/** The parameters that specify a request to download a checkpoint file from iModelHub.\r\n * @internal\r\n */\r\nexport interface DownloadRequest {\r\n /** name of local file to hold the downloaded data. */\r\n localFile: LocalFileName;\r\n\r\n /** A list of full fileName paths to test before downloading. If a valid file exists by one of these names,\r\n * no download is performed and `localFile` is updated to reflect the fact that the file exists with that name.\r\n * This can be used, for example, to look for checkpoints from previous versions if the naming strategy changes.\r\n */\r\n readonly aliasFiles?: ReadonlyArray<string>;\r\n\r\n /** Properties of the checkpoint to be downloaded */\r\n readonly checkpoint: CheckpointProps;\r\n\r\n /** If present, this function will be called to indicate progress as the briefcase is downloaded. If this\r\n * function returns a non-zero value, the download is aborted.\r\n */\r\n readonly onProgress?: ProgressFunction;\r\n}\r\n\r\n/** @internal */\r\nexport interface DownloadJob {\r\n request: DownloadRequest;\r\n promise?: Promise<any>;\r\n}\r\n\r\n/** @internal */\r\nexport class Downloads {\r\n private static _active = new Map<string, DownloadJob>();\r\n\r\n private static async process<T>(job: DownloadJob, fn: (job: DownloadJob) => Promise<T>) {\r\n const jobName = job.request.localFile; // save this, it can change inside call to `fn`!\r\n this._active.set(jobName, job);\r\n try {\r\n return await fn(job);\r\n } finally {\r\n this._active.delete(jobName);\r\n }\r\n }\r\n\r\n public static isInProgress(pathName: LocalFileName): DownloadJob | undefined {\r\n return this._active.get(pathName);\r\n }\r\n\r\n public static async download<T>(request: DownloadRequest, downloadFn: (job: DownloadJob) => Promise<T>) {\r\n const pathName = request.localFile;\r\n let job = this.isInProgress(pathName);\r\n if (undefined !== job)\r\n return job.promise;\r\n\r\n IModelJsFs.recursiveMkDirSync(path.dirname(pathName));\r\n job = { request };\r\n return job.promise = this.process(job, downloadFn);\r\n }\r\n}\r\n\r\n/**\r\n * Utility class for opening V2 checkpoints from cloud containers, and also for downloading them.\r\n * @internal\r\n*/\r\nexport class V2CheckpointManager {\r\n public static readonly cloudCacheName = \"v2Checkpoints\";\r\n private static _cloudCache?: CloudSqlite.CloudCache;\r\n private static containers = new Map<string, CloudSqlite.CloudContainer>();\r\n\r\n public static getFolder(): LocalDirName {\r\n const cloudCachePath = path.join(BriefcaseManager.cacheDir, V2CheckpointManager.cloudCacheName);\r\n if (!(IModelJsFs.existsSync(cloudCachePath))) {\r\n IModelJsFs.recursiveMkDirSync(cloudCachePath);\r\n }\r\n return cloudCachePath;\r\n }\r\n\r\n /* only used by tests that reset the state of the v2CheckpointManager. all dbs should be closed before calling this function. */\r\n public static cleanup(): void {\r\n for (const [_, value] of this.containers.entries()) {\r\n if (value.isConnected)\r\n value.disconnect({ detach: true });\r\n }\r\n\r\n CloudSqlite.CloudCaches.dropCache(this.cloudCacheName)?.destroy();\r\n this._cloudCache = undefined;\r\n this.containers.clear();\r\n }\r\n\r\n public static getFileName(checkpoint: CheckpointProps): LocalFileName {\r\n const changesetId = checkpoint.changeset.id || \"first\";\r\n return path.join(this.getFolder(), `${changesetId}.bim`);\r\n }\r\n\r\n private static get cloudCache(): CloudSqlite.CloudCache {\r\n if (!this._cloudCache) {\r\n let cacheDir = process.env.CHECKPOINT_CACHE_DIR;\r\n if (!cacheDir) {\r\n cacheDir = this.getFolder();\r\n Logger.logWarning(loggerCategory, `No CHECKPOINT_CACHE_DIR found in process.env, using ${cacheDir} instead.`);\r\n } else {\r\n // Make sure the checkpoint_cache_dir has an iTwinDaemon specific file in it, otherwise fall back to other directory.\r\n if (!(IModelJsFs.existsSync(path.join(cacheDir, \"portnumber.bcv\")))) {\r\n cacheDir = this.getFolder();\r\n Logger.logWarning(loggerCategory, `No evidence of the iTwinDaemon in provided CHECKPOINT_CACHE_DIR: ${process.env.CHECKPOINT_CACHE_DIR}, using ${cacheDir} instead.`);\r\n }\r\n }\r\n\r\n this._cloudCache = CloudSqlite.CloudCaches.getCache({ cacheName: this.cloudCacheName, cacheDir });\r\n\r\n // Its fine if its not a daemon, but lets log an info message\r\n if (!this._cloudCache.isDaemon)\r\n Logger.logInfo(loggerCategory, \"V2Checkpoint manager running with no iTwinDaemon.\");\r\n }\r\n return this._cloudCache;\r\n }\r\n\r\n /** Member names differ slightly between the V2Checkpoint api and the CloudSqlite api. Add aliases `accessName` for `accountName` and `accessToken` for `sasToken` */\r\n private static toCloudContainerProps(from: V2CheckpointAccessProps): CloudSqlite.ContainerAccessProps {\r\n return { ...from, baseUri: `https://${from.accountName}.blob.core.windows.net`, accessToken: from.sasToken, storageType: \"azure\" };\r\n }\r\n\r\n private static getContainer(v2Props: V2CheckpointAccessProps) {\r\n let container = this.containers.get(v2Props.containerId);\r\n if (!container) {\r\n // note checkpoint tokens can't be auto-refreshed because they rely on user credentials supplied through RPC. They're refreshed in SnapshotDb._refreshSas.\r\n container = CloudSqlite.createCloudContainer({ ...this.toCloudContainerProps(v2Props), tokenRefreshSeconds: -1, logId: process.env.POD_NAME });\r\n this.containers.set(v2Props.containerId, container);\r\n }\r\n return container;\r\n }\r\n\r\n public static async attach(checkpoint: CheckpointProps): Promise<{ dbName: string, container: CloudSqlite.CloudContainer }> {\r\n let v2props: V2CheckpointAccessProps | undefined;\r\n try {\r\n v2props = await IModelHost.hubAccess.queryV2Checkpoint(checkpoint);\r\n if (!v2props)\r\n throw new Error(\"no checkpoint\");\r\n } catch (err: any) {\r\n throw new IModelError(IModelStatus.NotFound, `V2 checkpoint not found: err: ${err.message}`);\r\n }\r\n\r\n try {\r\n const container = this.getContainer(v2props);\r\n const dbName = v2props.dbName;\r\n if (!container.isConnected)\r\n container.connect(this.cloudCache);\r\n container.checkForChanges();\r\n const dbStats = container.queryDatabase(dbName);\r\n if (IModelHost.appWorkspace.settings.getBoolean(\"Checkpoints/prefetch\", false)) {\r\n const getPrefetchConfig = (name: string, defaultVal: number) => IModelHost.appWorkspace.settings.getNumber(`Checkpoints/prefetch/${name}`, defaultVal);\r\n const minRequests = getPrefetchConfig(\"minRequests\", 3);\r\n const maxRequests = getPrefetchConfig(\"maxRequests\", 6);\r\n const timeout = getPrefetchConfig(\"timeout\", 100);\r\n const maxBlocks = getPrefetchConfig(\"maxBlocks\", 500); // default size of 2GB. Assumes a checkpoint block size of 4MB.\r\n if (dbStats?.totalBlocks !== undefined && dbStats.totalBlocks <= maxBlocks) {\r\n const logPrefetch = async (prefetch: CloudSqlite.CloudPrefetch) => {\r\n const stopwatch = new StopWatch(`[${container.containerId}/${dbName}]`, true);\r\n Logger.logInfo(loggerCategory, `Starting prefetch of ${stopwatch.description}`, { minRequests, maxRequests, timeout });\r\n const done = await prefetch.promise;\r\n Logger.logInfo(loggerCategory, `Prefetch of ${stopwatch.description} complete=${done} (${stopwatch.elapsedSeconds} seconds)`, { minRequests, maxRequests, timeout });\r\n };\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n logPrefetch(CloudSqlite.startCloudPrefetch(container, dbName, { minRequests, nRequests: maxRequests, timeout }));\r\n } else {\r\n Logger.logInfo(loggerCategory, `Skipping prefetch due to size limits.`, { maxBlocks, totalBlocksInDb: dbStats?.totalBlocks, v2props });\r\n }\r\n }\r\n return { dbName, container };\r\n } catch (e: any) {\r\n const error = `Cloud cache connect failed: ${e.message}`;\r\n if (checkpoint.expectV2)\r\n Logger.logError(loggerCategory, error);\r\n\r\n throw new IModelError(e.errorNumber, error);\r\n }\r\n }\r\n\r\n private static async performDownload(job: DownloadJob): Promise<ChangesetId> {\r\n const request = job.request;\r\n const v2props: V2CheckpointAccessProps | undefined = await IModelHost.hubAccess.queryV2Checkpoint({ ...request.checkpoint, allowPreceding: true });\r\n if (!v2props)\r\n throw new IModelError(IModelStatus.NotFound, \"V2 checkpoint not found\");\r\n\r\n CheckpointManager.onDownloadV2.raiseEvent(job);\r\n const container = CloudSqlite.createCloudContainer(this.toCloudContainerProps(v2props));\r\n await CloudSqlite.transferDb(\"download\", container, { dbName: v2props.dbName, localFileName: request.localFile, onProgress: request.onProgress });\r\n return request.checkpoint.changeset.id;\r\n }\r\n\r\n /** Fully download a V2 checkpoint to a local file that can be used to create a briefcase or to work offline.\r\n * @returns a Promise that is resolved when the download completes with the changesetId of the downloaded checkpoint (which will\r\n * be the same as the requested changesetId or the most recent checkpoint before it.)\r\n */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<ChangesetId> {\r\n return Downloads.download(request, async (job: DownloadJob) => this.performDownload(job));\r\n }\r\n}\r\n\r\n/** Utility class to deal with downloading V1 checkpoints from iModelHub.\r\n * @internal\r\n */\r\nexport class V1CheckpointManager {\r\n public static getFolder(iModelId: GuidString): LocalDirName {\r\n return path.join(BriefcaseManager.getIModelPath(iModelId), \"checkpoints\");\r\n }\r\n\r\n public static getFileName(checkpoint: CheckpointProps): LocalFileName {\r\n const changesetId = checkpoint.changeset.id || \"first\";\r\n return path.join(this.getFolder(checkpoint.iModelId), `${changesetId}.bim`);\r\n }\r\n\r\n public static async getCheckpointDb(request: DownloadRequest): Promise<SnapshotDb> {\r\n const db = SnapshotDb.tryFindByKey(CheckpointManager.getKey(request.checkpoint));\r\n return (undefined !== db) ? db : Downloads.download(request, async (job: DownloadJob) => this.downloadAndOpen(job));\r\n }\r\n\r\n /** Download a V1 checkpoint */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<ChangesetId> {\r\n return Downloads.download(request, async (job: DownloadJob) => this.performDownload(job));\r\n }\r\n\r\n private static async downloadAndOpen(job: DownloadJob) {\r\n const db = CheckpointManager.tryOpenLocalFile(job.request);\r\n if (db)\r\n return db;\r\n await this.performDownload(job);\r\n await CheckpointManager.updateToRequestedVersion(job.request);\r\n return SnapshotDb.openCheckpointV1(job.request.localFile, job.request.checkpoint);\r\n }\r\n\r\n private static async performDownload(job: DownloadJob): Promise<ChangesetId> {\r\n CheckpointManager.onDownloadV1.raiseEvent(job);\r\n // eslint-disable-next-line deprecation/deprecation\r\n return (await IModelHost.hubAccess.downloadV1Checkpoint(job.request)).id;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class CheckpointManager {\r\n public static readonly onDownloadV1 = new BeEvent<(job: DownloadJob) => void>();\r\n public static readonly onDownloadV2 = new BeEvent<(job: DownloadJob) => void>();\r\n public static getKey(checkpoint: CheckpointProps) { return `${checkpoint.iModelId}:${checkpoint.changeset.id}`; }\r\n\r\n private static async doDownload(request: DownloadRequest): Promise<ChangesetId> {\r\n try {\r\n // first see if there's a V2 checkpoint available.\r\n const changesetId = await V2CheckpointManager.downloadCheckpoint(request);\r\n if (changesetId !== request.checkpoint.changeset.id)\r\n Logger.logInfo(loggerCategory, `Downloaded previous v2 checkpoint because requested checkpoint not found.`, { requestedChangesetId: request.checkpoint.changeset.id, iModelId: request.checkpoint.iModelId, changesetId, iTwinId: request.checkpoint.iTwinId });\r\n else\r\n Logger.logInfo(loggerCategory, `Downloaded v2 checkpoint.`, { iModelId: request.checkpoint.iModelId, changesetId: request.checkpoint.changeset.id, iTwinId: request.checkpoint.iTwinId });\r\n return changesetId;\r\n } catch (error: any) {\r\n if (error.errorNumber === IModelStatus.NotFound) { // No V2 checkpoint available, try a v1 checkpoint\r\n const changeset = await V1CheckpointManager.downloadCheckpoint(request);\r\n Logger.logWarning(loggerCategory, `Got an error downloading v2 checkpoint, but downloaded v1 checkpoint successfully!`, { error, iModelId: request.checkpoint.iModelId, iTwinId: request.checkpoint.iTwinId, requestedChangesetId: request.checkpoint.changeset.id, changesetId: changeset });\r\n return changeset;\r\n }\r\n throw error; // most likely, was aborted\r\n }\r\n }\r\n\r\n public static async updateToRequestedVersion(request: DownloadRequest) {\r\n const checkpoint = request.checkpoint;\r\n const targetFile = request.localFile;\r\n const traceInfo = { iTwinId: checkpoint.iTwinId, iModelId: checkpoint.iModelId, changeset: checkpoint.changeset };\r\n try {\r\n // Open checkpoint for write\r\n Logger.setLevel(NativeLoggerCategory.SQLite, LogLevel.None); // Ignores noisy error messages when applying changesets.\r\n const db = SnapshotDb.openForApplyChangesets(targetFile);\r\n const nativeDb = db.nativeDb;\r\n try {\r\n\r\n if (nativeDb.hasPendingTxns()) {\r\n Logger.logWarning(loggerCategory, \"Checkpoint with Txns found - deleting them\", () => traceInfo);\r\n nativeDb.deleteAllTxns();\r\n }\r\n\r\n if (nativeDb.getBriefcaseId() !== BriefcaseIdValue.Unassigned)\r\n nativeDb.resetBriefcaseId(BriefcaseIdValue.Unassigned);\r\n\r\n CheckpointManager.validateCheckpointGuids(checkpoint, db);\r\n // Apply change sets if necessary\r\n const currentChangeset: Mutable<ChangesetIndexAndId> = nativeDb.getCurrentChangeset();\r\n if (currentChangeset.id !== checkpoint.changeset.id) {\r\n const accessToken = checkpoint.accessToken;\r\n const toIndex = checkpoint.changeset.index ??\r\n (await IModelHost.hubAccess.getChangesetFromVersion({ accessToken, iModelId: checkpoint.iModelId, version: IModelVersion.asOfChangeSet(checkpoint.changeset.id) })).index;\r\n await BriefcaseManager.pullAndApplyChangesets(db, { accessToken, toIndex });\r\n } else {\r\n // make sure the parent changeset index is saved in the file - old versions didn't have it.\r\n currentChangeset.index = checkpoint.changeset.index!; // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n nativeDb.saveLocalValue(\"parentChangeSet\", JSON.stringify(currentChangeset));\r\n }\r\n } finally {\r\n Logger.setLevel(NativeLoggerCategory.SQLite, LogLevel.Error); // Turn logging back on after applying changesets.\r\n db.saveChanges();\r\n db.close();\r\n }\r\n } catch (error: any) {\r\n\r\n Logger.logError(loggerCategory, \"Error downloading checkpoint - deleting it\", () => traceInfo);\r\n IModelJsFs.removeSync(targetFile);\r\n\r\n if (error.errorNumber === ChangeSetStatus.CorruptedChangeStream || error.errorNumber === ChangeSetStatus.InvalidId || error.errorNumber === ChangeSetStatus.InvalidVersion) {\r\n Logger.logError(loggerCategory, \"Detected potential corruption of change sets. Deleting them to enable retries\", () => traceInfo);\r\n BriefcaseManager.deleteChangeSetsFromLocalDisk(checkpoint.iModelId);\r\n }\r\n throw error;\r\n }\r\n }\r\n\r\n /** Download a checkpoint file from iModelHub into a local file specified in the request parameters. */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<void> {\r\n if (this.verifyCheckpoint(request.checkpoint, request.localFile))\r\n return;\r\n\r\n if (request.aliasFiles) {\r\n for (const alias of request.aliasFiles) {\r\n if (this.verifyCheckpoint(request.checkpoint, alias)) {\r\n request.localFile = alias;\r\n return;\r\n }\r\n }\r\n }\r\n\r\n await this.doDownload(request);\r\n return this.updateToRequestedVersion(request);\r\n }\r\n\r\n /** checks a file's dbGuid & iTwinId for consistency, and updates the dbGuid when possible */\r\n public static validateCheckpointGuids(checkpoint: CheckpointProps, snapshotDb: SnapshotDb) {\r\n const traceInfo = { iTwinId: checkpoint.iTwinId, iModelId: checkpoint.iModelId };\r\n\r\n const nativeDb = snapshotDb.nativeDb;\r\n const dbChangeset = nativeDb.getCurrentChangeset();\r\n const iModelId = Guid.normalize(nativeDb.getIModelId());\r\n if (iModelId !== Guid.normalize(checkpoint.iModelId)) {\r\n if (nativeDb.isReadonly())\r\n throw new IModelError(IModelStatus.ValidationFailed, \"iModelId is not properly set up in the checkpoint\");\r\n\r\n Logger.logWarning(loggerCategory, \"iModelId is not properly set up in the checkpoint. Updated checkpoint to the correct iModelId.\", () => ({ ...traceInfo, dbGuid: iModelId }));\r\n const iModelIdNormalized = Guid.normalize(checkpoint.iModelId);\r\n nativeDb.setIModelId(iModelIdNormalized);\r\n (snapshotDb as any)._iModelId = iModelIdNormalized;\r\n // Required to reset the ChangeSetId because setDbGuid clears the value.\r\n nativeDb.saveLocalValue(\"ParentChangeSetId\", dbChangeset.id);\r\n if (undefined !== dbChangeset.index)\r\n nativeDb.saveLocalValue(\"parentChangeSet\", JSON.stringify(dbChangeset));\r\n }\r\n\r\n const iTwinId = Guid.normalize(nativeDb.getITwinId());\r\n if (iTwinId !== Guid.normalize(checkpoint.iTwinId))\r\n throw new IModelError(IModelStatus.ValidationFailed, \"iTwinId was not properly set up in the checkpoint\");\r\n }\r\n\r\n /** @returns true if the file is the checkpoint requested */\r\n public static verifyCheckpoint(checkpoint: CheckpointProps, fileName: LocalFileName): boolean {\r\n if (!IModelJsFs.existsSync(fileName))\r\n return false;\r\n\r\n const nativeDb = new IModelHost.platform.DgnDb();\r\n try {\r\n nativeDb.openIModel(fileName, OpenMode.Readonly);\r\n } catch (error) {\r\n return false;\r\n }\r\n\r\n const isValid = checkpoint.iModelId === nativeDb.getIModelId() && checkpoint.changeset.id === nativeDb.getCurrentChangeset().id;\r\n nativeDb.closeIModel();\r\n if (!isValid)\r\n IModelJsFs.removeSync(fileName);\r\n\r\n return isValid;\r\n }\r\n\r\n /** try to open an existing local file to satisfy a download request */\r\n public static tryOpenLocalFile(request: DownloadRequest): SnapshotDb | undefined {\r\n const checkpoint = request.checkpoint;\r\n if (this.verifyCheckpoint(checkpoint, request.localFile))\r\n return SnapshotDb.openCheckpointV1(request.localFile, checkpoint);\r\n\r\n // check a list of aliases for finding checkpoints downloaded to non-default locations (e.g. from older versions)\r\n if (request.aliasFiles) {\r\n for (const alias of request.aliasFiles) {\r\n if (this.verifyCheckpoint(checkpoint, alias)) {\r\n request.localFile = alias;\r\n return SnapshotDb.openCheckpointV1(alias, checkpoint);\r\n }\r\n }\r\n }\r\n return undefined;\r\n }\r\n}\r\n"]}
|
|
@@ -67,8 +67,9 @@ export declare class ClassRegistry {
|
|
|
67
67
|
static unregisterClassesFrom(schema: typeof Schema): void;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
* A cache that records the mapping between class names and class metadata
|
|
71
|
-
* @
|
|
70
|
+
* A cache that records the mapping between class names and class metadata.
|
|
71
|
+
* @see [[IModelDb.classMetaDataRegistry]] to access the registry for a specific iModel.
|
|
72
|
+
* @beta
|
|
72
73
|
*/
|
|
73
74
|
export declare class MetaDataRegistry {
|
|
74
75
|
private _registry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassRegistry.d.ts","sourceRoot":"","sources":["../../src/ClassRegistry.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,cAAc,EAAsB,WAAW,EAAkB,MAAM,oBAAoB,CAAC;AACrG,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,MAAM,EAAW,MAAM,UAAU,CAAC;AAM3C;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC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
241
|
/**
|
|
242
|
-
* A cache that records the mapping between class names and class metadata
|
|
243
|
-
* @
|
|
242
|
+
* A cache that records the mapping between class names and class metadata.
|
|
243
|
+
* @see [[IModelDb.classMetaDataRegistry]] to access the registry for a specific iModel.
|
|
244
|
+
* @beta
|
|
244
245
|
*/
|
|
245
246
|
class MetaDataRegistry {
|
|
246
247
|
constructor() {
|