UNPKG

dino-core

Version:

A dependency injection framework for NodeJS applications

63 lines 2.38 kB
"use strict"; // Copyright 2025 Quirino Brizi // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. Object.defineProperty(exports, "__esModule", { value: true }); exports.Transactional = exports.Cacheable = exports.Lazy = exports.Transient = exports.Singleton = exports.Profile = void 0; const node_crypto_1 = require("node:crypto"); const cache_context_1 = require("../cache/cache.context"); const scope_1 = require("../scope"); const Profile = function (profile) { return function (target) { target.profile = () => profile; }; }; exports.Profile = Profile; const Singleton = function () { return function (target) { target.scope = () => scope_1.Scope.SINGLETON; }; }; exports.Singleton = Singleton; const Transient = function () { return function (target) { target.scope = () => scope_1.Scope.TRANSIENT; }; }; exports.Transient = Transient; const Lazy = function () { return function (target) { target.lazy = () => true; }; }; exports.Lazy = Lazy; const Cacheable = function (key = (0, node_crypto_1.randomUUID)(), excludedMethods = [], opts = { max: 100, maxAge: 300000, updateAgeOnGet: true }) { return function (target) { target.cacheable = () => cache_context_1.CacheContext.create(key, excludedMethods, opts); }; }; exports.Cacheable = Cacheable; /** * A decorator which allows to define the methods that should be treated as requiring transactions. * @param enableTransactionOn array containing the names of the methods that should be wrapped in * a transaction * @public */ const Transactional = function (enableTransactionOn) { return function (target) { target.transactional = () => enableTransactionOn.length > 0; target.enableTransactionOn = () => enableTransactionOn; }; }; exports.Transactional = Transactional; //# sourceMappingURL=CommonDecorators.js.map