UNPKG

azurite

Version:

An open source Azure Storage API compatible server

49 lines 2.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const models_1 = require("../generated/artifacts/models"); const LeaseAvailableState_1 = tslib_1.__importDefault(require("./LeaseAvailableState")); const LeaseBreakingState_1 = tslib_1.__importDefault(require("./LeaseBreakingState")); const LeaseBrokenState_1 = tslib_1.__importDefault(require("./LeaseBrokenState")); const LeaseExpiredState_1 = tslib_1.__importDefault(require("./LeaseExpiredState")); const LeaseLeasedState_1 = tslib_1.__importDefault(require("./LeaseLeasedState")); class LeaseFactory { static createLeaseState(lease, context) { if (context.startTime === undefined) { throw new RangeError(`LeaseFactory:createLeaseState() context.startTime should not be undefined.`); } if (lease.leaseState === models_1.LeaseStateType.Available || lease.leaseState === undefined) { return new LeaseAvailableState_1.default(lease, context); } if (lease.leaseState === models_1.LeaseStateType.Leased) { if (lease.leaseExpireTime === undefined || context.startTime < lease.leaseExpireTime) { return new LeaseLeasedState_1.default(lease, context); } else { return new LeaseExpiredState_1.default(lease, context); } } if (lease.leaseState === models_1.LeaseStateType.Expired) { return new LeaseExpiredState_1.default(lease, context); } if (lease.leaseState === models_1.LeaseStateType.Breaking) { if (lease.leaseBreakTime === undefined) { throw new RangeError(`LeaseFactory:createLeaseState() leaseBreakTime should not be undefined when leaseState is ${models_1.LeaseStateType.Breaking}.`); } if (context.startTime < lease.leaseBreakTime) { return new LeaseBreakingState_1.default(lease, context); } else { return new LeaseBrokenState_1.default(lease, context); } } if (lease.leaseState === models_1.LeaseStateType.Broken) { return new LeaseBrokenState_1.default(lease, context); } throw new RangeError(`LeaseFactory:createLeaseState() Cannot create LeaseState instance from lease ${JSON.stringify(lease)}`); } } exports.default = LeaseFactory; //# sourceMappingURL=LeaseFactory.js.map