Changelog
All notable changes to drea are documented here. Full documentation → dreav4.dev (replace with your deployed URL)
[4.0.0] – TypeScript Support, File Validation & Full Guard System
🚀 Highlights
- First-class TypeScript support shipped directly in the package — no
@types/dreaneeded. __Fileutility — validateFileobjects as atomic entities insidenestvalidate().- Full guard system — every public function now calls a dedicated type-narrowing guard before any validation logic runs. Every guard error follows
"Expected X for 'paramName', got Y". Nonetype — setrule: Noneto explicitly skip validation for any entry or field.
✨ New Features
- TypeScript types bundled with the package (
PureObject,SchemaRestriction,ModelResultObj<T>,DreaFileWrapper,RuleAndError_t,Err, and more) - Generic return types on
validate<T>andnestvalidate<T>— result type is inferred from input asserts value is Treturn types on all guards for compile-time type narrowing__File(file)— wraps aFileinstance sonestvalidatetreats it as a leaf, not a nested objectisDreaFile(v)— internal brand check (used byhasNest)AssertDreaFile(v, paramName?)— guard that assertsv instanceof FileDreaFileWrapperopaque type for TypeScript users
🛡️ Guard System (new in v4)
Every public surface now has a dedicated guard called as its very first action:
| Function / Method | Guard |
|---|---|
new URL(url) | AssertNonEmptyString |
URL.verifyPattern(constraints?) | AssertOptionalPlainObject |
validateEntry({entry, RuleAndError}) | AssertRuleAndErrorArray |
isUsernameValid / isEmailValid / isPhoneNumberValid / isPasswordValid | AssertString |
isRequired(entry) | AssertStringOrNumber |
validateMany(schema) | AssertValidateManyInput |
new CustomClassicModel(schema) | AssertPlainObject |
CustomClassicModel.validate(obj) | AssertPlainObject |
CustomClassicModel.nestvalidate(obj) | AssertPlainObject |
CustomClassicModel.extend(ext) | AssertPlainObject |
CustomClassicModel.remove(key) | AssertNonEmptyString |
CustomClassicModel.swap(restr) | AssertPlainObject |
__File(v) | AssertDreaFile |
🐛 Bug Fixes
- Fixed
hasNest(null)returningtruedue totypeof null === 'object'— null is now correctly treated as a leaf - Fixed
DreaFileWrappernot being unwrapped beforevalidateEntryreceives it — rules now receive the realFileinstance, sov instanceof File,v.type,v.size, andv.nameall work correctly - Fixed
error.codevserror.error_codeproperty mismatch in catch-block checks
📦 Migration from v3 (JavaScript)
No breaking changes. Everything from v3 continues to work. TypeScript users simply gain types automatically.
📦 Migration for TypeScript Users
bash
npm install drea@4ts
import { validateEntry, CustomClassicModel, None, __File } from 'drea'
// Types are included — no @types/drea needed[3.0.1] – Consistent Result Shape
🛠 Improvements
ClassicModelandCustomClassicModelnow return a consistent{ status, data, error }object on every callstatusis alwaystrueorfalse— neverundefineddatais the validated object on success,nullon failureerroris a per-field error map on failure,nullon success
[3.0.0] – Nested Validation, Multi-Rule Fields & None Type
🚨 Breaking Changes
betweeninURL.verifyPattern()now treats a single-element array as maximum (was minimum)- Fixed a bug that prevented using only one constraint in
verifyPattern() nullentries are now accepted byvalidateEntry()statusis always a boolean — neverundefined
✨ New Features
RuleAndError[]— one field can now have multiple{rule, errorMsg}pairs. Validation stops at the first failure, giving you ordered, granular error messagesNonetype — setrule: Noneto skip validation for any field entirely. Best practice: seterrorMsg: nullalongside itnestvalidate()— recursively validates deeply nested plain objects. The error tree mirrors your data's shape exactly — a failure atdata.company.address.zipappears atresult.error.company.address.zip
🛠 Improvements
- More predictable validation flow
- Cleaner error semantics
- Improved documentation and examples
[2.0.0] – Structured Error Objects & URL Validator
🚨 Breaking Changes
- Structured error objects introduced with
error_code/error_description - Unknown schema keys now throw
UnknownKeyError(code:ERR_UNKNOWN_KEY) - Strict type enforcement on all constraint arguments
nullandundefinedvalues explicitly rejected where not allowed
✨ New Features
- Custom error classes:
ArgumentTypeError,UnknownKeyError,NullValueError,DuplicateKeyError,MissingKeyError,ValidationError - Schema-driven constraint validation
URLclass — lightweight structural URL/URI pattern validator with opt-in constraint rules (allowed_protocols,allowed_domains,allowed_ports,contain_query,contain_fragment,contain_path,between)- Clearer, developer-friendly error messages
🛠 Improvements
- Predictable validation flow
- Clean error semantics
- Full documentation and examples
⚠️ Migration Notes
- Update error handling to read
error.code(populated fromerror_code) - Ensure constraint objects only contain supported keys
