Skip to content

Composite index projection types too narrow for keys_only and array projections #558

@anatolzak

Description

@anatolzak

Describe the bug

When a composite index (type: "composite") uses projection: "keys_only" or an array projection, the TypeScript response types don't account for the fact that composite key attributes are stored as native DynamoDB columns and are always physically present in query responses.

Current behavior

  • keys_only + composite index: response type is {} (empty object)
  • Array projection (e.g. ["name"]) + composite index: response type only includes name, missing the pk/sk composite attributes
  • attributes parameter rejects composite key attributes under restricted projections
  • Collection queries have the same issues

ElectroDB Version
Specify the version of ElectroDB you are using
3.7.1

ElectroDB Playground Link
https://electrodb.fun/?#code/PQKgBAsg9gJgpgGzARwK5wE4Es4GcA0YuccYGeqCALgUQBYCG5YA7llXWAGbZwB2MXGBDAAUKKwBbAA5QMVMAG8wAUT5V2AT0IBlTADcsAY1IBfbhiiSwAIkRwjVSzABGNgNzijUPrgVUGFwRSAF5bTShUDAB9AKC4aL4GSTgPcVAwABUGXABrITUNKk1hMW9fBX4ikrC+OBZVdS0AClEwJTb2sElYRAAuDq6uqq0BmwC83Bt8TqH9TFwsHzGARmnZruIMQxMxidyGaWkbDdMZoYYqJywXVCo8AcUN9qwYR7Bi6TgBgHI-bD4AHMfmAzs8wHREAgoO9Pt8wH9rkCQWChu0WHIEG8lB9NF9fv8sMjQadzl0ifAAB4PQZo6TYSRMTSPcHtaS5FlotFcHBYsbs9ZcobeGRQRb3AYAbRsrxsAF1WaCyUNUWjcnBNLgAPJ8BDM2lcilwSljQGLFbsgC0ZqwKzylqNlMFQvpUAAVg4NMsEerNdEfHqfsq0XDfiLZOK4EHFezOUL2uGxex4dLIQhofLFaquXk4-HE5GpT9Xj8FfHTOIudnyXwjAhUPA82jHabzVabXbcg6BMbnVzXR7HEs+EWMRgsaXg0NQwiC8no-HYwahXOJWBU1CoJny1OladOqrlHFgiSAJSeUTlPw4mCXBigsBhBgsBjsMAjYoAOjQmE0n992q6pozTKGm0K-GOE6gqen6AlAzSnqIwDAPGAB6SimJKCrIe+lJfI4cAwDirwDISQKEGBMJEEigIkkhKG4HQkRYmALikIEJ5UFAYCAnACgAAaUfxYBEmQeCyL4cCiM+r6VE0X4-hgf4ATqeogRCm4QZiMAojBcEgZ0lzXLc9y4EWlGlqIpiIZePjXsot4BAMjkMAATA+T4vm+H5-opf5EnWDZwOplFaeOOnQbB8GIThQrocokEwAA-KRNHuKCWH0bh+H3ERoGadRAKAoQiUpYVRK0RWWWMcxRFsWAHGkFxPF8WAgmbsJonkLgEnENJXlydU37oEpn4BfW8AhQVPyJbpUUGe0RnYCZNKSj8FkKtZQA

Entity/Service Definitions
Include your entity model (or a model that sufficiently recreates your issue) to help troubleshoot.

{
  model: {
    entity: "tasks",
    version: "1",
    service: "taskapp"
  },
  attributes: {
    id: { type: 'string' },
    hello: { type: 'string' },
    world: { type: 'string' }
  },
  indexes: {
    primary: {
      pk: {
        field: "pk",
        composite: ["id"]
      },
    },
    keysOnly: {
      index: "gsi1pk-gsi1sk-index",
      projection: 'keys_only',
      type: 'composite',
      pk: {
        composite: ["hello"]
      },
      sk: {
        composite: ['id']
      }

    },
    include: {
      index: "gsi1pk-gsi1sk-index",
      projection: ['world'],
      type: 'composite',
      pk: {
        composite: ["hello"]
      },
    },
  }
}

Expected behavior

  • keys_only + composite index: response type should include all pk and sk composite attributes (e.g. { tenantId: string; age: number })
  • Array projection + composite index: response type should include the listed attributes plus all pk and sk composite attributes
  • attributes parameter should accept composite key attributes
  • Collection response types should reflect composite key availability per entity

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions