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: Support for nested values in SpecialKey #96

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

Conversation

Hyuga-Tsukui
Copy link

@Hyuga-Tsukui Hyuga-Tsukui commented Apr 17, 2024

Description:

This pull request introduces the capability to use SpecialKey for specifying values in nested structures within sessions, enhancing the flexibility of our session management. The primary motivation for this change is to support complex querying scenarios, such as cross-querying session data by user IDs, which are stored in nested objects within session structures.

Key Changes:

  1. Nested Structure Support: Previously, accessing nested attributes like userId within a user object in the session data was not possible with SpecialKey. This update enables this functionality, allowing SpecialKey to target nested attributes.

  2. Compatibility and Testing:

    • The changes maintain backward compatibility and do not alter existing functionalities.
    • New tests have been added to ensure that SpecialKey can now handle nested attributes without breaking existing functionalities.

Use Case:
Consider a session structured as follows:

{
  "sess": {
    "cookie": "...",
    "user": {
      "id": "uid-00001",
      "name": "..."
    }
  }
}

set special keys.

  const store = new DynamoDBStore({
    client: client,
    table: tableName,
    specialKeys: [
      {
        name: "user.id",
        type: "S",
      },
    ],
  });

dynamodb-client query output

Item: {
    id: { S: 'sess:0.45441392681127013' },
    userId: { S: 'uid-00001' }, // convert key path to camel case.
    expires: { N: '1713351239' },
    type: { S: 'connect-session' },
    sess: {
      S: '{"cookie":{"maxAge":2000},"name":"0.46261875390220175","user":{"id":"uid-00001'"}}'
    },
  }

With the current system, it is impossible to set userId as a SpecialKey for purposes like querying in DynamoDB's Global Secondary Indexes (GSI) for cross-session user data retrieval. This update addresses such limitations by allowing userId to be specified as a SpecialKey.

Impact:
This enhancement will significantly improve our ability to perform more complex queries on session data, facilitating better data management and retrieval based on user-specific or other nested session attributes.

@tfrancois
Copy link

tfrancois commented Nov 13, 2024

This pull request actually adds this important feature and also corrects an important bug in how it calculates session expiration (line 348-349).

I respectfully urge @ca98am79 to please merge this into master build and release an update to this IMPORTANT library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants