@message-queue-toolkit/s3-payload-store
Version:
AWS S3-based message store implementation for message-queue-toolkit
43 lines • 1.19 kB
JavaScript
import { randomUUID } from 'node:crypto';
import { NoSuchKey } from '@aws-sdk/client-s3';
export class S3PayloadStore {
s3;
config;
constructor({ s3 }, config) {
this.s3 = s3;
this.config = config;
}
async storePayload(payload) {
const id = 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 NoSuchKey) {
return null;
}
throw e;
}
}
async deletePayload(key) {
await this.s3.deleteObject({
Bucket: this.config.bucketName,
Key: key,
});
}
}
//# sourceMappingURL=S3PayloadStore.js.map