fix(document): deprecate validateSync re #16291 - #16310
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR deprecates Document.prototype.validateSync() across runtime, TypeScript types, and docs to reflect that validateSync() does not run validation middleware, and removes middleware options from the validateSync() TypeScript surface.
Changes:
- Deprecates
Document#validateSync()in JSDoc and TypeScript declarations, and emits a runtime warning whenvalidateSync()is called. - Introduces an internal
Document#$__validateSync()entry point and updates internal validators (subdocs, document arrays, unions, bulkSave) to use it to avoid cascading warnings. - Updates deprecations documentation and adds focused runtime/type coverage around the new deprecation behavior.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| types/document.d.ts | Adds ValidateSyncOptions (excluding middleware) and marks validateSync() overloads as deprecated. |
| test/types/model.skip.middleware.test.ts | Updates type tests to assert validateSync() rejects middleware options. |
| test/document.test.js | Adds runtime tests for the new validateSync() deprecation warning behavior, including bulkSave and nested validation. |
| lib/schema/union.js | Preferentially calls $__validateSync() to avoid repeated deprecation warnings for union values. |
| lib/schema/subdocument.js | Switches subdocument sync validation to $__validateSync(). |
| lib/schema/documentArray.js | Switches document array sync validation to $__validateSync(options). |
| lib/model.js | Uses $__validateSync() during bulk write operation building to avoid user-facing warnings. |
| lib/document.js | Deprecates validateSync() with warning wrapper and moves prior logic to $__validateSync(). |
| docs/deprecations.md | Documents the validateSync() deprecation and behavioral notes (no middleware + skips async validators). |
vkarpov15
reviewed
May 29, 2026
vkarpov15
left a comment
Collaborator
There was a problem hiding this comment.
One minor comment but looks good overall
vkarpov15
approved these changes
May 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
re #16291
This PR:
middlewaresupport from thevalidateSync()TypeScript surface, becausevalidateSync()does not run validate middlewareDocument.prototype.validateSync()as deprecated in the runtime JSDoc and TypeScript declarationsvalidateSync()is calledRuntime validation behavior is otherwise unchanged.