From b7a58d4bff9051e68cb67d23066f00759aa406d0 Mon Sep 17 00:00:00 2001 From: godu Date: Fri, 10 Jan 2025 13:45:35 +0100 Subject: [PATCH] feat: add finalizer --- .changeset/five-poems-vanish.md | 41 +++++++++++++++++++ .../src/AccountClientInstance.ts | 10 +++-- .../ApiGatewayManagementApiClientInstance.ts | 10 +++-- .../src/AutoScalingClientInstance.ts | 10 +++-- .../src/BedrockClientInstance.ts | 10 +++-- .../src/CloudSearchClientInstance.ts | 10 +++-- .../src/CloudTrailClientInstance.ts | 10 +++-- .../src/CloudWatchEventsClientInstance.ts | 10 +++-- .../src/CloudWatchLogsClientInstance.ts | 10 +++-- .../src/CloudWatchClientInstance.ts | 10 +++-- .../src/CodeDeployClientInstance.ts | 10 +++-- .../CognitoIdentityProviderClientInstance.ts | 10 +++-- .../src/DynamoDBClientInstance.ts | 10 +++-- packages/client-ec2/src/EC2ClientInstance.ts | 10 +++-- packages/client-ecr/src/ECRClientInstance.ts | 10 +++-- packages/client-ecs/src/ECSClientInstance.ts | 10 +++-- .../src/ElastiCacheClientInstance.ts | 10 +++-- .../src/EventBridgeClientInstance.ts | 10 +++-- packages/client-iam/src/IAMClientInstance.ts | 10 +++-- .../src/KinesisClientInstance.ts | 10 +++-- packages/client-kms/src/KMSClientInstance.ts | 10 +++-- .../client-lambda/src/LambdaClientInstance.ts | 10 +++-- packages/client-mq/src/MqClientInstance.ts | 10 +++-- .../src/OpenSearchServerlessClientInstance.ts | 10 +++-- .../src/OpenSearchClientInstance.ts | 10 +++-- .../src/OrganizationsClientInstance.ts | 10 +++-- packages/client-rds/src/RDSClientInstance.ts | 10 +++-- packages/client-s3/src/S3ClientInstance.ts | 10 +++-- .../src/SchedulerClientInstance.ts | 10 +++-- .../src/SecretsManagerClientInstance.ts | 10 +++-- packages/client-sfn/src/SFNClientInstance.ts | 10 +++-- packages/client-sns/src/SNSClientInstance.ts | 10 +++-- packages/client-sqs/src/SQSClientInstance.ts | 10 +++-- packages/client-ssm/src/SSMClientInstance.ts | 10 +++-- packages/client-sts/src/STSClientInstance.ts | 10 +++-- .../src/TextractClientInstance.ts | 10 +++-- .../src/DynamoDBDocumentClientInstance.ts | 2 +- scripts/codegen-client.ts | 12 ++++-- 38 files changed, 295 insertions(+), 110 deletions(-) create mode 100644 .changeset/five-poems-vanish.md diff --git a/.changeset/five-poems-vanish.md b/.changeset/five-poems-vanish.md new file mode 100644 index 0000000..097d7e1 --- /dev/null +++ b/.changeset/five-poems-vanish.md @@ -0,0 +1,41 @@ +--- +"@effect-aws/client-api-gateway-management-api": minor +"@effect-aws/client-cognito-identity-provider": minor +"@effect-aws/client-opensearch-serverless": minor +"@effect-aws/client-cloudwatch-events": minor +"@effect-aws/client-cloudwatch-logs": minor +"@effect-aws/client-secrets-manager": minor +"@effect-aws/client-organizations": minor +"@effect-aws/client-auto-scaling": minor +"@effect-aws/client-cloudsearch": minor +"@effect-aws/client-elasticache": minor +"@effect-aws/client-eventbridge": minor +"@effect-aws/client-cloudtrail": minor +"@effect-aws/client-cloudwatch": minor +"@effect-aws/client-codedeploy": minor +"@effect-aws/client-opensearch": minor +"@effect-aws/client-scheduler": minor +"@effect-aws/client-dynamodb": minor +"@effect-aws/client-textract": minor +"@effect-aws/client-account": minor +"@effect-aws/client-bedrock": minor +"@effect-aws/client-kinesis": minor +"@effect-aws/client-lambda": minor +"@effect-aws/lib-dynamodb": minor +"@effect-aws/client-ec2": minor +"@effect-aws/client-ecr": minor +"@effect-aws/client-ecs": minor +"@effect-aws/client-iam": minor +"@effect-aws/client-kms": minor +"@effect-aws/client-rds": minor +"@effect-aws/client-sfn": minor +"@effect-aws/client-sns": minor +"@effect-aws/client-sqs": minor +"@effect-aws/client-ssm": minor +"@effect-aws/client-sts": minor +"@effect-aws/client-mq": minor +"@effect-aws/client-s3": minor +"@effect-aws/lib-dynamodb": minor +--- + +Destroy client after layer lifecycle to release idle connections. diff --git a/packages/client-account/src/AccountClientInstance.ts b/packages/client-account/src/AccountClientInstance.ts index d488839..bd8dd1c 100644 --- a/packages/client-account/src/AccountClientInstance.ts +++ b/packages/client-account/src/AccountClientInstance.ts @@ -22,16 +22,20 @@ export class AccountClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeAccountClientInstance = Effect.map( +export const makeAccountClientInstance = Effect.flatMap( AccountClientInstanceConfig, - (config) => new AccountClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new AccountClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const AccountClientInstanceLayer = Layer.effect( +export const AccountClientInstanceLayer = Layer.scoped( AccountClientInstance, makeAccountClientInstance, ); diff --git a/packages/client-api-gateway-management-api/src/ApiGatewayManagementApiClientInstance.ts b/packages/client-api-gateway-management-api/src/ApiGatewayManagementApiClientInstance.ts index ec1377a..f6a86d7 100644 --- a/packages/client-api-gateway-management-api/src/ApiGatewayManagementApiClientInstance.ts +++ b/packages/client-api-gateway-management-api/src/ApiGatewayManagementApiClientInstance.ts @@ -22,16 +22,20 @@ export class ApiGatewayManagementApiClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeApiGatewayManagementApiClientInstance = Effect.map( +export const makeApiGatewayManagementApiClientInstance = Effect.flatMap( ApiGatewayManagementApiClientInstanceConfig, - (config) => new ApiGatewayManagementApiClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new ApiGatewayManagementApiClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const ApiGatewayManagementApiClientInstanceLayer = Layer.effect( +export const ApiGatewayManagementApiClientInstanceLayer = Layer.scoped( ApiGatewayManagementApiClientInstance, makeApiGatewayManagementApiClientInstance, ); diff --git a/packages/client-auto-scaling/src/AutoScalingClientInstance.ts b/packages/client-auto-scaling/src/AutoScalingClientInstance.ts index 7de544c..5ecbb98 100644 --- a/packages/client-auto-scaling/src/AutoScalingClientInstance.ts +++ b/packages/client-auto-scaling/src/AutoScalingClientInstance.ts @@ -22,16 +22,20 @@ export class AutoScalingClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeAutoScalingClientInstance = Effect.map( +export const makeAutoScalingClientInstance = Effect.flatMap( AutoScalingClientInstanceConfig, - (config) => new AutoScalingClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new AutoScalingClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const AutoScalingClientInstanceLayer = Layer.effect( +export const AutoScalingClientInstanceLayer = Layer.scoped( AutoScalingClientInstance, makeAutoScalingClientInstance, ); diff --git a/packages/client-bedrock/src/BedrockClientInstance.ts b/packages/client-bedrock/src/BedrockClientInstance.ts index c5aa566..50e73f5 100644 --- a/packages/client-bedrock/src/BedrockClientInstance.ts +++ b/packages/client-bedrock/src/BedrockClientInstance.ts @@ -22,16 +22,20 @@ export class BedrockClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeBedrockClientInstance = Effect.map( +export const makeBedrockClientInstance = Effect.flatMap( BedrockClientInstanceConfig, - (config) => new BedrockClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new BedrockClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const BedrockClientInstanceLayer = Layer.effect( +export const BedrockClientInstanceLayer = Layer.scoped( BedrockClientInstance, makeBedrockClientInstance, ); diff --git a/packages/client-cloudsearch/src/CloudSearchClientInstance.ts b/packages/client-cloudsearch/src/CloudSearchClientInstance.ts index 7aeaa03..59f6d2c 100644 --- a/packages/client-cloudsearch/src/CloudSearchClientInstance.ts +++ b/packages/client-cloudsearch/src/CloudSearchClientInstance.ts @@ -22,16 +22,20 @@ export class CloudSearchClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeCloudSearchClientInstance = Effect.map( +export const makeCloudSearchClientInstance = Effect.flatMap( CloudSearchClientInstanceConfig, - (config) => new CloudSearchClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new CloudSearchClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const CloudSearchClientInstanceLayer = Layer.effect( +export const CloudSearchClientInstanceLayer = Layer.scoped( CloudSearchClientInstance, makeCloudSearchClientInstance, ); diff --git a/packages/client-cloudtrail/src/CloudTrailClientInstance.ts b/packages/client-cloudtrail/src/CloudTrailClientInstance.ts index 1baf507..f74ef7c 100644 --- a/packages/client-cloudtrail/src/CloudTrailClientInstance.ts +++ b/packages/client-cloudtrail/src/CloudTrailClientInstance.ts @@ -22,16 +22,20 @@ export class CloudTrailClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeCloudTrailClientInstance = Effect.map( +export const makeCloudTrailClientInstance = Effect.flatMap( CloudTrailClientInstanceConfig, - (config) => new CloudTrailClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new CloudTrailClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const CloudTrailClientInstanceLayer = Layer.effect( +export const CloudTrailClientInstanceLayer = Layer.scoped( CloudTrailClientInstance, makeCloudTrailClientInstance, ); diff --git a/packages/client-cloudwatch-events/src/CloudWatchEventsClientInstance.ts b/packages/client-cloudwatch-events/src/CloudWatchEventsClientInstance.ts index 0626af4..e70377d 100644 --- a/packages/client-cloudwatch-events/src/CloudWatchEventsClientInstance.ts +++ b/packages/client-cloudwatch-events/src/CloudWatchEventsClientInstance.ts @@ -22,16 +22,20 @@ export class CloudWatchEventsClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeCloudWatchEventsClientInstance = Effect.map( +export const makeCloudWatchEventsClientInstance = Effect.flatMap( CloudWatchEventsClientInstanceConfig, - (config) => new CloudWatchEventsClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new CloudWatchEventsClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const CloudWatchEventsClientInstanceLayer = Layer.effect( +export const CloudWatchEventsClientInstanceLayer = Layer.scoped( CloudWatchEventsClientInstance, makeCloudWatchEventsClientInstance, ); diff --git a/packages/client-cloudwatch-logs/src/CloudWatchLogsClientInstance.ts b/packages/client-cloudwatch-logs/src/CloudWatchLogsClientInstance.ts index 9204619..bcb04ca 100644 --- a/packages/client-cloudwatch-logs/src/CloudWatchLogsClientInstance.ts +++ b/packages/client-cloudwatch-logs/src/CloudWatchLogsClientInstance.ts @@ -22,16 +22,20 @@ export class CloudWatchLogsClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeCloudWatchLogsClientInstance = Effect.map( +export const makeCloudWatchLogsClientInstance = Effect.flatMap( CloudWatchLogsClientInstanceConfig, - (config) => new CloudWatchLogsClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new CloudWatchLogsClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const CloudWatchLogsClientInstanceLayer = Layer.effect( +export const CloudWatchLogsClientInstanceLayer = Layer.scoped( CloudWatchLogsClientInstance, makeCloudWatchLogsClientInstance, ); diff --git a/packages/client-cloudwatch/src/CloudWatchClientInstance.ts b/packages/client-cloudwatch/src/CloudWatchClientInstance.ts index 5f126ec..ac911e3 100644 --- a/packages/client-cloudwatch/src/CloudWatchClientInstance.ts +++ b/packages/client-cloudwatch/src/CloudWatchClientInstance.ts @@ -22,16 +22,20 @@ export class CloudWatchClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeCloudWatchClientInstance = Effect.map( +export const makeCloudWatchClientInstance = Effect.flatMap( CloudWatchClientInstanceConfig, - (config) => new CloudWatchClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new CloudWatchClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const CloudWatchClientInstanceLayer = Layer.effect( +export const CloudWatchClientInstanceLayer = Layer.scoped( CloudWatchClientInstance, makeCloudWatchClientInstance, ); diff --git a/packages/client-codedeploy/src/CodeDeployClientInstance.ts b/packages/client-codedeploy/src/CodeDeployClientInstance.ts index 5d1103f..3159010 100644 --- a/packages/client-codedeploy/src/CodeDeployClientInstance.ts +++ b/packages/client-codedeploy/src/CodeDeployClientInstance.ts @@ -22,16 +22,20 @@ export class CodeDeployClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeCodeDeployClientInstance = Effect.map( +export const makeCodeDeployClientInstance = Effect.flatMap( CodeDeployClientInstanceConfig, - (config) => new CodeDeployClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new CodeDeployClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const CodeDeployClientInstanceLayer = Layer.effect( +export const CodeDeployClientInstanceLayer = Layer.scoped( CodeDeployClientInstance, makeCodeDeployClientInstance, ); diff --git a/packages/client-cognito-identity-provider/src/CognitoIdentityProviderClientInstance.ts b/packages/client-cognito-identity-provider/src/CognitoIdentityProviderClientInstance.ts index 438469a..3563ca3 100644 --- a/packages/client-cognito-identity-provider/src/CognitoIdentityProviderClientInstance.ts +++ b/packages/client-cognito-identity-provider/src/CognitoIdentityProviderClientInstance.ts @@ -22,16 +22,20 @@ export class CognitoIdentityProviderClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeCognitoIdentityProviderClientInstance = Effect.map( +export const makeCognitoIdentityProviderClientInstance = Effect.flatMap( CognitoIdentityProviderClientInstanceConfig, - (config) => new CognitoIdentityProviderClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new CognitoIdentityProviderClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const CognitoIdentityProviderClientInstanceLayer = Layer.effect( +export const CognitoIdentityProviderClientInstanceLayer = Layer.scoped( CognitoIdentityProviderClientInstance, makeCognitoIdentityProviderClientInstance, ); diff --git a/packages/client-dynamodb/src/DynamoDBClientInstance.ts b/packages/client-dynamodb/src/DynamoDBClientInstance.ts index 2252e54..cb33a2c 100644 --- a/packages/client-dynamodb/src/DynamoDBClientInstance.ts +++ b/packages/client-dynamodb/src/DynamoDBClientInstance.ts @@ -22,16 +22,20 @@ export class DynamoDBClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeDynamoDBClientInstance = Effect.map( +export const makeDynamoDBClientInstance = Effect.flatMap( DynamoDBClientInstanceConfig, - (config) => new DynamoDBClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new DynamoDBClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const DynamoDBClientInstanceLayer = Layer.effect( +export const DynamoDBClientInstanceLayer = Layer.scoped( DynamoDBClientInstance, makeDynamoDBClientInstance, ); diff --git a/packages/client-ec2/src/EC2ClientInstance.ts b/packages/client-ec2/src/EC2ClientInstance.ts index 2d7a02d..b2b1d98 100644 --- a/packages/client-ec2/src/EC2ClientInstance.ts +++ b/packages/client-ec2/src/EC2ClientInstance.ts @@ -22,16 +22,20 @@ export class EC2ClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeEC2ClientInstance = Effect.map( +export const makeEC2ClientInstance = Effect.flatMap( EC2ClientInstanceConfig, - (config) => new EC2Client(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new EC2Client(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const EC2ClientInstanceLayer = Layer.effect( +export const EC2ClientInstanceLayer = Layer.scoped( EC2ClientInstance, makeEC2ClientInstance, ); diff --git a/packages/client-ecr/src/ECRClientInstance.ts b/packages/client-ecr/src/ECRClientInstance.ts index 6218ff0..4fe5d85 100644 --- a/packages/client-ecr/src/ECRClientInstance.ts +++ b/packages/client-ecr/src/ECRClientInstance.ts @@ -22,16 +22,20 @@ export class ECRClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeECRClientInstance = Effect.map( +export const makeECRClientInstance = Effect.flatMap( ECRClientInstanceConfig, - (config) => new ECRClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new ECRClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const ECRClientInstanceLayer = Layer.effect( +export const ECRClientInstanceLayer = Layer.scoped( ECRClientInstance, makeECRClientInstance, ); diff --git a/packages/client-ecs/src/ECSClientInstance.ts b/packages/client-ecs/src/ECSClientInstance.ts index c179b08..d3a5022 100644 --- a/packages/client-ecs/src/ECSClientInstance.ts +++ b/packages/client-ecs/src/ECSClientInstance.ts @@ -22,16 +22,20 @@ export class ECSClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeECSClientInstance = Effect.map( +export const makeECSClientInstance = Effect.flatMap( ECSClientInstanceConfig, - (config) => new ECSClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new ECSClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const ECSClientInstanceLayer = Layer.effect( +export const ECSClientInstanceLayer = Layer.scoped( ECSClientInstance, makeECSClientInstance, ); diff --git a/packages/client-elasticache/src/ElastiCacheClientInstance.ts b/packages/client-elasticache/src/ElastiCacheClientInstance.ts index 495a6f1..5ec16c5 100644 --- a/packages/client-elasticache/src/ElastiCacheClientInstance.ts +++ b/packages/client-elasticache/src/ElastiCacheClientInstance.ts @@ -22,16 +22,20 @@ export class ElastiCacheClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeElastiCacheClientInstance = Effect.map( +export const makeElastiCacheClientInstance = Effect.flatMap( ElastiCacheClientInstanceConfig, - (config) => new ElastiCacheClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new ElastiCacheClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const ElastiCacheClientInstanceLayer = Layer.effect( +export const ElastiCacheClientInstanceLayer = Layer.scoped( ElastiCacheClientInstance, makeElastiCacheClientInstance, ); diff --git a/packages/client-eventbridge/src/EventBridgeClientInstance.ts b/packages/client-eventbridge/src/EventBridgeClientInstance.ts index 4bc1bec..659cca6 100644 --- a/packages/client-eventbridge/src/EventBridgeClientInstance.ts +++ b/packages/client-eventbridge/src/EventBridgeClientInstance.ts @@ -22,16 +22,20 @@ export class EventBridgeClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeEventBridgeClientInstance = Effect.map( +export const makeEventBridgeClientInstance = Effect.flatMap( EventBridgeClientInstanceConfig, - (config) => new EventBridgeClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new EventBridgeClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const EventBridgeClientInstanceLayer = Layer.effect( +export const EventBridgeClientInstanceLayer = Layer.scoped( EventBridgeClientInstance, makeEventBridgeClientInstance, ); diff --git a/packages/client-iam/src/IAMClientInstance.ts b/packages/client-iam/src/IAMClientInstance.ts index 6e36655..7821242 100644 --- a/packages/client-iam/src/IAMClientInstance.ts +++ b/packages/client-iam/src/IAMClientInstance.ts @@ -22,16 +22,20 @@ export class IAMClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeIAMClientInstance = Effect.map( +export const makeIAMClientInstance = Effect.flatMap( IAMClientInstanceConfig, - (config) => new IAMClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new IAMClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const IAMClientInstanceLayer = Layer.effect( +export const IAMClientInstanceLayer = Layer.scoped( IAMClientInstance, makeIAMClientInstance, ); diff --git a/packages/client-kinesis/src/KinesisClientInstance.ts b/packages/client-kinesis/src/KinesisClientInstance.ts index 8108c08..e2fe885 100644 --- a/packages/client-kinesis/src/KinesisClientInstance.ts +++ b/packages/client-kinesis/src/KinesisClientInstance.ts @@ -22,16 +22,20 @@ export class KinesisClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeKinesisClientInstance = Effect.map( +export const makeKinesisClientInstance = Effect.flatMap( KinesisClientInstanceConfig, - (config) => new KinesisClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new KinesisClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const KinesisClientInstanceLayer = Layer.effect( +export const KinesisClientInstanceLayer = Layer.scoped( KinesisClientInstance, makeKinesisClientInstance, ); diff --git a/packages/client-kms/src/KMSClientInstance.ts b/packages/client-kms/src/KMSClientInstance.ts index 102cf12..0dc3f20 100644 --- a/packages/client-kms/src/KMSClientInstance.ts +++ b/packages/client-kms/src/KMSClientInstance.ts @@ -22,16 +22,20 @@ export class KMSClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeKMSClientInstance = Effect.map( +export const makeKMSClientInstance = Effect.flatMap( KMSClientInstanceConfig, - (config) => new KMSClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new KMSClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const KMSClientInstanceLayer = Layer.effect( +export const KMSClientInstanceLayer = Layer.scoped( KMSClientInstance, makeKMSClientInstance, ); diff --git a/packages/client-lambda/src/LambdaClientInstance.ts b/packages/client-lambda/src/LambdaClientInstance.ts index 9a204fe..51ddd37 100644 --- a/packages/client-lambda/src/LambdaClientInstance.ts +++ b/packages/client-lambda/src/LambdaClientInstance.ts @@ -22,16 +22,20 @@ export class LambdaClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeLambdaClientInstance = Effect.map( +export const makeLambdaClientInstance = Effect.flatMap( LambdaClientInstanceConfig, - (config) => new LambdaClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new LambdaClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const LambdaClientInstanceLayer = Layer.effect( +export const LambdaClientInstanceLayer = Layer.scoped( LambdaClientInstance, makeLambdaClientInstance, ); diff --git a/packages/client-mq/src/MqClientInstance.ts b/packages/client-mq/src/MqClientInstance.ts index 75be33c..aca8485 100644 --- a/packages/client-mq/src/MqClientInstance.ts +++ b/packages/client-mq/src/MqClientInstance.ts @@ -22,16 +22,20 @@ export class MqClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeMqClientInstance = Effect.map( +export const makeMqClientInstance = Effect.flatMap( MqClientInstanceConfig, - (config) => new MqClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new MqClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const MqClientInstanceLayer = Layer.effect( +export const MqClientInstanceLayer = Layer.scoped( MqClientInstance, makeMqClientInstance, ); diff --git a/packages/client-opensearch-serverless/src/OpenSearchServerlessClientInstance.ts b/packages/client-opensearch-serverless/src/OpenSearchServerlessClientInstance.ts index 7539612..254c776 100644 --- a/packages/client-opensearch-serverless/src/OpenSearchServerlessClientInstance.ts +++ b/packages/client-opensearch-serverless/src/OpenSearchServerlessClientInstance.ts @@ -22,16 +22,20 @@ export class OpenSearchServerlessClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeOpenSearchServerlessClientInstance = Effect.map( +export const makeOpenSearchServerlessClientInstance = Effect.flatMap( OpenSearchServerlessClientInstanceConfig, - (config) => new OpenSearchServerlessClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new OpenSearchServerlessClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const OpenSearchServerlessClientInstanceLayer = Layer.effect( +export const OpenSearchServerlessClientInstanceLayer = Layer.scoped( OpenSearchServerlessClientInstance, makeOpenSearchServerlessClientInstance, ); diff --git a/packages/client-opensearch/src/OpenSearchClientInstance.ts b/packages/client-opensearch/src/OpenSearchClientInstance.ts index 97d5eab..4a2d165 100644 --- a/packages/client-opensearch/src/OpenSearchClientInstance.ts +++ b/packages/client-opensearch/src/OpenSearchClientInstance.ts @@ -22,16 +22,20 @@ export class OpenSearchClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeOpenSearchClientInstance = Effect.map( +export const makeOpenSearchClientInstance = Effect.flatMap( OpenSearchClientInstanceConfig, - (config) => new OpenSearchClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new OpenSearchClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const OpenSearchClientInstanceLayer = Layer.effect( +export const OpenSearchClientInstanceLayer = Layer.scoped( OpenSearchClientInstance, makeOpenSearchClientInstance, ); diff --git a/packages/client-organizations/src/OrganizationsClientInstance.ts b/packages/client-organizations/src/OrganizationsClientInstance.ts index 1108a52..c4c1f68 100644 --- a/packages/client-organizations/src/OrganizationsClientInstance.ts +++ b/packages/client-organizations/src/OrganizationsClientInstance.ts @@ -22,16 +22,20 @@ export class OrganizationsClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeOrganizationsClientInstance = Effect.map( +export const makeOrganizationsClientInstance = Effect.flatMap( OrganizationsClientInstanceConfig, - (config) => new OrganizationsClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new OrganizationsClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const OrganizationsClientInstanceLayer = Layer.effect( +export const OrganizationsClientInstanceLayer = Layer.scoped( OrganizationsClientInstance, makeOrganizationsClientInstance, ); diff --git a/packages/client-rds/src/RDSClientInstance.ts b/packages/client-rds/src/RDSClientInstance.ts index ac7f880..ec0b75e 100644 --- a/packages/client-rds/src/RDSClientInstance.ts +++ b/packages/client-rds/src/RDSClientInstance.ts @@ -22,16 +22,20 @@ export class RDSClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeRDSClientInstance = Effect.map( +export const makeRDSClientInstance = Effect.flatMap( RDSClientInstanceConfig, - (config) => new RDSClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new RDSClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const RDSClientInstanceLayer = Layer.effect( +export const RDSClientInstanceLayer = Layer.scoped( RDSClientInstance, makeRDSClientInstance, ); diff --git a/packages/client-s3/src/S3ClientInstance.ts b/packages/client-s3/src/S3ClientInstance.ts index c6da8a4..2552181 100644 --- a/packages/client-s3/src/S3ClientInstance.ts +++ b/packages/client-s3/src/S3ClientInstance.ts @@ -22,16 +22,20 @@ export class S3ClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeS3ClientInstance = Effect.map( +export const makeS3ClientInstance = Effect.flatMap( S3ClientInstanceConfig, - (config) => new S3Client(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new S3Client(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const S3ClientInstanceLayer = Layer.effect( +export const S3ClientInstanceLayer = Layer.scoped( S3ClientInstance, makeS3ClientInstance, ); diff --git a/packages/client-scheduler/src/SchedulerClientInstance.ts b/packages/client-scheduler/src/SchedulerClientInstance.ts index addefce..dc54f00 100644 --- a/packages/client-scheduler/src/SchedulerClientInstance.ts +++ b/packages/client-scheduler/src/SchedulerClientInstance.ts @@ -22,16 +22,20 @@ export class SchedulerClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeSchedulerClientInstance = Effect.map( +export const makeSchedulerClientInstance = Effect.flatMap( SchedulerClientInstanceConfig, - (config) => new SchedulerClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new SchedulerClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const SchedulerClientInstanceLayer = Layer.effect( +export const SchedulerClientInstanceLayer = Layer.scoped( SchedulerClientInstance, makeSchedulerClientInstance, ); diff --git a/packages/client-secrets-manager/src/SecretsManagerClientInstance.ts b/packages/client-secrets-manager/src/SecretsManagerClientInstance.ts index e8df558..72f26d8 100644 --- a/packages/client-secrets-manager/src/SecretsManagerClientInstance.ts +++ b/packages/client-secrets-manager/src/SecretsManagerClientInstance.ts @@ -22,16 +22,20 @@ export class SecretsManagerClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeSecretsManagerClientInstance = Effect.map( +export const makeSecretsManagerClientInstance = Effect.flatMap( SecretsManagerClientInstanceConfig, - (config) => new SecretsManagerClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new SecretsManagerClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const SecretsManagerClientInstanceLayer = Layer.effect( +export const SecretsManagerClientInstanceLayer = Layer.scoped( SecretsManagerClientInstance, makeSecretsManagerClientInstance, ); diff --git a/packages/client-sfn/src/SFNClientInstance.ts b/packages/client-sfn/src/SFNClientInstance.ts index eaa7531..35f1a12 100644 --- a/packages/client-sfn/src/SFNClientInstance.ts +++ b/packages/client-sfn/src/SFNClientInstance.ts @@ -22,16 +22,20 @@ export class SFNClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeSFNClientInstance = Effect.map( +export const makeSFNClientInstance = Effect.flatMap( SFNClientInstanceConfig, - (config) => new SFNClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new SFNClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const SFNClientInstanceLayer = Layer.effect( +export const SFNClientInstanceLayer = Layer.scoped( SFNClientInstance, makeSFNClientInstance, ); diff --git a/packages/client-sns/src/SNSClientInstance.ts b/packages/client-sns/src/SNSClientInstance.ts index ac6441f..b2de7ea 100644 --- a/packages/client-sns/src/SNSClientInstance.ts +++ b/packages/client-sns/src/SNSClientInstance.ts @@ -22,16 +22,20 @@ export class SNSClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeSNSClientInstance = Effect.map( +export const makeSNSClientInstance = Effect.flatMap( SNSClientInstanceConfig, - (config) => new SNSClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new SNSClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const SNSClientInstanceLayer = Layer.effect( +export const SNSClientInstanceLayer = Layer.scoped( SNSClientInstance, makeSNSClientInstance, ); diff --git a/packages/client-sqs/src/SQSClientInstance.ts b/packages/client-sqs/src/SQSClientInstance.ts index 0be5904..a0e1f4f 100644 --- a/packages/client-sqs/src/SQSClientInstance.ts +++ b/packages/client-sqs/src/SQSClientInstance.ts @@ -22,16 +22,20 @@ export class SQSClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeSQSClientInstance = Effect.map( +export const makeSQSClientInstance = Effect.flatMap( SQSClientInstanceConfig, - (config) => new SQSClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new SQSClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const SQSClientInstanceLayer = Layer.effect( +export const SQSClientInstanceLayer = Layer.scoped( SQSClientInstance, makeSQSClientInstance, ); diff --git a/packages/client-ssm/src/SSMClientInstance.ts b/packages/client-ssm/src/SSMClientInstance.ts index ab14acd..8de1e7b 100644 --- a/packages/client-ssm/src/SSMClientInstance.ts +++ b/packages/client-ssm/src/SSMClientInstance.ts @@ -22,16 +22,20 @@ export class SSMClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeSSMClientInstance = Effect.map( +export const makeSSMClientInstance = Effect.flatMap( SSMClientInstanceConfig, - (config) => new SSMClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new SSMClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const SSMClientInstanceLayer = Layer.effect( +export const SSMClientInstanceLayer = Layer.scoped( SSMClientInstance, makeSSMClientInstance, ); diff --git a/packages/client-sts/src/STSClientInstance.ts b/packages/client-sts/src/STSClientInstance.ts index fe0fb41..a9fcca1 100644 --- a/packages/client-sts/src/STSClientInstance.ts +++ b/packages/client-sts/src/STSClientInstance.ts @@ -22,16 +22,20 @@ export class STSClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeSTSClientInstance = Effect.map( +export const makeSTSClientInstance = Effect.flatMap( STSClientInstanceConfig, - (config) => new STSClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new STSClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const STSClientInstanceLayer = Layer.effect( +export const STSClientInstanceLayer = Layer.scoped( STSClientInstance, makeSTSClientInstance, ); diff --git a/packages/client-textract/src/TextractClientInstance.ts b/packages/client-textract/src/TextractClientInstance.ts index fd3ceb4..b3b04e7 100644 --- a/packages/client-textract/src/TextractClientInstance.ts +++ b/packages/client-textract/src/TextractClientInstance.ts @@ -22,16 +22,20 @@ export class TextractClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const makeTextractClientInstance = Effect.map( +export const makeTextractClientInstance = Effect.flatMap( TextractClientInstanceConfig, - (config) => new TextractClient(config), + (config) => + Effect.acquireRelease( + Effect.sync(() => new TextractClient(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const TextractClientInstanceLayer = Layer.effect( +export const TextractClientInstanceLayer = Layer.scoped( TextractClientInstance, makeTextractClientInstance, ); diff --git a/packages/lib-dynamodb/src/DynamoDBDocumentClientInstance.ts b/packages/lib-dynamodb/src/DynamoDBDocumentClientInstance.ts index b75e27f..ae6c533 100644 --- a/packages/lib-dynamodb/src/DynamoDBDocumentClientInstance.ts +++ b/packages/lib-dynamodb/src/DynamoDBDocumentClientInstance.ts @@ -35,7 +35,7 @@ export const makeDynamoDBDocumentClientInstance = Effect.all([ * @since 1.0.0 * @category layers */ -export const DynamoDBDocumentClientInstanceLayer = Layer.effect( +export const DynamoDBDocumentClientInstanceLayer = Layer.scoped( DynamoDBDocumentClientInstance, makeDynamoDBDocumentClientInstance, ).pipe(Layer.provide(DefaultDynamoDBClientInstanceLayer)); diff --git a/scripts/codegen-client.ts b/scripts/codegen-client.ts index 6805de6..5d94630 100644 --- a/scripts/codegen-client.ts +++ b/scripts/codegen-client.ts @@ -257,16 +257,20 @@ export class ${sdkName}ClientInstance extends Context.Tag( * @since 1.0.0 * @category constructors */ -export const make${sdkName}ClientInstance = Effect.map( - ${sdkName}ClientInstanceConfig, - (config) => new ${sdkName}Client(config), +export const make${sdkName}ClientInstance = Effect.flatMap( + ${sdkName}ClientInstanceConfig, + (config) => + Effect.acquireRelease( + Effect.sync(() => new ${sdkName}Client(config)), + (client) => Effect.sync(() => client.destroy()), + ), ); /** * @since 1.0.0 * @category layers */ -export const ${sdkName}ClientInstanceLayer = Layer.effect( +export const ${sdkName}ClientInstanceLayer = Layer.scoped( ${sdkName}ClientInstance, make${sdkName}ClientInstance, );