UNPKG

@message-queue-toolkit/core

Version:

Useful utilities, interfaces and base classes for message queue handling. Supports AMQP and SQS with a common abstraction on top currently

50 lines 2.32 kB
import { z } from 'zod/v4'; /** * Multi-store payload reference schema. * Contains information about where and how the payload was stored. */ export const PAYLOAD_REF_SCHEMA = z.object({ /** Unique identifier for the stored payload */ id: z.string().min(1), /** Name/identifier of the store where the payload is stored */ store: z.string().min(1), /** Size of the payload in bytes */ size: z.number().int().positive(), }); /** * When the payload is too large to be sent in a single message, it is offloaded to a storage service and a pointer to the offloaded payload is sent instead. * This schema represents the reference to the payload that is sent in place of the original payload. * * The schema supports two formats: * 1. New format, payloadRef object with id, store, and size * 2. Old format, offloadedPayloadPointer and offloadedPayloadSize (for backward compatibility) * * At least one format must be present in the message. */ export const OFFLOADED_PAYLOAD_POINTER_PAYLOAD_SCHEMA = z .object({ // New, extended payload reference (supports multi-store functionality). payloadRef: PAYLOAD_REF_SCHEMA.optional(), // Legacy payload reference, preserved for backward compatibility. offloadedPayloadPointer: z.string().min(1).optional(), offloadedPayloadSize: z.number().int().positive().optional(), }) // Pass-through allows to pass message ID, type, timestamp and message-deduplication-related fields that are using dynamic keys. .passthrough() .refine((data) => { // At least one format must be present // For the legacy format, both offloadedPayloadPointer and offloadedPayloadSize are required return (data.payloadRef !== undefined || (data.offloadedPayloadPointer !== undefined && data.offloadedPayloadSize !== undefined)); }, { message: 'Either payloadRef or both offloadedPayloadPointer and offloadedPayloadSize must be present', }); export function isOffloadedPayloadPointerPayload(value) { if (typeof value !== 'object' || value === null) { return false; } const payload = value; return (payload.payloadRef !== undefined || (payload.offloadedPayloadPointer !== undefined && payload.offloadedPayloadSize !== undefined)); } //# sourceMappingURL=offloadedPayloadMessageSchemas.js.map