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

Function _addArrayPathsToValidate

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

Source from the content-addressed store, hash-verified

3178}
3179
3180function _addArrayPathsToValidate(doc, paths) {
3181 for (const path of paths) {
3182 const _pathType = doc.$__schema.path(path);
3183 if (!_pathType) {
3184 continue;
3185 }
3186
3187 if (!_pathType.$isMongooseArray ||
3188 // To avoid potential performance issues, skip doc arrays whose children
3189 // are not required. `getPositionalPathType()` may be slow, so avoid
3190 // it unless we have a case of #6364
3191 (!Array.isArray(_pathType) &&
3192 _pathType.$isMongooseDocumentArray &&
3193 !_pathType?.schemaOptions?.required)) {
3194 continue;
3195 }
3196
3197 // gh-11380: optimization. If the array isn't a document array and there's no validators
3198 // on the array type, there's no need to run validation on the individual array elements.
3199 if (_pathType.$isMongooseArray &&
3200 !_pathType.$isMongooseDocumentArray && // Skip document arrays...
3201 !_pathType.embeddedSchemaType.$isMongooseArray && // and arrays of arrays
3202 _pathType.embeddedSchemaType.validators.length === 0) {
3203 continue;
3204 }
3205
3206 const val = doc.$__getValue(path);
3207 _pushNestedArrayPaths(val, paths, path);
3208 }
3209}
3210
3211function _pushNestedArrayPaths(val, paths, path) {
3212 if (val != null) {

Callers 1

_getPathsToValidateFunction · 0.85

Calls 1

_pushNestedArrayPathsFunction · 0.85

Tested by

no test coverage detected