Files
smartbucket/ts/classes.smartbucket.ts

53 lines
1.5 KiB
TypeScript

// classes.smartbucket.ts
import * as plugins from './plugins.js';
import { Bucket } from './classes.bucket.js';
import { normalizeS3Descriptor } from './helpers.js';
export class SmartBucket {
public config: plugins.tsclass.storage.IS3Descriptor;
public s3Client: plugins.s3.S3Client;
/**
* the constructor of SmartBucket
*/
/**
* the constructor of SmartBucket
*/
constructor(configArg: plugins.tsclass.storage.IS3Descriptor) {
this.config = configArg;
// Use the normalizer to handle various endpoint formats
const { normalized } = normalizeS3Descriptor(configArg);
this.s3Client = new plugins.s3.S3Client({
endpoint: normalized.endpointUrl,
region: normalized.region,
credentials: normalized.credentials,
forcePathStyle: normalized.forcePathStyle, // Necessary for S3-compatible storage like MinIO or Wasabi
});
}
public async createBucket(bucketNameArg: string) {
const bucket = await Bucket.createBucketByName(this, bucketNameArg);
return bucket;
}
public async removeBucket(bucketName: string) {
await Bucket.removeBucketByName(this, bucketName);
}
public async getBucketByName(bucketNameArg: string) {
return Bucket.getBucketByName(this, bucketNameArg);
}
public async getBucketByNameStrict(...args: Parameters<SmartBucket['getBucketByName']>) {
const bucket = await this.getBucketByName(...args);
if (!bucket) {
throw new Error(`Bucket ${args[0]} does not exist.`);
}
return bucket;
}
}