2022-05-16 17:41:12 +00:00
|
|
|
export interface DocumentUsage {
|
2022-08-03 07:18:21 +00:00
|
|
|
rowCount?: RowCounts;
|
2022-05-16 17:41:12 +00:00
|
|
|
dataSizeBytes?: number;
|
|
|
|
attachmentsSizeBytes?: number;
|
2022-05-03 05:20:31 +00:00
|
|
|
}
|
|
|
|
|
2022-08-03 07:18:21 +00:00
|
|
|
export interface RowCounts {
|
|
|
|
total: number;
|
|
|
|
[tableRef: number]: number;
|
|
|
|
}
|
|
|
|
|
2022-05-16 17:41:12 +00:00
|
|
|
export type DataLimitStatus = 'approachingLimit' | 'gracePeriod' | 'deleteOnly' | null;
|
2022-05-03 05:20:31 +00:00
|
|
|
|
2022-05-16 17:41:12 +00:00
|
|
|
type DocUsageOrPending = {
|
|
|
|
[Metric in keyof Required<DocumentUsage>]: Required<DocumentUsage>[Metric] | 'pending'
|
|
|
|
}
|
2022-05-03 05:20:31 +00:00
|
|
|
|
2022-05-16 17:41:12 +00:00
|
|
|
export interface DocUsageSummary extends DocUsageOrPending {
|
|
|
|
dataLimitStatus: DataLimitStatus;
|
|
|
|
}
|
2022-05-03 05:20:31 +00:00
|
|
|
|
2022-05-16 17:41:12 +00:00
|
|
|
// Count of non-removed documents in an org, grouped by data limit status.
|
|
|
|
export type OrgUsageSummary = Record<NonNullable<DataLimitStatus>, number>;
|
2022-05-03 05:20:31 +00:00
|
|
|
|
2022-05-16 17:41:12 +00:00
|
|
|
type FilteredDocUsage = {
|
|
|
|
[Metric in keyof DocUsageOrPending]: DocUsageOrPending[Metric] | 'hidden'
|
|
|
|
}
|
2022-05-03 05:20:31 +00:00
|
|
|
|
2022-05-16 17:41:12 +00:00
|
|
|
export interface FilteredDocUsageSummary extends FilteredDocUsage {
|
|
|
|
dataLimitStatus: DataLimitStatus;
|
|
|
|
}
|
2022-05-03 05:20:31 +00:00
|
|
|
|
|
|
|
// Ratio of usage at which we start telling users that they're approaching limits.
|
|
|
|
export const APPROACHING_LIMIT_RATIO = 0.9;
|
|
|
|
|
2022-05-16 17:41:12 +00:00
|
|
|
/**
|
|
|
|
* Computes a ratio of `usage` to `limit`, if possible. Returns 0 if `usage` or `limit`
|
|
|
|
* is invalid or undefined.
|
|
|
|
*/
|
|
|
|
export function getUsageRatio(usage: number | undefined, limit: number | undefined): number {
|
|
|
|
if (!isEnforceableLimit(limit) || usage === undefined || usage < 0) {
|
|
|
|
// Treat undefined or invalid values as having 0 usage.
|
|
|
|
return 0;
|
2022-05-03 05:20:31 +00:00
|
|
|
}
|
2022-05-16 17:41:12 +00:00
|
|
|
|
|
|
|
return usage / limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an empty org usage summary with values initialized to 0.
|
|
|
|
*/
|
|
|
|
export function createEmptyOrgUsageSummary(): OrgUsageSummary {
|
|
|
|
return {
|
|
|
|
approachingLimit: 0,
|
|
|
|
gracePeriod: 0,
|
|
|
|
deleteOnly: 0,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if `limit` is defined and is a valid, positive number.
|
|
|
|
*/
|
|
|
|
function isEnforceableLimit(limit: number | undefined): limit is number {
|
|
|
|
return limit !== undefined && limit > 0;
|
2022-05-03 05:20:31 +00:00
|
|
|
}
|