@plyaz/types 1.4.1 → 1.5.0

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.
@@ -1,4 +1,4 @@
1
- import type { CacheStrategy } from '../../../features';
1
+ import type { CacheEntry, CacheStats, CacheStrategy } from '../../../features';
2
2
  /**
3
3
  * Configuration for cache strategy test suite
4
4
  *
@@ -41,3 +41,131 @@ export interface CacheStrategyTestConfig {
41
41
  supportsStats?: boolean;
42
42
  cleanup?: (strategy: CacheStrategy) => Promise<void>;
43
43
  }
44
+ /**
45
+ * Cache interface for testing
46
+ * @interface Cache
47
+ * @typeParam T - Type of cached values
48
+ */
49
+ export interface Cache<T = unknown> {
50
+ /** Get value from cache */
51
+ get(key: string): Promise<T | null>;
52
+ /** Set value in cache */
53
+ set(key: string, value: T, ttl?: number): Promise<void>;
54
+ /** Delete value from cache */
55
+ delete(key: string): Promise<boolean>;
56
+ /** Clear all cache entries */
57
+ clear(): Promise<void>;
58
+ /** Get cache size */
59
+ size(): Promise<number>;
60
+ /** Get cache statistics */
61
+ getStats?(): CacheStats;
62
+ /** Get raw cache entry */
63
+ getRaw?(key: string): Promise<CacheEntry<T> | null>;
64
+ /** Set eviction callback */
65
+ onEviction?(callback: (key: string, value: T) => void): void;
66
+ /** Restore cache state (internal) */
67
+ __restore?: () => void;
68
+ }
69
+ /**
70
+ * Cache eviction configuration
71
+ * @interface EvictionConfig
72
+ */
73
+ export interface EvictionConfig {
74
+ /** Maximum cache size */
75
+ maxSize: number;
76
+ /** Eviction policy */
77
+ evictionPolicy: 'LRU' | 'LFU' | 'FIFO';
78
+ /** Number of items to add */
79
+ itemsToAdd: number;
80
+ /** Expected evicted keys */
81
+ expectedEvictions: string[];
82
+ }
83
+ /**
84
+ * Cache concurrency testing options
85
+ * @interface ConcurrencyOptions
86
+ */
87
+ export interface ConcurrencyOptions {
88
+ /** Number of operations */
89
+ operations: number;
90
+ /** Concurrency level */
91
+ concurrency: number;
92
+ /** Type of operations */
93
+ operationType: 'read' | 'write' | 'mixed';
94
+ }
95
+ /**
96
+ * TTL testing options
97
+ * @interface TTLOptions
98
+ */
99
+ export interface TTLOptions {
100
+ /** Cache key */
101
+ key: string;
102
+ /** Cache value */
103
+ value: unknown;
104
+ /** Time to live */
105
+ ttl: number;
106
+ /** Check intervals */
107
+ checkIntervals: number[];
108
+ }
109
+ /**
110
+ * TTL test result
111
+ * @interface TTLResult
112
+ */
113
+ export interface TTLResult {
114
+ /** Cache key */
115
+ key: string;
116
+ /** TTL value */
117
+ ttl: number;
118
+ /** Actual expiration time */
119
+ actualExpiration: number;
120
+ /** Expected expiration time */
121
+ expectedExpiration: number;
122
+ /** Whether within tolerance */
123
+ withinTolerance: boolean;
124
+ }
125
+ /**
126
+ * Memory usage testing options
127
+ * @interface MemoryOptions
128
+ */
129
+ export interface MemoryOptions {
130
+ /** Sample size for testing */
131
+ sampleSize: number;
132
+ /** Maximum memory limit in MB */
133
+ maxMemoryMB?: number;
134
+ }
135
+ /**
136
+ * Memory usage test result
137
+ * @interface MemoryResult
138
+ */
139
+ export interface MemoryResult {
140
+ /** Total memory usage in MB */
141
+ totalMemoryMB: number;
142
+ /** Average item size in KB */
143
+ avgItemSizeKB: number;
144
+ /** Number of items */
145
+ itemCount: number;
146
+ /** Whether within memory limit */
147
+ withinLimit: boolean;
148
+ }
149
+ /**
150
+ * Cache test harness
151
+ * @interface CacheTestHarness
152
+ * @typeParam T - Type of cached values
153
+ */
154
+ export interface CacheTestHarness<T = unknown> {
155
+ /** Cache instance */
156
+ cache: Cache<T>;
157
+ /** Fill cache with entries */
158
+ fillCache: (entries: Array<{
159
+ key: string;
160
+ value: T;
161
+ }>) => Promise<void>;
162
+ /** Measure cache performance */
163
+ measurePerformance: (operations: number) => Promise<{
164
+ avgReadMs: number;
165
+ avgWriteMs: number;
166
+ }>;
167
+ /** Simulate concurrent access */
168
+ simulateConcurrentAccess: (options: ConcurrencyOptions) => Promise<void>;
169
+ /** Reset cache state */
170
+ reset: () => Promise<void>;
171
+ }
@@ -99,7 +99,7 @@ export interface SetupFeatureFlagModuleMocks {
99
99
  /** Mock logger instance */
100
100
  mockLogger: MockLogger;
101
101
  /** Mock HTTP exception constructor */
102
- HttpException: Vitest.Mock;
102
+ HttpException: Vitest.MockInstance;
103
103
  /** HTTP status code constants */
104
104
  HttpStatus: Record<string, number>;
105
105
  }
