All files / lib/libs/api/package packageStatus.ts

100% Statements 13/13
100% Branches 14/14
100% Functions 4/4
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38      38x 57x 57x         38x 121x 64x     57x 9x     48x     38x 83x             38x 15x            
import { SEATOOL_STATUS } from "shared-types";
import { ItemResult } from "shared-types/opensearch/main";
 
const hasKnownSeatoolStatus = (packageResult?: ItemResult): boolean => {
  const seatoolStatus = packageResult?._source?.seatoolStatus;
  return typeof seatoolStatus === "string" && seatoolStatus.trim().length > 0;
};
 
// Partial upserts can leave shell docs in `main` that only contain an id/timestamp.
// Those incomplete records should not block draft ID reuse or win package resolution.
export const isActiveMainNonDraftPackage = (packageResult?: ItemResult): boolean => {
  if (packageResult?.found !== true || packageResult._source?.deleted === true) {
    return false;
  }
 
  if (!hasKnownSeatoolStatus(packageResult)) {
    return false;
  }
 
  return packageResult._source.seatoolStatus !== SEATOOL_STATUS.DRAFT;
};
 
export const isActiveDraftPackage = (packageResult?: ItemResult): boolean => {
  return (
    packageResult?.found === true &&
    packageResult._source?.deleted !== true &&
    packageResult._source?.seatoolStatus === SEATOOL_STATUS.DRAFT
  );
};
 
export const isDeletedDraftPackage = (packageResult?: ItemResult): boolean => {
  return (
    packageResult?.found === true &&
    packageResult._source?.deleted === true &&
    packageResult._source?.seatoolStatus === SEATOOL_STATUS.DRAFT
  );
};