UNPKG

@raccoons-co/ethics

Version:
36 lines (35 loc) 1.28 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Strict_1 = __importDefault(require("./Strict")); /** * Encapsulates instance of annotated class into `ImmutableObject` instance. */ class Immutable { decorator() { return this.immutableObjectClass; } /** * Returns extended class which prevents mutation of the original class instance. * * @typeParam C - the type of the decorated class * @param originalClass - the class to decorate * @param context - the context provided to a class decorator * @returns class ImmutableObject. */ immutableObjectClass(originalClass, context) { Strict_1.default.notNull(originalClass); Strict_1.default.notNull(context); Strict_1.default.checkArgument(String(context.kind) === "class"); return class ImmutableObject extends originalClass { constructor(...args) { super(...args); this.originalClassName = String(context.name); Object.freeze(this); } }; } } exports.default = new Immutable().decorator();