domain-objects
Version:
A simple, convenient way to represent domain objects, leverage domain knowledge, and add runtime validation in your code base.
33 lines (31 loc) • 1.36 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DomainObjectMetadataMustBeDefinedError = void 0;
const helpful_errors_1 = require("helpful-errors");
// .why = an absent `static metadata` is a developer misconfiguration of the class, not a caller's
// bad input — so it is a MalfunctionError (exit 1, http 500), the system's fault to fix
class DomainObjectMetadataMustBeDefinedError extends helpful_errors_1.MalfunctionError {
constructor({ domainObjectName, nameOfFunctionNeededFor, }) {
const message = `
\`${domainObjectName}.metadata\` must be defined, to be able to \`${nameOfFunctionNeededFor}\`.
Without explicit metadata, it is ambiguous which keys should be checked.
Example:
\`\`\`ts
interface RocketShip {
uuid?: string;
serialNumber: string;
fuelQuantity: number;
passengers: number;
}
class RocketShip extends DomainEntity<RocketShip> implements RocketShip {
public static primary = ['uuid'] as const;
public static unique = ['serialNumber'] as const;
public static metadata = ['uuid'] as const;
}
\`\`\`
`.trim();
super(message, { domainObjectName, nameOfFunctionNeededFor });
}
}
exports.DomainObjectMetadataMustBeDefinedError = DomainObjectMetadataMustBeDefinedError;
//# sourceMappingURL=DomainObjectMetadataMustBeDefinedError.js.map