UNPKG

domain-objects

Version:

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

32 lines 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getKind = void 0; const markers_1 = require("../instantiation/markers"); /** * .what = reads a domain object class's `kind` from its static marker symbols * .why = * - the pragma stamps the true subclass so a consumer picks the right base class to rebuild * - replaces the fragile `primary`-non-empty heuristic with the class's own marker truth * .note = * - mirrors the instance-level `isOfDomainEntity` marker check, lifted to the class level * - static markers inherit down the constructor prototype chain, so a direct read resolves * subclasses (e.g. `class Job extends DomainEntity`) without a manual walk * - the marker symbols are global (`Symbol.for`), so the read is cross-version safe * - reads via typed bracket access (`dobj[MARK]` is `string | undefined`), not `Reflect.get`, * so the marker read keeps its type instead of a fall to `any` * - checks entity/literal/event, else falls back to `object` (a plain `DomainObject` with a * schema but no subclass marker) */ const getKind = (dobj) => { // read the marker off the class's static inheritance chain (entity/literal/event) if (dobj[markers_1.MARK_AS_DOMAIN_ENTITY]) return 'entity'; if (dobj[markers_1.MARK_AS_DOMAIN_LITERAL]) return 'literal'; if (dobj[markers_1.MARK_AS_DOMAIN_EVENT]) return 'event'; // fall back to the plain base class: a DomainObject with a schema but no subclass marker return 'object'; }; exports.getKind = getKind; //# sourceMappingURL=getKind.js.map