UNPKG

@elsikora/nestjs-crud-automator

Version:

A library for automating the creation of CRUD operations in NestJS.

44 lines (41 loc) 1.55 kB
import { __decorate } from '../../../../../external/tslib/tslib.es6.js'; import { ApiAuthorizationResolverCache } from '../../resolver/cache.class.js'; import { Injectable } from '@nestjs/common'; let ApiAuthorizationHookPermissionCache = class ApiAuthorizationHookPermissionCache { CACHE = new ApiAuthorizationResolverCache(); clear() { this.CACHE.clear(); } configure(options) { this.CACHE.configure(options); } get(principal) { return this.CACHE.get(this.createPrincipalCacheKey(principal)); } set(principal, permissions) { this.CACHE.set(this.createPrincipalCacheKey(principal), permissions); } createPrincipalCacheKey(principal) { return JSON.stringify(this.normalizeValue(principal)); } normalizeValue(value) { if (Array.isArray(value)) { return value.map((item) => this.normalizeValue(item)); } if (!value || typeof value !== "object") { return value; } const normalizedValue = {}; const recordValue = value; const sortedKeys = Object.keys(recordValue).toSorted((left, right) => left.localeCompare(right)); for (const key of sortedKeys) { normalizedValue[key] = this.normalizeValue(recordValue[key]); } return normalizedValue; } }; ApiAuthorizationHookPermissionCache = __decorate([ Injectable() ], ApiAuthorizationHookPermissionCache); export { ApiAuthorizationHookPermissionCache }; //# sourceMappingURL=cache.class.js.map