domain-objects
Version:
A simple, convenient way to represent domain objects, leverage domain knowledge, and add runtime validation in your code base.
18 lines • 805 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.isPrimaryKeyRef = void 0;
const helpful_errors_1 = require("helpful-errors");
const type_fns_1 = require("type-fns");
const isPrimaryKeyRef = ({ of, }) => (ref) => {
// get the primary key attributes
const primaryKeys = of.primary;
if (!primaryKeys)
throw new helpful_errors_1.UnexpectedCodePathError('can not check isPrimaryKeyRef on a dobj which does not declare its .primary keys', { dobj: of.name, primaryKeys });
// check that each key is defined
const hasMissingKeys = primaryKeys.some((key) => !(0, type_fns_1.isPresent)(ref[key]));
if (hasMissingKeys)
return false;
return true;
};
exports.isPrimaryKeyRef = isPrimaryKeyRef;
//# sourceMappingURL=isPrimaryKeyRef.js.map
;