@elsikora/nestjs-crud-automator
Version:
A library for automating the creation of CRUD operations in NestJS.
44 lines (41 loc) • 1.53 kB
JavaScript
;
var tslib_es6 = require('../../../../../external/tslib/tslib.es6.js');
var cache_class = require('../../resolver/cache.class.js');
var common = require('@nestjs/common');
exports.ApiAuthorizationHookPermissionCache = class ApiAuthorizationHookPermissionCache {
CACHE = new cache_class.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;
}
};
exports.ApiAuthorizationHookPermissionCache = tslib_es6.__decorate([
common.Injectable()
], exports.ApiAuthorizationHookPermissionCache);
//# sourceMappingURL=cache.class.js.map