Skip to content

feat(idempotency): add package exports #1483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 2, 2023
Merged

Conversation

dreamorosi
Copy link
Contributor

@dreamorosi dreamorosi commented Jun 2, 2023

Description of your changes

This PR sets the exports for the upcoming Idempotency module so that customers can import its modules easily while using the utility.

The exports the following structure:

import { makeFunctionIdempotent } from "@aws-lambda-powertools/idempotency";
import { IdempotencyRecord } from "@aws-lambda-powertools/idempotency/persistence";
import { DynamoDBPersistenceLayer } from "@aws-lambda-powertools/idempotency/dynamodb";

This structure allows to:

  • have all the main modules (i.e. makeFunctionIdempotent, idempotencyConfig, etc.) at the top level
  • have general persistence-related modules under /persistence
  • and have a scoped import for the DynamoDBPersistenceLayer, which in the future will allow customers to tree-shake and avoid a dependency on @aws-sdk/lib-dynamodb if they decide to use a different persistence layer

In upcoming PRs, we'll also add an export for types (i.e. @aws-lambda-powertools/idempotency/types) and one for the Middy middleware (@aws-lambda-powertools/idempotency/middleware).

Implementation Details

These exports were possible thanks to the addition of a few new fields in the package.json of the utility, which allow us to specify the exports and control the paths in a way similar to aliases:

{
  "name": "@aws-lambda-powertools/idempotency",
  "exports": {
    ".": {
      "import": "./lib/index.js",
      "require": "./lib/index.js"
    },
    "./persistence": {
      "import": "./lib/persistence/index.js",
      "require": "./lib/persistence/index.js"
    },
    "./dynamodb": {
      "import": "./lib/persistence/DynamoDbPersistenceLayer.js",
      "require": "./lib/persistence/DynamoDbPersistenceLayer.js"
    }
  },
  "typesVersions": {
    "*": {
      "persistence": [
        "lib/persistence/index.d.ts"
      ],
      "dynamodb": [
        "lib/persistence/DynamoDbPersistenceLayer.d.ts"
      ]
    }
  },
  "main": "./lib/index.js",
  "types": "./lib/index.d.ts"
}

The benefits of this structure are several:

  • we can have more freedom to reorganize the folder/project structure without causing breaking changes in the output
  • we have more control over what's exposed and what isn't
  • we can specify different destinations for different types of imports (i.e. import vs require)
  • we can flatten and/or shorten the imports (i.e. @aws-lambda-powertools/idempotency/dynamodb vs @aws-lambda-powertools/idempotency/lib/persistence/DynamoDBPersistenceLayer)

This structure/pattern was heavily influenced by the work done by @shdq (thanks!) here and will be rolled out to all other modules in due process.

Related issues, RFCs

Issue number: #1479

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my change is effective and works
  • The PR title follows the conventional commit semantics

Breaking change checklist

Is it a breaking change?: NO

  • I have documented the migration process
  • I have added, implemented necessary warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@dreamorosi dreamorosi self-assigned this Jun 2, 2023
@boring-cyborg boring-cyborg bot added idempotency This item relates to the Idempotency Utility dependencies Changes that touch dependencies, e.g. Dependabot, etc. tests PRs that add or change tests labels Jun 2, 2023
@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Jun 2, 2023
@github-actions github-actions bot added the feature PRs that introduce new features or minor changes label Jun 2, 2023
@dreamorosi dreamorosi changed the title feat(idempotency): feat(idempotency): add package exports Jun 2, 2023
@dreamorosi dreamorosi linked an issue Jun 2, 2023 that may be closed by this pull request
@dreamorosi dreamorosi marked this pull request as ready for review June 2, 2023 20:15
@dreamorosi dreamorosi merged commit faa9307 into main Jun 2, 2023
@dreamorosi dreamorosi deleted the dreamorosi/issue1479 branch June 2, 2023 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Changes that touch dependencies, e.g. Dependabot, etc. feature PRs that introduce new features or minor changes idempotency This item relates to the Idempotency Utility size/L PRs between 100-499 LOC tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Idempotency Package has No Exports
1 participant