import StorageErrorFactory from "../errors/StorageErrorFactory" ; import { LeaseAccessConditions , LeaseStatusType } from "../generated/artifacts/models" ; import Context from "../generated/Context" ; import { ILease , ILeaseValidator } from "./ILeaseState" ; export default class BlobReadLeaseValidator implements ILeaseValidator { public constructor ( public readonly leaseAccessConditions ? ) { } public validate ( lease , context ) { if ( this . leaseAccessConditions !== undefined && this . leaseAccessConditions . leaseId !== undefined && this . leaseAccessConditions . leaseId !== "" ) { if ( lease . leaseStatus === LeaseStatusType . Unlocked ) { throw StorageErrorFactory . getBlobLeaseLost ( context . contextId ) ; } else if ( lease . leaseId !== undefined && this . leaseAccessConditions . leaseId . toLowerCase ( ) !== lease . leaseId . toLowerCase ( ) ) { throw StorageErrorFactory . getBlobLeaseIdMismatchWithBlobOperation ( context . contextId ) ; } } } }