import { v4 } from 'uuid' ; import { CollectionConfiguration } from './CollectionConfiguration' ; import { S3Client } from '../s3' ; import { Logger } from '@mu-ts/logger' ; import { S3DB } from '../db' ; export abstract class CollectionBehavior < Of > { private readonly _logger : Logger ; private readonly _configuration : CollectionConfiguration ; private readonly _fullBucketName : string ; private readonly _s3Client : S3Client ; private readonly _idPrefix ? : string ; constructor ( configuration , s3Client , fullBucketName , idPrefix ? ) { this . _logger = S3DB . getRootLogger ( ) . child ( this . constructor . name ) ; this . _configuration = configuration ; this . _fullBucketName = fullBucketName ; this . _s3Client = s3Client ; this . _idPrefix = idPrefix ; this . _logger . info ( 'init()' , { idPrefix } ) ; } protected get logger ( ) { return this . _logger ; } protected get configuration ( ) { return this . _configuration ; } protected get fullBucketName ( ) { return this . _fullBucketName ; } protected get s3Client ( ) { return this . _s3Client ; } protected get s3 ( ) { return this . _s3Client . s3 ; } protected get idPrefix ( ) { return this . _idPrefix ; } param toSave protected generateKey ( toSave ) { return this . configuration . idGenerator ( toSave , v4 ( ) ) ; } param id protected adjustId ( id ) { return `${ this . idPrefix || '' }${ id }` ; } param toSave protected getKeyName ( ) { return this . configuration . keyName || 'id' ; } }