Skip to content

Commit

Permalink
feat: simplify layers (#80)
Browse files Browse the repository at this point in the history
* feat: prepare new layers

* feat: simplify s3 service layers

* feat: update codegen

* chore: update codegen and generate all clients

* fix: bug in iam service
  • Loading branch information
floydspace authored Nov 10, 2024
1 parent d7976b1 commit 4b16fbe
Show file tree
Hide file tree
Showing 99 changed files with 5,777 additions and 4,921 deletions.
35 changes: 35 additions & 0 deletions .changeset/polite-avocados-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
"@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-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/client-ec2": 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
---

simplify layers configuration (closes #78)
53 changes: 13 additions & 40 deletions packages/client-account/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,72 +14,45 @@ npm install --save @effect-aws/client-account
With default AccountClient instance:

```typescript
import { AccountService, DefaultAccountServiceLayer } from "@effect-aws/client-account";
import { Account } from "@effect-aws/client-account";

const program = AccountService.listRegions(args);
const program = Account.listRegions(args);

const result = pipe(
program,
Effect.provide(DefaultAccountServiceLayer),
Effect.provide(Account.defaultLayer),
Effect.runPromise,
);
```

With custom AccountClient instance:

```typescript
import {
AccountService,
BaseAccountServiceLayer,
AccountClientInstance,
} from "@effect-aws/client-account";
import { Account } from "@effect-aws/client-account";

const program = AccountService.listRegions(args);

const AccountClientInstanceLayer = Layer.succeed(
AccountClientInstance,
new AccountClient({ region: "eu-central-1" }),
);
const program = Account.listRegions(args);

const result = await pipe(
program,
Effect.provide(BaseAccountServiceLayer),
Effect.provide(AccountClientInstanceLayer),
Effect.provide(
Account.baseLayer(() => new AccountClient({ region: "eu-central-1" })),
),
Effect.runPromise,
);
```

With custom AccountClient configuration:

```typescript
import {
AccountService,
BaseAccountServiceLayer,
DefaultAccountClientConfigLayer,
AccountClientInstance,
AccountClientInstanceConfig,
} from "@effect-aws/client-account";

const program = AccountService.listRegions(args);

const AccountClientInstanceLayer = Layer.provide(
Layer.effect(
AccountClientInstance,
AccountClientInstanceConfig.pipe(
Effect.map(
(config) => new AccountClient({ ...config, region: "eu-central-1" }),
),
),
),
DefaultAccountClientConfigLayer,
);
import { Account } from "@effect-aws/client-account";

const program = Account.listRegions(args);

const result = await pipe(
program,
Effect.provide(BaseAccountServiceLayer),
Effect.provide(AccountClientInstanceLayer),
Effect.provide(Account.layer({ region: "eu-central-1" })),
Effect.runPromiseExit,
);
```

or map over `DefaultAccountClientConfigLayer` layer context and update the configuration...
or use `Account.baseLayer((default) => new AccountClient({ ...default, region: "eu-central-1" }))`
68 changes: 55 additions & 13 deletions packages/client-account/src/AccountService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
import {
AccountServiceException,
type AccountClient,
type AccountClientConfig,
AcceptPrimaryEmailUpdateCommand,
type AcceptPrimaryEmailUpdateCommandInput,
type AcceptPrimaryEmailUpdateCommandOutput,
Expand Down Expand Up @@ -45,7 +47,11 @@ import {
AccountClientInstance,
AccountClientInstanceLayer,
} from "./AccountClientInstance";
import { DefaultAccountClientConfigLayer } from "./AccountClientInstanceConfig";
import {
DefaultAccountClientConfigLayer,
makeDefaultAccountClientInstanceConfig,
AccountClientInstanceConfig,
} from "./AccountClientInstanceConfig";
import {
AllServiceErrors,
AccessDeniedError,
Expand All @@ -59,7 +65,7 @@ import {
} from "./Errors";

/**
* @since 1.0.1
* @since 1.0.0
*/
export interface HttpHandlerOptions {
/**
Expand Down Expand Up @@ -278,14 +284,6 @@ interface AccountService$ {
>;
}

/**
* @since 1.0.0
* @category models
*/
export class AccountService extends Effect.Tag(
"@effect-aws/client-account/AccountService",
)<AccountService, AccountService$>() {}

/**
* @since 1.0.0
* @category constructors
Expand Down Expand Up @@ -336,9 +334,53 @@ export const makeAccountService = Effect.gen(function* (_) {
}, {}) as AccountService$;
});

/**
* @since 1.0.0
* @category models
*/
export class AccountService extends Effect.Tag(
"@effect-aws/client-account/AccountService",
)<AccountService, AccountService$>() {
static readonly defaultLayer = Layer.effect(this, makeAccountService).pipe(
Layer.provide(AccountClientInstanceLayer),
Layer.provide(DefaultAccountClientConfigLayer),
);
static readonly layer = (config: AccountClientConfig) =>
Layer.effect(this, makeAccountService).pipe(
Layer.provide(AccountClientInstanceLayer),
Layer.provide(
Layer.effect(
AccountClientInstanceConfig,
makeDefaultAccountClientInstanceConfig.pipe(
Effect.map((defaultConfig) => ({ ...defaultConfig, ...config })),
),
),
),
);
static readonly baseLayer = (
evaluate: (defaultConfig: AccountClientConfig) => AccountClient,
) =>
Layer.effect(this, makeAccountService).pipe(
Layer.provide(
Layer.effect(
AccountClientInstance,
Effect.map(makeDefaultAccountClientInstanceConfig, evaluate),
),
),
);
}

/**
* @since 1.0.0
* @category models
* @alias AccountService
*/
export const Account = AccountService;

/**
* @since 1.0.0
* @category layers
* @deprecated use Account.baseLayer instead
*/
export const BaseAccountServiceLayer = Layer.effect(
AccountService,
Expand All @@ -348,6 +390,7 @@ export const BaseAccountServiceLayer = Layer.effect(
/**
* @since 1.0.0
* @category layers
* @deprecated use Account.layer instead
*/
export const AccountServiceLayer = BaseAccountServiceLayer.pipe(
Layer.provide(AccountClientInstanceLayer),
Expand All @@ -356,7 +399,6 @@ export const AccountServiceLayer = BaseAccountServiceLayer.pipe(
/**
* @since 1.0.0
* @category layers
* @deprecated use Account.defaultLayer instead
*/
export const DefaultAccountServiceLayer = AccountServiceLayer.pipe(
Layer.provide(DefaultAccountClientConfigLayer),
);
export const DefaultAccountServiceLayer = AccountService.defaultLayer;
Loading

0 comments on commit 4b16fbe

Please sign in to comment.