UNPKG

@leyyo/cache

Version:
75 lines (74 loc) 2.79 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CacheProviderAbstract = void 0; const cache_command_1 = require("../literal/cache-command"); // noinspection JSUnusedGlobalSymbols class CacheProviderAbstract { constructor(name) { this.name = name; this._notSupportCommands = []; this['$$leyyoType'] = Symbol('leyyo.cache,CacheProvider'); } _addNotSupported(...commands) { commands.forEach(command => { if (cache_command_1.CacheCommandItems.includes(command)) { if (!this.notSupportCommands.includes(command)) { this.notSupportCommands.push(command); } else { console.warn(`Duplicated not-supported command: ${command} for ${this.name} provider`); } } else { console.warn(`Invalid not-supported command: ${command} for ${this.name} provider`); } }); } info(check) { return __awaiter(this, void 0, void 0, function* () { if (!check.providers) { check.providers = []; } if (check.providers.includes(this.name)) { return { name: this.name }; } check.providers.push(this.name); return { name: this.name, notSupportCommands: [...this._notSupportCommands] }; }); } isSupported(command) { return !this.notSupportCommands.includes(command); } get defaultClient() { return this._defaultClient; } get notSupportCommands() { return [...this._notSupportCommands]; } // region secure get $back() { return this; } get $secure() { return this; } $setDefaultClient(client) { if (this._defaultClient) { throw new Error(`Default client was already set for provider: ${this.name}`); } this._defaultClient = client; } } exports.CacheProviderAbstract = CacheProviderAbstract;