UNPKG

@ganbarodigital/ts-lib-value-objects

Version:

Helps you create value objects and refined types for safer software

49 lines 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EntityObject = void 0; /** * Entity<ID, T> is the base class for defining your Entity hierarchies. * * Every Entity: * * - has an identity * - that you can access by an `id` property * - has a stored value * - that you can get the valueOf() * * Your child classes should implement readonly `get` accessors for * any fields of type `T` that you'd like to access without having * to call `valueOf()` all the time. */ class EntityObject { /** * this constructor does no contract / specification enforcement at all * do that in your constructor, before calling super() * * if you don't need to enforce a contract, your class can safely * create a public constructor */ constructor(input) { this.value = input; } /** * returns the wrapped value * * for types passed by reference, we do NOT return a clone of any kind. * You have to be careful not to accidentally change this value. */ valueOf() { return this.value; } /** * a type-guard. It proves that an object is a wrapper around type `T` * that has ID `ID`. * * added mostly for completeness */ isEntity() { return true; } } exports.EntityObject = EntityObject; //# sourceMappingURL=EntityObject.js.map