@@ -250,25 +250,25 @@ export interface FeatureFlagScenarios<FeatureFlagKey extends string> {
250
250
  */
251
251
  export interface MockFeatureFlagProvider {
252
252
  /** Get a specific feature flag */
253
- getFlag: Vitest.Mock;
253
+ getFlag: Vitest.MockInstance;
254
254
  /** Get all feature flags */
255
- getAllFlags: Vitest.Mock;
255
+ getAllFlags: Vitest.MockInstance;
256
256
  /** Evaluate a feature flag */
257
- evaluateFlag: Vitest.Mock;
257
+ evaluateFlag: Vitest.MockInstance;
258
258
  /** Check if a flag is enabled */
259
- isEnabled: Vitest.Mock;
259
+ isEnabled: Vitest.MockInstance;
260
260
  /** Get a flag's value */
261
- getValue: Vitest.Mock;
261
+ getValue: Vitest.MockInstance;
262
262
  /** Update a feature flag */
263
- updateFlag: Vitest.Mock;
263
+ updateFlag: Vitest.MockInstance;
264
264
  /** Delete a feature flag */
265
- deleteFlag: Vitest.Mock;
265
+ deleteFlag: Vitest.MockInstance;
266
266
  /** Refresh flag data */
267
- refresh: Vitest.Mock;
267
+ refresh: Vitest.MockInstance;
268
268
  /** Subscribe to flag changes */
269
- subscribe: Vitest.Mock;
269
+ subscribe: Vitest.MockInstance;
270
270
  /** Unsubscribe from flag changes */
271
- unsubscribe: Vitest.Mock;
271
+ unsubscribe: Vitest.MockInstance;
272
272
  }
273
273
  /**
274
274
  * Mock feature flag repository interface for database operations testing
@@ -289,21 +289,21 @@ export interface MockFeatureFlagProvider {
289
289
  */
290
290
  export interface MockFeatureFlagRepository {
291
291
  /** Find a single flag by criteria */
292
- find: Vitest.Mock;
292
+ find: Vitest.MockInstance;
293
293
  /** Find all flags */
294
- findAll: Vitest.Mock;
294
+ findAll: Vitest.MockInstance;
295
295
  /** Create a new flag */
296
- create: Vitest.Mock;
296
+ create: Vitest.MockInstance;
297
297
  /** Update an existing flag */
298
- update: Vitest.Mock;
298
+ update: Vitest.MockInstance;
299
299
  /** Delete a flag */
300
- delete: Vitest.Mock;
300
+ delete: Vitest.MockInstance;
301
301
  /** Save a flag */
302
- save: Vitest.Mock;
302
+ save: Vitest.MockInstance;
303
303
  /** Check if a flag exists */
304
- exists: Vitest.Mock;
304
+ exists: Vitest.MockInstance;
305
305
  /** Count total flags */
306
- count: Vitest.Mock;
306
+ count: Vitest.MockInstance;
307
307
  }
308
308
  /**
309
309
  * Mock feature flag service interface for business logic testing
@@ -324,21 +324,21 @@ export interface MockFeatureFlagRepository {
324
324
  */
325
325
  export interface MockFeatureFlagService {
326
326
  /** Evaluate a single flag */
327
- evaluate: Vitest.Mock;
327
+ evaluate: Vitest.MockInstance;
328
328
  /** Evaluate all flags */
329
- evaluateAll: Vitest.Mock;
329
+ evaluateAll: Vitest.MockInstance;
330
330
  /** Check if flag is enabled */
331
- isEnabled: Vitest.Mock;
331
+ isEnabled: Vitest.MockInstance;
332
332
  /** Get flag value */
333
- getValue: Vitest.Mock;
333
+ getValue: Vitest.MockInstance;
334
334
  /** Get flag variation */
335
- getVariation: Vitest.Mock;
335
+ getVariation: Vitest.MockInstance;
336
336
  /** Track flag usage */
337
- track: Vitest.Mock;
337
+ track: Vitest.MockInstance;
338
338
  /** Refresh flag data */
339
- refresh: Vitest.Mock;
339
+ refresh: Vitest.MockInstance;
340
340
  /** Clear cache */
341
- invalidateCache: Vitest.Mock;
341
+ invalidateCache: Vitest.MockInstance;
342
342
  }
343
343
  /**
344
344
  * Mock feature flag evaluation engine interface for testing flag logic
@@ -356,15 +356,15 @@ export interface MockFeatureFlagService {
356
356
  */
357
357
  export interface MockFeatureFlagEngine {
358
358
  /** Evaluate flag with context */
359
- evaluate: Vitest.Mock;
359
+ evaluate: Vitest.MockInstance;
360
360
  /** Evaluate conditions */
361
- evaluateConditions: Vitest.Mock;
361
+ evaluateConditions: Vitest.MockInstance;
362
362
  /** Check rollout eligibility */
363
- checkRollout: Vitest.Mock;
363
+ checkRollout: Vitest.MockInstance;
364
364
  /** Calculate variation */
365
- calculateVariation: Vitest.Mock;
365
+ calculateVariation: Vitest.MockInstance;
366
366
  /** Get default value */
367
- getDefaultValue: Vitest.Mock;
367
+ getDefaultValue: Vitest.MockInstance;
368
368
  }
369
369
  /**
370
370
  * Mock feature flag cache interface for testing caching behavior
@@ -385,21 +385,21 @@ export interface MockFeatureFlagEngine {
385
385
  */
386
386
  export interface MockFeatureFlagCache {
387
387
  /** Get cached value */
388
- get: Vitest.Mock;
388
+ get: Vitest.MockInstance;
389
389
  /** Set cache value */
390
- set: Vitest.Mock;
390
+ set: Vitest.MockInstance;
391
391
  /** Delete cached value */
392
- delete: Vitest.Mock;
392
+ delete: Vitest.MockInstance;
393
393
  /** Clear all cache */
394
- clear: Vitest.Mock;
394
+ clear: Vitest.MockInstance;
395
395
  /** Check if key exists */
396
- has: Vitest.Mock;
396
+ has: Vitest.MockInstance;
397
397
  /** Get all cache keys */
398
- keys: Vitest.Mock;
398
+ keys: Vitest.MockInstance;
399
399
  /** Get all cache values */
400
- values: Vitest.Mock;
400
+ values: Vitest.MockInstance;
401
401
  /** Get cache size */
402
- size: Vitest.Mock;
402
+ size: Vitest.MockInstance;
403
403
  }
404
404
  /**
405
405
  * Test context for feature flag testing with React components
@@ -1076,7 +1076,7 @@ export interface SubscriptionFeatureFlagTracker<FeatureFlagKey extends string> {
1076
1076
  /** Track a new subscription */
1077
1077
  track: (provider: IFeatureFlagProvider<FeatureFlagKey>, id?: string) => {
1078
1078
  id: string;
1079
- callback: Vitest.Mock;
1079
+ callback: Vitest.MockInstance;
1080
1080
  unsubscribe: () => void;
1081
1081
  };
1082
1082
  /** Unsubscribe by ID */
@@ -1369,3 +1369,165 @@ export interface FileProviderTestScenario<FeatureFlagKey extends string> extends
1369
1369
  /** Wait for file system changes to propagate */
1370
1370
  waitForFileChange: (ms?: number) => Promise<void>;
1371
1371
  }
