packageDocumentation module import { AccessToken , GuidString , Logger } from "@itwin/core-bentley" ; import { IModelHubClientLoggerCategory } from "../IModelHubClientLoggerCategories" ; import { ECJsonTypeMap , WsgInstance } from "../wsg/ECJsonTypeMap" ; import { WsgQuery } from "../wsg/WsgQuery" ; import { IModelBaseHandler } from "./BaseHandler" ; import { ArgumentCheck } from "./Errors" ; import { addSelectContainerAccessKey } from "./HubQuery" ; const loggerCategory = IModelHubClientLoggerCategory . IModelHub ; internal export enum CheckpointV2State { /** CheckpointV2 creation is in progress. */ InProgress = 0 , /** CheckpointV2 creation was successful. */ Successful = 1 , /** CheckpointV2 creation failed. */ Failed = 2 , /** CheckpointV2 is not generated. It was never created or was deleted. This state is set by the server. It is possible to recreate CheckpointV2. */ NotGenerated = 3 } internal export enum CheckpointV2ErrorId { UnknownError = 0 , FileDownloadError = 1 , FileUploadError = 2 , FileOpenError = 3 , ApplyChangeSetError = 4 , TimeOut = 5 } internal @ ECJsonTypeMap . classToJson ( "wsg" , "iModelScope.CheckpointV2" , { schemaPropertyName : "schemaName" , classPropertyName : "className" } ) export class CheckpointV2 extends WsgInstance { /** Id of the last [[ChangeSet]] that was applied into this checkpoint file. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "properties.ChangeSetId" ) public changeSetId ? : string ; /** State of checkpoint generation. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "properties.State" ) public state ? : CheckpointV2State ; /** Container AccessKey account name of the storage that can be used to download the checkpoint blocks from iModelHub. See [[CheckpointV2Query.selectContainerAccessKey]]. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "relationshipInstances[HasContainer].relatedInstance[ContainerAccessKey].properties.Account" ) public containerAccessKeyAccount ? : string ; /** Container AccessKey container name of the storage that can be used to download the checkpoint blocks from iModelHub. See [[CheckpointV2Query.selectContainerAccessKey]]. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "relationshipInstances[HasContainer].relatedInstance[ContainerAccessKey].properties.Container" ) public containerAccessKeyContainer ? : string ; /** Container AccessKey SAS token of the storage that can be used to download the checkpoint blocks from iModelHub. See [[CheckpointV2Query.selectContainerAccessKey]]. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "relationshipInstances[HasContainer].relatedInstance[ContainerAccessKey].properties.SAS" ) public containerAccessKeySAS ? : string ; /** Container AccessKey database name of the storage that can be used to download the checkpoint blocks from iModelHub. See [[CheckpointV2Query.selectContainerAccessKey]]. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "relationshipInstances[HasContainer].relatedInstance[ContainerAccessKey].properties.DbName" ) public containerAccessKeyDbName ? : string ; /** Error type that occurred while generating [[CheckpointV2]]. See [[CheckpointV2Query.selectCheckpointV2FailureInfo]] to query failure info. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "relationshipInstances[HasCheckpointV2FailureInfo](direction:forward).relatedInstance[CheckpointV2FailureInfo].properties.ErrorId" ) public failureInfoErrorId ? : CheckpointV2ErrorId ; /** Id of the [[ChangeSet]] which failed to apply when [[CheckpointV2]] was generated. See [[CheckpointV2Query.selectCheckpointV2FailureInfo]] to query failure info. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "relationshipInstances[HasCheckpointV2FailureInfo](direction:forward).relatedInstance[CheckpointV2FailureInfo].properties.FailedChangeSetId" ) public failureInfoFailedChangeSetId ? : string ; /** [[CheckpointV2]] generation job start date. This property can not be set by the user. See [[CheckpointV2Query.selectCheckpointV2FailureInfo]] to query failure info. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "relationshipInstances[HasCheckpointV2FailureInfo](direction:forward).relatedInstance[CheckpointV2FailureInfo].properties.StartDate" ) public failureInfoStartDate ? : string ; /** [[CheckpointV2]] generation job failure date. This property can not be set by the user. See [[CheckpointV2Query.selectCheckpointV2FailureInfo]] to query failure info. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "relationshipInstances[HasCheckpointV2FailureInfo](direction:forward).relatedInstance[CheckpointV2FailureInfo].properties.FailureDate" ) public failureInfoFailureDate ? : string ; /** [[CheckpointV2]] generation job id. It should be unique for every job. See [[CheckpointV2Query.selectCheckpointV2FailureInfo]] to query failure info. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "relationshipInstances[HasCheckpointV2FailureInfo](direction:forward).relatedInstance[CheckpointV2FailureInfo].properties.JobId" ) public failureInfoJobId ? : string ; /** [[CheckpointV2]] generation job duration in milliseconds. See [[CheckpointV2Query.selectCheckpointV2FailureInfo]] to query failure info. */ @ ECJsonTypeMap . propertyToJson ( "wsg" , "relationshipInstances[HasCheckpointV2FailureInfo](direction:forward).relatedInstance[CheckpointV2FailureInfo].properties.JobRunDurationMS" ) public failureInfoJobRunDurationMS ? : string ; } internal export class CheckpointV2Query extends WsgQuery { returns public byChangeSetId ( changeSetId ) { ArgumentCheck . validChangeSetId ( "changeSetId" , changeSetId , true ) ; this . addFilter ( `ChangeSetId+eq+'${ changeSetId }'` , "and" ) ; return this ; } returns public precedingCheckpointV2 ( targetChangeSetId ) { this . filter ( `PrecedingCheckpointV2-backward-ChangeSet.Id+eq+'${ targetChangeSetId }'` ) ; return this ; } returns public byState ( state ) { this . addFilter ( `State+eq+${ state }` , "and" ) ; return this ; } returns public selectContainerAccessKey ( ) { addSelectContainerAccessKey ( this . _query ) ; return this ; } returns public selectFailureInfo ( ) { if ( ! this . _query . $select ) this . _query . $select = "*" ; this . _query . $select += ",HasCheckpointV2FailureInfo-forward-CheckpointV2FailureInfo.*" ; return this ; } } internal export class CheckpointV2Handler { private _handler : IModelBaseHandler ; param handler internal constructor ( handler ) { this . _handler = handler ; } param iModelId param briefcaseId internal private getRelativeUrl ( iModelId , checkpointId ? ) { return `/Repositories/iModel--${ iModelId }/iModelScope/CheckpointV2/${ checkpointId || "" }` ; } param iModelId param query returns throws public async get ( accessToken , iModelId , query = new CheckpointV2Query ( ) ) { Logger . logInfo ( loggerCategory , "Querying CheckpointsV2 for iModel" , ( ) => ( { iModelId } ) ) ; ArgumentCheck . validGuid ( "iModelId" , iModelId ) ; const checkpoints = await this . _handler . getInstances < CheckpointV2 > ( accessToken , CheckpointV2 , this . getRelativeUrl ( iModelId ) , query . getQueryOptions ( ) ) ; Logger . logTrace ( loggerCategory , "Queried CheckpointsV2 for iModel" , ( ) => ( { iModelId , count : checkpoints . length } ) ) ; return checkpoints ; } param iModelId param checkpoint returns throws throws internal public async create ( accessToken , iModelId , checkpoint ) { Logger . logInfo ( loggerCategory , "Creating CheckpointV2 for iModel" , ( ) => ( { iModelId } ) ) ; ArgumentCheck . validGuid ( "iModelId" , iModelId ) ; ArgumentCheck . defined ( "checkpoint" , checkpoint ) ; ArgumentCheck . validChangeSetId ( "checkpoint.changeSetId" , checkpoint . changeSetId , false ) ; checkpoint = await this . _handler . postInstance < CheckpointV2 > ( accessToken , CheckpointV2 , this . getRelativeUrl ( iModelId ) , checkpoint ) ; Logger . logTrace ( loggerCategory , "Created CheckpointV2 for iModel" , ( ) => ( { iModelId , checkpoint } ) ) ; return checkpoint ; } param iModelId param checkpoint returns throws throws internal public async update ( accessToken , iModelId , checkpoint ) { Logger . logInfo ( loggerCategory , "Updating CheckpointV2 for iModel" , ( ) => ( { iModelId , checkpoint } ) ) ; ArgumentCheck . validGuid ( "iModelId" , iModelId ) ; ArgumentCheck . defined ( "checkpoint" , checkpoint ) ; const checkpointId = parseInt ( checkpoint . wsgId , 10 ) ; ArgumentCheck . definedNumber ( "checkpoint.wsgId" , checkpointId ) ; const updatedCheckpoint = await this . _handler . postInstance < CheckpointV2 > ( accessToken , CheckpointV2 , this . getRelativeUrl ( iModelId , checkpointId ) , checkpoint ) ; Logger . logTrace ( loggerCategory , "Updated CheckpointV2 for iModel" , ( ) => ( { iModelId , updatedCheckpoint } ) ) ; return updatedCheckpoint ; } }