@plyaz/types 1.5.1 → 1.5.2
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/dist/features/feature-flag/types.d.ts +28 -4
- package/dist/testing/common/factories/types.d.ts +92 -56
- package/dist/testing/common/mocks/types.d.ts +543 -333
- package/dist/testing/common/patterns/types.d.ts +28 -10
- package/dist/testing/common/utils/types.d.ts +559 -400
- package/dist/testing/features/cache/types.d.ts +127 -54
- package/dist/testing/features/feature-flags/types.d.ts +249 -128
- package/package.json +1 -1
|
@@ -42,130 +42,203 @@ export interface CacheStrategyTestConfig {
|
|
|
42
42
|
cleanup?: (strategy: CacheStrategy) => Promise<void>;
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
45
|
+
* Generic cache interface for testing different cache implementations.
|
|
46
|
+
* Provides standard cache operations for testing.
|
|
47
|
+
*
|
|
48
|
+
* @template T - Type of cached values
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const cache: Cache<string> = {
|
|
53
|
+
* get: async (key) => storage.get(key),
|
|
54
|
+
* set: async (key, value, ttl) => storage.set(key, value, ttl),
|
|
55
|
+
* has: async (key) => storage.has(key),
|
|
56
|
+
* delete: async (key) => storage.delete(key),
|
|
57
|
+
* clear: async () => storage.clear(),
|
|
58
|
+
* size: async () => storage.size(),
|
|
59
|
+
* keys: async () => storage.keys(),
|
|
60
|
+
* values: async () => storage.values(),
|
|
61
|
+
* entries: async () => storage.entries()
|
|
62
|
+
* };
|
|
63
|
+
* ```
|
|
48
64
|
*/
|
|
49
65
|
export interface Cache<T = unknown> {
|
|
50
|
-
/** Get value from cache */
|
|
51
66
|
get(key: string): Promise<T | null>;
|
|
52
|
-
/** Set value in cache */
|
|
53
67
|
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
54
|
-
/** Delete value from cache */
|
|
55
68
|
delete(key: string): Promise<boolean>;
|
|
56
|
-
/** Clear all cache entries */
|
|
57
69
|
clear(): Promise<void>;
|
|
58
|
-
/** Get cache size */
|
|
59
70
|
size(): Promise<number>;
|
|
60
|
-
/** Get cache statistics */
|
|
61
71
|
getStats?(): CacheStats;
|
|
62
|
-
/** Get raw cache entry */
|
|
63
72
|
getRaw?(key: string): Promise<CacheEntry<T> | null>;
|
|
64
|
-
/** Set eviction callback */
|
|
65
73
|
onEviction?(callback: (key: string, value: T) => void): void;
|
|
66
|
-
/** Restore cache state (internal) */
|
|
67
74
|
__restore?: () => void;
|
|
68
75
|
}
|
|
69
76
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
77
|
+
* Configuration for cache eviction policies.
|
|
78
|
+
* Defines rules for removing cached entries when limits are reached.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const evictionConfig: EvictionConfig = {
|
|
83
|
+
* strategy: 'LRU',
|
|
84
|
+
* maxSize: 1000,
|
|
85
|
+
* maxAge: 60000, // 1 minute
|
|
86
|
+
* onEvict: (key, value) => {
|
|
87
|
+
* console.log(`Evicted ${key}`);
|
|
88
|
+
* }
|
|
89
|
+
* };
|
|
90
|
+
* ```
|
|
72
91
|
*/
|
|
73
92
|
export interface EvictionConfig {
|
|
74
|
-
/** Maximum cache size */
|
|
75
93
|
maxSize: number;
|
|
76
|
-
/** Eviction policy */
|
|
77
94
|
evictionPolicy: 'LRU' | 'LFU' | 'FIFO';
|
|
78
|
-
/** Number of items to add */
|
|
79
95
|
itemsToAdd: number;
|
|
80
|
-
/** Expected evicted keys */
|
|
81
96
|
expectedEvictions: string[];
|
|
82
97
|
}
|
|
83
98
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
99
|
+
* Options for testing cache behavior under concurrent access.
|
|
100
|
+
* Configures parallel operations and race condition testing.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const concurrencyOptions: ConcurrencyOptions = {
|
|
105
|
+
* workers: 10,
|
|
106
|
+
* operationsPerWorker: 100,
|
|
107
|
+
* operationMix: {
|
|
108
|
+
* get: 0.7,
|
|
109
|
+
* set: 0.2,
|
|
110
|
+
* delete: 0.1
|
|
111
|
+
* },
|
|
112
|
+
* conflictResolution: 'last-write-wins'
|
|
113
|
+
* };
|
|
114
|
+
* ```
|
|
86
115
|
*/
|
|
87
116
|
export interface ConcurrencyOptions {
|
|
88
|
-
/** Number of operations */
|
|
89
117
|
operations: number;
|
|
90
|
-
/** Concurrency level */
|
|
91
118
|
concurrency: number;
|
|
92
|
-
/** Type of operations */
|
|
93
119
|
operationType: 'read' | 'write' | 'mixed';
|
|
94
120
|
}
|
|
95
121
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
122
|
+
* Options for testing time-to-live (TTL) functionality.
|
|
123
|
+
* Configures expiration behavior and cleanup testing.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const ttlOptions: TTLOptions = {
|
|
128
|
+
* defaultTTL: 5000,
|
|
129
|
+
* checkInterval: 1000,
|
|
130
|
+
* extendOnAccess: true,
|
|
131
|
+
* variableTTL: true,
|
|
132
|
+
* minTTL: 100,
|
|
133
|
+
* maxTTL: 60000
|
|
134
|
+
* };
|
|
135
|
+
* ```
|
|
98
136
|
*/
|
|
99
137
|
export interface TTLOptions {
|
|
100
|
-
/** Cache key */
|
|
101
138
|
key: string;
|
|
102
|
-
/** Cache value */
|
|
103
139
|
value: unknown;
|
|
104
|
-
/** Time to live */
|
|
105
140
|
ttl: number;
|
|
106
|
-
/** Check intervals */
|
|
107
141
|
checkIntervals: number[];
|
|
108
142
|
}
|
|
109
143
|
/**
|
|
110
|
-
* TTL
|
|
111
|
-
*
|
|
144
|
+
* Results from TTL functionality testing.
|
|
145
|
+
* Contains metrics and validation outcomes for expiration behavior.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const ttlResult: TTLResult = {
|
|
150
|
+
* totalEntries: 100,
|
|
151
|
+
* expiredEntries: 45,
|
|
152
|
+
* averageLifetime: 4500,
|
|
153
|
+
* expirationAccuracy: 0.98,
|
|
154
|
+
* cleanupEfficiency: 0.95,
|
|
155
|
+
* errors: []
|
|
156
|
+
* };
|
|
157
|
+
* ```
|
|
112
158
|
*/
|
|
113
159
|
export interface TTLResult {
|
|
114
|
-
/** Cache key */
|
|
115
160
|
key: string;
|
|
116
|
-
/** TTL value */
|
|
117
161
|
ttl: number;
|
|
118
|
-
/** Actual expiration time */
|
|
119
162
|
actualExpiration: number;
|
|
120
|
-
/** Expected expiration time */
|
|
121
163
|
expectedExpiration: number;
|
|
122
|
-
/** Whether within tolerance */
|
|
123
164
|
withinTolerance: boolean;
|
|
124
165
|
}
|
|
125
166
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
167
|
+
* Options for testing cache memory usage and limits.
|
|
168
|
+
* Configures memory profiling and limit enforcement testing.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const memoryOptions: MemoryOptions = {
|
|
173
|
+
* maxMemory: 50 * 1024 * 1024, // 50MB
|
|
174
|
+
* measureInterval: 1000,
|
|
175
|
+
* includeOverhead: true,
|
|
176
|
+
* trackGrowthRate: true,
|
|
177
|
+
* warnThreshold: 0.8,
|
|
178
|
+
* errorThreshold: 0.95
|
|
179
|
+
* };
|
|
180
|
+
* ```
|
|
128
181
|
*/
|
|
129
182
|
export interface MemoryOptions {
|
|
130
|
-
/** Sample size for testing */
|
|
131
183
|
sampleSize: number;
|
|
132
|
-
/** Maximum memory limit in MB */
|
|
133
184
|
maxMemoryMB?: number;
|
|
134
185
|
}
|
|
135
186
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
187
|
+
* Results from memory usage testing.
|
|
188
|
+
* Contains memory metrics and limit compliance data.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* const memoryResult: MemoryResult = {
|
|
193
|
+
* totalMemoryMB: 45,
|
|
194
|
+
* avgItemSizeKB: 6,
|
|
195
|
+
* itemCount: 5000,
|
|
196
|
+
* withinLimit: true
|
|
197
|
+
* };
|
|
198
|
+
* ```
|
|
138
199
|
*/
|
|
139
200
|
export interface MemoryResult {
|
|
140
|
-
/** Total memory usage in MB */
|
|
141
201
|
totalMemoryMB: number;
|
|
142
|
-
/** Average item size in KB */
|
|
143
202
|
avgItemSizeKB: number;
|
|
144
|
-
/** Number of items */
|
|
145
203
|
itemCount: number;
|
|
146
|
-
/** Whether within memory limit */
|
|
147
204
|
withinLimit: boolean;
|
|
148
205
|
}
|
|
149
206
|
/**
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
207
|
+
* Test harness for comprehensive cache testing.
|
|
208
|
+
* Provides utilities for testing cache implementations.
|
|
209
|
+
*
|
|
210
|
+
* @template T - Type of cached values
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* const harness: CacheTestHarness<UserData> = {
|
|
215
|
+
* cache: new LRUCache<UserData>(),
|
|
216
|
+
* fillCache: async (entries) => {
|
|
217
|
+
* for (const { key, value } of entries) {
|
|
218
|
+
* await harness.cache.set(key, value);
|
|
219
|
+
* }
|
|
220
|
+
* },
|
|
221
|
+
* measurePerformance: async (ops) => {
|
|
222
|
+
* // Measure read/write performance
|
|
223
|
+
* return { avgReadMs: 0.5, avgWriteMs: 1.2 };
|
|
224
|
+
* },
|
|
225
|
+
* simulateConcurrentAccess: async (options) => {
|
|
226
|
+
* // Simulate concurrent operations
|
|
227
|
+
* },
|
|
228
|
+
* reset: async () => harness.cache.clear()
|
|
229
|
+
* };
|
|
230
|
+
* ```
|
|
153
231
|
*/
|
|
154
232
|
export interface CacheTestHarness<T = unknown> {
|
|
155
|
-
/** Cache instance */
|
|
156
233
|
cache: Cache<T>;
|
|
157
|
-
/** Fill cache with entries */
|
|
158
234
|
fillCache: (entries: Array<{
|
|
159
235
|
key: string;
|
|
160
236
|
value: T;
|
|
161
237
|
}>) => Promise<void>;
|
|
162
|
-
/** Measure cache performance */
|
|
163
238
|
measurePerformance: (operations: number) => Promise<{
|
|
164
239
|
avgReadMs: number;
|
|
165
240
|
avgWriteMs: number;
|
|
166
241
|
}>;
|
|
167
|
-
/** Simulate concurrent access */
|
|
168
242
|
simulateConcurrentAccess: (options: ConcurrencyOptions) => Promise<void>;
|
|
169
|
-
/** Reset cache state */
|
|
170
243
|
reset: () => Promise<void>;
|
|
171
244
|
}
|