UNPKG

@speckle/shared

Version:

Shared code between various Speckle JS packages

33 lines 1.61 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getProjectLimitDateFactory = exports.calculateLimitCutoffDate = exports.isCreatedBeyondHistoryLimitCutoffFactory = void 0; const dayjs_1 = __importDefault(require("dayjs")); const isCreatedBeyondHistoryLimitCutoffFactory = ({ getProjectLimitDate }) => async ({ entity, project, limitType }) => { const limitDate = await getProjectLimitDate({ project, limitType }); return limitDate ? (0, dayjs_1.default)(limitDate).isAfter(entity.createdAt) : false; }; exports.isCreatedBeyondHistoryLimitCutoffFactory = isCreatedBeyondHistoryLimitCutoffFactory; const calculateLimitCutoffDate = (historyLimits, limitType) => { if (!historyLimits) return null; if (!historyLimits[limitType]) return null; return (0, dayjs_1.default)() .subtract(historyLimits[limitType].value, historyLimits[limitType].unit) .toDate(); }; exports.calculateLimitCutoffDate = calculateLimitCutoffDate; const getProjectLimitDateFactory = ({ getWorkspaceLimits, getPersonalProjectLimits }) => async ({ project, limitType }) => { const limits = project.workspaceId ? await getWorkspaceLimits({ workspaceId: project.workspaceId }) : await getPersonalProjectLimits(); return (0, exports.calculateLimitCutoffDate)(limits, limitType); }; exports.getProjectLimitDateFactory = getProjectLimitDateFactory; //# sourceMappingURL=utils.js.map