UNPKG

mongoe

Version:

MongoDB driver with relational functionalities

22 lines (21 loc) 942 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.substractKeys = exports.idify = exports.ObjectId = void 0; var mongodb_1 = require("mongodb"); Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return mongodb_1.ObjectId; } }); function idify(str) { if (typeof str !== "string") return null; if (!mongodb_1.ObjectId.isValid(str)) throw new Error("Invalid hex value <" + str + "> passed to idify"); return mongodb_1.ObjectId.createFromHexString(str); } exports.idify = idify; function substractKeys(keys, alreadyDeleted) { var normalizedKey = function (key) { return key instanceof mongodb_1.ObjectId ? key.toHexString() : key; }; var set = new Set(alreadyDeleted.map(normalizedKey)); return keys.filter(function (key) { return !set.has(normalizedKey(key)); }); } exports.substractKeys = substractKeys;