Skip to content
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

feat(adapter-dynamodb): extend schema options #11463

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DylanLacey
Copy link

This change allows for more flexibility when customising the schema used by the DynamoDB adapter. Specifically, it adds the ability to customize:

  • EntityTagName: The attribute name under which to store the type of the entity.
  • EntityTags: The value to use for each Entity type for the above attribute.
  • EntitySlugs: The slug which is prepended to each type's partition/sort key.

index.test.ts and format.test.ts were updated to reflect changes required to the format.from function.

custom_config.test.ts was added, which runs a full suite of the basic tests against both the existing customizations and those included in this PR.

💻 Example

EntityTags and EntitySlug are both of type DynamoDBEntityTypeOptions and can take an (optional, string) value for each type of entity the adapter stores:

const entityTags: DynamoDBEntityTypeOptions = {
    user: "AUTHUSER",
    account: "ACT",
    session: "SES",
    vt: "VT"
}

EntitySlug does not format the provided slugs in any way; If users wish to include a separator such as #, they need to include it.

☕️ Reasoning

Firstly, to increase the ability to integrate Auth.js with other systems. For instance , DynamoDBToolbox uses an attribute _et by default to type records.

Secondly, to give users more control in general. They may wish to disambiguate AuthJS User items from some extant User entity, or shorten ACCOUNT to ACNT.

Documentation was not added, as the documentation on the

🧢 Checklist

  • Documentation
  • Tests
  • Ready to be merged

This change allows for more flexibility when customising the schema used
by the DynamoDB adapter. Specifically, it adds the ability to customize:
* **EntityTagName**: The attribute name under which to store the *type* of the entity.
* **EntityTags**: The value to use for each Entity type for the above attribute.
* **EntitySlugs**: The slug which is prepended to each type's partition/sort key.

`EntityTags` and `EntitySlug` are both of type `DynamoDBEntityTypeOptions` and
can take an (optional, string) value for each type of entity the adapter stores:

```
const entityTags: DynamoDBEntityTypeOptions = {
    user: "AUTHUSER",
    account: "ACT",
    session: "SES",
    vt: "VT"
}
```

`EntitySlug` does not format the provided slugs in any way; If users wish
to include a separator such as `#`, they need to include it.

`index.test.ts` and `format.test.ts` were updated to reflect changes required
to the `format.from` function.

`custom_config.test.ts` was added, which runs a full suite of the basic
tests against both the existing customizations _and_ those included in
this PR.
Copy link

vercel bot commented Jul 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 26, 2024 2:28pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Jul 26, 2024 2:28pm

Copy link

vercel bot commented Jul 26, 2024

@DylanLacey is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added adapters Changes related to the core code concerning database adapters dynamodb @auth/dynamodb-adapter labels Jul 26, 2024
@ndom91 ndom91 changed the title <feat>[adapter-dynamodb]: Extend Schema Options feat(adapter-dynamodb): extend schema options Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters Changes related to the core code concerning database adapters dynamodb @auth/dynamodb-adapter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant