UNPKG

rethinkts

Version:

A model system for RethinkDB, written in and for TypeScript.

48 lines 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function assignWithArrays(target, ...sources) { sources .filter(source => source != null) .forEach(source => { Object.keys(source) .filter(key => source[key] !== undefined) .forEach(key => { target[key] = merge(target[key], source[key]); }); }); return target; } exports.assignWithArrays = assignWithArrays; function merge(a, b) { if (Array.isArray(a) && Array.isArray(b)) { return [...a, ...b]; } if (a instanceof Map && b instanceof Map) { return mergeMap(a, b); } if (a instanceof Set && b instanceof Set) { return mergeSet(a, b); } return b; } function mergeMap(a, b) { const aEntries = Array.from(a); const bEntries = Array.from(b); const overrides = bEntries .filter(entryB => aEntries.some(entryA => entryA[0] === entryB[0])) .map(entryB => { const entryA = aEntries.find(entryA => entryA[0] === entryB[0]); return [entryB[0], merge(entryA[1], entryB[1])]; }); return new Map([...aEntries, ...bEntries, ...overrides]); } function mergeSet(a, b) { const aValues = Array.from(a); const bValues = Array.from(b); return new Set([...aValues, ...bValues]); } function pick(obj, ...keys) { return keys.reduce((target, key) => (Object.assign({}, target, { [key]: obj[key] })), {}); } exports.pick = pick; //# sourceMappingURL=utils.js.map