merge.js 678 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. module.exports = function merge(s1, s2, skipConflictingPaths) {
  3. const paths = Object.keys(s2.tree);
  4. const pathsToAdd = {};
  5. for (const key of paths) {
  6. if (skipConflictingPaths && (s1.paths[key] || s1.nested[key] || s1.singleNestedPaths[key])) {
  7. continue;
  8. }
  9. pathsToAdd[key] = s2.tree[key];
  10. }
  11. s1.add(pathsToAdd);
  12. s1.callQueue = s1.callQueue.concat(s2.callQueue);
  13. s1.method(s2.methods);
  14. s1.static(s2.statics);
  15. for (const query in s2.query) {
  16. s1.query[query] = s2.query[query];
  17. }
  18. for (const virtual in s2.virtuals) {
  19. s1.virtuals[virtual] = s2.virtuals[virtual].clone();
  20. }
  21. s1.s.hooks.merge(s2.s.hooks, false);
  22. };