Skip to content

Commit

Permalink
feat: also simplify lib-dynamodb
Browse files Browse the repository at this point in the history
  • Loading branch information
floydspace committed Nov 10, 2024
1 parent d6ba4d3 commit cc97eae
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 99 deletions.
7 changes: 7 additions & 0 deletions .changeset/big-moons-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@effect-aws/lib-dynamodb": minor
"@effect-aws/secrets-manager": patch
"@effect-aws/ssm": patch
---

simplify layers configuration (closes #78)
23 changes: 20 additions & 3 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ const dynamodbLib = new TypeScriptLibProject({
"@aws-sdk/client-dynamodb@^3",
"@aws-sdk/lib-dynamodb@^3",
],
devDeps: commonDevDeps,
devDeps: [
...commonDevDeps,
"@effect-aws/client-dynamodb@workspace:^",
"[email protected]",
],
peerDeps: [...commonPeerDeps, dynamodbClient.package.packageName],
peerDependencyOptions: { pinnedDevDependency: false },
});

new TypeScriptLibProject({
Expand Down Expand Up @@ -313,15 +318,27 @@ new TypeScriptLibProject({
const secretsManager = new TypeScriptLibProject({
parent: project,
name: "secrets-manager",
devDeps: ["@aws-sdk/client-secrets-manager@^3", "@fluffy-spoon/substitute"],
devDeps: [
"@aws-sdk/client-secrets-manager@^3",
"@effect-aws/client-secrets-manager@workspace:^",
"@fluffy-spoon/substitute",
"[email protected]",
],
peerDeps: [...commonPeerDeps, secretsManagerClient.package.packageName],
peerDependencyOptions: { pinnedDevDependency: false },
});

const ssm = new TypeScriptLibProject({
parent: project,
name: "ssm",
devDeps: ["@aws-sdk/client-ssm@^3", "@fluffy-spoon/substitute"],
devDeps: [
"@aws-sdk/client-ssm@^3",
"@effect-aws/client-ssm@workspace:^",
"@fluffy-spoon/substitute",
"[email protected]",
],
peerDeps: [...commonPeerDeps, ssmClient.package.packageName],
peerDependencyOptions: { pinnedDevDependency: false },
});

new TypeScriptLibProject({
Expand Down
10 changes: 10 additions & 0 deletions packages/lib-dynamodb/.projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/lib-dynamodb/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 62 additions & 13 deletions packages/lib-dynamodb/src/DynamoDBDocumentService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/**
* @since 1.0.0
*/
import { DynamoDBServiceException } from "@aws-sdk/client-dynamodb";
import {
DynamoDBClientConfig,
DynamoDBServiceException,
} from "@aws-sdk/client-dynamodb";
import {
BatchExecuteStatementCommand,
BatchExecuteStatementCommandInput,
Expand All @@ -15,6 +18,7 @@ import {
DeleteCommand,
DeleteCommandInput,
DeleteCommandOutput,
DynamoDBDocumentClient,
ExecuteStatementCommand,
ExecuteStatementCommandInput,
ExecuteStatementCommandOutput,
Expand All @@ -39,6 +43,7 @@ import {
TransactWriteCommand,
TransactWriteCommandInput,
TransactWriteCommandOutput,
TranslateConfig,
UpdateCommand,
UpdateCommandInput,
UpdateCommandOutput,
Expand All @@ -50,6 +55,7 @@ import {
InternalServerError,
InvalidEndpointError,
ItemCollectionSizeLimitExceededError,
makeDefaultDynamoDBClientInstanceConfig,
ProvisionedThroughputExceededError,
RequestLimitExceededError,
ResourceNotFoundError,
Expand All @@ -64,7 +70,11 @@ import {
DynamoDBDocumentClientInstance,
DynamoDBDocumentClientInstanceLayer,
} from "./DynamoDBDocumentClientInstance";
import { DefaultDynamoDBDocumentClientConfigLayer } from "./DynamoDBDocumentClientInstanceConfig";
import {
DefaultDynamoDBDocumentClientConfigLayer,
DynamoDBDocumentClientInstanceConfig,
makeDefaultDynamoDBDocumentClientInstanceConfig,
} from "./DynamoDBDocumentClientInstanceConfig";

/**
* @since 1.3.1
Expand Down Expand Up @@ -319,14 +329,6 @@ interface DynamoDBDocumentService$ {
>;
}

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

/**
* @since 1.0.0
* @category constructors
Expand Down Expand Up @@ -374,9 +376,56 @@ export const makeDynamoDBDocumentService = Effect.gen(function* (_) {
}, {}) as DynamoDBDocumentService$;
});

/**
* @since 1.0.0
* @category models
*/
export class DynamoDBDocumentService extends Effect.Tag(
"@effect-aws/lib-dynamodb/DynamoDBDocumentService",
)<DynamoDBDocumentService, DynamoDBDocumentService$>() {
static readonly defaultLayer = Layer.effect(
this,
makeDynamoDBDocumentService,
).pipe(
Layer.provide(DynamoDBDocumentClientInstanceLayer),
Layer.provide(DefaultDynamoDBDocumentClientConfigLayer),
);
static readonly layer = (config: TranslateConfig) =>
Layer.effect(this, makeDynamoDBDocumentService).pipe(
Layer.provide(DynamoDBDocumentClientInstanceLayer),
Layer.provide(
Layer.effect(
DynamoDBDocumentClientInstanceConfig,
makeDefaultDynamoDBDocumentClientInstanceConfig.pipe(
Effect.map((defaultConfig) => ({ ...defaultConfig, ...config })),
),
),
),
);
static readonly baseLayer = (
evaluate: (defaultConfig: DynamoDBClientConfig) => DynamoDBDocumentClient,
) =>
Layer.effect(this, makeDynamoDBDocumentService).pipe(
Layer.provide(
Layer.effect(
DynamoDBDocumentClientInstance,
Effect.map(makeDefaultDynamoDBClientInstanceConfig, evaluate),
),
),
);
}

/**
* @since 1.0.0
* @category models
* @alias DynamoDBDocumentService
*/
export const DynamoDBDocument = DynamoDBDocumentService;

/**
* @since 1.0.0
* @category layers
* @deprecated use DynamoDBDocument.baseLayer instead
*/
export const BaseDynamoDBDocumentServiceLayer = Layer.effect(
DynamoDBDocumentService,
Expand All @@ -386,6 +435,7 @@ export const BaseDynamoDBDocumentServiceLayer = Layer.effect(
/**
* @since 1.0.0
* @category layers
* @deprecated use DynamoDBDocument.layer instead
*/
export const DynamoDBDocumentServiceLayer =
BaseDynamoDBDocumentServiceLayer.pipe(
Expand All @@ -395,8 +445,7 @@ export const DynamoDBDocumentServiceLayer =
/**
* @since 1.0.0
* @category layers
* @deprecated use DynamoDBDocument.defaultLayer instead
*/
export const DefaultDynamoDBDocumentServiceLayer =
DynamoDBDocumentServiceLayer.pipe(
Layer.provide(DefaultDynamoDBDocumentClientConfigLayer),
);
DynamoDBDocumentService.defaultLayer;
Loading

0 comments on commit cc97eae

Please sign in to comment.