UNPKG

domain-objects

Version:

A simple, convenient way to represent domain objects, leverage domain knowledge, and add runtime validation in your code base.

18 lines 793 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isUniqueKeyRef = void 0; const helpful_errors_1 = require("helpful-errors"); const type_fns_1 = require("type-fns"); const isUniqueKeyRef = ({ of, }) => (ref) => { // get the primary key attributes const uniqueKeys = of.unique; if (!uniqueKeys) throw new helpful_errors_1.UnexpectedCodePathError('can not check isUniqueKeyRef on a dobj which does not declare its .unique keys', { dobj: of.name, uniqueKeys }); // check that each key is defined const hasMissingKeys = uniqueKeys.some((key) => !(0, type_fns_1.isPresent)(ref[key])); if (hasMissingKeys) return false; return true; }; exports.isUniqueKeyRef = isUniqueKeyRef; //# sourceMappingURL=isUniqueKeyRef.js.map