@onn-software/ddl-to-gql
Version:
Convert a SQL DDL to a GraphQL implementation with all relations.
21 lines (20 loc) • 658 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.distinctBy = exports.distinct = exports.associateBy = void 0;
const associateBy = (array, getKey) => array.reduce((res, cur) => {
res[getKey(cur)] = cur;
return res;
}, {});
exports.associateBy = associateBy;
const distinct = (value) => {
const collector = {};
value.forEach((v) => (collector[v] = v));
return Object.values(collector);
};
exports.distinct = distinct;
const distinctBy = (value, by) => {
const collector = {};
value.forEach((v) => (collector[by(v)] = v));
return Object.values(collector);
};
exports.distinctBy = distinctBy;