tywalch / electrodb

A DynamoDB library to ease the use of modeling complex hierarchical relationships and implementing a Single Table Design while keeping your query code readable.
MIT License
956 stars 58 forks source link

Setter not triggered on removing a watching attribute #395

Open jw-meta opened 3 weeks ago

jw-meta commented 3 weeks ago

Describe the bug with attribute updatedAt having property watch: ['status'] the attribute updatedAt setter is not triggered when patch.remove() is called to remove the attribute status

it works as expected when watch: '*' is set

ElectroDB Version 2.13.1

ElectroDB Playground Link config with watch as array of attribute names config with watch as wildcard

Entity/Service Definitions

{
  model: {
    entity: "tasks",
      version: "1",
        service: "taskapp"
  },
  attributes: {
    id: {
      type: "string",
        required: true
    },
    status: {
      type: 'string'
    },
    createdAt: {
      type: "number",
        default: () => Date.now(),
        readOnly: true
    },
    updatedAt: {
      type: "number",
        watch: ['status'],
          set: () => Date.now(),
            readOnly: true
    }
  },
  indexes: {
    projects: {
      pk: {
        field: "pk",
          composite: ["id"]
      },
    },
  }
}

Expected behavior The setter of updated_at should be triggered on removing status attribute with patch.remove()

tywalch commented 6 days ago

Thank you, I will look into this!