UNPKG

@message-queue-toolkit/s3-payload-store

Version:

AWS S3-based message store implementation for message-queue-toolkit

47 lines 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.S3PayloadStore = void 0; const node_crypto_1 = require("node:crypto"); const client_s3_1 = require("@aws-sdk/client-s3"); class S3PayloadStore { s3; config; constructor({ s3 }, config) { this.s3 = s3; this.config = config; } async storePayload(payload) { const id = (0, node_crypto_1.randomUUID)(); const key = this.config?.keyPrefix?.length ? `${this.config.keyPrefix}/${id}` : id; await this.s3.putObject({ Bucket: this.config.bucketName, Key: key, Body: payload.value, ContentLength: payload.size, }); return key; } async retrievePayload(key) { try { const result = await this.s3.getObject({ Bucket: this.config.bucketName, Key: key, }); return result.Body ? result.Body : null; } catch (e) { if (e instanceof client_s3_1.NoSuchKey) { return null; } throw e; } } async deletePayload(key) { await this.s3.deleteObject({ Bucket: this.config.bucketName, Key: key, }); } } exports.S3PayloadStore = S3PayloadStore; //# sourceMappingURL=S3PayloadStore.js.map