Skip to content

Docs inconsistency: attributes.validate boolean semantics reversed vs v3 migration (true should be valid) #532

@shinking02

Description

@shinking02

Summary

The boolean semantics for attributes.validate in the docs appear inverted for v3.

  • The Attributes page says: (value: T) => booleantrue (or truthy) signifies invalid, false (or falsy) is considered valid.
  • The v3 Migration guide says the opposite and also states the callback return type is strictly boolean: return true for valid values and false for invalid values.

Observed runtime behavior in v3 matches the migration guide (true = valid, false = invalid).

A related discussion from before v3 also suggested flipping semantics and treating this as a breaking change: #411

Environment

  • ElectroDB: v3.x (observed on v3.4.5)
  • Node.js: 24.4.1

Where the docs disagree

Minimal reproduction

import { Entity } from "electrodb";

const table = "test";

const Passes = new Entity({
  model: { entity: "e", service: "svc", version: "1" },
  attributes: {
    id: { type: "string", required: true },
    v:  { type: "string", required: true, validate: () => true }, // <-- true should ACCEPT
  },
  indexes: { primary: { pk: { field: "pk", composite: ["id"] }, sk: { field: "sk", composite: [] } } }
}, { table });

await Passes.create({ id: "1", v: "x" }).go(); // ✅ passes

const Fails = new Entity({
  model: { entity: "e2", service: "svc", version: "1" },
  attributes: {
    id: { type: "string", required: true },
    v:  { type: "string", required: true, validate: () => false }, // <-- false should REJECT
  },
  indexes: { primary: { pk: { field: "pk", composite: ["id"] }, sk: { field: "sk", composite: [] } } }
}, { table });

await Fails.create({ id: "1", v: "x" }).go(); // ❌ throws ElectroValidationError: Invalid Attribute (code 3001)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions