packageDocumentation module import { AccessToken , GuidString , Logger } from "@itwin/core-bentley" ; import { ECJsonTypeMap , WsgInstance } from "../wsg/ECJsonTypeMap" ; import { IModelHubClientLoggerCategory } from "../IModelHubClientLoggerCategories" ; import { IModelBaseHandler } from "./BaseHandler" ; import { ArgumentCheck } from "./Errors" ; import { addSelectApplicationData , InstanceIdQuery } from "./HubQuery" ; import { ThumbnailSize } from "./Thumbnails" ; const loggerCategory = IModelHubClientLoggerCategory . IModelHub ; internal @ ECJsonTypeMap . classToJson ( "wsg" , "iModelScope.Version" , { schemaPropertyName : "schemaName" , classPropertyName : "className" } ) export class Version extends WsgInstance { @ ECJsonTypeMap . propertyToJson ( "wsg" , "instanceId" ) public id ? : GuidString ; /** Description of the named Version. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "properties.Description" ) public description ? : string ; /** Name of the named Version. Must be unique per iModel. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "properties.Name" ) public name ? : string ; /** Id of the user that created the named Version. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "properties.UserCreated" ) public userCreated ? : string ; /** Date when the named Version was created. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "properties.CreatedDate" ) public createdDate ? : string ; /** Id of the [[ChangeSet]] that the named Version was created for. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "properties.ChangeSetId" ) public changeSetId ? : string ; /** Index of the [[ChangeSet]] that the named Version was created for. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "properties.ChangeSetIndex" ) public changeSetIndex ? : number ; /** Set to true, if named Version is hidden. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "properties.Hidden" ) public hidden ? : boolean ; internal deprecated @ ECJsonTypeMap . propertyToJson ( "wsg" , "relationshipInstances[HasThumbnail].relatedInstance[SmallThumbnail].instanceId" ) public smallThumbnailId ? : GuidString ; internal deprecated @ ECJsonTypeMap . propertyToJson ( "wsg" , "relationshipInstances[HasThumbnail].relatedInstance[LargeThumbnail].instanceId" ) public largeThumbnailId ? : GuidString ; /** Id of the application that created this named Version. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "relationshipInstances[CreatedByApplication].relatedInstance[Application].properties.Id" ) public applicationId ? : string ; /** Name of the application that created this named Version. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "relationshipInstances[CreatedByApplication].relatedInstance[Application].properties.Name" ) public applicationName ? : string ; } internal export class VersionQuery extends InstanceIdQuery { param name returns throws public byName ( name ) { ArgumentCheck . defined ( "name" , name ) ; this . addFilter ( `Name+eq+'${ encodeURIComponent ( name ) }'` ) ; return this ; } param changesetId returns throws public byChangeSet ( changeSetId ) { ArgumentCheck . validChangeSetId ( "changeSetId" , changeSetId , true ) ; this . addFilter ( `ChangeSetId+eq+'${ changeSetId }'` ) ; return this ; } returns throws internal deprecated public selectThumbnailId ( ... sizes ) { ArgumentCheck . nonEmptyArray ( "sizes" , sizes ) ; if ( ! this . _query . $select ) this . _query . $select = "*" ; for ( const size of sizes ) { this . _query . $select += `,HasThumbnail-forward-${ size }Thumbnail.*` ; } return this ; } returns public selectApplicationData ( ) { addSelectApplicationData ( this . _query ) ; return this ; } returns public notHidden ( ) { this . addFilter ( "Hidden+eq+false" ) ; return this ; } } internal export class VersionHandler { private _handler : IModelBaseHandler ; param handler internal constructor ( handler ) { this . _handler = handler ; } param iModelId param versionId private getRelativeUrl ( iModelId , versionId ? ) { return `/Repositories/iModel--${ iModelId }/iModelScope/Version/${ versionId || "" }` ; } param iModelId param query returns throws throws public async get ( accessToken , iModelId , query = new VersionQuery ( ) ) { Logger . logInfo ( loggerCategory , "Querying named versions for iModel" , ( ) => ( { iModelId } ) ) ; ArgumentCheck . validGuid ( "iModelId" , iModelId ) ; const versions = await this . _handler . getInstances < Version > ( accessToken , Version , this . getRelativeUrl ( iModelId , query . getId ( ) ) , query . getQueryOptions ( ) ) ; Logger . logTrace ( loggerCategory , "Queried named versions for iModel" , ( ) => ( { iModelId } ) ) ; return versions ; } param iModelId param changeSetId param name param description returns throws throws throws throws throws public async create ( accessToken , iModelId , changeSetId , name , description ? ) { Logger . logInfo ( loggerCategory , "Creating named version for iModel" , ( ) => ( { iModelId , changeSetId } ) ) ; ArgumentCheck . validGuid ( "iModelId" , iModelId ) ; ArgumentCheck . validChangeSetId ( "changeSetId" , changeSetId , true ) ; ArgumentCheck . defined ( "name" , name ) ; let version = new Version ( ) ; version . changeSetId = changeSetId ; version . name = name ; version . description = description ; version = await this . _handler . postInstance < Version > ( accessToken , Version , this . getRelativeUrl ( iModelId ) , version ) ; Logger . logTrace ( loggerCategory , "Created named version for iModel" , ( ) => ( { iModelId , changeSetId } ) ) ; return version ; } param iModelId param version returns throws throws throws public async update ( accessToken , iModelId , version ) { Logger . logInfo ( loggerCategory , "Updating named version for iModel" , ( ) => ( { iModelId , changeSetId : version . changeSetId } ) ) ; ArgumentCheck . validGuid ( "iModelId" , iModelId ) ; ArgumentCheck . validGuid ( "version.wsgId" , version . wsgId ) ; const updatedVersion = await this . _handler . postInstance < Version > ( accessToken , Version , this . getRelativeUrl ( iModelId , version . id ) , version ) ; Logger . logTrace ( loggerCategory , "Updated named version for iModel" , ( ) => ( { iModelId , changeSetId : version . changeSetId } ) ) ; return updatedVersion ; } }