(path, type)
| 297 | } |
| 298 | |
| 299 | function analyzePath(path, type) { |
| 300 | if (fields == null) { |
| 301 | return; |
| 302 | } |
| 303 | |
| 304 | // If schema-level selected not set, nothing to do |
| 305 | if (typeof type.selected !== 'boolean') { |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | // User overwriting default exclusion |
| 310 | if (type.selected === false && fields[path]) { |
| 311 | if (sanitizeProjection) { |
| 312 | fields[path] = 0; |
| 313 | } |
| 314 | |
| 315 | return; |
| 316 | } |
| 317 | |
| 318 | // If set to 0, we're explicitly excluding the discriminator key. Can't do this for all fields, |
| 319 | // because we have tests that assert that using `-path` to exclude schema-level `select: true` |
| 320 | // fields counts as an exclusive projection. See gh-11546 |
| 321 | if (!exclude && type.selected && path === schema.options.discriminatorKey && fields[path] != null && !fields[path]) { |
| 322 | delete fields[path]; |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | if (exclude === false && type.selected && fields[path] != null && !fields[path]) { |
| 327 | delete fields[path]; |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | const plusPath = '+' + path; |
| 332 | const hasPlusPath = fields && plusPath in fields; |
| 333 | if (hasPlusPath) { |
| 334 | // forced inclusion |
| 335 | delete fields[plusPath]; |
| 336 | |
| 337 | // if there are other fields being included, add this one |
| 338 | // if no other included fields, leave this out (implied inclusion) |
| 339 | if (exclude === false && keys.length > 1 && !~keys.indexOf(path) && !sanitizeProjection) { |
| 340 | fields[path] = 1; |
| 341 | } else if (exclude == null && sanitizeProjection && type.selected === false) { |
| 342 | fields[path] = 0; |
| 343 | } |
| 344 | |
| 345 | return; |
| 346 | } |
| 347 | |
| 348 | // check for parent exclusions |
| 349 | const pieces = path.split('.'); |
| 350 | let cur = ''; |
| 351 | for (let i = 0; i < pieces.length; ++i) { |
| 352 | cur += cur.length ? '.' + pieces[i] : pieces[i]; |
| 353 | if (excluded.indexOf(cur) !== -1) { |
| 354 | return; |
| 355 | } |
| 356 | } |
no test coverage detected
searching dependent graphs…