MCPcopy Create free account
hub / github.com/Automattic/mongoose / _addArrayPathsToValidate

Function _addArrayPathsToValidate

lib/document.js:3278–3307  ·  view source on GitHub ↗
(doc, paths)

Source from the content-addressed store, hash-verified

3276}
3277
3278function _addArrayPathsToValidate(doc, paths) {
3279 for (const path of paths) {
3280 const _pathType = doc.$__schema.path(path);
3281 if (!_pathType) {
3282 continue;
3283 }
3284
3285 if (!_pathType.$isMongooseArray ||
3286 // To avoid potential performance issues, skip doc arrays whose children
3287 // are not required. `getPositionalPathType()` may be slow, so avoid
3288 // it unless we have a case of #6364
3289 (!Array.isArray(_pathType) &&
3290 _pathType.$isMongooseDocumentArray &&
3291 !_pathType?.schemaOptions?.required)) {
3292 continue;
3293 }
3294
3295 // gh-11380: optimization. If the array isn't a document array and there's no validators
3296 // on the array type, there's no need to run validation on the individual array elements.
3297 if (_pathType.$isMongooseArray &&
3298 !_pathType.$isMongooseDocumentArray && // Skip document arrays...
3299 !_pathType.embeddedSchemaType.$isMongooseArray && // and arrays of arrays
3300 _pathType.embeddedSchemaType.validators.length === 0) {
3301 continue;
3302 }
3303
3304 const val = doc.$__getValue(path);
3305 _pushNestedArrayPaths(val, paths, path);
3306 }
3307}
3308
3309function _pushNestedArrayPaths(val, paths, path) {
3310 if (val != null) {

Callers 1

_getPathsToValidateFunction · 0.85

Calls 1

_pushNestedArrayPathsFunction · 0.85

Tested by

no test coverage detected