dynamodb-onetable: unable to use value functions as they are deprecated

Hi, We are using value function to conditionally remove gsi indexes as below.

      gsi3pk: {
        type: String,
        value: (name: string, message: Message): string => message.flagged ? `${message.type}#user#${message.userId}#flagged` : undefined,
      },
      gsi3sk: {
        type: String,
        value: (name: string, message: Message): string => message.flagged ? `message#${message.id}` : undefined,
      },

When message is un-flagged, we are removing gsi3pk and gsi3sk But when we updated the onetable to latest version, we are getting error that value functions are deprecated.

Can you please help us understand how we can resolve this without using remove in update operation?

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (13 by maintainers)

Most upvoted comments

Perhaps more direct and have one callback function.

Set the schema field value: true to indicate a value template callback is being used for this field and then a Table.params.value function to provide the values.

The value callback would be invoked at the same time as runTemplates.

gs1pk: { type: String, value: true }

new Table({
    value: (model, name, properties) => {
        if (name == 'gs1pk') {
          if (properties.deletedAt) {
               return null
          } else if (properties.claimedDriverId) {
               return `driver#${properties.claimedDriverId}`
          } else {
            return `zone#${properties.launchZoneId}#${properties.deliveryDate}`
          }
    }
})

Can you post the warning text you are seeing and your schema? You should only be seeing warnings if the schema field value is a function. You need to set the schema field value to true On Feb 10, 2022, at 5:44 AM, Muthu @.***> wrote: @mobsense https://github.com/mobsense Having the value function at the table level works fine. But still see warning logs, can you remove warnings when value functions are used at create-table level? (During batch updates, our logs are flooded with warnings)

ignore my comment, i deleted it - still you might have got notified via email i believe. It works fine, please ignore 👍🏻

Can I close the issue?

This worked. Thank you so much!

Okay, understand. It should work if you remove the value from the schema definition for the GSI pk/sk.

Mixing using a value template sometimes and explicit properties in other cases is the issue and probably not ideal. In your case, your GSI key values are not constant literals but are different formats for different cases. So best to not use value templates.

Does that makes sense?

NOTE: you can also do this by running that code when you provide the properties. i.e. providing the GSI PK/SK values directly in properties. So I’m not really sure what you gain by the params.value I proposed.

user = await User.create({
    gsi3pk: message.flagged ? `${message.type}#user#${message.userId}#flagged` : undefined,
    gsi3sk: message.flagged ? `message#${message.id}` : undefined,
})

Property values override template values.

Here is a proposal. We’re very open to better / more elegant ideas.

BTW: having the same discussion at: #147

Could we make the value template function be provided in params using the same calling sequence.

    user = await User.create({
        ....
    }, {
        value(name: string, message: OneProperties): string {
            if (name == 'gsi3pk') {
                return message.flagged ? `${message.type}#user#${message.userId}#flagged` : undefined
            } else if (name == 'gsi3sk') {
                return message.flagged ? `message#${message.id}` : undefined
            },
        },
})