1372
+ /**
1373
+ * Feature flag service interface for NestJS
1374
+ * @interface FeatureFlagService
1375
+ */
1376
+ export interface FeatureFlagService {
1377
+ /** Logger instance */
1378
+ logger: unknown;
1379
+ /** Feature flag provider */
1380
+ provider: unknown;
1381
+ /** Check if feature is enabled */
1382
+ isEnabled: (key: string, context?: Record<string, unknown>) => Promise<boolean>;
1383
+ /** Get feature value */
1384
+ getValue: <T>(key: string, defaultValue: T, context?: Record<string, unknown>) => Promise<T>;
1385
+ /** Get all features */
1386
+ getAll: () => Promise<Record<string, unknown>>;
1387
+ /** Refresh feature flags */
1388
+ refresh: () => Promise<void>;
1389
+ }
1390
+ /**
1391
+ * Feature flag repository interface for NestJS
1392
+ * @interface FeatureFlagRepository
1393
+ * @typeParam FeatureFlagKey - Type of feature flag keys
1394
+ */
1395
+ export interface FeatureFlagRepository<FeatureFlagKey extends string> {
1396
+ /** Logger instance */
1397
+ logger: unknown;
1398
+ /** Find feature flag by key */
1399
+ findByKey: (key: FeatureFlagKey) => Promise<unknown>;
1400
+ /** Create new feature flag */
1401
+ create: (key: FeatureFlagKey, data: unknown) => Promise<unknown>;
1402
+ /** Update feature flag */
1403
+ update: (key: FeatureFlagKey, data: unknown) => Promise<unknown>;
1404
+ /** Delete feature flag */
1405
+ delete: (key: FeatureFlagKey) => Promise<void>;
1406
+ /** Find all feature flags */
1407
+ findAll: () => Promise<Array<{
1408
+ key: FeatureFlagKey;
1409
+ data: unknown;
1410
+ }>>;
1411
+ }
1412
+ /**
1413
+ * Rollout configuration for testing
1414
+ * @interface RolloutConfig
1415
+ * @typeParam T - Type of feature flag keys
1416
+ */
1417
+ export interface RolloutConfig<T extends string> {
1418
+ /** Feature flag key */
1419
+ flagKey: T;
1420
+ /** Starting rollout percentage */
1421
+ startPercentage: number;
1422
+ /** Ending rollout percentage */
1423
+ endPercentage: number;
1424
+ /** Duration of rollout */
1425
+ duration: number;
1426
+ }
1427
+ /**
1428
+ * Rollout scenario for testing
1429
+ * @interface RolloutScenario
1430
+ * @typeParam T - Type of feature flag keys
1431
+ */
1432
+ export interface RolloutScenario<T extends string> {
1433
+ /** Rollout configuration */
1434
+ config: RolloutConfig<T>;
1435
+ /** Get current percentage */
1436
+ getCurrentPercentage: () => number;
1437
+ /** Update percentage */
1438
+ updatePercentage: (percentage: number) => void;
1439
+ /** Check if flag is enabled for user */
1440
+ isEnabledForUser: (userId: string) => boolean;
1441
+ }
1442
+ /**
1443
+ * A/B test configuration
1444
+ * @interface ABTestConfig
1445
+ * @typeParam T - Type of feature flag keys
1446
+ */
1447
+ export interface ABTestConfig<T extends string> {
1448
+ /** Feature flag key */
1449
+ flagKey: T;
1450
+ /** Test variants */
1451
+ variants: {
1452
+ /** Variant A configuration */
1453
+ A: {
1454
+ /** Variant percentage */
1455
+ percentage: number;
1456
+ /** Variant value */
1457
+ value: FeatureFlagValue;
1458
+ };
1459
+ /** Variant B configuration */
1460
+ B: {
1461
+ /** Variant percentage */
1462
+ percentage: number;
1463
+ /** Variant value */
1464
+ value: FeatureFlagValue;
1465
+ };
1466
+ };
1467
+ /** Test duration */
1468
+ duration?: number;
1469
+ /** Target audience */
1470
+ audience?: {
1471
+ /** Include criteria */
1472
+ include?: string[];
1473
+ /** Exclude criteria */
1474
+ exclude?: string[];
1475
+ };
1476
+ }
1477
+ /**
1478
+ * A/B test scenario for testing
1479
+ * @interface ABTestScenario
1480
+ * @typeParam T - Type of feature flag keys
1481
+ */
1482
+ export interface CreateABTestScenario<T extends string> {
1483
+ /** A/B test configuration */
1484
+ config: ABTestConfig<T>;
1485
+ /** Get variant for user */
1486
+ getVariantForUser: (userId: string, attributes?: Record<string, unknown>) => FeatureFlagValue;
1487
+ /** Get variant statistics */
1488
+ getVariantStats: () => {
1489
+ /** Variant A statistics */
1490
+ A: {
1491
+ count: number;
1492
+ percentage: number;
1493
+ };
1494
+ /** Variant B statistics */
1495
+ B: {
1496
+ count: number;
1497
+ percentage: number;
1498
+ };
1499
+ };
1500
+ /** Reset test state */
1501
+ reset: () => void;
1502
+ }
1503
+ /**
1504
+ * Flag defaults interface
1505
+ * @interface FlagDefaults
1506
+ */
1507
+ export interface FlagDefaults {
1508
+ /** Flag name */
1509
+ name: string;
1510
+ /** Flag description */
1511
+ description: string;
1512
+ /** Whether flag is enabled */
1513
+ isEnabled: boolean;
1514
+ /** Default value */
1515
+ value: FeatureFlagValue;
1516
+ /** Flag type */
1517
+ type: FlagType;
1518
+ /** Environment */
1519
+ environment: 'development' | 'staging' | 'production' | 'all';
1520
+ /** Created date */
1521
+ createdAt: Date;
1522
+ /** Updated date */
1523
+ updatedAt: Date;
1524
+ /** Created by */
1525
+ createdBy: string;
1526
+ /** Updated by */
1527
+ updatedBy: string;
1528
+ }
1529
+ /**
1530
+ * Feature flag value type
1531
+ * @type FlagType
1532
+ */
1533
+ export type FlagType = 'boolean' | 'string' | 'number' | 'json';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plyaz/types",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "author": "Redeemer Pace",
5
5
  "license": "ISC",
6
6
  "description": "Provides shared TypeScript types and schema utilities for validation and parsing in the @playz ecosystem.",