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

@TransformToDynamo and @TransformFromDynamo not being called #365

Open
pawelzebrowski opened this issue Sep 29, 2023 · 2 comments
Open

@TransformToDynamo and @TransformFromDynamo not being called #365

pawelzebrowski opened this issue Sep 29, 2023 · 2 comments

Comments

@pawelzebrowski
Copy link

I can't seem to get @TransformToDynamo and @TransformFromDynamo to fire. I've followed all variations and examples I could find.

Minimal reproduction

@Entity({
  name: "test",
  primaryKey: {
    partitionKey: "test_{{testId}}",
    sortKey: "test_{{testId}}",
  },
})
export class Test {
  constructor(created: Date) {
    this.created = created;
  }

  @AutoGenerateAttribute({
    strategy: AUTO_GENERATE_ATTRIBUTE_STRATEGY.UUID4,
  })
  testId: string;

  @Attribute()
  @Type(() => Date)
  @TransformToDynamo(({ value }: { value: Date }) => Test.toDynamo(value))
  @TransformFromDynamo(({ value }: { value: string }) => Test.fromDynamo(value))
  created: Date;

  static toDynamo(value: Date): string {
    console.log("toDynamo", value);
    return value.toISOString();
  }

  static fromDynamo(value: string): Date {
    console.log("fromDynamo", value);
    return new Date(value);
  }
}

Called with

const test = new Test(new Date());
const entityManager = getEntityManager();
await entityManager.create(test);

Results in

Unsupported type passed: Fri Sep 29 2023 09:14:38 GMT-0700 (Pacific Daylight Saving Time). Pass options.convertClassInstanceToMap=true to marshall typeof object as map attribute.

and neither console statement being emitted. As far as I can tell, neither of the two transformers is firing.

Any hints to point me in the right direction?

node 18.16.0
aws-sdk 3
typescript 5.2.2
typedorm 1.15.4
class-transformer 0.5.1

@pawelzebrowski
Copy link
Author

After some digging, I discovered that it seems to have to do with typescript "target". Anything less than es2022 doesn't appear to call the functions, but as soon as target is es2022/esnext, it works.

Unfortunately, setting things to es2022/esnext comes with it's own set of problems, for example #236.

The same appears to be the case with the examples in https://github.com/typedorm/typedorm-examples.

Is there a typescript configuration where this library works as expected?

@mareksnincak
Copy link

Hello, I'm facing the same issue. I think the same issue was already mentioned in the past as well in #229. Solution may be to define relaxed peerDependencies as suggested here: #341. Do you think this would be possible @whimzyLive or is there some blocker for this approach?

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

No branches or pull requests

2 participants