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

[v1] anyOf + const overwrite item #577

Open
CorentinDoue opened this issue Aug 25, 2023 · 2 comments
Open

[v1] anyOf + const overwrite item #577

CorentinDoue opened this issue Aug 25, 2023 · 2 comments
Assignees
Labels

Comments

@CorentinDoue
Copy link

CorentinDoue commented Aug 25, 2023

With dynamoDb v1,

export const myEntity = new EntityV2({
  name: "MyEntity",
  table,
  schema: schema({
    id: string().key().savedAs("PK"),
    entityName: string().key().const("MyEntity").savedAs("SK"),
    payload: export const myEntity = new EntityV2({
  name: "MyEntity",
  table,
  schema: schema({
    id: string().key().savedAs("PK"),
    entityName: string().key().const("MyEntity").savedAs("SK"),
    payload: anyOf([
      map({
        toto: boolean().const(true),
      }),
      map({
        toto: boolean().enum(false).optional(),
        tata: number(),
      }),
    ]),
  }),
});

const command = new PutItemCommand(myEntity, {
  id: "123",
  payload: {
    tata: 1,
  },
});

await command.send();

Creates the following item:

{
  "id": "123",
  "entityName": "MyEntity", 
  "payload": {
    "toto": true
  }
}

The payload I provided has been overridden 😢

Workaround:

anyOf([
      map({
        toto: boolean().enum(true),
      }),
      map({
        toto: boolean().enum(false).optional(),
        tata: number(),
      }),
    ]),

without any default value

@naorpeled
Copy link
Collaborator

@ThomasAribart could you please take a look at this? 🙏

@ThomasAribart
Copy link
Collaborator

Yes I will !

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

No branches or pull requests

3 participants