UNPKG

@cumulus/message

Version:

Utilities for building and parsing Cumulus messages

124 lines 5.05 kB
import { Message } from '@cumulus/types'; import { ExecutionProcessingTimes } from '@cumulus/types/api/executions'; import { ApiGranule, GranuleStatus, GranuleTemporalInfo, PartialGranuleTemporalInfo, MessageGranule } from '@cumulus/types/api/granules'; import { ApiFile } from '@cumulus/types/api/files'; import { CmrUtilsClass } from './types'; interface MetaWithGranuleQueryFields extends Message.Meta { granule?: { queryFields?: unknown; }; } interface MessageWithGranules extends Message.CumulusMessage { meta: MetaWithGranuleQueryFields; payload: { granules?: object[]; }; } /** * Get granules from payload?.granules of a workflow message. * * @param {Message.CumulusMessage} message - A workflow message * @returns {Array<object>|undefined} An array of granule objects, or * undefined if `message.payload.granules` is not set * @alias module:Granules */ export declare const getMessageGranules: (message: Message.CumulusMessage) => unknown[]; /** * Determine if message has a granules object. * * @param {Message.CumulusMessage} message - A workflow message object * @returns {boolean} true if message has a granules object * @alias module:Granules */ export declare function messageHasGranules(message: Message.CumulusMessage): message is MessageWithGranules; /** * Determine the status of a granule. * * @param {string} workflowStatus - The workflow status * @param {MessageGranule} granule - A granule record conforming to the 'api' schema * @returns {string} The granule status * * @alias module:Granules */ export declare const getGranuleStatus: (workflowStatus: Message.WorkflowStatus, granule: MessageGranule) => Message.WorkflowStatus | GranuleStatus; /** * Get the query fields of a granule, if any * * @param {MessageWithGranules} message - A workflow message * @returns {unknown|undefined} The granule query fields, if any * * @alias module:Granules */ export declare const getGranuleQueryFields: (message: MessageWithGranules) => unknown; /** * Calculate granule product volume, which is the sum of the file * sizes in bytes * * @param {Array<Object>} granuleFiles - array of granule file objects that conform to the * Cumulus 'api' schema * @returns {string} - sum of granule file sizes in bytes as a string */ export declare const getGranuleProductVolume: (granuleFiles?: ApiFile[]) => string; export declare const getGranuleTimeToPreprocess: ({ sync_granule_duration, }?: { sync_granule_duration?: number | undefined; }) => number; export declare const getGranuleTimeToArchive: ({ post_to_cmr_duration, }?: { post_to_cmr_duration?: number | undefined; }) => number; /** * Convert granule processing timestamps to a standardized ISO string * format for compatibility across database systems. * * @param {ExecutionProcessingTimes} [processingTimeInfo] * Granule processing time info, if any * @returns {Promise<ExecutionProcessingTimes | undefined>} */ export declare const getGranuleProcessingTimeInfo: (processingTimeInfo?: ExecutionProcessingTimes) => ExecutionProcessingTimes | {}; /** * Get granule temporal information from argument, directly from CMR * file or from granule object. * * Converts temporal information timestamps to a standardized ISO string * format for compatibility across database systems. * * @param {Object} params * @param {MessageGranule} params.granule - Granule from workflow message * @param {Object} [params.cmrTemporalInfo] - CMR temporal info, if any * @param {CmrUtilsClass} params.cmrUtils - CMR utilities object * @returns {Promise<GranuleTemporalInfo | undefined>} */ export declare const getGranuleCmrTemporalInfo: ({ granule, cmrTemporalInfo, cmrUtils, }: { granule: MessageGranule; cmrTemporalInfo?: GranuleTemporalInfo | undefined; cmrUtils: CmrUtilsClass; }) => Promise<PartialGranuleTemporalInfo | {}>; /** * Generate an API granule record * * @param {MessageWithGranules} message - A workflow message * @returns {Promise<ApiGranule>} The granule API record * * @alias module:Granules */ export declare const generateGranuleApiRecord: ({ granule, executionUrl, collectionId, provider, error, pdrName, status, queryFields, updatedAt, files, processingTimeInfo, cmrUtils, timestamp, duration, productVolume, timeToPreprocess, timeToArchive, cmrTemporalInfo, }: { granule: MessageGranule; executionUrl?: string | undefined; collectionId: string; provider?: string | undefined; error?: Object | undefined; pdrName?: string | undefined; status: GranuleStatus; queryFields?: Object | undefined; updatedAt: number; processingTimeInfo?: ExecutionProcessingTimes | undefined; files?: ApiFile[] | undefined; timestamp: number; cmrUtils: CmrUtilsClass; cmrTemporalInfo?: GranuleTemporalInfo | undefined; duration: number; productVolume: string; timeToPreprocess: number; timeToArchive: number; }) => Promise<ApiGranule>; export {}; //# sourceMappingURL=Granules.d.ts.map