@plyaz/types 1.3.2 → 1.3.4
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/api/index.d.ts +1 -0
- package/dist/api/types.d.ts +84 -0
- package/dist/auth/enums.d.ts +32 -0
- package/dist/auth/index.d.ts +3 -0
- package/dist/auth/schemas.d.ts +27 -0
- package/dist/auth/types.d.ts +34 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/types.d.ts +22 -0
- package/dist/entities/index.d.ts +1 -0
- package/dist/errors/enums.d.ts +33 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/types.d.ts +79 -0
- package/dist/events/enums.d.ts +25 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/payload.d.ts +6 -0
- package/dist/events/types.d.ts +136 -0
- package/dist/features/cache/index.d.ts +1 -0
- package/dist/features/cache/types.d.ts +142 -0
- package/dist/features/feature-flag/index.d.ts +1 -0
- package/dist/features/feature-flag/types.d.ts +491 -0
- package/dist/features/index.d.ts +2 -0
- package/dist/index.d.ts +13 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/testing/common/assertions/index.d.ts +1 -0
- package/dist/testing/common/assertions/types.d.ts +137 -0
- package/dist/testing/common/factories/index.d.ts +1 -0
- package/dist/testing/common/factories/types.d.ts +701 -0
- package/dist/testing/common/index.d.ts +6 -0
- package/dist/testing/common/mocks/index.d.ts +1 -0
- package/dist/testing/common/mocks/types.d.ts +1662 -0
- package/dist/testing/common/patterns/index.d.ts +1 -0
- package/dist/testing/common/patterns/types.d.ts +397 -0
- package/dist/testing/common/utils/index.d.ts +1 -0
- package/dist/testing/common/utils/types.d.ts +1970 -0
- package/dist/testing/common/wrappers/index.d.ts +1 -0
- package/dist/testing/common/wrappers/types.d.ts +373 -0
- package/dist/testing/features/cache/index.d.ts +1 -0
- package/dist/testing/features/cache/types.d.ts +43 -0
- package/dist/testing/features/feature-flags/index.d.ts +1 -0
- package/dist/testing/features/feature-flags/types.d.ts +1133 -0
- package/dist/testing/features/index.d.ts +2 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/translations/index.d.ts +1 -0
- package/dist/translations/types.d.ts +390 -0
- package/dist/ui/index.d.ts +1 -0
- package/dist/web3/enums.d.ts +17 -0
- package/dist/web3/index.d.ts +2 -0
- package/dist/web3/types.d.ts +63 -0
- package/package.json +5 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './types';
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Testing Pattern Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for common testing patterns including batch operations,
|
|
5
|
+
* CRUD operations, and test result management. Provides standardized interfaces
|
|
6
|
+
* for building scalable and maintainable test suites.
|
|
7
|
+
*
|
|
8
|
+
* This module includes types for:
|
|
9
|
+
* - Operation types and interfaces (CRUD + custom)
|
|
10
|
+
* - Batch processing and operation results
|
|
11
|
+
* - Test helpers and mock handlers
|
|
12
|
+
* - Progress tracking and error handling
|
|
13
|
+
* - Concurrent operation management
|
|
14
|
+
* - Stream processing for large datasets
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import type {
|
|
19
|
+
* Operation,
|
|
20
|
+
* BatchOperationResult,
|
|
21
|
+
* CreateBatchProcessorReturn
|
|
22
|
+
* } from './types';
|
|
23
|
+
*
|
|
24
|
+
* // Define operations
|
|
25
|
+
* const operations: Operation<User>[] = [
|
|
26
|
+
* { type: 'create', data: { name: 'John' } },
|
|
27
|
+
* { type: 'update', data: { id: 1, name: 'Jane' } },
|
|
28
|
+
* { type: 'delete', data: { id: 2 } }
|
|
29
|
+
* ];
|
|
30
|
+
*
|
|
31
|
+
* // Process operations in batch
|
|
32
|
+
* const processor: CreateBatchProcessorReturn<User> = createBatchProcessor({
|
|
33
|
+
* batchSize: 10,
|
|
34
|
+
* concurrency: 3
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* const result: BatchOperationResult<User> = await processor.process(operations);
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @module TestingPatternTypes
|
|
41
|
+
* @since 1.0.0
|
|
42
|
+
*/
|
|
43
|
+
import type * as Vitest from 'vitest';
|
|
44
|
+
/**
|
|
45
|
+
* Base operation types for CRUD and custom operations
|
|
46
|
+
*
|
|
47
|
+
* Defines the standard operation types supported by the testing framework.
|
|
48
|
+
* Covers basic CRUD operations plus custom operations for specialized testing.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const userOperations: OperationType[] = ['create', 'read', 'update', 'delete'];
|
|
53
|
+
* const customOperation: OperationType = 'custom';
|
|
54
|
+
*
|
|
55
|
+
* // Use in operation definitions
|
|
56
|
+
* const createUser: Operation = { type: 'create', data: userData };
|
|
57
|
+
* const validateData: Operation = { type: 'custom', data: validationRules };
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export type OperationType = 'create' | 'update' | 'delete' | 'read' | 'custom';
|
|
61
|
+
/**
|
|
62
|
+
* Generic operation interface for testing patterns
|
|
63
|
+
*
|
|
64
|
+
* Represents a single operation to be performed during testing. Supports
|
|
65
|
+
* any operation type with optional data payload and metadata for tracking.
|
|
66
|
+
*
|
|
67
|
+
* @typeParam T - Type of data associated with the operation
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* // User management operations
|
|
72
|
+
* const createUser: Operation<CreateUserData> = {
|
|
73
|
+
* id: 'op-1',
|
|
74
|
+
* type: 'create',
|
|
75
|
+
* data: { name: 'John Doe', email: 'john@example.com' },
|
|
76
|
+
* metadata: { timestamp: Date.now(), source: 'test-suite' }
|
|
77
|
+
* };
|
|
78
|
+
*
|
|
79
|
+
* const updateUser: Operation<UpdateUserData> = {
|
|
80
|
+
* id: 'op-2',
|
|
81
|
+
* type: 'update',
|
|
82
|
+
* data: { id: 1, name: 'Jane Doe' },
|
|
83
|
+
* metadata: { reason: 'name-change' }
|
|
84
|
+
* };
|
|
85
|
+
*
|
|
86
|
+
* const deleteUser: Operation<{ id: number }> = {
|
|
87
|
+
* id: 'op-3',
|
|
88
|
+
* type: 'delete',
|
|
89
|
+
* data: { id: 1 }
|
|
90
|
+
* };
|
|
91
|
+
*
|
|
92
|
+
* // Custom validation operation
|
|
93
|
+
* const validateData: Operation<ValidationRules> = {
|
|
94
|
+
* type: 'custom',
|
|
95
|
+
* data: { rules: ['required', 'email'], field: 'userEmail' },
|
|
96
|
+
* metadata: { validator: 'email-validator' }
|
|
97
|
+
* };
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export interface Operation<T = unknown> {
|
|
101
|
+
id?: string;
|
|
102
|
+
type: OperationType;
|
|
103
|
+
data?: T;
|
|
104
|
+
metadata?: Record<string, unknown>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Result of a single operation execution
|
|
108
|
+
*
|
|
109
|
+
* Contains the outcome of executing an operation, including success status,
|
|
110
|
+
* result data, error information, and performance metrics.
|
|
111
|
+
*
|
|
112
|
+
* @typeParam T - Type of data returned by the operation
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* // Successful operation result
|
|
117
|
+
* const successResult: OperationResult<User> = {
|
|
118
|
+
* id: 'op-1',
|
|
119
|
+
* success: true,
|
|
120
|
+
* data: { id: 1, name: 'John Doe', email: 'john@example.com' },
|
|
121
|
+
* duration: 250 // milliseconds
|
|
122
|
+
* };
|
|
123
|
+
*
|
|
124
|
+
* // Failed operation result
|
|
125
|
+
* const failureResult: OperationResult<User> = {
|
|
126
|
+
* id: 'op-2',
|
|
127
|
+
* success: false,
|
|
128
|
+
* error: new Error('User validation failed'),
|
|
129
|
+
* duration: 100
|
|
130
|
+
* };
|
|
131
|
+
*
|
|
132
|
+
* // Process results
|
|
133
|
+
* function handleResult(result: OperationResult<User>) {
|
|
134
|
+
* if (result.success) {
|
|
135
|
+
* console.log('Created user:', result.data?.name);
|
|
136
|
+
* } else {
|
|
137
|
+
* console.error('Operation failed:', result.error?.message);
|
|
138
|
+
* }
|
|
139
|
+
*
|
|
140
|
+
* if (result.duration && result.duration > 1000) {
|
|
141
|
+
* console.warn('Slow operation detected:', result.duration, 'ms');
|
|
142
|
+
* }
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export interface OperationResult<T = unknown> {
|
|
147
|
+
id?: string;
|
|
148
|
+
success: boolean;
|
|
149
|
+
data?: T;
|
|
150
|
+
error?: Error;
|
|
151
|
+
duration?: number;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Result of batch operation processing
|
|
155
|
+
*
|
|
156
|
+
* Aggregates results from multiple operations processed as a batch,
|
|
157
|
+
* providing summary statistics, individual results, and error tracking.
|
|
158
|
+
*
|
|
159
|
+
* @typeParam T - Type of data processed in the batch operations
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* // Process a batch of user operations
|
|
164
|
+
* const batchResult: BatchOperationResult<User> = {
|
|
165
|
+
* totalOperations: 100,
|
|
166
|
+
* successCount: 95,
|
|
167
|
+
* failureCount: 5,
|
|
168
|
+
* results: [
|
|
169
|
+
* { id: 'op-1', success: true, data: user1, duration: 150 },
|
|
170
|
+
* { id: 'op-2', success: false, error: validationError, duration: 50 },
|
|
171
|
+
* // ... more results
|
|
172
|
+
* ],
|
|
173
|
+
* totalDuration: 15000, // 15 seconds total
|
|
174
|
+
* errors: [
|
|
175
|
+
* new Error('Validation failed for op-2'),
|
|
176
|
+
* new Error('Database timeout for op-47'),
|
|
177
|
+
* // ... more errors
|
|
178
|
+
* ]
|
|
179
|
+
* };
|
|
180
|
+
*
|
|
181
|
+
* // Analyze batch results
|
|
182
|
+
* function analyzeBatch(result: BatchOperationResult<User>) {
|
|
183
|
+
* const successRate = (result.successCount / result.totalOperations) * 100;
|
|
184
|
+
* const avgDuration = result.totalDuration / result.totalOperations;
|
|
185
|
+
*
|
|
186
|
+
* console.log(`Batch completed: ${successRate}% success rate`);
|
|
187
|
+
* console.log(`Average operation time: ${avgDuration}ms`);
|
|
188
|
+
*
|
|
189
|
+
* if (result.errors.length > 0) {
|
|
190
|
+
* console.log('Errors encountered:', result.errors.map(e => e.message));
|
|
191
|
+
* }
|
|
192
|
+
* }
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
export interface BatchOperationResult<T = unknown> {
|
|
196
|
+
totalOperations: number;
|
|
197
|
+
successCount: number;
|
|
198
|
+
failureCount: number;
|
|
199
|
+
results: OperationResult<T>[];
|
|
200
|
+
totalDuration: number;
|
|
201
|
+
errors: Error[];
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Configuration options for batch operation processors
|
|
205
|
+
*
|
|
206
|
+
* Defines how batch operations should be processed, including performance
|
|
207
|
+
* tuning, error handling, retry logic, and progress tracking.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* // High-throughput batch processing
|
|
212
|
+
* const highThroughputOptions: BatchProcessorOptions = {
|
|
213
|
+
* batchSize: 50,
|
|
214
|
+
* concurrency: 10,
|
|
215
|
+
* retryCount: 3,
|
|
216
|
+
* retryDelay: 1000,
|
|
217
|
+
* continueOnError: true,
|
|
218
|
+
* timeout: 30000,
|
|
219
|
+
* onProgress: (progress) => {
|
|
220
|
+
* const percent = (progress.completed / progress.total) * 100;
|
|
221
|
+
* console.log(`Progress: ${percent.toFixed(1)}% (${progress.completed}/${progress.total})`);
|
|
222
|
+
* }
|
|
223
|
+
* };
|
|
224
|
+
*
|
|
225
|
+
* // Conservative batch processing
|
|
226
|
+
* const conservativeOptions: BatchProcessorOptions = {
|
|
227
|
+
* batchSize: 10,
|
|
228
|
+
* concurrency: 2,
|
|
229
|
+
* retryCount: 5,
|
|
230
|
+
* retryDelay: 2000,
|
|
231
|
+
* continueOnError: false,
|
|
232
|
+
* timeout: 60000
|
|
233
|
+
* };
|
|
234
|
+
*
|
|
235
|
+
* // Quick testing batch
|
|
236
|
+
* const testOptions: BatchProcessorOptions = {
|
|
237
|
+
* batchSize: 5,
|
|
238
|
+
* concurrency: 1,
|
|
239
|
+
* retryCount: 0,
|
|
240
|
+
* continueOnError: true,
|
|
241
|
+
* timeout: 5000
|
|
242
|
+
* };
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
export interface BatchProcessorOptions {
|
|
246
|
+
batchSize?: number;
|
|
247
|
+
concurrency?: number;
|
|
248
|
+
retryCount?: number;
|
|
249
|
+
retryDelay?: number;
|
|
250
|
+
continueOnError?: boolean;
|
|
251
|
+
timeout?: number;
|
|
252
|
+
onProgress?: (progress: {
|
|
253
|
+
completed: number;
|
|
254
|
+
total: number;
|
|
255
|
+
}) => void;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Return type for batch processor factory functions
|
|
259
|
+
*
|
|
260
|
+
* Provides methods for processing operations in batches, supporting both
|
|
261
|
+
* array-based and stream-based operation processing.
|
|
262
|
+
*
|
|
263
|
+
* @typeParam T - Type of data being processed in operations
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```typescript
|
|
267
|
+
* // Create a batch processor
|
|
268
|
+
* const processor: CreateBatchProcessorReturn<User> = createBatchProcessor({
|
|
269
|
+
* batchSize: 25,
|
|
270
|
+
* concurrency: 5,
|
|
271
|
+
* retryCount: 3
|
|
272
|
+
* });
|
|
273
|
+
*
|
|
274
|
+
* // Process array of operations
|
|
275
|
+
* const operations: Operation<User>[] = generateUserOperations(100);
|
|
276
|
+
* const result = await processor.process(operations);
|
|
277
|
+
*
|
|
278
|
+
* console.log(`Processed ${result.totalOperations} operations`);
|
|
279
|
+
* console.log(`Success rate: ${(result.successCount / result.totalOperations) * 100}%`);
|
|
280
|
+
*
|
|
281
|
+
* // Process stream of operations (for large datasets)
|
|
282
|
+
* async function* operationGenerator(): AsyncGenerator<Operation<User>> {
|
|
283
|
+
* for (let i = 0; i < 10000; i++) {
|
|
284
|
+
* yield { type: 'create', data: generateUser() };
|
|
285
|
+
* }
|
|
286
|
+
* }
|
|
287
|
+
*
|
|
288
|
+
* const streamResult = await processor.processStream(operationGenerator());
|
|
289
|
+
* console.log(`Stream processed ${streamResult.totalOperations} operations`);
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
export interface CreateBatchProcessorReturn<T> {
|
|
293
|
+
process(operations: Operation<T>[]): Promise<BatchOperationResult<T>>;
|
|
294
|
+
processStream(operationStream: AsyncIterable<Operation<T>>): Promise<BatchOperationResult<T>>;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Return type for batch test helper factory functions
|
|
298
|
+
*
|
|
299
|
+
* Provides utilities for generating test operations, simulating failures,
|
|
300
|
+
* and asserting batch results. Essential for comprehensive batch testing.
|
|
301
|
+
*
|
|
302
|
+
* @typeParam T - Type of data used in test operations
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```typescript
|
|
306
|
+
* // Create batch test helper
|
|
307
|
+
* const helper: CreateBatchTestHelperReturn<User> = createBatchTestHelper<User>();
|
|
308
|
+
*
|
|
309
|
+
* // Generate mixed operations for testing
|
|
310
|
+
* const operations = helper.generateOperations(100, {
|
|
311
|
+
* create: 0.4, // 40% create operations
|
|
312
|
+
* update: 0.3, // 30% update operations
|
|
313
|
+
* delete: 0.2, // 20% delete operations
|
|
314
|
+
* read: 0.1 // 10% read operations
|
|
315
|
+
* });
|
|
316
|
+
*
|
|
317
|
+
* // Simulate failures in the processor
|
|
318
|
+
* const mockProcessor = vi.fn();
|
|
319
|
+
* helper.simulateFailures(mockProcessor, 0.1, new Error('Simulated failure'));
|
|
320
|
+
*
|
|
321
|
+
* // Process operations and assert results
|
|
322
|
+
* const processor = createBatchProcessor({ batchSize: 10 });
|
|
323
|
+
* const result = await processor.process(operations);
|
|
324
|
+
*
|
|
325
|
+
* await helper.assertBatchResult(result, {
|
|
326
|
+
* minSuccessRate: 0.85, // At least 85% success
|
|
327
|
+
* maxDuration: 30000, // Complete within 30 seconds
|
|
328
|
+
* expectedErrors: ['Simulated failure', 'Network timeout']
|
|
329
|
+
* });
|
|
330
|
+
*
|
|
331
|
+
* console.log('Batch test completed successfully!');
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
export interface CreateBatchTestHelperReturn<T> {
|
|
335
|
+
generateOperations(count: number, distribution?: Partial<Record<OperationType, number>>): Operation<T>[];
|
|
336
|
+
simulateFailures(processor: Vitest.Mock, failureRate: number, error?: Error): void;
|
|
337
|
+
assertBatchResult(result: BatchOperationResult<T>, expectations: {
|
|
338
|
+
minSuccessRate?: number;
|
|
339
|
+
maxDuration?: number;
|
|
340
|
+
expectedErrors?: string[];
|
|
341
|
+
}): Promise<void>;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Return type for mock batch handler factory functions
|
|
345
|
+
*
|
|
346
|
+
* Provides a mock handler for testing batch operations with tracking
|
|
347
|
+
* capabilities for processed operations, results, and state management.
|
|
348
|
+
*
|
|
349
|
+
* @typeParam T - Type of data returned by the mock handler
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```typescript
|
|
353
|
+
* // Create mock batch handler for user operations
|
|
354
|
+
* const mockHandler: CreateMockBatchHandlerReturn<User> = createMockBatchHandler<User>();
|
|
355
|
+
*
|
|
356
|
+
* // Configure handler behavior
|
|
357
|
+
* mockHandler.handler.mockImplementation(async (operation) => {
|
|
358
|
+
* switch (operation.type) {
|
|
359
|
+
* case 'create':
|
|
360
|
+
* return { id: Math.random(), ...operation.data };
|
|
361
|
+
* case 'update':
|
|
362
|
+
* return { ...operation.data };
|
|
363
|
+
* case 'delete':
|
|
364
|
+
* return operation.data;
|
|
365
|
+
* default:
|
|
366
|
+
* throw new Error(`Unsupported operation: ${operation.type}`);
|
|
367
|
+
* }
|
|
368
|
+
* });
|
|
369
|
+
*
|
|
370
|
+
* // Process some operations
|
|
371
|
+
* const operations: Operation<User>[] = [
|
|
372
|
+
* { type: 'create', data: { name: 'John' } },
|
|
373
|
+
* { type: 'update', data: { id: 1, name: 'Jane' } }
|
|
374
|
+
* ];
|
|
375
|
+
*
|
|
376
|
+
* for (const op of operations) {
|
|
377
|
+
* await mockHandler.handler(op);
|
|
378
|
+
* }
|
|
379
|
+
*
|
|
380
|
+
* // Inspect processed operations
|
|
381
|
+
* const processed = mockHandler.getProcessedOperations();
|
|
382
|
+
* console.log(`Processed ${processed.length} operations`);
|
|
383
|
+
*
|
|
384
|
+
* // Get results by operation ID
|
|
385
|
+
* const results = mockHandler.getResults();
|
|
386
|
+
* console.log('Results:', Object.fromEntries(results));
|
|
387
|
+
*
|
|
388
|
+
* // Clear for next test
|
|
389
|
+
* mockHandler.clear();
|
|
390
|
+
* ```
|
|
391
|
+
*/
|
|
392
|
+
export interface CreateMockBatchHandlerReturn<T> {
|
|
393
|
+
handler: Vitest.Mock<(operation: Operation<T>) => Promise<T>>;
|
|
394
|
+
getProcessedOperations: () => Operation<T>[];
|
|
395
|
+
getResults: () => Map<string, T>;
|
|
396
|
+
clear: () => void;
|
|
397
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './types';
|