(operationName, operationArgs, context)
| 573 | } |
| 574 | |
| 575 | function resolveOperationArgs(operationName, operationArgs, context) { |
| 576 | const result = []; |
| 577 | function pluck(fromObject, toArray, fields) { |
| 578 | for (const field of fields) { |
| 579 | if (fromObject[field]) toArray.push(fromObject[field]); |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | // TODO: migrate all operations here |
| 584 | if (operationName === 'distinct') { |
| 585 | pluck(operationArgs, result, ['fieldName', 'filter']); |
| 586 | if (result.length === 1) result.push({}); |
| 587 | } else { |
| 588 | return; |
| 589 | } |
| 590 | |
| 591 | // compile the options |
| 592 | const options = {}; |
| 593 | if (operationArgs.options) { |
| 594 | Object.assign(options, operationArgs.options); |
| 595 | if (options.readPreference) { |
| 596 | options.readPreference = normalizeReadPreference(options.readPreference.mode); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | if (operationArgs.session) { |
| 601 | if (isTransactionCommand(operationName)) return; |
| 602 | options.session = context[operationArgs.session]; |
| 603 | } |
| 604 | |
| 605 | result.push(options); |
| 606 | |
| 607 | // determine if there is a callback to add |
| 608 | if (operationArgs.callback) { |
| 609 | result.push(() => |
| 610 | testOperations(operationArgs.callback, context, { swallowOperationErrors: false }) |
| 611 | ); |
| 612 | } |
| 613 | |
| 614 | return result; |
| 615 | } |
| 616 | |
| 617 | const CURSOR_COMMANDS = new Set(['find', 'aggregate', 'listIndexes', 'listCollections']); |
| 618 | const ADMIN_COMMANDS = new Set(['listDatabases']); |
no test coverage detected