-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Remove schematype caster and casterConstructor properties in favor of embeddedSchemaType and Constructor #15513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors array and subdocument schema types by removing the old caster
/casterConstructor
properties and replacing them with embeddedSchemaType
and Constructor
, simplifying internal logic and improving TypeScript types.
- Replace
path.caster.instance
checks and uses withpath.embeddedSchemaType.instance
- Migrate all
casterConstructor
references to the newConstructor
property - Update tests and documentation to reflect the new property names
Reviewed Changes
Copilot reviewed 31 out of 32 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
test/schema.test.js | Updated assertions from caster /casterConstructor to embeddedSchemaType /Constructor |
test/schema.documentarray.test.js | Switched .$embeddedSchemaType to .embeddedSchemaType |
test/query.test.js | Replaced .caster with .Constructor for bookHolder path |
test/document.test.js | Updated path.casterConstructor to path.Constructor |
package.json | Contains unresolved merge conflict markers |
lib/types/documentArray/methods/... | Replaced casterConstructor with Constructor in methods |
lib/types/documentArray/index.js | Updated internal array schema symbol to use embeddedSchemaType |
lib/types/array/methods/index.js | Redirected setter/getter calls from caster to embeddedSchemaType |
lib/types/array/index.js | Switched getter logic to use embeddedSchemaType |
lib/schemaType.js | Updated getEmbeddedSchemaType to return this.embeddedSchemaType |
lib/schema/subdocument.js | Removed this.caster , added this.Constructor assignments |
lib/schema/documentArrayElement.js | Changed constructor signature to (path, schema, options) |
lib/schema/documentArray.js | Reworked document array initialization to use embeddedSchemaType and Constructor |
lib/schema/array.js | Refactored SchemaArray to set embeddedSchemaType |
lib/schema.js | Updated childSchemas logic to reference Constructor and embeddedSchemaType |
lib/helpers/... | Various query, populate, plugin helpers updated from caster /casterConstructor to new properties |
docs/migrating_to_9.md | Added migration guide for caster → embeddedSchemaType and Constructor |
Comments suppressed due to low confidence (2)
package.json:57
- Resolve the Git merge conflict markers by removing
<<<<<<<
,=======
, and>>>>>>>
and consolidating the correct dependency versions under a single block.
"pug": "3.0.3",
lib/schema/documentArrayElement.js:21
- [nitpick] Update the JSDoc or add parameter comments to document the newly introduced
schema
parameter forSchemaDocumentArrayElement
.
function SchemaDocumentArrayElement(path, schema, options) {
Co-authored-by: hasezoey <hasezoey@gmail.com>
Co-authored-by: hasezoey <hasezoey@gmail.com>
Summary
#15179 is a result of an issue that's frustrated me for several years: inconsistency in the
caster
andcasterConstructor
properties. In Mongoose 8,caster
can be either a schema type instance or an embedded document constructor depending on document array vs primitive array, which is inconsistent and confusing. With this PR, we split it up into:embeddedSchemaType
now stores the embedded schema type for arrays and document arrays. Likely should consider switching maps too, but maps for now use$__schemaType
.Constructor
now stores the embedded document constructor for subdocuments and document arrays.This should improve internal maintainability, and make our TypeScript types more coherent. However, this will also unfortunately break anyone's code that relies on
caster
, which is why we're putting this in Mongoose 9.Examples