-
Notifications
You must be signed in to change notification settings - Fork 81
Open
Description
Summary
The boolean semantics for attributes.validate in the docs appear inverted for v3.
- The Attributes page says:
(value: T) => boolean— true (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
truefor valid values andfalsefor 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
-
Attributes → Attribute Validation: shows
true = invalid,false = validand also lists legacy signatures (RegExp,(value) => string,(value) => void).
https://electrodb.dev/en/modeling/attributes/#attribute-validation -
v3 Migration → Changes to validate callback on attributes: “strict return type of boolean” and “return true for valid, false for invalid”.
https://electrodb.dev/en/core-concepts/v3-migration/#changes-to-validate-callback-on-attributes
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
Labels
No labels