From 42c7059d5a11d988d0e09c8507492fdfce30c5c7 Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Thu, 22 Aug 2024 12:16:21 +1200 Subject: [PATCH] refactor: define property and not set it --- packages/source-aws/src/__test__/source.aws.test.ts | 4 +++- packages/source-aws/src/index.ts | 8 ++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/source-aws/src/__test__/source.aws.test.ts b/packages/source-aws/src/__test__/source.aws.test.ts index d8348491..c3a1f1e2 100644 --- a/packages/source-aws/src/__test__/source.aws.test.ts +++ b/packages/source-aws/src/__test__/source.aws.test.ts @@ -9,7 +9,9 @@ describe('SourceAwsS3', () => { }); it('should not expose "client" for logging', () => { - const keys = Object.keys(new SourceAwsS3('s3://foo/bar.txt')); + const source = new SourceAwsS3('s3://foo/bar.txt'); + const keys = Object.keys(source); assert.equal(keys.includes('client'), false); + assert.notEqual(source.client.config, null); }); }); diff --git a/packages/source-aws/src/index.ts b/packages/source-aws/src/index.ts index d8b2004a..7c61205b 100644 --- a/packages/source-aws/src/index.ts +++ b/packages/source-aws/src/index.ts @@ -51,13 +51,9 @@ export class SourceAwsS3 implements Source { constructor(url: URL | string, client: S3Client = new S3Client({})) { this.url = typeof url === 'string' ? new URL(url) : url; - // Make typescript happy + // S3 clients are very large and if this object gets logged the log is very very large + Object.defineProperty(this, 'client', { enumerable: false }); this.client = client; - // S3 clients are very large and if this object gets logged the client is very very large - Object.defineProperty(this, 'client', { - enumerable: false, - value: client, - }); } _head?: Promise;