Enterprise-CMCS/macpro-mako

View on GitHub
lib/libs/api/package/itemExists.ts

Summary

Maintainability
A
0 mins
Test Coverage
D
60%
import * as os from "../../../libs/opensearch-lib";

export async function itemExists(params: {
  id: string;
  osDomain?: string;
  indexNamespace?: string;
}): Promise<boolean> {
  try {
    const packageResult = await os.getItem(
      params.osDomain || process.env.osDomain!,
      `${params.indexNamespace || process.env.indexNamespace!}main`,
      params.id,
    );
    return !!packageResult?._source;
  } catch (error) {
    console.error("Error checking item existence in OpenSearch:", error);
    return false;
  }
}