sam-goodwin / typesafe-dynamodb

TypeSafe type definitions for the AWS DynamoDB API
Apache License 2.0
207 stars 11 forks source link

fix: upgrade to latest AWS SDK #51

Closed sam-goodwin closed 1 year ago

sam-goodwin commented 1 year ago

Still doesn't compile ... types need work.

I am considering:

  1. dropping aws-sdk support
  2. dropping attribute values (document client only) since it would be faster and easier to support

Errors:

 FAIL  test/v3-document.test.ts
  ● Test suite failed to run

    test/v3-document.test.ts:53:13 - error TS2339: Property 'key' does not exist on type 'never'.

    53   get.Item?.key;
                   ~~~

 FAIL  test/v3.test.ts
  ● Test suite failed to run

    test/v3.test.ts:43:13 - error TS2339: Property 'key' does not exist on type 'never'.

    43   get.Item?.key;
                   ~~~
    test/v3.test.ts:162:28 - error TS2339: Property 'key' does not exist on type 'never'.

    162   returnAllNew.Attributes?.key?.S;
                                   ~~~
    test/v3.test.ts:179:28 - error TS2339: Property 'key' does not exist on type 'never'.

    179   returnAllOld.Attributes?.key?.S;
                                   ~~~
    test/v3.test.ts:196:32 - error TS2339: Property 'key' does not exist on type 'never'.

    196   returnUpdatedNew.Attributes?.key?.S;
                                       ~~~
    test/v3.test.ts:213:32 - error TS2339: Property 'key' does not exist on type 'never'.

    213   returnUpdatedOld.Attributes?.key?.S;
sam-goodwin commented 1 year ago
image
sam-goodwin commented 1 year ago

Ah-ha! breakthrough, the projectionExpression was not being const:

export type GetCommand<
  Item extends object,
  PartitionKey extends keyof Item,
  RangeKey extends keyof Item | undefined,
  Format extends JsonFormat
> = new <
  Key extends TableKey<Item, PartitionKey, RangeKey, Format>,
  AttributesToGet extends keyof Item | undefined,
  const ProjectionExpression extends string | undefined
>(

Specifically adding const to the type:

  const ProjectionExpression extends string | undefined
sam-goodwin commented 1 year ago

Have got it working for v3 Document type but it breaks for AttributeValue. Which is fine because I'm considering dropping support for both that and all of AWS SDK v2

sam-goodwin commented 1 year ago

Merging this so we at least have a working version for V3 AWS SDK.

TBH, I'm pretty tempted to re-write this package. It's way too complicated.

sam-goodwin commented 1 year ago

@sizuhiko this change is available at 0.2.4. I think that as long as you use the TypeSafeDocument clients it will work.

This library needs a lot of love though. Types need to be completely re-written (simplified down) and it may be useful to add an actual client that is safe.

Perhaps integrate with my https://github.com/sam-goodwin/itty-aws. Type safe + "zero" bundle impact would be awesome