@noony-serverless/core 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/middlewares/guards/RouteGuards.d.ts +255 -0
- package/build/middlewares/guards/RouteGuards.js +500 -0
- package/build/middlewares/guards/cache/CacheAdapter.d.ts +132 -0
- package/build/middlewares/guards/cache/CacheAdapter.js +86 -0
- package/build/middlewares/guards/cache/ConservativeCacheInvalidation.d.ts +191 -0
- package/build/middlewares/guards/cache/ConservativeCacheInvalidation.js +510 -0
- package/build/middlewares/guards/cache/MemoryCacheAdapter.d.ts +119 -0
- package/build/middlewares/guards/cache/MemoryCacheAdapter.js +294 -0
- package/build/middlewares/guards/cache/NoopCacheAdapter.d.ts +95 -0
- package/build/middlewares/guards/cache/NoopCacheAdapter.js +131 -0
- package/build/middlewares/guards/config/GuardConfiguration.d.ts +112 -0
- package/build/middlewares/guards/config/GuardConfiguration.js +137 -0
- package/build/middlewares/guards/guards/FastAuthGuard.d.ts +201 -0
- package/build/middlewares/guards/guards/FastAuthGuard.js +460 -0
- package/build/middlewares/guards/guards/PermissionGuardFactory.d.ts +202 -0
- package/build/middlewares/guards/guards/PermissionGuardFactory.js +563 -0
- package/build/middlewares/guards/index.d.ts +67 -0
- package/build/middlewares/guards/index.js +192 -0
- package/build/middlewares/guards/registry/PermissionRegistry.d.ts +188 -0
- package/build/middlewares/guards/registry/PermissionRegistry.js +425 -0
- package/build/middlewares/guards/resolvers/ExpressionPermissionResolver.d.ts +129 -0
- package/build/middlewares/guards/resolvers/ExpressionPermissionResolver.js +451 -0
- package/build/middlewares/guards/resolvers/PermissionResolver.d.ts +155 -0
- package/build/middlewares/guards/resolvers/PermissionResolver.js +176 -0
- package/build/middlewares/guards/resolvers/PlainPermissionResolver.d.ts +101 -0
- package/build/middlewares/guards/resolvers/PlainPermissionResolver.js +248 -0
- package/build/middlewares/guards/resolvers/WildcardPermissionResolver.d.ts +146 -0
- package/build/middlewares/guards/resolvers/WildcardPermissionResolver.js +377 -0
- package/build/middlewares/guards/services/FastUserContextService.d.ts +216 -0
- package/build/middlewares/guards/services/FastUserContextService.js +434 -0
- package/build/middlewares/index.d.ts +1 -0
- package/build/middlewares/index.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Memory Cache Adapter with LRU Eviction
|
|
4
|
+
*
|
|
5
|
+
* High-performance in-memory cache implementation using Least Recently Used (LRU)
|
|
6
|
+
* eviction strategy. Optimized for single-instance deployments where sub-millisecond
|
|
7
|
+
* cache lookups are critical for authentication performance.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - O(1) get/set operations using Map and doubly-linked list
|
|
11
|
+
* - TTL support with lazy expiration checking
|
|
12
|
+
* - Configurable size limits with automatic eviction
|
|
13
|
+
* - Pattern-based deletion for cache invalidation
|
|
14
|
+
* - Performance metrics for monitoring
|
|
15
|
+
* - Memory usage tracking
|
|
16
|
+
*
|
|
17
|
+
* @author Noony Framework Team
|
|
18
|
+
* @version 1.0.0
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.MemoryCacheAdapter = void 0;
|
|
22
|
+
/**
|
|
23
|
+
* Memory cache adapter with LRU eviction policy
|
|
24
|
+
*
|
|
25
|
+
* Uses a combination of Map for O(1) key lookups and a doubly-linked list
|
|
26
|
+
* for O(1) LRU operations. TTL is implemented with lazy expiration checking
|
|
27
|
+
* to avoid timer overhead.
|
|
28
|
+
*/
|
|
29
|
+
class MemoryCacheAdapter {
|
|
30
|
+
cache = new Map();
|
|
31
|
+
maxSize;
|
|
32
|
+
defaultTTL;
|
|
33
|
+
name;
|
|
34
|
+
// Doubly-linked list for LRU tracking
|
|
35
|
+
head;
|
|
36
|
+
tail;
|
|
37
|
+
// Performance metrics
|
|
38
|
+
stats = {
|
|
39
|
+
hits: 0,
|
|
40
|
+
misses: 0,
|
|
41
|
+
evictions: 0,
|
|
42
|
+
startTime: Date.now(),
|
|
43
|
+
};
|
|
44
|
+
constructor(config) {
|
|
45
|
+
this.maxSize = config.maxSize;
|
|
46
|
+
this.defaultTTL = config.defaultTTL;
|
|
47
|
+
this.name = config.name || 'memory-cache';
|
|
48
|
+
// Validate configuration
|
|
49
|
+
if (this.maxSize <= 0) {
|
|
50
|
+
throw new Error('Cache maxSize must be greater than 0');
|
|
51
|
+
}
|
|
52
|
+
if (this.defaultTTL <= 0) {
|
|
53
|
+
throw new Error('Cache defaultTTL must be greater than 0');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Retrieve a value from cache
|
|
58
|
+
*
|
|
59
|
+
* @param key - Cache key to retrieve
|
|
60
|
+
* @returns Promise resolving to cached value or null if not found/expired
|
|
61
|
+
*/
|
|
62
|
+
async get(key) {
|
|
63
|
+
const entry = this.cache.get(key);
|
|
64
|
+
if (!entry) {
|
|
65
|
+
this.stats.misses++;
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
// Check expiration (lazy expiration)
|
|
69
|
+
if (entry.expiresAt && Date.now() > entry.expiresAt) {
|
|
70
|
+
this.removeEntry(entry);
|
|
71
|
+
this.stats.misses++;
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
// Move to head (mark as recently used)
|
|
75
|
+
this.moveToHead(entry);
|
|
76
|
+
this.stats.hits++;
|
|
77
|
+
return entry.value;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Store a value in cache with optional TTL
|
|
81
|
+
*
|
|
82
|
+
* @param key - Cache key to store under
|
|
83
|
+
* @param value - Value to cache
|
|
84
|
+
* @param ttlMs - Time to live in milliseconds (defaults to defaultTTL)
|
|
85
|
+
*/
|
|
86
|
+
async set(key, value, ttlMs) {
|
|
87
|
+
const ttl = ttlMs ?? this.defaultTTL;
|
|
88
|
+
const expiresAt = ttl > 0 ? Date.now() + ttl : undefined;
|
|
89
|
+
// Check if key already exists
|
|
90
|
+
const existingEntry = this.cache.get(key);
|
|
91
|
+
if (existingEntry) {
|
|
92
|
+
// Update existing entry
|
|
93
|
+
existingEntry.value = value;
|
|
94
|
+
existingEntry.expiresAt = expiresAt;
|
|
95
|
+
this.moveToHead(existingEntry);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
// Create new entry
|
|
99
|
+
const entry = {
|
|
100
|
+
key,
|
|
101
|
+
value,
|
|
102
|
+
expiresAt,
|
|
103
|
+
};
|
|
104
|
+
// Add to cache and linked list
|
|
105
|
+
this.cache.set(key, entry);
|
|
106
|
+
this.addToHead(entry);
|
|
107
|
+
// Evict oldest entry if cache is full
|
|
108
|
+
if (this.cache.size > this.maxSize) {
|
|
109
|
+
this.evictTail();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Delete a specific cache entry
|
|
114
|
+
*
|
|
115
|
+
* @param key - Cache key to delete
|
|
116
|
+
*/
|
|
117
|
+
async delete(key) {
|
|
118
|
+
const entry = this.cache.get(key);
|
|
119
|
+
if (entry) {
|
|
120
|
+
this.removeEntry(entry);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Delete multiple cache entries matching a pattern
|
|
125
|
+
*
|
|
126
|
+
* Supports simple wildcard patterns:
|
|
127
|
+
* - "user:*" matches all keys starting with "user:"
|
|
128
|
+
* - "*:123" matches all keys ending with ":123"
|
|
129
|
+
* - "*pattern*" matches all keys containing "pattern"
|
|
130
|
+
*
|
|
131
|
+
* @param pattern - Pattern to match keys
|
|
132
|
+
*/
|
|
133
|
+
async deletePattern(pattern) {
|
|
134
|
+
const regex = this.patternToRegex(pattern);
|
|
135
|
+
const keysToDelete = [];
|
|
136
|
+
// Collect matching keys
|
|
137
|
+
for (const key of this.cache.keys()) {
|
|
138
|
+
if (regex.test(key)) {
|
|
139
|
+
keysToDelete.push(key);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Delete matching entries
|
|
143
|
+
for (const key of keysToDelete) {
|
|
144
|
+
await this.delete(key);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Clear all cache entries
|
|
149
|
+
*/
|
|
150
|
+
async flush() {
|
|
151
|
+
this.cache.clear();
|
|
152
|
+
this.head = undefined;
|
|
153
|
+
this.tail = undefined;
|
|
154
|
+
this.stats.evictions += this.cache.size;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Get cache statistics for monitoring
|
|
158
|
+
*
|
|
159
|
+
* @returns Cache statistics including hit rate and memory usage
|
|
160
|
+
*/
|
|
161
|
+
async getStats() {
|
|
162
|
+
const totalRequests = this.stats.hits + this.stats.misses;
|
|
163
|
+
const hitRate = totalRequests > 0 ? (this.stats.hits / totalRequests) * 100 : 0;
|
|
164
|
+
// Estimate memory usage (rough approximation)
|
|
165
|
+
let memoryUsage = 0;
|
|
166
|
+
for (const entry of this.cache.values()) {
|
|
167
|
+
memoryUsage += this.estimateEntrySize(entry);
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
totalEntries: this.cache.size,
|
|
171
|
+
hits: this.stats.hits,
|
|
172
|
+
misses: this.stats.misses,
|
|
173
|
+
hitRate: Math.round(hitRate * 100) / 100, // Round to 2 decimal places
|
|
174
|
+
memoryUsage,
|
|
175
|
+
uptime: Date.now() - this.stats.startTime,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get cache name for debugging
|
|
180
|
+
*/
|
|
181
|
+
getName() {
|
|
182
|
+
return this.name;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get current cache size
|
|
186
|
+
*/
|
|
187
|
+
size() {
|
|
188
|
+
return this.cache.size;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Check if cache is at maximum capacity
|
|
192
|
+
*/
|
|
193
|
+
isFull() {
|
|
194
|
+
return this.cache.size >= this.maxSize;
|
|
195
|
+
}
|
|
196
|
+
// === Private LRU Implementation Methods ===
|
|
197
|
+
/**
|
|
198
|
+
* Add entry to head of linked list (most recently used)
|
|
199
|
+
*/
|
|
200
|
+
addToHead(entry) {
|
|
201
|
+
entry.prev = undefined;
|
|
202
|
+
entry.next = this.head;
|
|
203
|
+
if (this.head) {
|
|
204
|
+
this.head.prev = entry;
|
|
205
|
+
}
|
|
206
|
+
this.head = entry;
|
|
207
|
+
if (!this.tail) {
|
|
208
|
+
this.tail = entry;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Move existing entry to head of linked list
|
|
213
|
+
*/
|
|
214
|
+
moveToHead(entry) {
|
|
215
|
+
// Remove from current position
|
|
216
|
+
this.removeFromList(entry);
|
|
217
|
+
// Add to head
|
|
218
|
+
this.addToHead(entry);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Remove entry from linked list (but not from cache)
|
|
222
|
+
*/
|
|
223
|
+
removeFromList(entry) {
|
|
224
|
+
if (entry.prev) {
|
|
225
|
+
entry.prev.next = entry.next;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
// This was the head
|
|
229
|
+
this.head = entry.next;
|
|
230
|
+
}
|
|
231
|
+
if (entry.next) {
|
|
232
|
+
entry.next.prev = entry.prev;
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
// This was the tail
|
|
236
|
+
this.tail = entry.prev;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Remove entry from both cache and linked list
|
|
241
|
+
*/
|
|
242
|
+
removeEntry(entry) {
|
|
243
|
+
this.cache.delete(entry.key);
|
|
244
|
+
this.removeFromList(entry);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Evict least recently used entry (tail)
|
|
248
|
+
*/
|
|
249
|
+
evictTail() {
|
|
250
|
+
if (this.tail) {
|
|
251
|
+
this.removeEntry(this.tail);
|
|
252
|
+
this.stats.evictions++;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Convert glob pattern to regular expression
|
|
257
|
+
*/
|
|
258
|
+
patternToRegex(pattern) {
|
|
259
|
+
// Convert * to placeholder first to avoid escaping issues
|
|
260
|
+
const withPlaceholder = pattern.replace(/\*/g, '__WILDCARD__');
|
|
261
|
+
// Escape special regex characters
|
|
262
|
+
const escaped = withPlaceholder.replace(/[.+?^${}()|[\]\\]/g, '\\$&');
|
|
263
|
+
// Convert placeholder to regex equivalent
|
|
264
|
+
const regexPattern = escaped.replace(/__WILDCARD__/g, '.*');
|
|
265
|
+
return new RegExp(`^${regexPattern}$`);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Estimate memory usage of a cache entry (rough approximation)
|
|
269
|
+
*/
|
|
270
|
+
estimateEntrySize(entry) {
|
|
271
|
+
let size = 0;
|
|
272
|
+
// Key size (2 bytes per character for UTF-16)
|
|
273
|
+
size += entry.key.length * 2;
|
|
274
|
+
// Value size estimation
|
|
275
|
+
if (typeof entry.value === 'string') {
|
|
276
|
+
size += entry.value.length * 2;
|
|
277
|
+
}
|
|
278
|
+
else if (typeof entry.value === 'number') {
|
|
279
|
+
size += 8;
|
|
280
|
+
}
|
|
281
|
+
else if (typeof entry.value === 'boolean') {
|
|
282
|
+
size += 1;
|
|
283
|
+
}
|
|
284
|
+
else if (entry.value && typeof entry.value === 'object') {
|
|
285
|
+
// JSON string length as approximation
|
|
286
|
+
size += JSON.stringify(entry.value).length * 2;
|
|
287
|
+
}
|
|
288
|
+
// Overhead for entry object and pointers
|
|
289
|
+
size += 64;
|
|
290
|
+
return size;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
exports.MemoryCacheAdapter = MemoryCacheAdapter;
|
|
294
|
+
//# sourceMappingURL=MemoryCacheAdapter.js.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* No-Operation Cache Adapter
|
|
3
|
+
*
|
|
4
|
+
* A cache adapter implementation that doesn't actually cache anything.
|
|
5
|
+
* Useful for testing scenarios, disabled caching configurations, or
|
|
6
|
+
* development environments where cache behavior needs to be bypassed.
|
|
7
|
+
*
|
|
8
|
+
* All operations return immediately without storing or retrieving data,
|
|
9
|
+
* ensuring that the guard system can operate without caching when needed.
|
|
10
|
+
*
|
|
11
|
+
* @author Noony Framework Team
|
|
12
|
+
* @version 1.0.0
|
|
13
|
+
*/
|
|
14
|
+
import { CacheAdapter, CacheStats } from './CacheAdapter';
|
|
15
|
+
/**
|
|
16
|
+
* No-operation cache adapter that doesn't cache anything
|
|
17
|
+
*
|
|
18
|
+
* This implementation provides the CacheAdapter interface but performs
|
|
19
|
+
* no actual caching operations. All get operations return null, all set
|
|
20
|
+
* operations are ignored, and all delete operations are no-ops.
|
|
21
|
+
*
|
|
22
|
+
* Useful for:
|
|
23
|
+
* - Testing scenarios where caching should be disabled
|
|
24
|
+
* - Development environments with live data
|
|
25
|
+
* - Troubleshooting cache-related issues
|
|
26
|
+
* - Performance baseline measurements
|
|
27
|
+
*/
|
|
28
|
+
export declare class NoopCacheAdapter implements CacheAdapter {
|
|
29
|
+
private readonly startTime;
|
|
30
|
+
private readonly name;
|
|
31
|
+
private stats;
|
|
32
|
+
constructor(name?: string);
|
|
33
|
+
/**
|
|
34
|
+
* Always returns null (no caching)
|
|
35
|
+
*
|
|
36
|
+
* @param key - Cache key to retrieve (ignored)
|
|
37
|
+
* @returns Promise resolving to null
|
|
38
|
+
*/
|
|
39
|
+
get<T>(_key: string): Promise<T | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Does nothing (no caching)
|
|
42
|
+
*
|
|
43
|
+
* @param key - Cache key to store under (ignored)
|
|
44
|
+
* @param value - Value to cache (ignored)
|
|
45
|
+
* @param ttlMs - Time to live in milliseconds (ignored)
|
|
46
|
+
*/
|
|
47
|
+
set<T>(_key: string, _value: T, _ttlMs?: number): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Does nothing (no caching)
|
|
50
|
+
*
|
|
51
|
+
* @param key - Cache key to delete (ignored)
|
|
52
|
+
*/
|
|
53
|
+
delete(_key: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Does nothing (no caching)
|
|
56
|
+
*
|
|
57
|
+
* @param pattern - Pattern to match keys (ignored)
|
|
58
|
+
*/
|
|
59
|
+
deletePattern(_pattern: string): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Does nothing (no caching)
|
|
62
|
+
*/
|
|
63
|
+
flush(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Get statistics for monitoring
|
|
66
|
+
*
|
|
67
|
+
* Returns statistics about operations performed, even though
|
|
68
|
+
* no actual caching occurs. This helps with monitoring and
|
|
69
|
+
* understanding system behavior.
|
|
70
|
+
*
|
|
71
|
+
* @returns Cache statistics with 0% hit rate
|
|
72
|
+
*/
|
|
73
|
+
getStats(): Promise<CacheStats>;
|
|
74
|
+
/**
|
|
75
|
+
* Get adapter name for debugging
|
|
76
|
+
*/
|
|
77
|
+
getName(): string;
|
|
78
|
+
/**
|
|
79
|
+
* Get operation statistics for debugging
|
|
80
|
+
*/
|
|
81
|
+
getOperationStats(): {
|
|
82
|
+
gets: number;
|
|
83
|
+
sets: number;
|
|
84
|
+
deletes: number;
|
|
85
|
+
flushes: number;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Check if this is a no-op cache adapter
|
|
89
|
+
*
|
|
90
|
+
* Utility method for other components to detect when
|
|
91
|
+
* caching is disabled and adjust behavior accordingly.
|
|
92
|
+
*/
|
|
93
|
+
isNoop(): boolean;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=NoopCacheAdapter.d.ts.map
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* No-Operation Cache Adapter
|
|
4
|
+
*
|
|
5
|
+
* A cache adapter implementation that doesn't actually cache anything.
|
|
6
|
+
* Useful for testing scenarios, disabled caching configurations, or
|
|
7
|
+
* development environments where cache behavior needs to be bypassed.
|
|
8
|
+
*
|
|
9
|
+
* All operations return immediately without storing or retrieving data,
|
|
10
|
+
* ensuring that the guard system can operate without caching when needed.
|
|
11
|
+
*
|
|
12
|
+
* @author Noony Framework Team
|
|
13
|
+
* @version 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.NoopCacheAdapter = void 0;
|
|
17
|
+
/**
|
|
18
|
+
* No-operation cache adapter that doesn't cache anything
|
|
19
|
+
*
|
|
20
|
+
* This implementation provides the CacheAdapter interface but performs
|
|
21
|
+
* no actual caching operations. All get operations return null, all set
|
|
22
|
+
* operations are ignored, and all delete operations are no-ops.
|
|
23
|
+
*
|
|
24
|
+
* Useful for:
|
|
25
|
+
* - Testing scenarios where caching should be disabled
|
|
26
|
+
* - Development environments with live data
|
|
27
|
+
* - Troubleshooting cache-related issues
|
|
28
|
+
* - Performance baseline measurements
|
|
29
|
+
*/
|
|
30
|
+
class NoopCacheAdapter {
|
|
31
|
+
startTime = Date.now();
|
|
32
|
+
name;
|
|
33
|
+
// Track statistics even though we don't cache
|
|
34
|
+
stats = {
|
|
35
|
+
gets: 0,
|
|
36
|
+
sets: 0,
|
|
37
|
+
deletes: 0,
|
|
38
|
+
flushes: 0,
|
|
39
|
+
};
|
|
40
|
+
constructor(name = 'noop-cache') {
|
|
41
|
+
this.name = name;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Always returns null (no caching)
|
|
45
|
+
*
|
|
46
|
+
* @param key - Cache key to retrieve (ignored)
|
|
47
|
+
* @returns Promise resolving to null
|
|
48
|
+
*/
|
|
49
|
+
async get(_key) {
|
|
50
|
+
this.stats.gets++;
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Does nothing (no caching)
|
|
55
|
+
*
|
|
56
|
+
* @param key - Cache key to store under (ignored)
|
|
57
|
+
* @param value - Value to cache (ignored)
|
|
58
|
+
* @param ttlMs - Time to live in milliseconds (ignored)
|
|
59
|
+
*/
|
|
60
|
+
async set(_key, _value, _ttlMs) {
|
|
61
|
+
this.stats.sets++;
|
|
62
|
+
// Intentionally do nothing
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Does nothing (no caching)
|
|
66
|
+
*
|
|
67
|
+
* @param key - Cache key to delete (ignored)
|
|
68
|
+
*/
|
|
69
|
+
async delete(_key) {
|
|
70
|
+
this.stats.deletes++;
|
|
71
|
+
// Intentionally do nothing
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Does nothing (no caching)
|
|
75
|
+
*
|
|
76
|
+
* @param pattern - Pattern to match keys (ignored)
|
|
77
|
+
*/
|
|
78
|
+
async deletePattern(_pattern) {
|
|
79
|
+
this.stats.deletes++;
|
|
80
|
+
// Intentionally do nothing
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Does nothing (no caching)
|
|
84
|
+
*/
|
|
85
|
+
async flush() {
|
|
86
|
+
this.stats.flushes++;
|
|
87
|
+
// Intentionally do nothing
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get statistics for monitoring
|
|
91
|
+
*
|
|
92
|
+
* Returns statistics about operations performed, even though
|
|
93
|
+
* no actual caching occurs. This helps with monitoring and
|
|
94
|
+
* understanding system behavior.
|
|
95
|
+
*
|
|
96
|
+
* @returns Cache statistics with 0% hit rate
|
|
97
|
+
*/
|
|
98
|
+
async getStats() {
|
|
99
|
+
return {
|
|
100
|
+
totalEntries: 0, // Never stores anything
|
|
101
|
+
hits: 0, // Never hits (always returns null)
|
|
102
|
+
misses: this.stats.gets, // Every get is a miss
|
|
103
|
+
hitRate: 0, // Always 0% hit rate
|
|
104
|
+
memoryUsage: 0, // Uses no memory for caching
|
|
105
|
+
uptime: Date.now() - this.startTime,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get adapter name for debugging
|
|
110
|
+
*/
|
|
111
|
+
getName() {
|
|
112
|
+
return this.name;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get operation statistics for debugging
|
|
116
|
+
*/
|
|
117
|
+
getOperationStats() {
|
|
118
|
+
return { ...this.stats };
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Check if this is a no-op cache adapter
|
|
122
|
+
*
|
|
123
|
+
* Utility method for other components to detect when
|
|
124
|
+
* caching is disabled and adjust behavior accordingly.
|
|
125
|
+
*/
|
|
126
|
+
isNoop() {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.NoopCacheAdapter = NoopCacheAdapter;
|
|
131
|
+
//# sourceMappingURL=NoopCacheAdapter.js.map
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guard System Configuration
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive configuration system for the high-performance guard system.
|
|
5
|
+
* Provides type-safe configuration for different deployment environments with
|
|
6
|
+
* configurable performance strategies and security policies.
|
|
7
|
+
*
|
|
8
|
+
* Key Features:
|
|
9
|
+
* - Permission resolution strategy configuration (pre-expansion vs on-demand)
|
|
10
|
+
* - Cache adapter injection for different environments
|
|
11
|
+
* - Performance profiles for development, staging, and production
|
|
12
|
+
* - Security policies with conservative cache invalidation
|
|
13
|
+
* - Bounded complexity limits for patterns and expressions
|
|
14
|
+
*
|
|
15
|
+
* @author Noony Framework Team
|
|
16
|
+
* @version 1.0.0
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Permission resolution strategies for wildcard permissions
|
|
20
|
+
*
|
|
21
|
+
* PRE_EXPANSION: Expand wildcards at user context load time
|
|
22
|
+
* - Pros: Faster runtime permission checks (O(1) set lookups)
|
|
23
|
+
* - Cons: Higher memory usage, requires permission registry
|
|
24
|
+
*
|
|
25
|
+
* ON_DEMAND: Match wildcards at permission check time
|
|
26
|
+
* - Pros: Lower memory usage, supports dynamic permissions
|
|
27
|
+
* - Cons: Pattern matching overhead per request
|
|
28
|
+
*/
|
|
29
|
+
export declare enum PermissionResolutionStrategy {
|
|
30
|
+
PRE_EXPANSION = "pre-expansion",
|
|
31
|
+
ON_DEMAND = "on-demand"
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Cache invalidation strategies for security
|
|
35
|
+
*/
|
|
36
|
+
export declare enum CacheInvalidationStrategy {
|
|
37
|
+
FLUSH_ALL = "flush-all",
|
|
38
|
+
USER_SPECIFIC = "user-specific"
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Performance monitoring levels
|
|
42
|
+
*/
|
|
43
|
+
export declare enum MonitoringLevel {
|
|
44
|
+
NONE = "none",
|
|
45
|
+
BASIC = "basic",
|
|
46
|
+
DETAILED = "detailed",
|
|
47
|
+
VERBOSE = "verbose"
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Security configuration for the guard system
|
|
51
|
+
*/
|
|
52
|
+
export interface GuardSecurityConfig {
|
|
53
|
+
permissionResolutionStrategy: PermissionResolutionStrategy;
|
|
54
|
+
conservativeCacheInvalidation: boolean;
|
|
55
|
+
maxExpressionComplexity: number;
|
|
56
|
+
maxPatternDepth: number;
|
|
57
|
+
maxNestingDepth: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Cache configuration for the guard system
|
|
61
|
+
*/
|
|
62
|
+
export interface GuardCacheConfig {
|
|
63
|
+
maxEntries: number;
|
|
64
|
+
defaultTtlMs: number;
|
|
65
|
+
userContextTtlMs: number;
|
|
66
|
+
authTokenTtlMs: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Monitoring configuration for the guard system
|
|
70
|
+
*/
|
|
71
|
+
export interface GuardMonitoringConfig {
|
|
72
|
+
enablePerformanceTracking: boolean;
|
|
73
|
+
enableDetailedLogging: boolean;
|
|
74
|
+
logLevel: string;
|
|
75
|
+
metricsCollectionInterval: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Environment profile for guard system configuration
|
|
79
|
+
*/
|
|
80
|
+
export interface GuardEnvironmentProfile {
|
|
81
|
+
environment: string;
|
|
82
|
+
cacheType: 'memory' | 'redis' | 'none';
|
|
83
|
+
security: GuardSecurityConfig;
|
|
84
|
+
cache: GuardCacheConfig;
|
|
85
|
+
monitoring: GuardMonitoringConfig;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* GuardConfiguration class implementation
|
|
89
|
+
*/
|
|
90
|
+
export declare class GuardConfiguration {
|
|
91
|
+
readonly security: GuardSecurityConfig;
|
|
92
|
+
readonly cache: GuardCacheConfig;
|
|
93
|
+
readonly monitoring: GuardMonitoringConfig;
|
|
94
|
+
constructor(security: GuardSecurityConfig, cache: GuardCacheConfig, monitoring: GuardMonitoringConfig);
|
|
95
|
+
/**
|
|
96
|
+
* Create GuardConfiguration from environment profile
|
|
97
|
+
*/
|
|
98
|
+
static fromEnvironmentProfile(profile: GuardEnvironmentProfile): GuardConfiguration;
|
|
99
|
+
/**
|
|
100
|
+
* Create default development configuration
|
|
101
|
+
*/
|
|
102
|
+
static development(): GuardConfiguration;
|
|
103
|
+
/**
|
|
104
|
+
* Create default production configuration
|
|
105
|
+
*/
|
|
106
|
+
static production(): GuardConfiguration;
|
|
107
|
+
/**
|
|
108
|
+
* Validate configuration
|
|
109
|
+
*/
|
|
110
|
+
validate(): void;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=GuardConfiguration.d.ts.map
|