uni-types 1.4.0 → 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.
- package/README.md +177 -1
- package/dist/index.d.cts +2877 -413
- package/dist/index.d.mts +2877 -413
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -221,6 +221,293 @@ interface AsyncFailure<E = Error> {
|
|
|
221
221
|
error: E;
|
|
222
222
|
}
|
|
223
223
|
//#endregion
|
|
224
|
+
//#region src/auth/index.d.ts
|
|
225
|
+
/**
|
|
226
|
+
* Authorization & Permissions Types
|
|
227
|
+
*
|
|
228
|
+
* Types for authorization and permission management.
|
|
229
|
+
*/
|
|
230
|
+
/**
|
|
231
|
+
* Permission type
|
|
232
|
+
*/
|
|
233
|
+
interface Permission<T = string> {
|
|
234
|
+
name: T;
|
|
235
|
+
description?: string;
|
|
236
|
+
resource?: string;
|
|
237
|
+
action?: Action;
|
|
238
|
+
conditions?: PermissionCondition[];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Permission set
|
|
242
|
+
*/
|
|
243
|
+
type PermissionSet<T = string> = Set<T> | T[];
|
|
244
|
+
/**
|
|
245
|
+
* Permission grant
|
|
246
|
+
*/
|
|
247
|
+
interface PermissionGrant<T = string> {
|
|
248
|
+
permission: T;
|
|
249
|
+
granted: true;
|
|
250
|
+
grantedBy: string;
|
|
251
|
+
grantedAt: Date;
|
|
252
|
+
expiresAt?: Date;
|
|
253
|
+
conditions?: PermissionCondition[];
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Permission deny
|
|
257
|
+
*/
|
|
258
|
+
interface PermissionDeny<T = string> {
|
|
259
|
+
permission: T;
|
|
260
|
+
granted: false;
|
|
261
|
+
deniedBy: string;
|
|
262
|
+
deniedAt: Date;
|
|
263
|
+
reason?: string;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Permission condition
|
|
267
|
+
*/
|
|
268
|
+
interface PermissionCondition<T = unknown> {
|
|
269
|
+
attribute: string;
|
|
270
|
+
operator: ConditionOperator;
|
|
271
|
+
value: T;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Condition operator
|
|
275
|
+
*/
|
|
276
|
+
type ConditionOperator = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'notIn' | 'contains' | 'startsWith' | 'endsWith' | 'exists' | 'notExists';
|
|
277
|
+
/**
|
|
278
|
+
* Permission check result
|
|
279
|
+
*/
|
|
280
|
+
type PermissionCheckResult = {
|
|
281
|
+
allowed: true;
|
|
282
|
+
reason?: string;
|
|
283
|
+
} | {
|
|
284
|
+
allowed: false;
|
|
285
|
+
reason: string;
|
|
286
|
+
missingPermissions?: string[];
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Role type
|
|
290
|
+
*/
|
|
291
|
+
interface Role<T = string> {
|
|
292
|
+
name: T;
|
|
293
|
+
description?: string;
|
|
294
|
+
permissions: PermissionSet;
|
|
295
|
+
inherits?: T[];
|
|
296
|
+
createdAt?: Date;
|
|
297
|
+
updatedAt?: Date;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Role set
|
|
301
|
+
*/
|
|
302
|
+
type RoleSet<T = string> = Set<T> | T[];
|
|
303
|
+
/**
|
|
304
|
+
* Role permission mapping
|
|
305
|
+
*/
|
|
306
|
+
interface RolePermission<R = string, P = string> {
|
|
307
|
+
role: R;
|
|
308
|
+
permissions: P[];
|
|
309
|
+
grantedAt?: Date;
|
|
310
|
+
grantedBy?: string;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Role hierarchy
|
|
314
|
+
*/
|
|
315
|
+
interface RoleHierarchy<T = string> {
|
|
316
|
+
role: T;
|
|
317
|
+
parent?: T;
|
|
318
|
+
children?: T[];
|
|
319
|
+
level: number;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Policy type
|
|
323
|
+
*/
|
|
324
|
+
interface Policy {
|
|
325
|
+
id: string;
|
|
326
|
+
name: string;
|
|
327
|
+
description?: string;
|
|
328
|
+
effect: PolicyEffect;
|
|
329
|
+
principals: string[];
|
|
330
|
+
actions: Action[];
|
|
331
|
+
resources: string[];
|
|
332
|
+
conditions?: PolicyCondition[];
|
|
333
|
+
version?: string;
|
|
334
|
+
createdAt: Date;
|
|
335
|
+
updatedAt: Date;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Policy rule
|
|
339
|
+
*/
|
|
340
|
+
interface PolicyRule<T = unknown> {
|
|
341
|
+
effect: PolicyEffect;
|
|
342
|
+
action: Action | Action[];
|
|
343
|
+
resource: string | string[];
|
|
344
|
+
condition?: PolicyCondition<T>[];
|
|
345
|
+
description?: string;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Policy effect
|
|
349
|
+
*/
|
|
350
|
+
type PolicyEffect = 'allow' | 'deny';
|
|
351
|
+
/**
|
|
352
|
+
* Policy condition
|
|
353
|
+
*/
|
|
354
|
+
interface PolicyCondition<T = unknown> {
|
|
355
|
+
key: string;
|
|
356
|
+
operator: ConditionOperator;
|
|
357
|
+
value: T;
|
|
358
|
+
description?: string;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Policy evaluation context
|
|
362
|
+
*/
|
|
363
|
+
interface PolicyContext<T = unknown> {
|
|
364
|
+
principal: string;
|
|
365
|
+
action: Action;
|
|
366
|
+
resource: string;
|
|
367
|
+
environment?: Record<string, unknown>;
|
|
368
|
+
context?: T;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Policy evaluation result
|
|
372
|
+
*/
|
|
373
|
+
interface PolicyResult {
|
|
374
|
+
effect: PolicyEffect;
|
|
375
|
+
matchedPolicies: string[];
|
|
376
|
+
deniedBy?: string[];
|
|
377
|
+
allowedBy?: string[];
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Access control type
|
|
381
|
+
*/
|
|
382
|
+
interface AccessControl<T = unknown> {
|
|
383
|
+
check: (context: PolicyContext<T>) => PolicyResult;
|
|
384
|
+
grant: (principal: string, permission: string) => void;
|
|
385
|
+
revoke: (principal: string, permission: string) => void;
|
|
386
|
+
getPermissions: (principal: string) => PermissionSet;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* ACL (Access Control List)
|
|
390
|
+
*/
|
|
391
|
+
interface ACL {
|
|
392
|
+
entries: ACLEntry[];
|
|
393
|
+
getEntry: (principal: string, resource: string) => ACLEntry | undefined;
|
|
394
|
+
addEntry: (entry: ACLEntry) => void;
|
|
395
|
+
removeEntry: (principal: string, resource: string) => void;
|
|
396
|
+
check: (principal: string, resource: string, action: Action) => boolean;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* ACL entry
|
|
400
|
+
*/
|
|
401
|
+
interface ACLEntry {
|
|
402
|
+
principal: string;
|
|
403
|
+
resource: string;
|
|
404
|
+
actions: Action[];
|
|
405
|
+
effect: PolicyEffect;
|
|
406
|
+
conditions?: PolicyCondition[];
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Resource type
|
|
410
|
+
*/
|
|
411
|
+
interface Resource<T = unknown> {
|
|
412
|
+
type: string;
|
|
413
|
+
id: string;
|
|
414
|
+
attributes?: T;
|
|
415
|
+
owner?: string;
|
|
416
|
+
createdAt?: Date;
|
|
417
|
+
updatedAt?: Date;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Action type
|
|
421
|
+
*/
|
|
422
|
+
type Action = 'create' | 'read' | 'update' | 'delete' | 'list' | 'execute' | 'admin' | string;
|
|
423
|
+
/**
|
|
424
|
+
* RBAC (Role-Based Access Control)
|
|
425
|
+
*/
|
|
426
|
+
interface RBAC<R extends string = string, P extends string = string> {
|
|
427
|
+
roles: Map<R, Role<R>>;
|
|
428
|
+
rolePermissions: Map<R, P[]>;
|
|
429
|
+
userRoles: Map<string, R[]>;
|
|
430
|
+
assignRole: (userId: string, role: R) => void;
|
|
431
|
+
revokeRole: (userId: string, role: R) => void;
|
|
432
|
+
getUserRoles: (userId: string) => R[];
|
|
433
|
+
getUserPermissions: (userId: string) => P[];
|
|
434
|
+
checkPermission: (userId: string, permission: P) => boolean;
|
|
435
|
+
addRole: (role: Role<R>) => void;
|
|
436
|
+
removeRole: (roleName: R) => void;
|
|
437
|
+
getRole: (roleName: R) => Role<R> | undefined;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* RBAC configuration
|
|
441
|
+
*/
|
|
442
|
+
interface RBACConfig<R = string, P = string> {
|
|
443
|
+
roles: Role<R>[];
|
|
444
|
+
rolePermissions: RolePermission<R, P>[];
|
|
445
|
+
userRoleAssignments: {
|
|
446
|
+
userId: string;
|
|
447
|
+
roles: R[];
|
|
448
|
+
}[];
|
|
449
|
+
defaultRole?: R;
|
|
450
|
+
superAdminRole?: R;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* ABAC (Attribute-Based Access Control)
|
|
454
|
+
*/
|
|
455
|
+
interface ABAC<T = unknown> {
|
|
456
|
+
policies: Policy[];
|
|
457
|
+
addPolicy: (policy: Policy) => void;
|
|
458
|
+
removePolicy: (policyId: string) => void;
|
|
459
|
+
getPolicy: (policyId: string) => Policy | undefined;
|
|
460
|
+
evaluate: (context: PolicyContext<T>) => PolicyResult;
|
|
461
|
+
getApplicablePolicies: (context: PolicyContext<T>) => Policy[];
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Attribute type
|
|
465
|
+
*/
|
|
466
|
+
interface Attribute<T = unknown> {
|
|
467
|
+
name: string;
|
|
468
|
+
value: T;
|
|
469
|
+
type: 'string' | 'number' | 'boolean' | 'date' | 'list' | 'map';
|
|
470
|
+
description?: string;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Attribute value
|
|
474
|
+
*/
|
|
475
|
+
interface AttributeValue<T = unknown> {
|
|
476
|
+
attribute: string;
|
|
477
|
+
value: T;
|
|
478
|
+
source: 'user' | 'resource' | 'environment' | 'context';
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* ABAC configuration
|
|
482
|
+
*/
|
|
483
|
+
interface ABACConfig {
|
|
484
|
+
policies: Policy[];
|
|
485
|
+
defaultDecision: PolicyEffect;
|
|
486
|
+
attributeResolvers?: Record<string, (context: PolicyContext) => AttributeValue>;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Authorization provider
|
|
490
|
+
*/
|
|
491
|
+
interface AuthorizationProvider<T = unknown> {
|
|
492
|
+
initialize: () => Promise<void>;
|
|
493
|
+
checkPermission: (userId: string, permission: string, context?: T) => Promise<PermissionCheckResult>;
|
|
494
|
+
getUserPermissions: (userId: string) => Promise<PermissionSet>;
|
|
495
|
+
getUserRoles: (userId: string) => Promise<RoleSet>;
|
|
496
|
+
grantPermission: (userId: string, permission: string) => Promise<void>;
|
|
497
|
+
revokePermission: (userId: string, permission: string) => Promise<void>;
|
|
498
|
+
assignRole: (userId: string, role: string) => Promise<void>;
|
|
499
|
+
revokeRole: (userId: string, role: string) => Promise<void>;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Authorization options
|
|
503
|
+
*/
|
|
504
|
+
interface AuthorizationOptions {
|
|
505
|
+
cache: boolean;
|
|
506
|
+
cacheTTL: number;
|
|
507
|
+
throwOnDenied: boolean;
|
|
508
|
+
logDecisions: boolean;
|
|
509
|
+
}
|
|
510
|
+
//#endregion
|
|
224
511
|
//#region src/brand/index.d.ts
|
|
225
512
|
/**
|
|
226
513
|
* Brand/Opaque types for nominal typing
|
|
@@ -260,6 +547,264 @@ type Unbrand<T> = T extends Brand<infer U, infer _> ? U : T;
|
|
|
260
547
|
type BrandedString<B extends string> = Brand<string, B>;
|
|
261
548
|
type BrandedNumber<B extends string> = Brand<number, B>;
|
|
262
549
|
//#endregion
|
|
550
|
+
//#region src/cache/index.d.ts
|
|
551
|
+
/**
|
|
552
|
+
* Caching Strategies Types
|
|
553
|
+
*
|
|
554
|
+
* Types for caching patterns and implementations.
|
|
555
|
+
*/
|
|
556
|
+
/**
|
|
557
|
+
* Cache type
|
|
558
|
+
*/
|
|
559
|
+
interface Cache<T = unknown> {
|
|
560
|
+
get: (key: string) => Promise<T | undefined>;
|
|
561
|
+
set: (key: string, value: T, options?: CacheOptions) => Promise<void>;
|
|
562
|
+
has: (key: string) => Promise<boolean>;
|
|
563
|
+
delete: (key: string) => Promise<boolean>;
|
|
564
|
+
clear: () => Promise<void>;
|
|
565
|
+
keys: () => Promise<string[]>;
|
|
566
|
+
getMany: (keys: string[]) => Promise<(T | undefined)[]>;
|
|
567
|
+
setMany: (entries: CacheEntry<T>[]) => Promise<void>;
|
|
568
|
+
deleteMany: (keys: string[]) => Promise<number>;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Cache entry
|
|
572
|
+
*/
|
|
573
|
+
interface CacheEntry<T = unknown> {
|
|
574
|
+
key: string;
|
|
575
|
+
value: T;
|
|
576
|
+
ttl?: number;
|
|
577
|
+
createdAt?: Date;
|
|
578
|
+
updatedAt?: Date;
|
|
579
|
+
tags?: string[];
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Cache key type
|
|
583
|
+
*/
|
|
584
|
+
type CacheKey = string | CacheKeyBuilder;
|
|
585
|
+
/**
|
|
586
|
+
* Cache key builder
|
|
587
|
+
*/
|
|
588
|
+
type CacheKeyBuilder = (params: unknown) => string;
|
|
589
|
+
/**
|
|
590
|
+
* Cache value
|
|
591
|
+
*/
|
|
592
|
+
type CacheValue<T = unknown> = T;
|
|
593
|
+
/**
|
|
594
|
+
* Cache options
|
|
595
|
+
*/
|
|
596
|
+
interface CacheOptions {
|
|
597
|
+
ttl?: number;
|
|
598
|
+
tags?: string[];
|
|
599
|
+
version?: number;
|
|
600
|
+
noEvict?: boolean;
|
|
601
|
+
priority?: number;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Cache statistics
|
|
605
|
+
*/
|
|
606
|
+
interface CacheStats {
|
|
607
|
+
hits: number;
|
|
608
|
+
misses: number;
|
|
609
|
+
hitRate: number;
|
|
610
|
+
missRate: number;
|
|
611
|
+
size: number;
|
|
612
|
+
maxSize?: number;
|
|
613
|
+
evictions: number;
|
|
614
|
+
memoryUsage?: number;
|
|
615
|
+
uptime: number;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Hit rate type
|
|
619
|
+
*/
|
|
620
|
+
type HitRate = number;
|
|
621
|
+
/**
|
|
622
|
+
* Miss rate type
|
|
623
|
+
*/
|
|
624
|
+
type MissRate = number;
|
|
625
|
+
/**
|
|
626
|
+
* Cache strategy
|
|
627
|
+
*/
|
|
628
|
+
type CacheStrategy = 'lru' | 'lfu' | 'fifo' | 'ttl' | 'arc' | 'lfru' | '2q';
|
|
629
|
+
/**
|
|
630
|
+
* LRU Cache
|
|
631
|
+
*/
|
|
632
|
+
type LRUCache<T = unknown> = Cache<T> & {
|
|
633
|
+
readonly maxSize: number;
|
|
634
|
+
readonly currentSize: number;
|
|
635
|
+
peek: (key: string) => T | undefined;
|
|
636
|
+
dump: () => CacheEntry<T>[];
|
|
637
|
+
restore: (entries: CacheEntry<T>[]) => void;
|
|
638
|
+
prune: () => void;
|
|
639
|
+
};
|
|
640
|
+
/**
|
|
641
|
+
* LFU Cache
|
|
642
|
+
*/
|
|
643
|
+
type LFUCache<T = unknown> = Cache<T> & {
|
|
644
|
+
readonly maxSize: number;
|
|
645
|
+
getFrequency: (key: string) => number;
|
|
646
|
+
};
|
|
647
|
+
/**
|
|
648
|
+
* TTL Cache
|
|
649
|
+
*/
|
|
650
|
+
type TTLCache<T = unknown> = Cache<T> & {
|
|
651
|
+
readonly defaultTTL: number;
|
|
652
|
+
getRemainingTTL: (key: string) => number;
|
|
653
|
+
refresh: (key: string) => boolean;
|
|
654
|
+
};
|
|
655
|
+
/**
|
|
656
|
+
* FIFO Cache
|
|
657
|
+
*/
|
|
658
|
+
type FIFOCache<T = unknown> = Cache<T> & {
|
|
659
|
+
readonly maxSize: number;
|
|
660
|
+
readonly currentSize: number;
|
|
661
|
+
};
|
|
662
|
+
/**
|
|
663
|
+
* ARC Cache (Adaptive Replacement Cache)
|
|
664
|
+
*/
|
|
665
|
+
type ARCCache<T = unknown> = Cache<T> & {
|
|
666
|
+
readonly p: number;
|
|
667
|
+
readonly recentKeys: Set<string>;
|
|
668
|
+
readonly frequentKeys: Set<string>;
|
|
669
|
+
};
|
|
670
|
+
/**
|
|
671
|
+
* Cache invalidation
|
|
672
|
+
*/
|
|
673
|
+
interface CacheInvalidation<T = unknown> {
|
|
674
|
+
invalidate: (key: string) => Promise<void>;
|
|
675
|
+
invalidateByTag: (tag: string) => Promise<void>;
|
|
676
|
+
invalidateByPattern: (pattern: string | RegExp) => Promise<void>;
|
|
677
|
+
invalidateAll: () => Promise<void>;
|
|
678
|
+
onInvalidation?: (event: InvalidationEvent<T>) => void;
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Invalidation rule
|
|
682
|
+
*/
|
|
683
|
+
interface InvalidationRule<T = unknown> {
|
|
684
|
+
type: 'key' | 'tag' | 'pattern' | 'custom';
|
|
685
|
+
pattern?: string | RegExp;
|
|
686
|
+
tags?: string[];
|
|
687
|
+
custom?: (entry: CacheEntry<T>) => boolean;
|
|
688
|
+
debounce?: number;
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Invalidation strategy
|
|
692
|
+
*/
|
|
693
|
+
type InvalidationStrategy = 'time-based' | 'event-based' | 'manual' | 'write-through' | 'write-behind';
|
|
694
|
+
/**
|
|
695
|
+
* Invalidation event
|
|
696
|
+
*/
|
|
697
|
+
interface InvalidationEvent<T = unknown> {
|
|
698
|
+
type: InvalidationStrategy;
|
|
699
|
+
keys: string[];
|
|
700
|
+
timestamp: Date;
|
|
701
|
+
reason?: string;
|
|
702
|
+
entry?: CacheEntry<T>;
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Distributed cache
|
|
706
|
+
*/
|
|
707
|
+
type DistributedCache<T = unknown> = Cache<T> & {
|
|
708
|
+
nodes: CacheNode[];
|
|
709
|
+
consistentHash: ConsistentHash;
|
|
710
|
+
replicate: (key: string, value: T) => Promise<void>;
|
|
711
|
+
failover: (failedNode: string) => Promise<void>;
|
|
712
|
+
sync: () => Promise<void>;
|
|
713
|
+
};
|
|
714
|
+
/**
|
|
715
|
+
* Cache cluster
|
|
716
|
+
*/
|
|
717
|
+
interface CacheCluster {
|
|
718
|
+
nodes: CacheNode[];
|
|
719
|
+
strategy: 'replicated' | 'partitioned' | 'consistent-hashing';
|
|
720
|
+
replicationFactor: number;
|
|
721
|
+
partitioner?: (key: string) => string;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Cache node
|
|
725
|
+
*/
|
|
726
|
+
interface CacheNode {
|
|
727
|
+
id: string;
|
|
728
|
+
host: string;
|
|
729
|
+
port: number;
|
|
730
|
+
status: 'online' | 'offline' | 'syncing' | 'degraded';
|
|
731
|
+
weight: number;
|
|
732
|
+
tags?: string[];
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Consistent hash
|
|
736
|
+
*/
|
|
737
|
+
interface ConsistentHash {
|
|
738
|
+
addNode: (node: CacheNode) => void;
|
|
739
|
+
removeNode: (nodeId: string) => void;
|
|
740
|
+
getNode: (key: string) => CacheNode | undefined;
|
|
741
|
+
getNodes: (key: string, count?: number) => CacheNode[];
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Cache decorator options
|
|
745
|
+
*/
|
|
746
|
+
interface CacheDecoratorOptions {
|
|
747
|
+
key: string | ((...args: unknown[]) => string);
|
|
748
|
+
ttl?: number;
|
|
749
|
+
tags?: string[];
|
|
750
|
+
condition?: (...args: unknown[]) => boolean;
|
|
751
|
+
refresh?: boolean;
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Cache aside pattern
|
|
755
|
+
*/
|
|
756
|
+
interface CacheAside<T = unknown> {
|
|
757
|
+
get: (key: string, loader: () => Promise<T>) => Promise<T>;
|
|
758
|
+
set: (key: string, value: T) => Promise<void>;
|
|
759
|
+
invalidate: (key: string) => Promise<void>;
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Read through cache
|
|
763
|
+
*/
|
|
764
|
+
interface ReadThroughCache<T = unknown> {
|
|
765
|
+
get: (key: string) => Promise<T | undefined>;
|
|
766
|
+
set: (key: string, value: T) => Promise<void>;
|
|
767
|
+
invalidate: (key: string) => Promise<void>;
|
|
768
|
+
loader: (key: string) => Promise<T>;
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* Write through cache
|
|
772
|
+
*/
|
|
773
|
+
interface WriteThroughCache<T = unknown> {
|
|
774
|
+
set: (key: string, value: T) => Promise<void>;
|
|
775
|
+
get: (key: string) => Promise<T | undefined>;
|
|
776
|
+
delete: (key: string) => Promise<void>;
|
|
777
|
+
writer: (key: string, value: T) => Promise<void>;
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Write behind cache
|
|
781
|
+
*/
|
|
782
|
+
interface WriteBehindCache<T = unknown> {
|
|
783
|
+
set: (key: string, value: T) => Promise<void>;
|
|
784
|
+
get: (key: string) => Promise<T | undefined>;
|
|
785
|
+
delete: (key: string) => Promise<void>;
|
|
786
|
+
flush: () => Promise<void>;
|
|
787
|
+
writer: (entries: CacheEntry<T>[]) => Promise<void>;
|
|
788
|
+
writeDelay: number;
|
|
789
|
+
batchSize: number;
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Cache serializer
|
|
793
|
+
*/
|
|
794
|
+
interface CacheSerializer<T = unknown> {
|
|
795
|
+
serialize: (value: T) => string;
|
|
796
|
+
deserialize: (data: string) => T;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Cache compression options
|
|
800
|
+
*/
|
|
801
|
+
interface CacheCompressionOptions {
|
|
802
|
+
enabled: boolean;
|
|
803
|
+
threshold: number;
|
|
804
|
+
algorithm: 'gzip' | 'deflate' | 'brotli';
|
|
805
|
+
level?: number;
|
|
806
|
+
}
|
|
807
|
+
//#endregion
|
|
263
808
|
//#region src/collection/index.d.ts
|
|
264
809
|
/**
|
|
265
810
|
* Type-level collection utilities
|
|
@@ -819,80 +1364,317 @@ type Or<A extends boolean, B extends boolean> = A extends true ? true : B;
|
|
|
819
1364
|
*/
|
|
820
1365
|
type Assert<T, U extends T> = T extends U ? T : never;
|
|
821
1366
|
//#endregion
|
|
822
|
-
//#region src/
|
|
1367
|
+
//#region src/config/index.d.ts
|
|
823
1368
|
/**
|
|
824
|
-
*
|
|
825
|
-
*
|
|
826
|
-
* @example
|
|
827
|
-
* ```ts
|
|
828
|
-
* interface User {
|
|
829
|
-
* name?: string
|
|
830
|
-
* age?: number
|
|
831
|
-
* email?: string
|
|
832
|
-
* }
|
|
833
|
-
*
|
|
834
|
-
* type RequiredExceptName = OmitRequired<User, 'name'>
|
|
835
|
-
* // { name?: string; age: number; email: string }
|
|
836
|
-
* ```
|
|
1369
|
+
* Configuration Management Types
|
|
837
1370
|
*
|
|
838
|
-
*
|
|
839
|
-
* @see OmitPartial - Opposite operation
|
|
1371
|
+
* Types for configuration and environment management.
|
|
840
1372
|
*/
|
|
841
|
-
type OmitRequired<T, K extends keyof T> = { [P in K]: T[P] } & Omit<Required<T>, K>;
|
|
842
1373
|
/**
|
|
843
|
-
*
|
|
844
|
-
*
|
|
845
|
-
* @example
|
|
846
|
-
* ```ts
|
|
847
|
-
* interface User {
|
|
848
|
-
* name: string
|
|
849
|
-
* age: number
|
|
850
|
-
* email: string
|
|
851
|
-
* }
|
|
852
|
-
*
|
|
853
|
-
* type OptionalExceptName = OmitPartial<User, 'name'>
|
|
854
|
-
* // { name: string; age?: number; email?: string }
|
|
855
|
-
* ```
|
|
856
|
-
*
|
|
857
|
-
* @see PickPartial - Direct selection
|
|
858
|
-
* @see OmitRequired - Opposite operation
|
|
1374
|
+
* Configuration type
|
|
859
1375
|
*/
|
|
860
|
-
type
|
|
861
|
-
|
|
862
|
-
|
|
1376
|
+
type Config<T = unknown> = {
|
|
1377
|
+
[key: string]: T;
|
|
1378
|
+
} & {
|
|
1379
|
+
__config?: true;
|
|
1380
|
+
};
|
|
863
1381
|
/**
|
|
864
|
-
*
|
|
865
|
-
*
|
|
866
|
-
* @template T - Target type
|
|
867
|
-
* @template K - Property keys to make required
|
|
868
|
-
*
|
|
869
|
-
* @example
|
|
870
|
-
* ```ts
|
|
871
|
-
* interface User {
|
|
872
|
-
* name?: string
|
|
873
|
-
* age?: number
|
|
874
|
-
* email: string
|
|
875
|
-
* }
|
|
876
|
-
*
|
|
877
|
-
* type RequiredName = PickRequired<User, 'name'>
|
|
878
|
-
* // { name: string; age?: number; email: string }
|
|
879
|
-
* ```
|
|
880
|
-
*
|
|
881
|
-
* @see PickPartial - Opposite operation
|
|
882
|
-
* @see OmitRequired - Inverse selection
|
|
1382
|
+
* Configuration schema type
|
|
883
1383
|
*/
|
|
884
|
-
type
|
|
1384
|
+
type ConfigSchema<T = unknown> = { [K in keyof T]: ConfigField<T[K]> };
|
|
885
1385
|
/**
|
|
886
|
-
*
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
1386
|
+
* Configuration field
|
|
1387
|
+
*/
|
|
1388
|
+
interface ConfigField<T = unknown> {
|
|
1389
|
+
type: ConfigFieldType;
|
|
1390
|
+
required?: boolean;
|
|
1391
|
+
default?: T;
|
|
1392
|
+
validator?: (value: T) => boolean;
|
|
1393
|
+
transform?: (value: unknown) => T;
|
|
1394
|
+
description?: string;
|
|
1395
|
+
env?: string;
|
|
1396
|
+
sensitive?: boolean;
|
|
1397
|
+
}
|
|
1398
|
+
/**
|
|
1399
|
+
* Configuration field types
|
|
1400
|
+
*/
|
|
1401
|
+
type ConfigFieldType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'json';
|
|
1402
|
+
/**
|
|
1403
|
+
* Configuration value
|
|
1404
|
+
*/
|
|
1405
|
+
type ConfigValue<T = unknown> = T | undefined;
|
|
1406
|
+
/**
|
|
1407
|
+
* Configuration source
|
|
1408
|
+
*/
|
|
1409
|
+
type ConfigSource = 'file' | 'env' | 'remote' | 'default' | 'cli' | 'inline';
|
|
1410
|
+
/**
|
|
1411
|
+
* Configuration source priority
|
|
1412
|
+
*/
|
|
1413
|
+
type ConfigPriority = Record<ConfigSource, number>;
|
|
1414
|
+
/**
|
|
1415
|
+
* Environment type
|
|
1416
|
+
*/
|
|
1417
|
+
type Environment$1 = 'development' | 'staging' | 'production' | 'test' | 'local';
|
|
1418
|
+
/**
|
|
1419
|
+
* Environment variable type
|
|
1420
|
+
*/
|
|
1421
|
+
interface EnvVar<T = unknown> {
|
|
1422
|
+
value: T;
|
|
1423
|
+
source: ConfigSource;
|
|
1424
|
+
required: boolean;
|
|
1425
|
+
default?: T;
|
|
1426
|
+
description?: string;
|
|
1427
|
+
}
|
|
1428
|
+
/**
|
|
1429
|
+
* Environment configuration
|
|
1430
|
+
*/
|
|
1431
|
+
interface EnvConfig<T = unknown> {
|
|
1432
|
+
env: Environment$1;
|
|
1433
|
+
config: T;
|
|
1434
|
+
sources: Record<string, ConfigSource>;
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1437
|
+
* Environment variable mapping
|
|
1438
|
+
*/
|
|
1439
|
+
type EnvMapping<T = unknown> = { [K in keyof T]?: string };
|
|
1440
|
+
/**
|
|
1441
|
+
* Parse environment result
|
|
1442
|
+
*/
|
|
1443
|
+
type ParseEnvResult<T = unknown> = {
|
|
1444
|
+
success: true;
|
|
1445
|
+
config: T;
|
|
1446
|
+
} | {
|
|
1447
|
+
success: false;
|
|
1448
|
+
errors: ConfigError[];
|
|
1449
|
+
};
|
|
1450
|
+
/**
|
|
1451
|
+
* Configuration validator
|
|
1452
|
+
*/
|
|
1453
|
+
interface ConfigValidator<T = unknown> {
|
|
1454
|
+
validate: (config: T) => Promise<ConfigValidationResult<T>>;
|
|
1455
|
+
schema: ConfigSchema<T>;
|
|
1456
|
+
}
|
|
1457
|
+
/**
|
|
1458
|
+
* Configuration validation result
|
|
1459
|
+
*/
|
|
1460
|
+
type ConfigValidationResult<T = unknown> = {
|
|
1461
|
+
success: true;
|
|
1462
|
+
config: T;
|
|
1463
|
+
} | {
|
|
1464
|
+
success: false;
|
|
1465
|
+
errors: ConfigError[];
|
|
1466
|
+
};
|
|
1467
|
+
/**
|
|
1468
|
+
* Configuration error
|
|
1469
|
+
*/
|
|
1470
|
+
interface ConfigError {
|
|
1471
|
+
path: string;
|
|
1472
|
+
message: string;
|
|
1473
|
+
value?: unknown;
|
|
1474
|
+
expected?: string;
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* Configuration warnings
|
|
1478
|
+
*/
|
|
1479
|
+
interface ConfigWarning {
|
|
1480
|
+
path: string;
|
|
1481
|
+
message: string;
|
|
1482
|
+
value?: unknown;
|
|
1483
|
+
suggestion?: string;
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Secret type
|
|
1487
|
+
*/
|
|
1488
|
+
interface Secret<T = string> {
|
|
1489
|
+
__secret: true;
|
|
1490
|
+
value: T;
|
|
1491
|
+
expiresAt?: Date;
|
|
1492
|
+
rotatedAt?: Date;
|
|
1493
|
+
version?: number;
|
|
1494
|
+
}
|
|
1495
|
+
/**
|
|
1496
|
+
* Secret provider
|
|
1497
|
+
*/
|
|
1498
|
+
interface SecretProvider<T = string> {
|
|
1499
|
+
get: (key: string) => Promise<Secret<T>>;
|
|
1500
|
+
set: (key: string, value: T, options?: SecretOptions) => Promise<void>;
|
|
1501
|
+
delete: (key: string) => Promise<void>;
|
|
1502
|
+
rotate: (key: string) => Promise<Secret<T>>;
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1505
|
+
* Secret configuration
|
|
1506
|
+
*/
|
|
1507
|
+
interface SecretConfig<T = string> {
|
|
1508
|
+
provider: 'env' | 'file' | 'vault' | 'aws-secrets' | 'azure-keyvault' | 'gcp-secret';
|
|
1509
|
+
prefix?: string;
|
|
1510
|
+
cache?: boolean;
|
|
1511
|
+
cacheTTL?: number;
|
|
1512
|
+
transform?: (value: string) => T;
|
|
1513
|
+
}
|
|
1514
|
+
/**
|
|
1515
|
+
* Secret options
|
|
1516
|
+
*/
|
|
1517
|
+
interface SecretOptions {
|
|
1518
|
+
expiresIn?: number;
|
|
1519
|
+
tags?: Record<string, string>;
|
|
1520
|
+
metadata?: Record<string, unknown>;
|
|
1521
|
+
}
|
|
1522
|
+
/**
|
|
1523
|
+
* Feature flag type
|
|
1524
|
+
*/
|
|
1525
|
+
interface FeatureFlag<T = boolean> {
|
|
1526
|
+
name: string;
|
|
1527
|
+
enabled: T;
|
|
1528
|
+
description?: string;
|
|
1529
|
+
variants?: FeatureFlagVariant<T>[];
|
|
1530
|
+
targeting?: FeatureTargeting[];
|
|
1531
|
+
createdAt: Date;
|
|
1532
|
+
updatedAt: Date;
|
|
1533
|
+
}
|
|
1534
|
+
/**
|
|
1535
|
+
* Feature flag variant
|
|
1536
|
+
*/
|
|
1537
|
+
interface FeatureFlagVariant<T = unknown> {
|
|
1538
|
+
name: string;
|
|
1539
|
+
value: T;
|
|
1540
|
+
weight?: number;
|
|
1541
|
+
description?: string;
|
|
1542
|
+
}
|
|
1543
|
+
/**
|
|
1544
|
+
* Feature targeting
|
|
1545
|
+
*/
|
|
1546
|
+
interface FeatureTargeting {
|
|
1547
|
+
attribute: string;
|
|
1548
|
+
operator: TargetingOperator;
|
|
1549
|
+
values: unknown[];
|
|
1550
|
+
variant?: string;
|
|
1551
|
+
}
|
|
1552
|
+
/**
|
|
1553
|
+
* Targeting operator
|
|
1554
|
+
*/
|
|
1555
|
+
type TargetingOperator = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'contains' | 'startsWith' | 'endsWith' | 'matches' | 'in' | 'notIn';
|
|
1556
|
+
/**
|
|
1557
|
+
* Feature flags collection
|
|
1558
|
+
*/
|
|
1559
|
+
type FeatureFlags<T = Record<string, boolean>> = { [K in keyof T]: FeatureFlag<T[K]> };
|
|
1560
|
+
/**
|
|
1561
|
+
* Feature flag configuration
|
|
1562
|
+
*/
|
|
1563
|
+
interface FeatureFlagConfig<T = Record<string, boolean>> {
|
|
1564
|
+
flags: FeatureFlags<T>;
|
|
1565
|
+
defaultValue: boolean;
|
|
1566
|
+
refreshInterval?: number;
|
|
1567
|
+
provider?: 'local' | 'launchdarkly' | 'optimizely' | 'split' | 'custom';
|
|
1568
|
+
onChange?: (flag: string, value: boolean) => void;
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* Config loader type
|
|
1572
|
+
*/
|
|
1573
|
+
interface ConfigLoader<T = unknown> {
|
|
1574
|
+
load: () => Promise<T>;
|
|
1575
|
+
reload: () => Promise<T>;
|
|
1576
|
+
watch: (callback: (config: T) => void) => () => void;
|
|
1577
|
+
}
|
|
1578
|
+
/**
|
|
1579
|
+
* Config loader options
|
|
1580
|
+
*/
|
|
1581
|
+
interface ConfigLoaderOptions {
|
|
1582
|
+
sources: ConfigSource[];
|
|
1583
|
+
priority?: ConfigPriority;
|
|
1584
|
+
env?: Environment$1;
|
|
1585
|
+
envPrefix?: string;
|
|
1586
|
+
configPath?: string;
|
|
1587
|
+
validate?: boolean;
|
|
1588
|
+
schema?: ConfigSchema;
|
|
1589
|
+
}
|
|
1590
|
+
/**
|
|
1591
|
+
* Config file format
|
|
1592
|
+
*/
|
|
1593
|
+
type ConfigFileFormat = 'json' | 'yaml' | 'toml' | 'ini' | 'env';
|
|
1594
|
+
/**
|
|
1595
|
+
* Remote config provider
|
|
1596
|
+
*/
|
|
1597
|
+
interface RemoteConfigProvider {
|
|
1598
|
+
get: (key: string) => Promise<ConfigValue>;
|
|
1599
|
+
set: (key: string, value: unknown) => Promise<void>;
|
|
1600
|
+
delete: (key: string) => Promise<void>;
|
|
1601
|
+
watch: (key: string, callback: (value: ConfigValue) => void) => () => void;
|
|
1602
|
+
}
|
|
1603
|
+
//#endregion
|
|
1604
|
+
//#region src/core/omit.d.ts
|
|
1605
|
+
/**
|
|
1606
|
+
* Make all properties required except specified ones
|
|
1607
|
+
*
|
|
1608
|
+
* @example
|
|
1609
|
+
* ```ts
|
|
1610
|
+
* interface User {
|
|
1611
|
+
* name?: string
|
|
1612
|
+
* age?: number
|
|
1613
|
+
* email?: string
|
|
1614
|
+
* }
|
|
1615
|
+
*
|
|
1616
|
+
* type RequiredExceptName = OmitRequired<User, 'name'>
|
|
1617
|
+
* // { name?: string; age: number; email: string }
|
|
1618
|
+
* ```
|
|
1619
|
+
*
|
|
1620
|
+
* @see PickRequired - Direct selection
|
|
1621
|
+
* @see OmitPartial - Opposite operation
|
|
1622
|
+
*/
|
|
1623
|
+
type OmitRequired<T, K extends keyof T> = { [P in K]: T[P] } & Omit<Required<T>, K>;
|
|
1624
|
+
/**
|
|
1625
|
+
* Make all properties optional except specified ones
|
|
1626
|
+
*
|
|
1627
|
+
* @example
|
|
1628
|
+
* ```ts
|
|
1629
|
+
* interface User {
|
|
1630
|
+
* name: string
|
|
1631
|
+
* age: number
|
|
1632
|
+
* email: string
|
|
1633
|
+
* }
|
|
1634
|
+
*
|
|
1635
|
+
* type OptionalExceptName = OmitPartial<User, 'name'>
|
|
1636
|
+
* // { name: string; age?: number; email?: string }
|
|
1637
|
+
* ```
|
|
1638
|
+
*
|
|
1639
|
+
* @see PickPartial - Direct selection
|
|
1640
|
+
* @see OmitRequired - Opposite operation
|
|
1641
|
+
*/
|
|
1642
|
+
type OmitPartial<T, K extends keyof T> = { [P in K]: T[P] } & Omit<Partial<T>, K>;
|
|
1643
|
+
//#endregion
|
|
1644
|
+
//#region src/core/pick.d.ts
|
|
1645
|
+
/**
|
|
1646
|
+
* Make specified properties required
|
|
1647
|
+
*
|
|
1648
|
+
* @template T - Target type
|
|
1649
|
+
* @template K - Property keys to make required
|
|
1650
|
+
*
|
|
1651
|
+
* @example
|
|
1652
|
+
* ```ts
|
|
1653
|
+
* interface User {
|
|
1654
|
+
* name?: string
|
|
1655
|
+
* age?: number
|
|
1656
|
+
* email: string
|
|
1657
|
+
* }
|
|
1658
|
+
*
|
|
1659
|
+
* type RequiredName = PickRequired<User, 'name'>
|
|
1660
|
+
* // { name: string; age?: number; email: string }
|
|
1661
|
+
* ```
|
|
1662
|
+
*
|
|
1663
|
+
* @see PickPartial - Opposite operation
|
|
1664
|
+
* @see OmitRequired - Inverse selection
|
|
1665
|
+
*/
|
|
1666
|
+
type PickRequired<T, K extends keyof T> = { [P in K]-?: T[P] } & Omit<T, K>;
|
|
1667
|
+
/**
|
|
1668
|
+
* Make specified properties optional
|
|
1669
|
+
*
|
|
1670
|
+
* @example
|
|
1671
|
+
* ```ts
|
|
1672
|
+
* interface User {
|
|
1673
|
+
* name: string
|
|
1674
|
+
* age: number
|
|
1675
|
+
* email: string
|
|
1676
|
+
* }
|
|
1677
|
+
*
|
|
896
1678
|
* type OptionalName = PickPartial<User, 'name'>
|
|
897
1679
|
* // { name?: string; age: number; email: string }
|
|
898
1680
|
* ```
|
|
@@ -2608,6 +3390,244 @@ interface VueComponentInstance<P = unknown, S = unknown> {
|
|
|
2608
3390
|
$emit: (event: string, ...args: unknown[]) => void;
|
|
2609
3391
|
}
|
|
2610
3392
|
//#endregion
|
|
3393
|
+
//#region src/event/index.d.ts
|
|
3394
|
+
/**
|
|
3395
|
+
* Event-Driven Architecture Types
|
|
3396
|
+
*
|
|
3397
|
+
* Types for event-driven patterns and architectures.
|
|
3398
|
+
*/
|
|
3399
|
+
/**
|
|
3400
|
+
* Event bus type
|
|
3401
|
+
*/
|
|
3402
|
+
interface EventBus<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
3403
|
+
publish: <E extends keyof T>(event: E, data: T[E]) => void;
|
|
3404
|
+
subscribe: <E extends keyof T>(event: E, handler: (data: T[E]) => void | Promise<void>) => () => void;
|
|
3405
|
+
unsubscribe: <E extends keyof T>(event: E, handler: (data: T[E]) => void | Promise<void>) => void;
|
|
3406
|
+
emit: <E extends keyof T>(event: E, data: T[E]) => Promise<void>;
|
|
3407
|
+
}
|
|
3408
|
+
/**
|
|
3409
|
+
* Event bus configuration
|
|
3410
|
+
*/
|
|
3411
|
+
interface EventBusConfig<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
3412
|
+
handlers?: { [E in keyof T]?: ((data: T[E]) => void | Promise<void>)[] };
|
|
3413
|
+
middleware?: EventBusMiddleware<T>;
|
|
3414
|
+
errorHandler?: (error: Error, event: keyof T, data: unknown) => void;
|
|
3415
|
+
}
|
|
3416
|
+
/**
|
|
3417
|
+
* Event bus handler
|
|
3418
|
+
*/
|
|
3419
|
+
type EventBusHandler<T, E extends keyof T = keyof T> = (data: T[E]) => void | Promise<void>;
|
|
3420
|
+
/**
|
|
3421
|
+
* Event bus middleware
|
|
3422
|
+
*/
|
|
3423
|
+
type EventBusMiddleware<T extends Record<string, unknown>> = (event: keyof T, data: T[keyof T], next: () => Promise<void>) => Promise<void>;
|
|
3424
|
+
/**
|
|
3425
|
+
* Event store type
|
|
3426
|
+
*/
|
|
3427
|
+
interface EventStore<E = unknown> {
|
|
3428
|
+
append: (event: E) => Promise<void>;
|
|
3429
|
+
getEvents: (aggregateId: string) => Promise<E[]>;
|
|
3430
|
+
getAllEvents: () => Promise<E[]>;
|
|
3431
|
+
subscribe: (handler: (event: E) => void) => () => void;
|
|
3432
|
+
}
|
|
3433
|
+
/**
|
|
3434
|
+
* Event stream type
|
|
3435
|
+
*/
|
|
3436
|
+
type EventStream<E = unknown> = AsyncIterable<E> & {
|
|
3437
|
+
subscribe: (handler: (event: E) => void) => () => void;
|
|
3438
|
+
pipe: <R>(transform: (event: E) => R) => EventStream<R>;
|
|
3439
|
+
};
|
|
3440
|
+
/**
|
|
3441
|
+
* Event version
|
|
3442
|
+
*/
|
|
3443
|
+
type EventVersion = number;
|
|
3444
|
+
/**
|
|
3445
|
+
* Event timestamp
|
|
3446
|
+
*/
|
|
3447
|
+
type EventTimestamp = number | string | Date;
|
|
3448
|
+
/**
|
|
3449
|
+
* Base event type
|
|
3450
|
+
*/
|
|
3451
|
+
interface BaseEvent<T = string, P = unknown> {
|
|
3452
|
+
type: T;
|
|
3453
|
+
payload: P;
|
|
3454
|
+
timestamp: EventTimestamp;
|
|
3455
|
+
version: EventVersion;
|
|
3456
|
+
aggregateId?: string;
|
|
3457
|
+
correlationId?: string;
|
|
3458
|
+
causationId?: string;
|
|
3459
|
+
}
|
|
3460
|
+
/**
|
|
3461
|
+
* Aggregate events
|
|
3462
|
+
*/
|
|
3463
|
+
type AggregateEvents<T extends Record<string, unknown>> = { [K in keyof T]: BaseEvent<K, T[K]> }[keyof T];
|
|
3464
|
+
/**
|
|
3465
|
+
* Command type
|
|
3466
|
+
*/
|
|
3467
|
+
interface Command<T = string, P = unknown> {
|
|
3468
|
+
type: T;
|
|
3469
|
+
payload: P;
|
|
3470
|
+
timestamp: EventTimestamp;
|
|
3471
|
+
commandId: string;
|
|
3472
|
+
aggregateId?: string;
|
|
3473
|
+
}
|
|
3474
|
+
/**
|
|
3475
|
+
* Command handler type
|
|
3476
|
+
*/
|
|
3477
|
+
type CommandHandler<C extends Command, R = void> = (command: C) => R | Promise<R>;
|
|
3478
|
+
/**
|
|
3479
|
+
* Query type
|
|
3480
|
+
*/
|
|
3481
|
+
interface Query<T = string, R = unknown> {
|
|
3482
|
+
type: T;
|
|
3483
|
+
params: R;
|
|
3484
|
+
timestamp: EventTimestamp;
|
|
3485
|
+
queryId: string;
|
|
3486
|
+
}
|
|
3487
|
+
/**
|
|
3488
|
+
* Query handler type
|
|
3489
|
+
*/
|
|
3490
|
+
type QueryHandler<Q extends Query, R> = (query: Q) => R | Promise<R>;
|
|
3491
|
+
/**
|
|
3492
|
+
* Command result type
|
|
3493
|
+
*/
|
|
3494
|
+
type CommandResult<T = unknown> = {
|
|
3495
|
+
success: true;
|
|
3496
|
+
data: T;
|
|
3497
|
+
} | {
|
|
3498
|
+
success: false;
|
|
3499
|
+
error: Error;
|
|
3500
|
+
};
|
|
3501
|
+
/**
|
|
3502
|
+
* Query result type
|
|
3503
|
+
*/
|
|
3504
|
+
type QueryResult<T = unknown> = {
|
|
3505
|
+
success: true;
|
|
3506
|
+
data: T;
|
|
3507
|
+
} | {
|
|
3508
|
+
success: false;
|
|
3509
|
+
error: Error;
|
|
3510
|
+
};
|
|
3511
|
+
/**
|
|
3512
|
+
* Command bus type
|
|
3513
|
+
*/
|
|
3514
|
+
interface CommandBus {
|
|
3515
|
+
dispatch: <C extends Command>(command: C) => Promise<CommandResult>;
|
|
3516
|
+
register: <C extends Command>(commandType: C['type'], handler: CommandHandler<C>) => void;
|
|
3517
|
+
}
|
|
3518
|
+
/**
|
|
3519
|
+
* Query bus type
|
|
3520
|
+
*/
|
|
3521
|
+
interface QueryBus {
|
|
3522
|
+
execute: <Q extends Query, R>(query: Q) => Promise<QueryResult<R>>;
|
|
3523
|
+
register: <Q extends Query, R>(queryType: Q['type'], handler: QueryHandler<Q, R>) => void;
|
|
3524
|
+
}
|
|
3525
|
+
/**
|
|
3526
|
+
* Saga type
|
|
3527
|
+
*/
|
|
3528
|
+
interface Saga<T = unknown> {
|
|
3529
|
+
sagaId: string;
|
|
3530
|
+
steps: SagaStep[];
|
|
3531
|
+
currentStep: number;
|
|
3532
|
+
status: SagaStatus;
|
|
3533
|
+
context: T;
|
|
3534
|
+
compensations: SagaCompensation[];
|
|
3535
|
+
}
|
|
3536
|
+
/**
|
|
3537
|
+
* Saga step type
|
|
3538
|
+
*/
|
|
3539
|
+
interface SagaStep<T = unknown> {
|
|
3540
|
+
stepId: string;
|
|
3541
|
+
name: string;
|
|
3542
|
+
execute: (context: T) => Promise<T>;
|
|
3543
|
+
compensate?: (context: T) => Promise<void>;
|
|
3544
|
+
status: StepStatus;
|
|
3545
|
+
error?: Error;
|
|
3546
|
+
}
|
|
3547
|
+
/**
|
|
3548
|
+
* Saga compensation type
|
|
3549
|
+
*/
|
|
3550
|
+
interface SagaCompensation<T = unknown> {
|
|
3551
|
+
stepId: string;
|
|
3552
|
+
compensate: (context: T) => Promise<void>;
|
|
3553
|
+
executed: boolean;
|
|
3554
|
+
}
|
|
3555
|
+
/**
|
|
3556
|
+
* Saga result type
|
|
3557
|
+
*/
|
|
3558
|
+
type SagaResult<T = unknown> = {
|
|
3559
|
+
success: true;
|
|
3560
|
+
data: T;
|
|
3561
|
+
} | {
|
|
3562
|
+
success: false;
|
|
3563
|
+
error: Error;
|
|
3564
|
+
compensatedSteps: string[];
|
|
3565
|
+
};
|
|
3566
|
+
/**
|
|
3567
|
+
* Saga status
|
|
3568
|
+
*/
|
|
3569
|
+
type SagaStatus = 'pending' | 'running' | 'completed' | 'failed' | 'compensating' | 'compensated';
|
|
3570
|
+
/**
|
|
3571
|
+
* Step status
|
|
3572
|
+
*/
|
|
3573
|
+
type StepStatus = 'pending' | 'running' | 'completed' | 'failed' | 'compensated';
|
|
3574
|
+
/**
|
|
3575
|
+
* Message queue type
|
|
3576
|
+
*/
|
|
3577
|
+
interface MessageQueue<M = unknown> {
|
|
3578
|
+
publish: (message: M) => Promise<void>;
|
|
3579
|
+
consume: (handler: (message: M) => Promise<void>) => void;
|
|
3580
|
+
ack: (messageId: string) => Promise<void>;
|
|
3581
|
+
nack: (messageId: string, reason?: string) => Promise<void>;
|
|
3582
|
+
close: () => Promise<void>;
|
|
3583
|
+
}
|
|
3584
|
+
/**
|
|
3585
|
+
* Queue message type
|
|
3586
|
+
*/
|
|
3587
|
+
interface QueueMessage<T = unknown> {
|
|
3588
|
+
id: string;
|
|
3589
|
+
payload: T;
|
|
3590
|
+
timestamp: EventTimestamp;
|
|
3591
|
+
retryCount: number;
|
|
3592
|
+
maxRetries: number;
|
|
3593
|
+
delay?: number;
|
|
3594
|
+
priority?: number;
|
|
3595
|
+
}
|
|
3596
|
+
/**
|
|
3597
|
+
* Queue consumer type
|
|
3598
|
+
*/
|
|
3599
|
+
interface QueueConsumer<T = unknown> {
|
|
3600
|
+
id: string;
|
|
3601
|
+
handler: (message: QueueMessage<T>) => Promise<void>;
|
|
3602
|
+
concurrency: number;
|
|
3603
|
+
prefetch: number;
|
|
3604
|
+
}
|
|
3605
|
+
/**
|
|
3606
|
+
* Queue producer type
|
|
3607
|
+
*/
|
|
3608
|
+
interface QueueProducer<T = unknown> {
|
|
3609
|
+
publish: (payload: T, options?: PublishOptions) => Promise<string>;
|
|
3610
|
+
publishBatch: (payloads: T[], options?: PublishOptions) => Promise<string[]>;
|
|
3611
|
+
}
|
|
3612
|
+
/**
|
|
3613
|
+
* Publish options
|
|
3614
|
+
*/
|
|
3615
|
+
interface PublishOptions {
|
|
3616
|
+
delay?: number;
|
|
3617
|
+
priority?: number;
|
|
3618
|
+
expiresAt?: Date | number;
|
|
3619
|
+
retryCount?: number;
|
|
3620
|
+
maxRetries?: number;
|
|
3621
|
+
}
|
|
3622
|
+
/**
|
|
3623
|
+
* Dead letter queue type
|
|
3624
|
+
*/
|
|
3625
|
+
interface DeadLetterQueue<T = unknown> {
|
|
3626
|
+
publish: (message: QueueMessage<T>, reason: string) => Promise<void>;
|
|
3627
|
+
getMessages: () => Promise<QueueMessage<T>[]>;
|
|
3628
|
+
retry: (messageId: string) => Promise<void>;
|
|
3629
|
+
}
|
|
3630
|
+
//#endregion
|
|
2611
3631
|
//#region src/functions/index.d.ts
|
|
2612
3632
|
/**
|
|
2613
3633
|
* Function type utilities
|
|
@@ -2725,7 +3745,156 @@ type AppendParameter<T, P> = T extends ((...args: infer A) => infer R) ? (...arg
|
|
|
2725
3745
|
*/
|
|
2726
3746
|
type PrependParameter<T, P> = T extends ((...args: infer A) => infer R) ? (...args: [P, ...A]) => R : never;
|
|
2727
3747
|
//#endregion
|
|
2728
|
-
//#region src/
|
|
3748
|
+
//#region src/graphql/index.d.ts
|
|
3749
|
+
/**
|
|
3750
|
+
* GraphQL Integration Types
|
|
3751
|
+
*
|
|
3752
|
+
* Type utilities for GraphQL schemas and operations.
|
|
3753
|
+
*/
|
|
3754
|
+
/**
|
|
3755
|
+
* GraphQL schema type representation
|
|
3756
|
+
*/
|
|
3757
|
+
interface GraphQLSchema<T> {
|
|
3758
|
+
query: T;
|
|
3759
|
+
mutation?: T;
|
|
3760
|
+
subscription?: T;
|
|
3761
|
+
types: Record<string, GraphQLType<any>>;
|
|
3762
|
+
}
|
|
3763
|
+
/**
|
|
3764
|
+
* GraphQL scalar and object types
|
|
3765
|
+
*/
|
|
3766
|
+
type GraphQLType<T> = GraphQLScalarType | GraphQLObjectType<T> | GraphQLEnumType | GraphQLInputObjectType<T> | GraphQLUnionType | GraphQLInterfaceType<T>;
|
|
3767
|
+
/**
|
|
3768
|
+
* GraphQL scalar types
|
|
3769
|
+
*/
|
|
3770
|
+
type GraphQLScalarType = 'String' | 'Int' | 'Float' | 'Boolean' | 'ID' | 'DateTime' | 'JSON';
|
|
3771
|
+
/**
|
|
3772
|
+
* GraphQL object type
|
|
3773
|
+
*/
|
|
3774
|
+
type GraphQLObjectType<T> = {
|
|
3775
|
+
__typename?: string;
|
|
3776
|
+
} & T;
|
|
3777
|
+
/**
|
|
3778
|
+
* GraphQL enum type
|
|
3779
|
+
*/
|
|
3780
|
+
type GraphQLEnumType = string;
|
|
3781
|
+
/**
|
|
3782
|
+
* GraphQL input object type
|
|
3783
|
+
*/
|
|
3784
|
+
type GraphQLInputObjectType<T> = T;
|
|
3785
|
+
/**
|
|
3786
|
+
* GraphQL union type
|
|
3787
|
+
*/
|
|
3788
|
+
type GraphQLUnionType = string;
|
|
3789
|
+
/**
|
|
3790
|
+
* GraphQL interface type
|
|
3791
|
+
*/
|
|
3792
|
+
type GraphQLInterfaceType<T> = T;
|
|
3793
|
+
/**
|
|
3794
|
+
* GraphQL input type
|
|
3795
|
+
*/
|
|
3796
|
+
type GraphQLInputType<T> = T extends GraphQLScalarType ? T : T extends object ? GraphQLInputObjectType<T> : never;
|
|
3797
|
+
/**
|
|
3798
|
+
* GraphQL output type
|
|
3799
|
+
*/
|
|
3800
|
+
type GraphQLOutputType<T> = T extends GraphQLScalarType ? T : T extends object ? GraphQLObjectType<T> : never;
|
|
3801
|
+
/**
|
|
3802
|
+
* GraphQL query type
|
|
3803
|
+
*/
|
|
3804
|
+
interface GraphQLQuery<T, V = Record<string, never>> {
|
|
3805
|
+
__query?: string;
|
|
3806
|
+
variables: V;
|
|
3807
|
+
return: T;
|
|
3808
|
+
}
|
|
3809
|
+
/**
|
|
3810
|
+
* GraphQL mutation type
|
|
3811
|
+
*/
|
|
3812
|
+
interface GraphQLMutation<T, V = Record<string, never>> {
|
|
3813
|
+
__mutation?: string;
|
|
3814
|
+
variables: V;
|
|
3815
|
+
return: T;
|
|
3816
|
+
}
|
|
3817
|
+
/**
|
|
3818
|
+
* GraphQL subscription type
|
|
3819
|
+
*/
|
|
3820
|
+
interface GraphQLSubscription<T, V = Record<string, never>> {
|
|
3821
|
+
__subscription?: string;
|
|
3822
|
+
variables: V;
|
|
3823
|
+
return: T;
|
|
3824
|
+
}
|
|
3825
|
+
/**
|
|
3826
|
+
* GraphQL fragment type
|
|
3827
|
+
*/
|
|
3828
|
+
type GraphQLFragment<T, N extends string> = {
|
|
3829
|
+
__fragment: N;
|
|
3830
|
+
__typename?: string;
|
|
3831
|
+
} & T;
|
|
3832
|
+
/**
|
|
3833
|
+
* GraphQL resolver function type
|
|
3834
|
+
*/
|
|
3835
|
+
type GraphQLResolver<T, C = unknown, A = Record<string, unknown>> = (parent: unknown, args: A, context: C, info: GraphQLResolveInfo) => T | Promise<T>;
|
|
3836
|
+
/**
|
|
3837
|
+
* GraphQL field resolver type
|
|
3838
|
+
*/
|
|
3839
|
+
type GraphQLFieldResolver<T, Args = Record<string, unknown>, C = unknown> = (source: unknown, args: Args, context: C, info: GraphQLResolveInfo) => T | Promise<T>;
|
|
3840
|
+
/**
|
|
3841
|
+
* GraphQL context type
|
|
3842
|
+
*/
|
|
3843
|
+
type GraphQLContext<T = Record<string, unknown>> = T & {
|
|
3844
|
+
__graphqlContext?: true;
|
|
3845
|
+
};
|
|
3846
|
+
/**
|
|
3847
|
+
* GraphQL resolve info
|
|
3848
|
+
*/
|
|
3849
|
+
interface GraphQLResolveInfo {
|
|
3850
|
+
fieldName: string;
|
|
3851
|
+
fieldNodes: unknown[];
|
|
3852
|
+
returnType: unknown;
|
|
3853
|
+
parentType: unknown;
|
|
3854
|
+
path: {
|
|
3855
|
+
key: string | number;
|
|
3856
|
+
prev: unknown;
|
|
3857
|
+
};
|
|
3858
|
+
schema: unknown;
|
|
3859
|
+
fragments: Record<string, unknown>;
|
|
3860
|
+
rootValue: unknown;
|
|
3861
|
+
operation: unknown;
|
|
3862
|
+
variableValues: Record<string, unknown>;
|
|
3863
|
+
}
|
|
3864
|
+
/**
|
|
3865
|
+
* GraphQL selection
|
|
3866
|
+
*/
|
|
3867
|
+
type GraphQLSelection<T> = { [K in keyof T]: T[K] extends object ? GraphQLSelection<T[K]> : boolean };
|
|
3868
|
+
/**
|
|
3869
|
+
* GraphQL selection set
|
|
3870
|
+
*/
|
|
3871
|
+
type GraphQLSelectionSet<T> = GraphQLSelection<T>;
|
|
3872
|
+
/**
|
|
3873
|
+
* GraphQL flat selection (flattened field names)
|
|
3874
|
+
*/
|
|
3875
|
+
type GraphQLFlatSelection<T, Prefix extends string = ''> = T extends object ? { [K in keyof T]: T[K] extends object ? GraphQLFlatSelection<T[K], `${Prefix}${K & string}.`> : `${Prefix}${K & string}` }[keyof T] : never;
|
|
3876
|
+
/**
|
|
3877
|
+
* Convert GraphQL type to TypeScript type
|
|
3878
|
+
*/
|
|
3879
|
+
type GraphQLToType<T> = T extends 'String' ? string : T extends 'Int' | 'Float' ? number : T extends 'Boolean' ? boolean : T extends 'ID' ? string : T extends 'DateTime' ? Date : T extends 'JSON' ? unknown : T;
|
|
3880
|
+
/**
|
|
3881
|
+
* Convert TypeScript type to GraphQL type
|
|
3882
|
+
*/
|
|
3883
|
+
type TypeToGraphQL<T> = T extends string ? 'String' : T extends number ? 'Int' : T extends boolean ? 'Boolean' : T extends Date ? 'DateTime' : 'JSON';
|
|
3884
|
+
/**
|
|
3885
|
+
* Extract field types from GraphQL object
|
|
3886
|
+
*/
|
|
3887
|
+
type GraphQLFieldTypes<T> = { [K in keyof T]: T[K] extends ((...args: any[]) => infer R) ? R : T[K] };
|
|
3888
|
+
/**
|
|
3889
|
+
* GraphQL argument types
|
|
3890
|
+
*/
|
|
3891
|
+
type GraphQLArgs<T> = T extends ((...args: infer A) => any) ? A[0] : never;
|
|
3892
|
+
/**
|
|
3893
|
+
* GraphQL return type
|
|
3894
|
+
*/
|
|
3895
|
+
type GraphQLReturn<T> = T extends ((...args: any[]) => infer R) ? R : never;
|
|
3896
|
+
//#endregion
|
|
3897
|
+
//#region src/guards/index.d.ts
|
|
2729
3898
|
/**
|
|
2730
3899
|
* Check if type is an array
|
|
2731
3900
|
*
|
|
@@ -2787,7 +3956,7 @@ type IsUnknown<T> = IsEqual<T, unknown> extends true ? IsAny<T> extends true ? f
|
|
|
2787
3956
|
* type Method = HTTPMethod // 'GET' | 'POST' | ...
|
|
2788
3957
|
* ```
|
|
2789
3958
|
*/
|
|
2790
|
-
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE';
|
|
3959
|
+
type HTTPMethod$1 = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE';
|
|
2791
3960
|
/**
|
|
2792
3961
|
* HTTP status codes
|
|
2793
3962
|
*
|
|
@@ -2797,15 +3966,6 @@ type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTION
|
|
|
2797
3966
|
* ```
|
|
2798
3967
|
*/
|
|
2799
3968
|
type HTTPStatus = 200 | 201 | 202 | 204 | 206 | 301 | 302 | 303 | 304 | 307 | 308 | 400 | 401 | 403 | 404 | 405 | 406 | 408 | 409 | 410 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 422 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 511;
|
|
2800
|
-
/**
|
|
2801
|
-
* HTTP status categories
|
|
2802
|
-
*
|
|
2803
|
-
* @example
|
|
2804
|
-
* ```ts
|
|
2805
|
-
* type Category = HTTPStatusCategory<404> // 'client_error'
|
|
2806
|
-
* ```
|
|
2807
|
-
*/
|
|
2808
|
-
type HTTPStatusCategory<S extends HTTPStatus> = S extends 200 | 201 | 202 | 204 | 206 ? 'success' : S extends 301 | 302 | 303 | 304 | 307 | 308 ? 'redirect' : S extends 400 | 401 | 403 | 404 | 405 | 406 | 408 | 409 | 410 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 422 | 425 | 426 | 428 | 429 | 431 | 451 ? 'client_error' : 'server_error';
|
|
2809
3969
|
/**
|
|
2810
3970
|
* HTTP headers type
|
|
2811
3971
|
*
|
|
@@ -2832,15 +3992,6 @@ type HTTPHeaders<T extends Record<string, string> = Record<string, never>> = T &
|
|
|
2832
3992
|
*/
|
|
2833
3993
|
'User-Agent'?: string;
|
|
2834
3994
|
};
|
|
2835
|
-
/**
|
|
2836
|
-
* Content-Type values
|
|
2837
|
-
*
|
|
2838
|
-
* @example
|
|
2839
|
-
* ```ts
|
|
2840
|
-
* type JsonContentType = ContentType // 'application/json'
|
|
2841
|
-
* ```
|
|
2842
|
-
*/
|
|
2843
|
-
type ContentType = 'application/json' | 'application/xml' | 'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/html' | 'text/plain' | 'text/css' | 'text/javascript' | 'image/jpeg' | 'image/png' | 'image/gif' | 'image/svg+xml';
|
|
2844
3995
|
/**
|
|
2845
3996
|
* Define a route
|
|
2846
3997
|
*
|
|
@@ -2849,105 +4000,12 @@ type ContentType = 'application/json' | 'application/xml' | 'application/x-www-f
|
|
|
2849
4000
|
* type UserRoute = Route<'/users/:id', 'GET', User>
|
|
2850
4001
|
* ```
|
|
2851
4002
|
*/
|
|
2852
|
-
interface Route<Path extends string, Method extends HTTPMethod, Response, Request = never> {
|
|
4003
|
+
interface Route<Path extends string, Method extends HTTPMethod$1, Response, Request = never> {
|
|
2853
4004
|
path: Path;
|
|
2854
4005
|
method: Method;
|
|
2855
4006
|
response: Response;
|
|
2856
4007
|
request: Request;
|
|
2857
4008
|
}
|
|
2858
|
-
/**
|
|
2859
|
-
* Extract path params from route path
|
|
2860
|
-
*
|
|
2861
|
-
* @example
|
|
2862
|
-
* ```ts
|
|
2863
|
-
* RouteParams<'/users/:id/posts/:postId'> // { id: string; postId: string }
|
|
2864
|
-
* ```
|
|
2865
|
-
*/
|
|
2866
|
-
type RouteParams<Path extends string> = ExtractParams<Path>;
|
|
2867
|
-
type ExtractParams<Path extends string, Acc extends Record<string, string> = Record<string, never>> = Path extends `/:${infer Param}/${infer Rest}` ? ExtractParams<Rest, Acc & { [K in Param]: string }> : Path extends `/:${infer Param}` ? Acc & { [K in Param]: string } : Acc;
|
|
2868
|
-
/**
|
|
2869
|
-
* Extract query params type
|
|
2870
|
-
*
|
|
2871
|
-
* @example
|
|
2872
|
-
* ```ts
|
|
2873
|
-
* RouteQuery<{ page: number; limit: number }> // { page?: string; limit?: string }
|
|
2874
|
-
* ```
|
|
2875
|
-
*/
|
|
2876
|
-
type RouteQuery<Q extends Record<string, any>> = { [K in keyof Q]?: string };
|
|
2877
|
-
/**
|
|
2878
|
-
* Router type
|
|
2879
|
-
*
|
|
2880
|
-
* @example
|
|
2881
|
-
* ```ts
|
|
2882
|
-
* type MyRouter = Router<{
|
|
2883
|
-
* '/users': { GET: User[]; POST: User }
|
|
2884
|
-
* '/users/:id': { GET: User; DELETE: void }
|
|
2885
|
-
* }>
|
|
2886
|
-
* ```
|
|
2887
|
-
*/
|
|
2888
|
-
type Router<Routes extends Record<string, Record<HTTPMethod, {
|
|
2889
|
-
response: any;
|
|
2890
|
-
request?: any;
|
|
2891
|
-
}>>> = Routes;
|
|
2892
|
-
/**
|
|
2893
|
-
* API endpoint type
|
|
2894
|
-
*
|
|
2895
|
-
* @example
|
|
2896
|
-
* ```ts
|
|
2897
|
-
* type Endpoint = APIEndpoint<{
|
|
2898
|
-
* method: 'GET'
|
|
2899
|
-
* path: '/users'
|
|
2900
|
-
* response: User[]
|
|
2901
|
-
* }>
|
|
2902
|
-
* ```
|
|
2903
|
-
*/
|
|
2904
|
-
type APIEndpoint<Config extends {
|
|
2905
|
-
method: HTTPMethod;
|
|
2906
|
-
path: string;
|
|
2907
|
-
response: any;
|
|
2908
|
-
request?: any;
|
|
2909
|
-
headers?: HTTPHeaders;
|
|
2910
|
-
}> = Config;
|
|
2911
|
-
/**
|
|
2912
|
-
* API request type
|
|
2913
|
-
*
|
|
2914
|
-
* @example
|
|
2915
|
-
* ```ts
|
|
2916
|
-
* type Request = APIRequest<{ body: CreateUserInput }>
|
|
2917
|
-
* ```
|
|
2918
|
-
*/
|
|
2919
|
-
type APIRequest<T extends {
|
|
2920
|
-
body?: any;
|
|
2921
|
-
headers?: HTTPHeaders;
|
|
2922
|
-
params?: Record<string, string>;
|
|
2923
|
-
query?: Record<string, string>;
|
|
2924
|
-
}> = T;
|
|
2925
|
-
/**
|
|
2926
|
-
* API response type
|
|
2927
|
-
*
|
|
2928
|
-
* @example
|
|
2929
|
-
* ```ts
|
|
2930
|
-
* type Response = APIResponse<{ data: User; status: 200 }>
|
|
2931
|
-
* ```
|
|
2932
|
-
*/
|
|
2933
|
-
type APIResponse<T extends {
|
|
2934
|
-
data: any;
|
|
2935
|
-
status?: HTTPStatus;
|
|
2936
|
-
headers?: HTTPHeaders;
|
|
2937
|
-
}> = T;
|
|
2938
|
-
/**
|
|
2939
|
-
* API error type
|
|
2940
|
-
*
|
|
2941
|
-
* @example
|
|
2942
|
-
* ```ts
|
|
2943
|
-
* type Error = APIError<{ message: string; code: 'INVALID_INPUT' }>
|
|
2944
|
-
* ```
|
|
2945
|
-
*/
|
|
2946
|
-
type APIError<T extends {
|
|
2947
|
-
message: string;
|
|
2948
|
-
code?: string;
|
|
2949
|
-
status?: HTTPStatus;
|
|
2950
|
-
}> = T;
|
|
2951
4009
|
/**
|
|
2952
4010
|
* Middleware function type
|
|
2953
4011
|
*
|
|
@@ -2967,7 +4025,7 @@ type Middleware<C extends Record<string, any> = object> = (ctx: Context<C>, next
|
|
|
2967
4025
|
*/
|
|
2968
4026
|
interface Context<C extends Record<string, any> = object> {
|
|
2969
4027
|
request: {
|
|
2970
|
-
method: HTTPMethod;
|
|
4028
|
+
method: HTTPMethod$1;
|
|
2971
4029
|
path: string;
|
|
2972
4030
|
headers: HTTPHeaders;
|
|
2973
4031
|
body?: unknown;
|
|
@@ -2981,86 +4039,6 @@ interface Context<C extends Record<string, any> = object> {
|
|
|
2981
4039
|
};
|
|
2982
4040
|
state: C;
|
|
2983
4041
|
}
|
|
2984
|
-
/**
|
|
2985
|
-
* Middleware chain type
|
|
2986
|
-
*
|
|
2987
|
-
* @example
|
|
2988
|
-
* ```ts
|
|
2989
|
-
* type Chain = MiddlewareChain<[AuthMiddleware, LoggingMiddleware]>
|
|
2990
|
-
* ```
|
|
2991
|
-
*/
|
|
2992
|
-
type MiddlewareChain<M extends Middleware<any>[] = []> = M;
|
|
2993
|
-
/**
|
|
2994
|
-
* Compose middleware chain
|
|
2995
|
-
*
|
|
2996
|
-
* @example
|
|
2997
|
-
* ```ts
|
|
2998
|
-
* type Composed = ComposeMiddleware<[AuthMiddleware]>
|
|
2999
|
-
* ```
|
|
3000
|
-
*/
|
|
3001
|
-
type ComposeMiddleware<M extends Middleware<any>[] = []> = (ctx: Context<ExtractContextFromMiddleware<M>>) => Promise<void>;
|
|
3002
|
-
type ExtractContextFromMiddleware<M extends Middleware<any>[] = []> = M extends [infer _First extends Middleware<infer C>, ...infer Rest extends Middleware<any>[]] ? C & ExtractContextFromMiddleware<Rest> : Record<string, never>;
|
|
3003
|
-
/**
|
|
3004
|
-
* Build request options type
|
|
3005
|
-
*
|
|
3006
|
-
* @example
|
|
3007
|
-
* ```ts
|
|
3008
|
-
* type Options = RequestOptions<{ timeout: 5000 }>
|
|
3009
|
-
* ```
|
|
3010
|
-
*/
|
|
3011
|
-
type RequestOptions<T extends {
|
|
3012
|
-
timeout?: number;
|
|
3013
|
-
retries?: number;
|
|
3014
|
-
headers?: HTTPHeaders;
|
|
3015
|
-
}> = T;
|
|
3016
|
-
/**
|
|
3017
|
-
* Parse response type
|
|
3018
|
-
*
|
|
3019
|
-
* @example
|
|
3020
|
-
* ```ts
|
|
3021
|
-
* type Data = ParseResponse<{ data: User }>
|
|
3022
|
-
* ```
|
|
3023
|
-
*/
|
|
3024
|
-
type ParseResponse<R extends {
|
|
3025
|
-
data?: any;
|
|
3026
|
-
}> = R['data'];
|
|
3027
|
-
/**
|
|
3028
|
-
* REST collection endpoints
|
|
3029
|
-
*
|
|
3030
|
-
* @example
|
|
3031
|
-
* ```ts
|
|
3032
|
-
* type UserEndpoints = RESTCollection<User, CreateUserInput>
|
|
3033
|
-
* ```
|
|
3034
|
-
*/
|
|
3035
|
-
interface RESTCollection<Resource, CreateInput = Partial<Resource>, UpdateInput = Partial<Resource>> {
|
|
3036
|
-
list: Route<'/', 'GET', Resource[]>;
|
|
3037
|
-
create: Route<'/', 'POST', Resource, CreateInput>;
|
|
3038
|
-
show: Route<'/:id', 'GET', Resource>;
|
|
3039
|
-
update: Route<'/:id', 'PUT', Resource, UpdateInput>;
|
|
3040
|
-
delete: Route<'/:id', 'DELETE', void>;
|
|
3041
|
-
}
|
|
3042
|
-
/**
|
|
3043
|
-
* REST resource endpoints
|
|
3044
|
-
*
|
|
3045
|
-
* @example
|
|
3046
|
-
* ```ts
|
|
3047
|
-
* type UserResource = RESTResource<User>
|
|
3048
|
-
* ```
|
|
3049
|
-
*/
|
|
3050
|
-
interface RESTResource<Resource> {
|
|
3051
|
-
show: Route<'/:id', 'GET', Resource>;
|
|
3052
|
-
update: Route<'/:id', 'PUT', Resource>;
|
|
3053
|
-
delete: Route<'/:id', 'DELETE', void>;
|
|
3054
|
-
}
|
|
3055
|
-
/**
|
|
3056
|
-
* CRUD operation types
|
|
3057
|
-
*
|
|
3058
|
-
* @example
|
|
3059
|
-
* ```ts
|
|
3060
|
-
* type Op = CRUDOperation // 'create' | 'read' | ...
|
|
3061
|
-
* ```
|
|
3062
|
-
*/
|
|
3063
|
-
type CRUDOperation = 'create' | 'read' | 'update' | 'delete';
|
|
3064
4042
|
//#endregion
|
|
3065
4043
|
//#region src/infer/index.d.ts
|
|
3066
4044
|
/**
|
|
@@ -3620,224 +4598,857 @@ type KeysByValueType<T, V> = { [K in keyof T]: T[K] extends V ? K : never }[keyo
|
|
|
3620
4598
|
*/
|
|
3621
4599
|
type FilterKeys<T, P extends string> = keyof T extends infer K ? K extends P ? K : never : never;
|
|
3622
4600
|
//#endregion
|
|
3623
|
-
//#region src/
|
|
4601
|
+
//#region src/logging/index.d.ts
|
|
3624
4602
|
/**
|
|
3625
|
-
*
|
|
4603
|
+
* Logging & Observability Types
|
|
4604
|
+
*
|
|
4605
|
+
* Types for logging and monitoring systems.
|
|
3626
4606
|
*/
|
|
3627
|
-
type NumberToArray<N extends number, Acc extends 0[] = []> = Acc['length'] extends N ? Acc : NumberToArray<N, [...Acc, 0]>;
|
|
3628
4607
|
/**
|
|
3629
|
-
*
|
|
3630
|
-
*
|
|
3631
|
-
* @example
|
|
3632
|
-
* ```ts
|
|
3633
|
-
* Inc<5> // 6
|
|
3634
|
-
* Inc<0> // 1
|
|
3635
|
-
* ```
|
|
4608
|
+
* Logger type
|
|
3636
4609
|
*/
|
|
3637
|
-
|
|
4610
|
+
interface Logger<T = Record<string, unknown>> {
|
|
4611
|
+
trace: (message: string, context?: T) => void;
|
|
4612
|
+
debug: (message: string, context?: T) => void;
|
|
4613
|
+
info: (message: string, context?: T) => void;
|
|
4614
|
+
warn: (message: string, context?: T) => void;
|
|
4615
|
+
error: (message: string, error?: Error, context?: T) => void;
|
|
4616
|
+
fatal: (message: string, error?: Error, context?: T) => void;
|
|
4617
|
+
child: (context: Partial<T>) => Logger<T>;
|
|
4618
|
+
}
|
|
3638
4619
|
/**
|
|
3639
|
-
*
|
|
3640
|
-
*
|
|
3641
|
-
* @example
|
|
3642
|
-
* ```ts
|
|
3643
|
-
* Dec<5> // 4
|
|
3644
|
-
* Dec<1> // 0
|
|
3645
|
-
* Dec<0> // 0 (clamped)
|
|
3646
|
-
* ```
|
|
4620
|
+
* Log level
|
|
3647
4621
|
*/
|
|
3648
|
-
type
|
|
4622
|
+
type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
3649
4623
|
/**
|
|
3650
|
-
*
|
|
3651
|
-
*
|
|
3652
|
-
* @example
|
|
3653
|
-
* ```ts
|
|
3654
|
-
* Add<3, 4> // 7
|
|
3655
|
-
* Add<0, 5> // 5
|
|
3656
|
-
* ```
|
|
4624
|
+
* Log entry
|
|
3657
4625
|
*/
|
|
3658
|
-
|
|
4626
|
+
interface LogEntry<T = Record<string, unknown>> {
|
|
4627
|
+
level: LogLevel;
|
|
4628
|
+
message: string;
|
|
4629
|
+
timestamp: Date;
|
|
4630
|
+
context?: T;
|
|
4631
|
+
error?: {
|
|
4632
|
+
message: string;
|
|
4633
|
+
stack?: string;
|
|
4634
|
+
name: string;
|
|
4635
|
+
};
|
|
4636
|
+
traceId?: string;
|
|
4637
|
+
spanId?: string;
|
|
4638
|
+
service?: string;
|
|
4639
|
+
version?: string;
|
|
4640
|
+
hostname?: string;
|
|
4641
|
+
}
|
|
3659
4642
|
/**
|
|
3660
|
-
*
|
|
3661
|
-
*
|
|
3662
|
-
* @example
|
|
3663
|
-
* ```ts
|
|
3664
|
-
* Subtract<10, 3> // 7
|
|
3665
|
-
* Subtract<5, 10> // 0 (clamped)
|
|
3666
|
-
* ```
|
|
4643
|
+
* Log context
|
|
3667
4644
|
*/
|
|
3668
|
-
type
|
|
4645
|
+
type LogContext<T = Record<string, unknown>> = T & {
|
|
4646
|
+
traceId?: string;
|
|
4647
|
+
spanId?: string;
|
|
4648
|
+
userId?: string;
|
|
4649
|
+
requestId?: string;
|
|
4650
|
+
sessionId?: string;
|
|
4651
|
+
};
|
|
3669
4652
|
/**
|
|
3670
|
-
*
|
|
3671
|
-
* Note: Limited to small ranges due to TypeScript recursion limits
|
|
3672
|
-
*
|
|
3673
|
-
* @example
|
|
3674
|
-
* ```ts
|
|
3675
|
-
* Range<1, 5> // 1 | 2 | 3 | 4 | 5
|
|
3676
|
-
* Range<0, 3> // 0 | 1 | 2 | 3
|
|
3677
|
-
* ```
|
|
4653
|
+
* Logger configuration
|
|
3678
4654
|
*/
|
|
3679
|
-
|
|
4655
|
+
interface LoggerConfig<T = Record<string, unknown>> {
|
|
4656
|
+
level: LogLevel;
|
|
4657
|
+
format: 'json' | 'pretty' | 'simple';
|
|
4658
|
+
transports: LogTransport[];
|
|
4659
|
+
context?: T;
|
|
4660
|
+
redact?: string[];
|
|
4661
|
+
}
|
|
3680
4662
|
/**
|
|
3681
|
-
*
|
|
3682
|
-
*
|
|
3683
|
-
* @example
|
|
3684
|
-
* ```ts
|
|
3685
|
-
* GreaterThan<5, 3> // true
|
|
3686
|
-
* GreaterThan<3, 5> // false
|
|
3687
|
-
* ```
|
|
4663
|
+
* Log transport
|
|
3688
4664
|
*/
|
|
3689
|
-
|
|
4665
|
+
interface LogTransport {
|
|
4666
|
+
type: 'console' | 'file' | 'http' | 'stream';
|
|
4667
|
+
options?: Record<string, unknown>;
|
|
4668
|
+
}
|
|
3690
4669
|
/**
|
|
3691
|
-
*
|
|
3692
|
-
*
|
|
3693
|
-
* @example
|
|
3694
|
-
* ```ts
|
|
3695
|
-
* LessThan<3, 5> // true
|
|
3696
|
-
* LessThan<5, 3> // false
|
|
3697
|
-
* ```
|
|
4670
|
+
* Metric type
|
|
3698
4671
|
*/
|
|
3699
|
-
|
|
4672
|
+
interface Metric<T = number> {
|
|
4673
|
+
name: string;
|
|
4674
|
+
value: T;
|
|
4675
|
+
timestamp: Date;
|
|
4676
|
+
labels?: Record<string, string>;
|
|
4677
|
+
help?: string;
|
|
4678
|
+
type: MetricType;
|
|
4679
|
+
}
|
|
3700
4680
|
/**
|
|
3701
|
-
*
|
|
3702
|
-
*
|
|
3703
|
-
* @example
|
|
3704
|
-
* ```ts
|
|
3705
|
-
* Max<3, 5> // 5
|
|
3706
|
-
* Max<5, 3> // 5
|
|
3707
|
-
* ```
|
|
4681
|
+
* Metric type enumeration
|
|
3708
4682
|
*/
|
|
3709
|
-
type
|
|
4683
|
+
type MetricType = 'counter' | 'gauge' | 'histogram' | 'summary';
|
|
3710
4684
|
/**
|
|
3711
|
-
*
|
|
3712
|
-
*
|
|
3713
|
-
* @example
|
|
3714
|
-
* ```ts
|
|
3715
|
-
* Min<3, 5> // 3
|
|
3716
|
-
* Min<5, 3> // 3
|
|
3717
|
-
* ```
|
|
4685
|
+
* Counter metric
|
|
3718
4686
|
*/
|
|
3719
|
-
|
|
4687
|
+
interface Counter<T = number> {
|
|
4688
|
+
inc: (value?: T) => void;
|
|
4689
|
+
dec: (value?: T) => void;
|
|
4690
|
+
reset: () => void;
|
|
4691
|
+
getValue: () => T;
|
|
4692
|
+
}
|
|
4693
|
+
/**
|
|
4694
|
+
* Gauge metric
|
|
4695
|
+
*/
|
|
4696
|
+
interface Gauge<T = number> {
|
|
4697
|
+
set: (value: T) => void;
|
|
4698
|
+
inc: (value?: T) => void;
|
|
4699
|
+
dec: (value?: T) => void;
|
|
4700
|
+
reset: () => void;
|
|
4701
|
+
getValue: () => T | undefined;
|
|
4702
|
+
}
|
|
4703
|
+
/**
|
|
4704
|
+
* Histogram metric
|
|
4705
|
+
*/
|
|
4706
|
+
interface Histogram {
|
|
4707
|
+
observe: (value: number) => void;
|
|
4708
|
+
reset: () => void;
|
|
4709
|
+
getBuckets: () => Record<string, number>;
|
|
4710
|
+
getSum: () => number;
|
|
4711
|
+
getCount: () => number;
|
|
4712
|
+
}
|
|
4713
|
+
/**
|
|
4714
|
+
* Summary metric
|
|
4715
|
+
*/
|
|
4716
|
+
interface Summary {
|
|
4717
|
+
observe: (value: number) => void;
|
|
4718
|
+
reset: () => void;
|
|
4719
|
+
getQuantiles: () => Record<string, number>;
|
|
4720
|
+
getSum: () => number;
|
|
4721
|
+
getCount: () => number;
|
|
4722
|
+
}
|
|
4723
|
+
/**
|
|
4724
|
+
* Metrics registry
|
|
4725
|
+
*/
|
|
4726
|
+
interface MetricsRegistry {
|
|
4727
|
+
register: <T extends Metric>(metric: T) => void;
|
|
4728
|
+
unregister: (name: string) => void;
|
|
4729
|
+
getMetric: (name: string) => Metric | undefined;
|
|
4730
|
+
getAllMetrics: () => Metric[];
|
|
4731
|
+
export: () => string;
|
|
4732
|
+
}
|
|
4733
|
+
/**
|
|
4734
|
+
* Span type
|
|
4735
|
+
*/
|
|
4736
|
+
interface Span {
|
|
4737
|
+
traceId: string;
|
|
4738
|
+
spanId: string;
|
|
4739
|
+
parentSpanId?: string;
|
|
4740
|
+
name: string;
|
|
4741
|
+
kind: SpanKind;
|
|
4742
|
+
startTime: Date;
|
|
4743
|
+
endTime?: Date;
|
|
4744
|
+
status: SpanStatus;
|
|
4745
|
+
attributes: Record<string, unknown>;
|
|
4746
|
+
events: SpanEvent[];
|
|
4747
|
+
}
|
|
4748
|
+
/**
|
|
4749
|
+
* Span kind
|
|
4750
|
+
*/
|
|
4751
|
+
type SpanKind = 'client' | 'server' | 'producer' | 'consumer' | 'internal';
|
|
4752
|
+
/**
|
|
4753
|
+
* Span status
|
|
4754
|
+
*/
|
|
4755
|
+
type SpanStatus = 'unset' | 'ok' | 'error';
|
|
4756
|
+
/**
|
|
4757
|
+
* Span event
|
|
4758
|
+
*/
|
|
4759
|
+
interface SpanEvent {
|
|
4760
|
+
name: string;
|
|
4761
|
+
timestamp: Date;
|
|
4762
|
+
attributes?: Record<string, unknown>;
|
|
4763
|
+
}
|
|
4764
|
+
/**
|
|
4765
|
+
* Trace type
|
|
4766
|
+
*/
|
|
4767
|
+
interface Trace<T = unknown> {
|
|
4768
|
+
traceId: string;
|
|
4769
|
+
spans: Span[];
|
|
4770
|
+
rootSpan: Span;
|
|
4771
|
+
startTime: Date;
|
|
4772
|
+
endTime?: Date;
|
|
4773
|
+
duration?: number;
|
|
4774
|
+
status: TraceStatus;
|
|
4775
|
+
metadata?: T;
|
|
4776
|
+
}
|
|
4777
|
+
/**
|
|
4778
|
+
* Trace status
|
|
4779
|
+
*/
|
|
4780
|
+
type TraceStatus = 'in-progress' | 'completed' | 'failed';
|
|
4781
|
+
/**
|
|
4782
|
+
* Trace context
|
|
4783
|
+
*/
|
|
4784
|
+
interface TraceContext {
|
|
4785
|
+
traceId: string;
|
|
4786
|
+
spanId: string;
|
|
4787
|
+
traceFlags: number;
|
|
4788
|
+
traceState?: string;
|
|
4789
|
+
}
|
|
4790
|
+
/**
|
|
4791
|
+
* Tracer type
|
|
4792
|
+
*/
|
|
4793
|
+
interface Tracer {
|
|
4794
|
+
startSpan: (name: string, options?: SpanOptions) => Span;
|
|
4795
|
+
getCurrentSpan: () => Span | undefined;
|
|
4796
|
+
setCurrentSpan: (span: Span) => void;
|
|
4797
|
+
withSpan: <T>(span: Span, fn: () => T) => T;
|
|
4798
|
+
}
|
|
4799
|
+
/**
|
|
4800
|
+
* Span options
|
|
4801
|
+
*/
|
|
4802
|
+
interface SpanOptions {
|
|
4803
|
+
kind?: SpanKind;
|
|
4804
|
+
attributes?: Record<string, unknown>;
|
|
4805
|
+
parent?: Span;
|
|
4806
|
+
links?: SpanLink[];
|
|
4807
|
+
startTime?: Date;
|
|
4808
|
+
}
|
|
4809
|
+
/**
|
|
4810
|
+
* Span link
|
|
4811
|
+
*/
|
|
4812
|
+
interface SpanLink {
|
|
4813
|
+
traceId: string;
|
|
4814
|
+
spanId: string;
|
|
4815
|
+
attributes?: Record<string, unknown>;
|
|
4816
|
+
}
|
|
4817
|
+
/**
|
|
4818
|
+
* Monitor type
|
|
4819
|
+
*/
|
|
4820
|
+
interface Monitor {
|
|
4821
|
+
name: string;
|
|
4822
|
+
check: () => Promise<MonitorResult>;
|
|
4823
|
+
interval: number;
|
|
4824
|
+
timeout: number;
|
|
4825
|
+
status: MonitorStatus;
|
|
4826
|
+
lastCheck?: Date;
|
|
4827
|
+
}
|
|
4828
|
+
/**
|
|
4829
|
+
* Monitor status
|
|
4830
|
+
*/
|
|
4831
|
+
type MonitorStatus = 'healthy' | 'unhealthy' | 'degraded' | 'unknown';
|
|
4832
|
+
/**
|
|
4833
|
+
* Monitor result
|
|
4834
|
+
*/
|
|
4835
|
+
interface MonitorResult<T = unknown> {
|
|
4836
|
+
status: MonitorStatus;
|
|
4837
|
+
message: string;
|
|
4838
|
+
timestamp: Date;
|
|
4839
|
+
duration: number;
|
|
4840
|
+
details?: T;
|
|
4841
|
+
}
|
|
4842
|
+
/**
|
|
4843
|
+
* Alert type
|
|
4844
|
+
*/
|
|
4845
|
+
interface Alert<T = unknown> {
|
|
4846
|
+
id: string;
|
|
4847
|
+
name: string;
|
|
4848
|
+
severity: AlertSeverity;
|
|
4849
|
+
status: AlertStatus;
|
|
4850
|
+
message: string;
|
|
4851
|
+
timestamp: Date;
|
|
4852
|
+
resolvedAt?: Date;
|
|
4853
|
+
labels: Record<string, string>;
|
|
4854
|
+
annotations: Record<string, string>;
|
|
4855
|
+
details?: T;
|
|
4856
|
+
}
|
|
4857
|
+
/**
|
|
4858
|
+
* Alert severity
|
|
4859
|
+
*/
|
|
4860
|
+
type AlertSeverity = 'info' | 'warning' | 'critical' | 'error';
|
|
4861
|
+
/**
|
|
4862
|
+
* Alert status
|
|
4863
|
+
*/
|
|
4864
|
+
type AlertStatus = 'firing' | 'resolved' | 'silenced' | 'inhibited';
|
|
4865
|
+
/**
|
|
4866
|
+
* Alert rule
|
|
4867
|
+
*/
|
|
4868
|
+
interface AlertRule<T = unknown> {
|
|
4869
|
+
name: string;
|
|
4870
|
+
expression: string;
|
|
4871
|
+
duration: number;
|
|
4872
|
+
severity: AlertSeverity;
|
|
4873
|
+
labels: Record<string, string>;
|
|
4874
|
+
annotations: Record<string, string>;
|
|
4875
|
+
for?: number;
|
|
4876
|
+
handler?: (alert: Alert<T>) => void;
|
|
4877
|
+
}
|
|
4878
|
+
/**
|
|
4879
|
+
* Alert configuration
|
|
4880
|
+
*/
|
|
4881
|
+
interface AlertConfig {
|
|
4882
|
+
rules: AlertRule[];
|
|
4883
|
+
receivers: AlertReceiver[];
|
|
4884
|
+
route: AlertRoute;
|
|
4885
|
+
inhibitRules?: InhibitRule[];
|
|
4886
|
+
}
|
|
4887
|
+
/**
|
|
4888
|
+
* Alert receiver
|
|
4889
|
+
*/
|
|
4890
|
+
interface AlertReceiver {
|
|
4891
|
+
name: string;
|
|
4892
|
+
type: 'email' | 'slack' | 'pagerduty' | 'webhook' | 'opsgenie' | 'victorops';
|
|
4893
|
+
config: Record<string, unknown>;
|
|
4894
|
+
}
|
|
4895
|
+
/**
|
|
4896
|
+
* Alert route
|
|
4897
|
+
*/
|
|
4898
|
+
interface AlertRoute {
|
|
4899
|
+
receiver: string;
|
|
4900
|
+
match?: Record<string, string>;
|
|
4901
|
+
continue?: boolean;
|
|
4902
|
+
routes?: AlertRoute[];
|
|
4903
|
+
}
|
|
4904
|
+
/**
|
|
4905
|
+
* Inhibit rule
|
|
4906
|
+
*/
|
|
4907
|
+
interface InhibitRule {
|
|
4908
|
+
sourceMatch: Record<string, string>;
|
|
4909
|
+
targetMatch: Record<string, string>;
|
|
4910
|
+
equal: string[];
|
|
4911
|
+
}
|
|
4912
|
+
/**
|
|
4913
|
+
* Health indicator
|
|
4914
|
+
*/
|
|
4915
|
+
interface HealthIndicator<T = unknown> {
|
|
4916
|
+
name: string;
|
|
4917
|
+
check: () => Promise<HealthCheckResult<T>>;
|
|
4918
|
+
critical: boolean;
|
|
4919
|
+
}
|
|
4920
|
+
/**
|
|
4921
|
+
* Health check result
|
|
4922
|
+
*/
|
|
4923
|
+
interface HealthCheckResult<T = unknown> {
|
|
4924
|
+
status: 'healthy' | 'unhealthy' | 'degraded';
|
|
4925
|
+
message?: string;
|
|
4926
|
+
timestamp: Date;
|
|
4927
|
+
duration?: number;
|
|
4928
|
+
details?: T;
|
|
4929
|
+
}
|
|
4930
|
+
/**
|
|
4931
|
+
* Liveness check
|
|
4932
|
+
*/
|
|
4933
|
+
interface LivenessCheck {
|
|
4934
|
+
check: () => Promise<boolean>;
|
|
4935
|
+
timeout: number;
|
|
4936
|
+
}
|
|
4937
|
+
/**
|
|
4938
|
+
* Readiness check
|
|
4939
|
+
*/
|
|
4940
|
+
interface ReadinessCheck {
|
|
4941
|
+
check: () => Promise<boolean>;
|
|
4942
|
+
timeout: number;
|
|
4943
|
+
dependencies: string[];
|
|
4944
|
+
}
|
|
3720
4945
|
//#endregion
|
|
3721
|
-
//#region src/
|
|
4946
|
+
//#region src/microservice/index.d.ts
|
|
3722
4947
|
/**
|
|
3723
|
-
*
|
|
4948
|
+
* Microservices Architecture Types
|
|
3724
4949
|
*
|
|
3725
|
-
*
|
|
3726
|
-
* - Object transformations: ObjectMap, ObjectFilter, ObjectPickByType
|
|
3727
|
-
* - Object merging: DeepMerge, DeepAssign, DeepDefaults
|
|
3728
|
-
* - Object validation: HasProperty, HasProperties, HasMethod
|
|
4950
|
+
* Types for microservices patterns and communication.
|
|
3729
4951
|
*/
|
|
3730
4952
|
/**
|
|
3731
|
-
*
|
|
4953
|
+
* Microservice type
|
|
3732
4954
|
*/
|
|
3733
|
-
|
|
4955
|
+
interface Microservice<T = unknown> {
|
|
4956
|
+
name: string;
|
|
4957
|
+
version: string;
|
|
4958
|
+
config: ServiceConfig<T>;
|
|
4959
|
+
start: () => Promise<void>;
|
|
4960
|
+
stop: () => Promise<void>;
|
|
4961
|
+
health: () => Promise<HealthReport>;
|
|
4962
|
+
}
|
|
3734
4963
|
/**
|
|
3735
|
-
*
|
|
4964
|
+
* Service configuration
|
|
3736
4965
|
*/
|
|
3737
|
-
|
|
4966
|
+
interface ServiceConfig<T = unknown> {
|
|
4967
|
+
name: string;
|
|
4968
|
+
version: string;
|
|
4969
|
+
port: number;
|
|
4970
|
+
host: string;
|
|
4971
|
+
env: Environment;
|
|
4972
|
+
options?: T;
|
|
4973
|
+
dependencies?: string[];
|
|
4974
|
+
timeouts?: {
|
|
4975
|
+
start?: number;
|
|
4976
|
+
stop?: number;
|
|
4977
|
+
request?: number;
|
|
4978
|
+
};
|
|
4979
|
+
}
|
|
3738
4980
|
/**
|
|
3739
|
-
*
|
|
4981
|
+
* Service registry type
|
|
3740
4982
|
*/
|
|
3741
|
-
|
|
4983
|
+
interface ServiceRegistry<S = unknown> {
|
|
4984
|
+
register: (service: S) => Promise<void>;
|
|
4985
|
+
deregister: (serviceName: string) => Promise<void>;
|
|
4986
|
+
getService: (serviceName: string) => Promise<ServiceInstance | undefined>;
|
|
4987
|
+
getAllServices: () => Promise<ServiceInstance[]>;
|
|
4988
|
+
heartbeat: (serviceName: string, instanceId: string) => Promise<void>;
|
|
4989
|
+
}
|
|
3742
4990
|
/**
|
|
3743
|
-
*
|
|
4991
|
+
* Service discovery type
|
|
3744
4992
|
*/
|
|
3745
|
-
|
|
4993
|
+
interface ServiceDiscovery {
|
|
4994
|
+
discover: (serviceName: string) => Promise<ServiceInstance[]>;
|
|
4995
|
+
watch: (serviceName: string, callback: (instances: ServiceInstance[]) => void) => () => void;
|
|
4996
|
+
getInstance: (serviceName: string, strategy?: LoadBalancerStrategy) => Promise<ServiceInstance | undefined>;
|
|
4997
|
+
}
|
|
3746
4998
|
/**
|
|
3747
|
-
*
|
|
4999
|
+
* Service client type
|
|
3748
5000
|
*/
|
|
3749
|
-
|
|
5001
|
+
interface ServiceClient<T = unknown> {
|
|
5002
|
+
call: <R>(method: string, params: T) => Promise<ServiceResponse<R>>;
|
|
5003
|
+
callStream: <R>(method: string, params: T) => AsyncIterable<R>;
|
|
5004
|
+
close: () => Promise<void>;
|
|
5005
|
+
}
|
|
3750
5006
|
/**
|
|
3751
|
-
*
|
|
5007
|
+
* Service request type
|
|
3752
5008
|
*/
|
|
3753
|
-
|
|
5009
|
+
interface ServiceRequest<T = unknown> {
|
|
5010
|
+
id: string;
|
|
5011
|
+
service: string;
|
|
5012
|
+
method: string;
|
|
5013
|
+
params: T;
|
|
5014
|
+
timestamp: number;
|
|
5015
|
+
timeout?: number;
|
|
5016
|
+
headers?: Record<string, string>;
|
|
5017
|
+
traceId?: string;
|
|
5018
|
+
}
|
|
3754
5019
|
/**
|
|
3755
|
-
*
|
|
5020
|
+
* Service response type
|
|
3756
5021
|
*/
|
|
3757
|
-
type
|
|
5022
|
+
type ServiceResponse<T = unknown> = {
|
|
5023
|
+
success: true;
|
|
5024
|
+
data: T;
|
|
5025
|
+
timestamp: number;
|
|
5026
|
+
duration: number;
|
|
5027
|
+
} | ServiceError;
|
|
3758
5028
|
/**
|
|
3759
|
-
*
|
|
5029
|
+
* Service error type
|
|
3760
5030
|
*/
|
|
3761
|
-
|
|
5031
|
+
interface ServiceError {
|
|
5032
|
+
success: false;
|
|
5033
|
+
error: {
|
|
5034
|
+
code: string;
|
|
5035
|
+
message: string;
|
|
5036
|
+
details?: unknown;
|
|
5037
|
+
stack?: string;
|
|
5038
|
+
};
|
|
5039
|
+
timestamp: number;
|
|
5040
|
+
duration: number;
|
|
5041
|
+
}
|
|
3762
5042
|
/**
|
|
3763
|
-
*
|
|
5043
|
+
* API Gateway type
|
|
3764
5044
|
*/
|
|
3765
|
-
|
|
5045
|
+
interface APIGateway {
|
|
5046
|
+
routes: GatewayRoute[];
|
|
5047
|
+
start: () => Promise<void>;
|
|
5048
|
+
stop: () => Promise<void>;
|
|
5049
|
+
addRoute: (route: GatewayRoute) => void;
|
|
5050
|
+
removeRoute: (path: string) => void;
|
|
5051
|
+
}
|
|
3766
5052
|
/**
|
|
3767
|
-
*
|
|
5053
|
+
* Gateway route type
|
|
3768
5054
|
*/
|
|
3769
|
-
|
|
5055
|
+
interface GatewayRoute {
|
|
5056
|
+
path: string;
|
|
5057
|
+
method: HTTPMethod | HTTPMethod[];
|
|
5058
|
+
service: string;
|
|
5059
|
+
servicePath?: string;
|
|
5060
|
+
timeout?: number;
|
|
5061
|
+
retryPolicy?: RetryPolicy;
|
|
5062
|
+
rateLimit?: RateLimit;
|
|
5063
|
+
auth?: AuthConfig;
|
|
5064
|
+
cors?: CORSConfig;
|
|
5065
|
+
}
|
|
3770
5066
|
/**
|
|
3771
|
-
*
|
|
5067
|
+
* Gateway configuration
|
|
3772
5068
|
*/
|
|
3773
|
-
|
|
5069
|
+
interface GatewayConfig {
|
|
5070
|
+
port: number;
|
|
5071
|
+
host: string;
|
|
5072
|
+
routes: GatewayRoute[];
|
|
5073
|
+
middleware?: GatewayMiddleware[];
|
|
5074
|
+
errorHandler?: (error: Error) => ServiceResponse;
|
|
5075
|
+
}
|
|
3774
5076
|
/**
|
|
3775
|
-
*
|
|
5077
|
+
* Gateway middleware
|
|
3776
5078
|
*/
|
|
3777
|
-
type
|
|
5079
|
+
type GatewayMiddleware = (request: ServiceRequest, next: () => Promise<ServiceResponse>) => Promise<ServiceResponse>;
|
|
3778
5080
|
/**
|
|
3779
|
-
*
|
|
5081
|
+
* Retry policy
|
|
3780
5082
|
*/
|
|
3781
|
-
|
|
5083
|
+
interface RetryPolicy {
|
|
5084
|
+
maxRetries: number;
|
|
5085
|
+
backoff: 'fixed' | 'exponential' | 'linear';
|
|
5086
|
+
initialDelay: number;
|
|
5087
|
+
maxDelay: number;
|
|
5088
|
+
retryableErrors?: string[];
|
|
5089
|
+
}
|
|
3782
5090
|
/**
|
|
3783
|
-
*
|
|
5091
|
+
* Rate limit configuration
|
|
3784
5092
|
*/
|
|
3785
|
-
|
|
5093
|
+
interface RateLimit {
|
|
5094
|
+
windowMs: number;
|
|
5095
|
+
max: number;
|
|
5096
|
+
keyGenerator?: (request: ServiceRequest) => string;
|
|
5097
|
+
skip?: (request: ServiceRequest) => boolean;
|
|
5098
|
+
}
|
|
3786
5099
|
/**
|
|
3787
|
-
*
|
|
5100
|
+
* Auth configuration
|
|
3788
5101
|
*/
|
|
3789
|
-
|
|
5102
|
+
interface AuthConfig {
|
|
5103
|
+
type: 'jwt' | 'apikey' | 'oauth2' | 'basic';
|
|
5104
|
+
required: boolean;
|
|
5105
|
+
validate: (token: string) => Promise<boolean>;
|
|
5106
|
+
}
|
|
5107
|
+
/**
|
|
5108
|
+
* CORS configuration
|
|
5109
|
+
*/
|
|
5110
|
+
interface CORSConfig {
|
|
5111
|
+
origin: string | string[] | boolean;
|
|
5112
|
+
methods?: HTTPMethod[];
|
|
5113
|
+
allowedHeaders?: string[];
|
|
5114
|
+
exposedHeaders?: string[];
|
|
5115
|
+
credentials?: boolean;
|
|
5116
|
+
maxAge?: number;
|
|
5117
|
+
}
|
|
5118
|
+
/**
|
|
5119
|
+
* Circuit breaker type
|
|
5120
|
+
*/
|
|
5121
|
+
interface CircuitBreaker<T = unknown> {
|
|
5122
|
+
execute: (fn: () => Promise<T>) => Promise<T>;
|
|
5123
|
+
getState: () => CircuitBreakerState;
|
|
5124
|
+
getStats: () => CircuitBreakerStats;
|
|
5125
|
+
reset: () => void;
|
|
5126
|
+
open: () => void;
|
|
5127
|
+
close: () => void;
|
|
5128
|
+
}
|
|
5129
|
+
/**
|
|
5130
|
+
* Circuit breaker state
|
|
5131
|
+
*/
|
|
5132
|
+
type CircuitBreakerState = 'closed' | 'open' | 'half-open';
|
|
5133
|
+
/**
|
|
5134
|
+
* Circuit breaker configuration
|
|
5135
|
+
*/
|
|
5136
|
+
interface CircuitBreakerConfig {
|
|
5137
|
+
failureThreshold: number;
|
|
5138
|
+
successThreshold: number;
|
|
5139
|
+
timeout: number;
|
|
5140
|
+
resetTimeout: number;
|
|
5141
|
+
volumeThreshold?: number;
|
|
5142
|
+
onStateChange?: (oldState: CircuitBreakerState, newState: CircuitBreakerState) => void;
|
|
5143
|
+
onFailure?: (error: Error) => void;
|
|
5144
|
+
onSuccess?: () => void;
|
|
5145
|
+
}
|
|
5146
|
+
/**
|
|
5147
|
+
* Circuit breaker stats
|
|
5148
|
+
*/
|
|
5149
|
+
interface CircuitBreakerStats {
|
|
5150
|
+
state: CircuitBreakerState;
|
|
5151
|
+
failures: number;
|
|
5152
|
+
successes: number;
|
|
5153
|
+
rejects: number;
|
|
5154
|
+
timeouts: number;
|
|
5155
|
+
lastFailure?: Date;
|
|
5156
|
+
lastSuccess?: Date;
|
|
5157
|
+
}
|
|
5158
|
+
/**
|
|
5159
|
+
* Load balancer type
|
|
5160
|
+
*/
|
|
5161
|
+
interface LoadBalancer {
|
|
5162
|
+
select: (instances: ServiceInstance[]) => ServiceInstance | undefined;
|
|
5163
|
+
getStrategy: () => LoadBalancerStrategy;
|
|
5164
|
+
setStrategy: (strategy: LoadBalancerStrategy) => void;
|
|
5165
|
+
}
|
|
5166
|
+
/**
|
|
5167
|
+
* Load balancer strategy
|
|
5168
|
+
*/
|
|
5169
|
+
type LoadBalancerStrategy = 'round-robin' | 'least-connections' | 'random' | 'weighted' | 'ip-hash';
|
|
5170
|
+
/**
|
|
5171
|
+
* Service instance type
|
|
5172
|
+
*/
|
|
5173
|
+
interface ServiceInstance {
|
|
5174
|
+
id: string;
|
|
5175
|
+
name: string;
|
|
5176
|
+
host: string;
|
|
5177
|
+
port: number;
|
|
5178
|
+
version: string;
|
|
5179
|
+
status: InstanceStatus;
|
|
5180
|
+
metadata?: Record<string, unknown>;
|
|
5181
|
+
weight?: number;
|
|
5182
|
+
connections?: number;
|
|
5183
|
+
lastHeartbeat?: Date;
|
|
5184
|
+
}
|
|
5185
|
+
/**
|
|
5186
|
+
* Instance status
|
|
5187
|
+
*/
|
|
5188
|
+
type InstanceStatus = 'healthy' | 'unhealthy' | 'draining' | 'starting' | 'stopping';
|
|
5189
|
+
/**
|
|
5190
|
+
* Health check type
|
|
5191
|
+
*/
|
|
5192
|
+
interface HealthCheck {
|
|
5193
|
+
name: string;
|
|
5194
|
+
check: () => Promise<HealthCheckResult$1>;
|
|
5195
|
+
interval?: number;
|
|
5196
|
+
timeout?: number;
|
|
5197
|
+
critical?: boolean;
|
|
5198
|
+
}
|
|
5199
|
+
/**
|
|
5200
|
+
* Health status
|
|
5201
|
+
*/
|
|
5202
|
+
type HealthStatus = 'healthy' | 'unhealthy' | 'degraded';
|
|
5203
|
+
/**
|
|
5204
|
+
* Health report type
|
|
5205
|
+
*/
|
|
5206
|
+
interface HealthReport<T = unknown> {
|
|
5207
|
+
status: HealthStatus;
|
|
5208
|
+
timestamp: Date;
|
|
5209
|
+
service: string;
|
|
5210
|
+
version: string;
|
|
5211
|
+
uptime: number;
|
|
5212
|
+
checks: Record<string, HealthCheckResult$1>;
|
|
5213
|
+
details?: T;
|
|
5214
|
+
}
|
|
5215
|
+
/**
|
|
5216
|
+
* Health check result
|
|
5217
|
+
*/
|
|
5218
|
+
interface HealthCheckResult$1 {
|
|
5219
|
+
status: HealthStatus;
|
|
5220
|
+
message?: string;
|
|
5221
|
+
timestamp: Date;
|
|
5222
|
+
duration?: number;
|
|
5223
|
+
details?: unknown;
|
|
5224
|
+
}
|
|
5225
|
+
/**
|
|
5226
|
+
* Environment type
|
|
5227
|
+
*/
|
|
5228
|
+
type Environment = 'development' | 'staging' | 'production' | 'test';
|
|
5229
|
+
/**
|
|
5230
|
+
* HTTP method
|
|
5231
|
+
*/
|
|
5232
|
+
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
3790
5233
|
//#endregion
|
|
3791
|
-
//#region src/
|
|
5234
|
+
//#region src/numeric/index.d.ts
|
|
3792
5235
|
/**
|
|
3793
|
-
*
|
|
3794
|
-
*
|
|
3795
|
-
* This module provides type-level parsers for:
|
|
3796
|
-
* - JSON: ParseJSON, StringifyJSON, IsValidJSON
|
|
3797
|
-
* - URL: ParseURL, QueryParams, PathParams
|
|
3798
|
-
* - CSV: ParseCSV
|
|
5236
|
+
* Numeric type operations for compile-time arithmetic
|
|
3799
5237
|
*/
|
|
5238
|
+
type NumberToArray<N extends number, Acc extends 0[] = []> = Acc['length'] extends N ? Acc : NumberToArray<N, [...Acc, 0]>;
|
|
3800
5239
|
/**
|
|
3801
|
-
*
|
|
5240
|
+
* Increment number type
|
|
3802
5241
|
*
|
|
3803
5242
|
* @example
|
|
3804
5243
|
* ```ts
|
|
3805
|
-
*
|
|
5244
|
+
* Inc<5> // 6
|
|
5245
|
+
* Inc<0> // 1
|
|
3806
5246
|
* ```
|
|
3807
5247
|
*/
|
|
3808
|
-
type
|
|
5248
|
+
type Inc<N extends number> = [...NumberToArray<N>, 0]['length'];
|
|
3809
5249
|
/**
|
|
3810
|
-
*
|
|
5250
|
+
* Decrement number type
|
|
3811
5251
|
*
|
|
3812
5252
|
* @example
|
|
3813
5253
|
* ```ts
|
|
3814
|
-
*
|
|
3815
|
-
*
|
|
5254
|
+
* Dec<5> // 4
|
|
5255
|
+
* Dec<1> // 0
|
|
5256
|
+
* Dec<0> // 0 (clamped)
|
|
3816
5257
|
* ```
|
|
3817
5258
|
*/
|
|
3818
|
-
type
|
|
5259
|
+
type Dec<N extends number> = N extends 0 ? 0 : NumberToArray<N> extends [0, ...infer Rest] ? Rest['length'] : 0;
|
|
3819
5260
|
/**
|
|
3820
|
-
*
|
|
5261
|
+
* Add two number types
|
|
3821
5262
|
*
|
|
3822
5263
|
* @example
|
|
3823
5264
|
* ```ts
|
|
3824
|
-
*
|
|
3825
|
-
*
|
|
5265
|
+
* Add<3, 4> // 7
|
|
5266
|
+
* Add<0, 5> // 5
|
|
3826
5267
|
* ```
|
|
3827
5268
|
*/
|
|
3828
|
-
type
|
|
3829
|
-
type StringifyArray<T extends unknown[]> = T extends [] ? '[]' : T extends [infer First, ...infer Rest] ? Rest extends [] ? `[${StringifyJSON<First>}]` : `[${StringifyJSON<First>}, ${StringifyArray<Rest>}]` : never;
|
|
5269
|
+
type Add<A extends number, B extends number> = [...NumberToArray<A>, ...NumberToArray<B>]['length'];
|
|
3830
5270
|
/**
|
|
3831
|
-
*
|
|
5271
|
+
* Subtract two number types
|
|
3832
5272
|
*
|
|
3833
5273
|
* @example
|
|
3834
5274
|
* ```ts
|
|
3835
|
-
*
|
|
3836
|
-
* //
|
|
5275
|
+
* Subtract<10, 3> // 7
|
|
5276
|
+
* Subtract<5, 10> // 0 (clamped)
|
|
3837
5277
|
* ```
|
|
3838
5278
|
*/
|
|
3839
|
-
type
|
|
3840
|
-
|
|
5279
|
+
type Subtract<A extends number, B extends number> = NumberToArray<B> extends [...number[], ...NumberToArray<A>] ? 0 : NumberToArray<A> extends [...NumberToArray<B>, ...infer Rest] ? Rest['length'] : 0;
|
|
5280
|
+
/**
|
|
5281
|
+
* Range of numbers from start to end (inclusive)
|
|
5282
|
+
* Note: Limited to small ranges due to TypeScript recursion limits
|
|
5283
|
+
*
|
|
5284
|
+
* @example
|
|
5285
|
+
* ```ts
|
|
5286
|
+
* Range<1, 5> // 1 | 2 | 3 | 4 | 5
|
|
5287
|
+
* Range<0, 3> // 0 | 1 | 2 | 3
|
|
5288
|
+
* ```
|
|
5289
|
+
*/
|
|
5290
|
+
type Range<From extends number, To extends number, Acc extends number = From> = From extends To ? Acc : From extends To ? Acc : never;
|
|
5291
|
+
/**
|
|
5292
|
+
* Check if A is greater than B
|
|
5293
|
+
*
|
|
5294
|
+
* @example
|
|
5295
|
+
* ```ts
|
|
5296
|
+
* GreaterThan<5, 3> // true
|
|
5297
|
+
* GreaterThan<3, 5> // false
|
|
5298
|
+
* ```
|
|
5299
|
+
*/
|
|
5300
|
+
type GreaterThan<A extends number, B extends number> = Subtract<A, B> extends 0 ? false : true;
|
|
5301
|
+
/**
|
|
5302
|
+
* Check if A is less than B
|
|
5303
|
+
*
|
|
5304
|
+
* @example
|
|
5305
|
+
* ```ts
|
|
5306
|
+
* LessThan<3, 5> // true
|
|
5307
|
+
* LessThan<5, 3> // false
|
|
5308
|
+
* ```
|
|
5309
|
+
*/
|
|
5310
|
+
type LessThan<A extends number, B extends number> = Subtract<B, A> extends 0 ? false : true;
|
|
5311
|
+
/**
|
|
5312
|
+
* Maximum of two numbers
|
|
5313
|
+
*
|
|
5314
|
+
* @example
|
|
5315
|
+
* ```ts
|
|
5316
|
+
* Max<3, 5> // 5
|
|
5317
|
+
* Max<5, 3> // 5
|
|
5318
|
+
* ```
|
|
5319
|
+
*/
|
|
5320
|
+
type Max<A extends number, B extends number> = GreaterThan<A, B> extends true ? A : B;
|
|
5321
|
+
/**
|
|
5322
|
+
* Minimum of two numbers
|
|
5323
|
+
*
|
|
5324
|
+
* @example
|
|
5325
|
+
* ```ts
|
|
5326
|
+
* Min<3, 5> // 3
|
|
5327
|
+
* Min<5, 3> // 3
|
|
5328
|
+
* ```
|
|
5329
|
+
*/
|
|
5330
|
+
type Min<A extends number, B extends number> = LessThan<A, B> extends true ? A : B;
|
|
5331
|
+
//#endregion
|
|
5332
|
+
//#region src/object/index.d.ts
|
|
5333
|
+
/**
|
|
5334
|
+
* Advanced object type operations
|
|
5335
|
+
*
|
|
5336
|
+
* This module provides advanced object manipulation types:
|
|
5337
|
+
* - Object transformations: ObjectMap, ObjectFilter, ObjectPickByType
|
|
5338
|
+
* - Object merging: DeepMerge, DeepAssign, DeepDefaults
|
|
5339
|
+
* - Object validation: HasProperty, HasProperties, HasMethod
|
|
5340
|
+
*/
|
|
5341
|
+
/**
|
|
5342
|
+
* Map over object values with transformation function
|
|
5343
|
+
*/
|
|
5344
|
+
type ObjectMap<T extends Record<string, any>, F> = { [K in keyof T]: F extends ((x: T[K]) => infer R) ? R : never };
|
|
5345
|
+
/**
|
|
5346
|
+
* Filter object properties by predicate
|
|
5347
|
+
*/
|
|
5348
|
+
type ObjectFilter<T extends Record<string, any>, P> = { [K in keyof T as T[K] extends P ? K : never]: T[K] };
|
|
5349
|
+
/**
|
|
5350
|
+
* Pick properties by value type
|
|
5351
|
+
*/
|
|
5352
|
+
type ObjectPickByType<T extends Record<string, any>, U> = { [K in keyof T as T[K] extends U ? K : never]: T[K] };
|
|
5353
|
+
/**
|
|
5354
|
+
* Omit properties by value type
|
|
5355
|
+
*/
|
|
5356
|
+
type ObjectOmitByType<T extends Record<string, any>, U> = { [K in keyof T as T[K] extends U ? never : K]: T[K] };
|
|
5357
|
+
/**
|
|
5358
|
+
* Invert object (swap keys and values)
|
|
5359
|
+
*/
|
|
5360
|
+
type ObjectInvert<T extends Record<string, string | number>> = { [K in T[keyof T]]: { [P in keyof T]: T[P] extends K ? P : never }[keyof T] };
|
|
5361
|
+
/**
|
|
5362
|
+
* Get object entries as tuple union
|
|
5363
|
+
*/
|
|
5364
|
+
type ObjectEntries<T extends Record<string, any>> = { [K in keyof T]: [K, T[K]] }[keyof T];
|
|
5365
|
+
/**
|
|
5366
|
+
* Deep merge two objects (B takes precedence)
|
|
5367
|
+
*/
|
|
5368
|
+
type DeepMerge<A, B> = A extends object ? B extends object ? { [K in keyof A | keyof B]: K extends keyof B ? K extends keyof A ? DeepMerge<A[K], B[K]> : B[K] : K extends keyof A ? A[K] : never } : B : B;
|
|
5369
|
+
/**
|
|
5370
|
+
* Merge multiple objects (right to left precedence)
|
|
5371
|
+
*/
|
|
5372
|
+
type MergeAllObjects<T extends object[], Acc extends object = object> = T extends [infer First extends object, ...infer Rest extends object[]] ? MergeAllObjects<Rest, Acc & First> : Acc;
|
|
5373
|
+
/**
|
|
5374
|
+
* Check if object has a property
|
|
5375
|
+
*/
|
|
5376
|
+
type HasProperty<T, K extends PropertyKey> = K extends keyof T ? true : false;
|
|
5377
|
+
/**
|
|
5378
|
+
* Check if object has multiple properties
|
|
5379
|
+
*/
|
|
5380
|
+
type HasProperties<T, K extends PropertyKey> = K extends keyof T ? true : false;
|
|
5381
|
+
/**
|
|
5382
|
+
* Check if object has a method
|
|
5383
|
+
*/
|
|
5384
|
+
type HasMethod<T, K extends keyof T> = T[K] extends ((...args: any[]) => any) ? true : false;
|
|
5385
|
+
/**
|
|
5386
|
+
* Check if object is empty
|
|
5387
|
+
*/
|
|
5388
|
+
type IsEmptyObject<T> = keyof T extends never ? true : false;
|
|
5389
|
+
/**
|
|
5390
|
+
* Get keys of specific type
|
|
5391
|
+
*/
|
|
5392
|
+
type KeysOfType<T extends Record<string, any>, U> = { [K in keyof T]: T[K] extends U ? K : never }[keyof T];
|
|
5393
|
+
/**
|
|
5394
|
+
* Get value at path (with default)
|
|
5395
|
+
*/
|
|
5396
|
+
type ObjectPath<T, P extends string, Default = never> = P extends `${infer First}.${infer Rest}` ? First extends keyof T ? ObjectPath<T[First], Rest, Default> : Default : P extends keyof T ? T[P] : Default;
|
|
5397
|
+
/**
|
|
5398
|
+
* Check if path exists
|
|
5399
|
+
*/
|
|
5400
|
+
type PathExists<T, P extends string> = P extends `${infer First}.${infer Rest}` ? First extends keyof T ? PathExists<T[First], Rest> : false : P extends keyof T ? true : false;
|
|
5401
|
+
//#endregion
|
|
5402
|
+
//#region src/parsers/index.d.ts
|
|
5403
|
+
/**
|
|
5404
|
+
* Type-level parsing utilities
|
|
5405
|
+
*
|
|
5406
|
+
* This module provides type-level parsers for:
|
|
5407
|
+
* - JSON: ParseJSON, StringifyJSON, IsValidJSON
|
|
5408
|
+
* - URL: ParseURL, QueryParams, PathParams
|
|
5409
|
+
* - CSV: ParseCSV
|
|
5410
|
+
*/
|
|
5411
|
+
/**
|
|
5412
|
+
* Check if string is valid JSON
|
|
5413
|
+
*
|
|
5414
|
+
* @example
|
|
5415
|
+
* ```ts
|
|
5416
|
+
* IsValidJSON<'{"name": "test"}'> // true
|
|
5417
|
+
* ```
|
|
5418
|
+
*/
|
|
5419
|
+
type IsValidJSON<S extends string> = S extends `{}` ? true : S extends `[]` ? true : S extends `"${string}"` ? true : S extends `${number}` ? true : S extends 'true' | 'false' | 'null' ? true : S extends `{${string}}` ? true : S extends `[${string}]` ? true : false;
|
|
5420
|
+
/**
|
|
5421
|
+
* Parse JSON string to type (limited support)
|
|
5422
|
+
*
|
|
5423
|
+
* @example
|
|
5424
|
+
* ```ts
|
|
5425
|
+
* ParseJSON<'"hello"'> // 'hello'
|
|
5426
|
+
* ParseJSON<'123'> // 123
|
|
5427
|
+
* ```
|
|
5428
|
+
*/
|
|
5429
|
+
type ParseJSON<S extends string> = S extends `"${infer Content}"` ? Content : S extends `${infer N extends number}` ? N : S extends 'true' ? true : S extends 'false' ? false : S extends 'null' ? null : S extends `{}` ? Record<string, never> : S extends `[]` ? [] : S extends `{${string}}` ? Record<string, unknown> : S extends `[${string}]` ? unknown[] : never;
|
|
5430
|
+
/**
|
|
5431
|
+
* Stringify type to JSON string representation
|
|
5432
|
+
*
|
|
5433
|
+
* @example
|
|
5434
|
+
* ```ts
|
|
5435
|
+
* StringifyJSON<'hello'> // '"hello"'
|
|
5436
|
+
* StringifyJSON<123> // '123'
|
|
5437
|
+
* ```
|
|
5438
|
+
*/
|
|
5439
|
+
type StringifyJSON<T> = T extends string ? `"${T}"` : T extends number ? `${T}` : T extends boolean ? `${T}` : T extends null ? 'null' : T extends undefined ? 'null' : T extends unknown[] ? StringifyArray<T> : T extends object ? '{}' : never;
|
|
5440
|
+
type StringifyArray<T extends unknown[]> = T extends [] ? '[]' : T extends [infer First, ...infer Rest] ? Rest extends [] ? `[${StringifyJSON<First>}]` : `[${StringifyJSON<First>}, ${StringifyArray<Rest>}]` : never;
|
|
5441
|
+
/**
|
|
5442
|
+
* Parse URL string into components
|
|
5443
|
+
*
|
|
5444
|
+
* @example
|
|
5445
|
+
* ```ts
|
|
5446
|
+
* ParseURL<'https://example.com/path?q=1'>
|
|
5447
|
+
* // { protocol: 'https'; host: 'example.com'; pathname: '/path'; search: '?q=1' }
|
|
5448
|
+
* ```
|
|
5449
|
+
*/
|
|
5450
|
+
type ParseURL<S extends string> = S extends `${infer Protocol}://${infer Rest}` ? ParseURLRest<Protocol, Rest> : never;
|
|
5451
|
+
type ParseURLRest<Protocol extends string, Rest extends string> = Rest extends `${infer Host}/${infer Path}` ? ParseURLPath<Protocol, Host, Path> : Rest extends `${infer Host}?${infer Search}` ? {
|
|
3841
5452
|
protocol: Protocol;
|
|
3842
5453
|
host: Host;
|
|
3843
5454
|
pathname: '/';
|
|
@@ -4184,20 +5795,6 @@ type CachedKeyOf<T> = Cached<keyof T>;
|
|
|
4184
5795
|
* Cached property access
|
|
4185
5796
|
*/
|
|
4186
5797
|
type CachedProperty<T, K extends keyof T> = Cached<T[K]>;
|
|
4187
|
-
/**
|
|
4188
|
-
* Type computation cache key
|
|
4189
|
-
*/
|
|
4190
|
-
type CacheKey<T> = symbol & {
|
|
4191
|
-
__cacheKey: T;
|
|
4192
|
-
};
|
|
4193
|
-
/**
|
|
4194
|
-
* Cache entry
|
|
4195
|
-
*/
|
|
4196
|
-
interface CacheEntry<K, V> {
|
|
4197
|
-
key: K;
|
|
4198
|
-
value: V;
|
|
4199
|
-
timestamp: number;
|
|
4200
|
-
}
|
|
4201
5798
|
/**
|
|
4202
5799
|
* Type cache structure
|
|
4203
5800
|
*/
|
|
@@ -5759,4 +7356,871 @@ type MarkType<T, Tag extends string> = T & {
|
|
|
5759
7356
|
__tag: Tag;
|
|
5760
7357
|
};
|
|
5761
7358
|
//#endregion
|
|
5762
|
-
|
|
7359
|
+
//#region src/validation/index.d.ts
|
|
7360
|
+
/**
|
|
7361
|
+
* Validation Rules Types
|
|
7362
|
+
*
|
|
7363
|
+
* Types for validation and sanitization.
|
|
7364
|
+
*/
|
|
7365
|
+
/**
|
|
7366
|
+
* Validator type
|
|
7367
|
+
*/
|
|
7368
|
+
interface Validator<T = unknown> {
|
|
7369
|
+
validate: (value: unknown) => ValidatorResult<T>;
|
|
7370
|
+
optional: () => Validator<T | undefined>;
|
|
7371
|
+
nullable: () => Validator<T | null>;
|
|
7372
|
+
}
|
|
7373
|
+
/**
|
|
7374
|
+
* Validator result
|
|
7375
|
+
*/
|
|
7376
|
+
type ValidatorResult<T = unknown> = {
|
|
7377
|
+
success: true;
|
|
7378
|
+
value: T;
|
|
7379
|
+
} | {
|
|
7380
|
+
success: false;
|
|
7381
|
+
errors: ValidationError[];
|
|
7382
|
+
};
|
|
7383
|
+
/**
|
|
7384
|
+
* Validation error
|
|
7385
|
+
*/
|
|
7386
|
+
interface ValidationError {
|
|
7387
|
+
path: string;
|
|
7388
|
+
message: string;
|
|
7389
|
+
code: string;
|
|
7390
|
+
value?: unknown;
|
|
7391
|
+
constraints?: Record<string, unknown>;
|
|
7392
|
+
}
|
|
7393
|
+
/**
|
|
7394
|
+
* Validation rule
|
|
7395
|
+
*/
|
|
7396
|
+
interface ValidationRule<T = unknown> {
|
|
7397
|
+
name: string;
|
|
7398
|
+
validate: (value: T) => boolean;
|
|
7399
|
+
message: string | ((value: T) => string);
|
|
7400
|
+
}
|
|
7401
|
+
/**
|
|
7402
|
+
* String field validator
|
|
7403
|
+
*/
|
|
7404
|
+
type StringFieldValidator<T = string> = Validator<T> & {
|
|
7405
|
+
minLength: (length: number) => StringFieldValidator<T>;
|
|
7406
|
+
maxLength: (length: number) => StringFieldValidator<T>;
|
|
7407
|
+
length: (min: number, max?: number) => StringFieldValidator<T>;
|
|
7408
|
+
pattern: (regex: RegExp) => StringFieldValidator<T>;
|
|
7409
|
+
email: () => StringFieldValidator<T>;
|
|
7410
|
+
url: () => StringFieldValidator<T>;
|
|
7411
|
+
uuid: () => StringFieldValidator<T>;
|
|
7412
|
+
alpha: () => StringFieldValidator<T>;
|
|
7413
|
+
alphanumeric: () => StringFieldValidator<T>;
|
|
7414
|
+
numeric: () => StringFieldValidator<T>;
|
|
7415
|
+
trim: () => StringFieldValidator<T>;
|
|
7416
|
+
lowercase: () => StringFieldValidator<T>;
|
|
7417
|
+
uppercase: () => StringFieldValidator<T>;
|
|
7418
|
+
oneOf: (values: T[]) => StringFieldValidator<T>;
|
|
7419
|
+
notOneOf: (values: T[]) => StringFieldValidator<T>;
|
|
7420
|
+
};
|
|
7421
|
+
/**
|
|
7422
|
+
* Number field validator
|
|
7423
|
+
*/
|
|
7424
|
+
type NumberFieldValidator<T = number> = Validator<T> & {
|
|
7425
|
+
min: (value: number) => NumberFieldValidator<T>;
|
|
7426
|
+
max: (value: number) => NumberFieldValidator<T>;
|
|
7427
|
+
range: (min: number, max: number) => NumberFieldValidator<T>;
|
|
7428
|
+
integer: () => NumberFieldValidator<T>;
|
|
7429
|
+
float: () => NumberFieldValidator<T>;
|
|
7430
|
+
positive: () => NumberFieldValidator<T>;
|
|
7431
|
+
negative: () => NumberFieldValidator<T>;
|
|
7432
|
+
nonNegative: () => NumberFieldValidator<T>;
|
|
7433
|
+
nonPositive: () => NumberFieldValidator<T>;
|
|
7434
|
+
multipleOf: (value: number) => NumberFieldValidator<T>;
|
|
7435
|
+
finite: () => NumberFieldValidator<T>;
|
|
7436
|
+
safe: () => NumberFieldValidator<T>;
|
|
7437
|
+
};
|
|
7438
|
+
/**
|
|
7439
|
+
* Boolean field validator
|
|
7440
|
+
*/
|
|
7441
|
+
type BooleanFieldValidator<T = boolean> = Validator<T> & {
|
|
7442
|
+
true: () => BooleanFieldValidator<T>;
|
|
7443
|
+
false: () => BooleanFieldValidator<T>;
|
|
7444
|
+
};
|
|
7445
|
+
/**
|
|
7446
|
+
* Date field validator
|
|
7447
|
+
*/
|
|
7448
|
+
type DateFieldValidator<T = Date> = Validator<T> & {
|
|
7449
|
+
min: (date: Date | string) => DateFieldValidator<T>;
|
|
7450
|
+
max: (date: Date | string) => DateFieldValidator<T>;
|
|
7451
|
+
range: (min: Date | string, max: Date | string) => DateFieldValidator<T>;
|
|
7452
|
+
before: (date: Date | string) => DateFieldValidator<T>;
|
|
7453
|
+
after: (date: Date | string) => DateFieldValidator<T>;
|
|
7454
|
+
past: () => DateFieldValidator<T>;
|
|
7455
|
+
future: () => DateFieldValidator<T>;
|
|
7456
|
+
};
|
|
7457
|
+
/**
|
|
7458
|
+
* Array field validator
|
|
7459
|
+
*/
|
|
7460
|
+
type ArrayFieldValidator<T = unknown[]> = Validator<T> & {
|
|
7461
|
+
minLength: (length: number) => ArrayFieldValidator<T>;
|
|
7462
|
+
maxLength: (length: number) => ArrayFieldValidator<T>;
|
|
7463
|
+
length: (min: number, max?: number) => ArrayFieldValidator<T>;
|
|
7464
|
+
nonEmpty: () => ArrayFieldValidator<T>;
|
|
7465
|
+
unique: () => ArrayFieldValidator<T>;
|
|
7466
|
+
of: <U>(validator: Validator<U>) => ArrayFieldValidator<U[]>;
|
|
7467
|
+
};
|
|
7468
|
+
/**
|
|
7469
|
+
* Object field validator
|
|
7470
|
+
*/
|
|
7471
|
+
type ObjectFieldValidator<T = Record<string, unknown>> = Validator<T> & {
|
|
7472
|
+
shape: <S extends Record<string, Validator>>(schema: S) => ObjectFieldValidator<{ [K in keyof S]: S[K] extends Validator<infer U> ? U : never }>;
|
|
7473
|
+
partial: () => ObjectFieldValidator<Partial<T>>;
|
|
7474
|
+
strict: () => ObjectFieldValidator<T>;
|
|
7475
|
+
stripUnknown: () => ObjectFieldValidator<T>;
|
|
7476
|
+
nonEmpty: () => ObjectFieldValidator<T>;
|
|
7477
|
+
};
|
|
7478
|
+
/**
|
|
7479
|
+
* Or validator
|
|
7480
|
+
*/
|
|
7481
|
+
interface OrValidator<T = unknown> {
|
|
7482
|
+
validators: Validator<T>[];
|
|
7483
|
+
validate: (value: unknown) => ValidatorResult<T>;
|
|
7484
|
+
}
|
|
7485
|
+
/**
|
|
7486
|
+
* Not validator
|
|
7487
|
+
*/
|
|
7488
|
+
interface NotValidator<T = unknown> {
|
|
7489
|
+
validator: Validator<T>;
|
|
7490
|
+
validate: (value: unknown) => ValidatorResult<T>;
|
|
7491
|
+
}
|
|
7492
|
+
/**
|
|
7493
|
+
* Custom validator
|
|
7494
|
+
*/
|
|
7495
|
+
interface CustomValidator<T = unknown> {
|
|
7496
|
+
validate: (value: unknown, context?: ValidationContext) => ValidatorResult<T>;
|
|
7497
|
+
}
|
|
7498
|
+
/**
|
|
7499
|
+
* Validation context
|
|
7500
|
+
*/
|
|
7501
|
+
interface ValidationContext<T = unknown> {
|
|
7502
|
+
path: string;
|
|
7503
|
+
parent?: T;
|
|
7504
|
+
root: unknown;
|
|
7505
|
+
options: ValidationOptions;
|
|
7506
|
+
}
|
|
7507
|
+
/**
|
|
7508
|
+
* Validation options
|
|
7509
|
+
*/
|
|
7510
|
+
interface ValidationOptions {
|
|
7511
|
+
abortEarly: boolean;
|
|
7512
|
+
stripUnknown: boolean;
|
|
7513
|
+
allowUnknown: boolean;
|
|
7514
|
+
cast: boolean;
|
|
7515
|
+
context?: Record<string, unknown>;
|
|
7516
|
+
}
|
|
7517
|
+
/**
|
|
7518
|
+
* Min length constraint
|
|
7519
|
+
*/
|
|
7520
|
+
type MinLength<N extends number> = N;
|
|
7521
|
+
/**
|
|
7522
|
+
* Max length constraint
|
|
7523
|
+
*/
|
|
7524
|
+
type MaxLength<N extends number> = N;
|
|
7525
|
+
/**
|
|
7526
|
+
* Min value constraint
|
|
7527
|
+
*/
|
|
7528
|
+
type MinValue<N extends number> = N;
|
|
7529
|
+
/**
|
|
7530
|
+
* Max value constraint
|
|
7531
|
+
*/
|
|
7532
|
+
type MaxValue<N extends number> = N;
|
|
7533
|
+
/**
|
|
7534
|
+
* Pattern constraint
|
|
7535
|
+
*/
|
|
7536
|
+
type Pattern<S extends string> = S;
|
|
7537
|
+
/**
|
|
7538
|
+
* Email constraint
|
|
7539
|
+
*/
|
|
7540
|
+
interface EmailConstraint {
|
|
7541
|
+
allowDisplayName: boolean;
|
|
7542
|
+
allowTld: boolean;
|
|
7543
|
+
requireTld: boolean;
|
|
7544
|
+
domainSpecificValidation: boolean;
|
|
7545
|
+
}
|
|
7546
|
+
/**
|
|
7547
|
+
* URL constraint
|
|
7548
|
+
*/
|
|
7549
|
+
interface URLConstraint {
|
|
7550
|
+
protocols: string[];
|
|
7551
|
+
requireProtocol: boolean;
|
|
7552
|
+
requireHost: boolean;
|
|
7553
|
+
allowRelative: boolean;
|
|
7554
|
+
allowProtocolRelativeUrls: boolean;
|
|
7555
|
+
}
|
|
7556
|
+
/**
|
|
7557
|
+
* UUID constraint
|
|
7558
|
+
*/
|
|
7559
|
+
interface UUIDConstraint {
|
|
7560
|
+
version: 1 | 3 | 4 | 5 | 'all';
|
|
7561
|
+
}
|
|
7562
|
+
/**
|
|
7563
|
+
* Sanitizer type
|
|
7564
|
+
*/
|
|
7565
|
+
interface Sanitizer<T = unknown> {
|
|
7566
|
+
sanitize: (value: unknown) => SanitizeResult<T>;
|
|
7567
|
+
}
|
|
7568
|
+
/**
|
|
7569
|
+
* Sanitize result
|
|
7570
|
+
*/
|
|
7571
|
+
type SanitizeResult<T = unknown> = {
|
|
7572
|
+
success: true;
|
|
7573
|
+
value: T;
|
|
7574
|
+
changed: boolean;
|
|
7575
|
+
} | {
|
|
7576
|
+
success: false;
|
|
7577
|
+
error: string;
|
|
7578
|
+
};
|
|
7579
|
+
/**
|
|
7580
|
+
* Sanitization rule
|
|
7581
|
+
*/
|
|
7582
|
+
interface SanitizationRule<T = unknown> {
|
|
7583
|
+
name: string;
|
|
7584
|
+
sanitize: (value: T) => T;
|
|
7585
|
+
description?: string;
|
|
7586
|
+
}
|
|
7587
|
+
/**
|
|
7588
|
+
* String sanitizer
|
|
7589
|
+
*/
|
|
7590
|
+
type StringSanitizer = Sanitizer<string> & {
|
|
7591
|
+
trim: () => StringSanitizer;
|
|
7592
|
+
lowercase: () => StringSanitizer;
|
|
7593
|
+
uppercase: () => StringSanitizer;
|
|
7594
|
+
escape: () => StringSanitizer;
|
|
7595
|
+
unescape: () => StringSanitizer;
|
|
7596
|
+
stripTags: () => StringSanitizer;
|
|
7597
|
+
stripLow: () => StringSanitizer;
|
|
7598
|
+
normalizeEmail: () => StringSanitizer;
|
|
7599
|
+
whitelist: (chars: string) => StringSanitizer;
|
|
7600
|
+
blacklist: (chars: string) => StringSanitizer;
|
|
7601
|
+
};
|
|
7602
|
+
/**
|
|
7603
|
+
* Number sanitizer
|
|
7604
|
+
*/
|
|
7605
|
+
type NumberSanitizer = Sanitizer<number> & {
|
|
7606
|
+
toInt: () => NumberSanitizer;
|
|
7607
|
+
toFloat: () => NumberSanitizer;
|
|
7608
|
+
round: (precision?: number) => NumberSanitizer;
|
|
7609
|
+
floor: () => NumberSanitizer;
|
|
7610
|
+
ceil: () => NumberSanitizer;
|
|
7611
|
+
clamp: (min: number, max: number) => NumberSanitizer;
|
|
7612
|
+
};
|
|
7613
|
+
/**
|
|
7614
|
+
* Schema builder
|
|
7615
|
+
*/
|
|
7616
|
+
interface SchemaBuilder {
|
|
7617
|
+
string: () => StringFieldValidator;
|
|
7618
|
+
number: () => NumberFieldValidator;
|
|
7619
|
+
boolean: () => BooleanFieldValidator;
|
|
7620
|
+
date: () => DateFieldValidator;
|
|
7621
|
+
array: <U>(validator?: Validator<U>) => ArrayFieldValidator<U[]>;
|
|
7622
|
+
object: <S extends Record<string, Validator>>(schema?: S) => ObjectFieldValidator;
|
|
7623
|
+
any: () => Validator<unknown>;
|
|
7624
|
+
unknown: () => Validator<unknown>;
|
|
7625
|
+
never: () => Validator<never>;
|
|
7626
|
+
undefined: () => Validator<undefined>;
|
|
7627
|
+
null: () => Validator<null>;
|
|
7628
|
+
void: () => Validator<void>;
|
|
7629
|
+
literal: <V extends string | number | boolean>(value: V) => Validator<V>;
|
|
7630
|
+
enum: <V extends string>(values: V[]) => Validator<V>;
|
|
7631
|
+
union: <U extends Validator[]>(...validators: U) => Validator<U[number] extends Validator<infer V> ? V : never>;
|
|
7632
|
+
intersection: <U extends Validator[]>(...validators: U) => Validator<U[number] extends Validator<infer V> ? V : never>;
|
|
7633
|
+
record: <K extends string, V>(keyValidator?: Validator<K>, valueValidator?: Validator<V>) => Validator<Record<K, V>>;
|
|
7634
|
+
tuple: <T extends Validator[]>(...validators: T) => Validator<{ [I in keyof T]: T[I] extends Validator<infer V> ? V : never }>;
|
|
7635
|
+
}
|
|
7636
|
+
//#endregion
|
|
7637
|
+
//#region src/websocket/index.d.ts
|
|
7638
|
+
/**
|
|
7639
|
+
* WebSocket & Real-Time Types
|
|
7640
|
+
*
|
|
7641
|
+
* Types for real-time communication with WebSocket.
|
|
7642
|
+
*/
|
|
7643
|
+
/**
|
|
7644
|
+
* WebSocket message type
|
|
7645
|
+
*/
|
|
7646
|
+
interface WebSocketMessage<T = unknown> {
|
|
7647
|
+
type: string;
|
|
7648
|
+
payload: T;
|
|
7649
|
+
timestamp?: number;
|
|
7650
|
+
id?: string;
|
|
7651
|
+
}
|
|
7652
|
+
/**
|
|
7653
|
+
* WebSocket event type
|
|
7654
|
+
*/
|
|
7655
|
+
interface WebSocketEvent<T = unknown> {
|
|
7656
|
+
event: string;
|
|
7657
|
+
data: T;
|
|
7658
|
+
timestamp: number;
|
|
7659
|
+
}
|
|
7660
|
+
/**
|
|
7661
|
+
* WebSocket handler function type
|
|
7662
|
+
*/
|
|
7663
|
+
type WebSocketHandler<T = unknown> = (message: WebSocketMessage<T>) => void | Promise<void>;
|
|
7664
|
+
/**
|
|
7665
|
+
* WebSocket connection state
|
|
7666
|
+
*/
|
|
7667
|
+
type WebSocketState = 'connecting' | 'connected' | 'disconnecting' | 'disconnected';
|
|
7668
|
+
/**
|
|
7669
|
+
* WebSocket options
|
|
7670
|
+
*/
|
|
7671
|
+
interface WebSocketOptions {
|
|
7672
|
+
url: string;
|
|
7673
|
+
protocols?: string | string[];
|
|
7674
|
+
reconnect?: boolean;
|
|
7675
|
+
reconnectInterval?: number;
|
|
7676
|
+
maxReconnectAttempts?: number;
|
|
7677
|
+
}
|
|
7678
|
+
/**
|
|
7679
|
+
* WebSocket configuration
|
|
7680
|
+
*/
|
|
7681
|
+
type WebSocketConfig<T = unknown> = WebSocketOptions & {
|
|
7682
|
+
onMessage?: WebSocketHandler<T>;
|
|
7683
|
+
onOpen?: () => void;
|
|
7684
|
+
onClose?: (event: {
|
|
7685
|
+
code: number;
|
|
7686
|
+
reason: string;
|
|
7687
|
+
}) => void;
|
|
7688
|
+
onError?: (error: Error) => void;
|
|
7689
|
+
};
|
|
7690
|
+
/**
|
|
7691
|
+
* Event map type
|
|
7692
|
+
*/
|
|
7693
|
+
type EventMap<T = Record<string, unknown>> = { [K in keyof T]: T[K] };
|
|
7694
|
+
/**
|
|
7695
|
+
* Event handler function type
|
|
7696
|
+
*/
|
|
7697
|
+
type EventHandler$1<T, E extends keyof T = keyof T> = (event: T[E]) => void | Promise<void>;
|
|
7698
|
+
/**
|
|
7699
|
+
* Event payload type
|
|
7700
|
+
*/
|
|
7701
|
+
type EventPayload<T, E extends keyof T = keyof T> = T[E];
|
|
7702
|
+
/**
|
|
7703
|
+
* Event listener options
|
|
7704
|
+
*/
|
|
7705
|
+
interface EventListenerOptions {
|
|
7706
|
+
once?: boolean;
|
|
7707
|
+
capture?: boolean;
|
|
7708
|
+
passive?: boolean;
|
|
7709
|
+
}
|
|
7710
|
+
/**
|
|
7711
|
+
* Event emitter type
|
|
7712
|
+
*/
|
|
7713
|
+
interface EventEmitter<T extends EventMap> {
|
|
7714
|
+
on: <E extends keyof T>(event: E, handler: EventHandler$1<T, E>) => void;
|
|
7715
|
+
off: <E extends keyof T>(event: E, handler: EventHandler$1<T, E>) => void;
|
|
7716
|
+
emit: <E extends keyof T>(event: E, payload: T[E]) => void;
|
|
7717
|
+
once: <E extends keyof T>(event: E, handler: EventHandler$1<T, E>) => void;
|
|
7718
|
+
}
|
|
7719
|
+
/**
|
|
7720
|
+
* Typed event target
|
|
7721
|
+
*/
|
|
7722
|
+
interface TypedEventTarget<T extends EventMap> {
|
|
7723
|
+
addEventListener: <E extends keyof T>(event: E, handler: EventHandler$1<T, E>, options?: EventListenerOptions) => void;
|
|
7724
|
+
removeEventListener: <E extends keyof T>(event: E, handler: EventHandler$1<T, E>) => void;
|
|
7725
|
+
dispatchEvent: <E extends keyof T>(event: E, payload: T[E]) => boolean;
|
|
7726
|
+
}
|
|
7727
|
+
/**
|
|
7728
|
+
* Real-time channel type
|
|
7729
|
+
*/
|
|
7730
|
+
interface RealTimeChannel<T = unknown> {
|
|
7731
|
+
name: string;
|
|
7732
|
+
subscribe: (handler: (message: T) => void) => () => void;
|
|
7733
|
+
publish: (message: T) => void;
|
|
7734
|
+
unsubscribe: (handler: (message: T) => void) => void;
|
|
7735
|
+
close: () => void;
|
|
7736
|
+
}
|
|
7737
|
+
/**
|
|
7738
|
+
* Real-time subscription type
|
|
7739
|
+
*/
|
|
7740
|
+
interface RealTimeSubscription<T = unknown> {
|
|
7741
|
+
id: string;
|
|
7742
|
+
channel: string;
|
|
7743
|
+
handler: (message: T) => void;
|
|
7744
|
+
unsubscribe: () => void;
|
|
7745
|
+
active: boolean;
|
|
7746
|
+
}
|
|
7747
|
+
/**
|
|
7748
|
+
* Real-time message type
|
|
7749
|
+
*/
|
|
7750
|
+
interface RealTimeMessage<T = unknown> {
|
|
7751
|
+
channel: string;
|
|
7752
|
+
data: T;
|
|
7753
|
+
timestamp: number;
|
|
7754
|
+
subscriptionId?: string;
|
|
7755
|
+
}
|
|
7756
|
+
/**
|
|
7757
|
+
* Real-time client type
|
|
7758
|
+
*/
|
|
7759
|
+
interface RealTimeClient<T extends EventMap = Record<string, unknown>> {
|
|
7760
|
+
connect: () => Promise<void>;
|
|
7761
|
+
disconnect: () => Promise<void>;
|
|
7762
|
+
subscribe: <E extends keyof T>(channel: E, handler: EventHandler$1<T, E>) => RealTimeSubscription<T[E]>;
|
|
7763
|
+
publish: <E extends keyof T>(channel: E, data: T[E]) => void;
|
|
7764
|
+
isConnected: boolean;
|
|
7765
|
+
}
|
|
7766
|
+
/**
|
|
7767
|
+
* Stream type
|
|
7768
|
+
*/
|
|
7769
|
+
interface Stream<T = unknown> {
|
|
7770
|
+
[Symbol.asyncIterator]: () => AsyncIterator<T>;
|
|
7771
|
+
readable: boolean;
|
|
7772
|
+
closed: boolean;
|
|
7773
|
+
}
|
|
7774
|
+
/**
|
|
7775
|
+
* Stream chunk type
|
|
7776
|
+
*/
|
|
7777
|
+
interface StreamChunk<T = unknown> {
|
|
7778
|
+
value: T;
|
|
7779
|
+
done: boolean;
|
|
7780
|
+
}
|
|
7781
|
+
/**
|
|
7782
|
+
* Stream reader type
|
|
7783
|
+
*/
|
|
7784
|
+
interface StreamReader<T = unknown> {
|
|
7785
|
+
read: () => Promise<StreamChunk<T>>;
|
|
7786
|
+
releaseLock: () => void;
|
|
7787
|
+
closed: boolean;
|
|
7788
|
+
}
|
|
7789
|
+
/**
|
|
7790
|
+
* Stream writer type
|
|
7791
|
+
*/
|
|
7792
|
+
interface StreamWriter<T = unknown> {
|
|
7793
|
+
write: (chunk: T) => Promise<void>;
|
|
7794
|
+
close: () => Promise<void>;
|
|
7795
|
+
abort: (reason?: unknown) => Promise<void>;
|
|
7796
|
+
closed: boolean;
|
|
7797
|
+
desiredSize: number | null;
|
|
7798
|
+
}
|
|
7799
|
+
/**
|
|
7800
|
+
* Readable stream type
|
|
7801
|
+
*/
|
|
7802
|
+
interface ReadableStreamLike<T = unknown> {
|
|
7803
|
+
getReader: () => StreamReader<T>;
|
|
7804
|
+
locked: boolean;
|
|
7805
|
+
cancel: (reason?: unknown) => Promise<void>;
|
|
7806
|
+
pipeThrough: <R>(transform: unknown) => ReadableStreamLike<R>;
|
|
7807
|
+
pipeTo: (dest: WritableStreamLike<T>) => Promise<void>;
|
|
7808
|
+
tee: () => [ReadableStreamLike<T>, ReadableStreamLike<T>];
|
|
7809
|
+
}
|
|
7810
|
+
/**
|
|
7811
|
+
* Writable stream type
|
|
7812
|
+
*/
|
|
7813
|
+
interface WritableStreamLike<T = unknown> {
|
|
7814
|
+
getWriter: () => StreamWriter<T>;
|
|
7815
|
+
locked: boolean;
|
|
7816
|
+
abort: (reason?: unknown) => Promise<void>;
|
|
7817
|
+
close: () => Promise<void>;
|
|
7818
|
+
}
|
|
7819
|
+
/**
|
|
7820
|
+
* Transform stream type
|
|
7821
|
+
*/
|
|
7822
|
+
interface TransformStreamLike<I = unknown, O = unknown> {
|
|
7823
|
+
readable: ReadableStreamLike<O>;
|
|
7824
|
+
writable: WritableStreamLike<I>;
|
|
7825
|
+
}
|
|
7826
|
+
/**
|
|
7827
|
+
* Pub/Sub type
|
|
7828
|
+
*/
|
|
7829
|
+
interface PubSub<T = unknown> {
|
|
7830
|
+
publish: (topic: string, message: T) => void;
|
|
7831
|
+
subscribe: (topic: string, handler: (message: T) => void) => () => void;
|
|
7832
|
+
unsubscribe: (topic: string, handler?: (message: T) => void) => void;
|
|
7833
|
+
topics: string[];
|
|
7834
|
+
}
|
|
7835
|
+
/**
|
|
7836
|
+
* Publisher type
|
|
7837
|
+
*/
|
|
7838
|
+
interface Publisher<T = unknown> {
|
|
7839
|
+
publish: (topic: string, message: T) => void;
|
|
7840
|
+
}
|
|
7841
|
+
/**
|
|
7842
|
+
* Subscriber type
|
|
7843
|
+
*/
|
|
7844
|
+
interface Subscriber<T = unknown> {
|
|
7845
|
+
subscribe: (topic: string, handler: (message: T) => void) => () => void;
|
|
7846
|
+
unsubscribe: (topic: string, handler?: (message: T) => void) => void;
|
|
7847
|
+
}
|
|
7848
|
+
/**
|
|
7849
|
+
* Subscription options type
|
|
7850
|
+
*/
|
|
7851
|
+
interface SubscriptionOptions<T = unknown> {
|
|
7852
|
+
topic: string;
|
|
7853
|
+
handler: (message: T) => void;
|
|
7854
|
+
once?: boolean;
|
|
7855
|
+
filter?: (message: T) => boolean;
|
|
7856
|
+
}
|
|
7857
|
+
//#endregion
|
|
7858
|
+
//#region src/workflow/index.d.ts
|
|
7859
|
+
/**
|
|
7860
|
+
* Workflow Engine Types
|
|
7861
|
+
*
|
|
7862
|
+
* Types for workflow and process management.
|
|
7863
|
+
*/
|
|
7864
|
+
/**
|
|
7865
|
+
* Workflow type
|
|
7866
|
+
*/
|
|
7867
|
+
interface Workflow<T = unknown> {
|
|
7868
|
+
id: string;
|
|
7869
|
+
name: string;
|
|
7870
|
+
description?: string;
|
|
7871
|
+
version: string;
|
|
7872
|
+
definition: WorkflowDefinition<T>;
|
|
7873
|
+
status: WorkflowStatus;
|
|
7874
|
+
createdAt: Date;
|
|
7875
|
+
updatedAt: Date;
|
|
7876
|
+
}
|
|
7877
|
+
/**
|
|
7878
|
+
* Workflow definition
|
|
7879
|
+
*/
|
|
7880
|
+
interface WorkflowDefinition<T = unknown> {
|
|
7881
|
+
steps: WorkflowStep[];
|
|
7882
|
+
transitions: WorkflowTransition[];
|
|
7883
|
+
initialStep: string;
|
|
7884
|
+
finalSteps: string[];
|
|
7885
|
+
timeouts?: WorkflowTimeout;
|
|
7886
|
+
errorHandler?: WorkflowErrorHandler<T>;
|
|
7887
|
+
context?: T;
|
|
7888
|
+
}
|
|
7889
|
+
/**
|
|
7890
|
+
* Workflow instance
|
|
7891
|
+
*/
|
|
7892
|
+
interface WorkflowInstance<T = unknown> {
|
|
7893
|
+
id: string;
|
|
7894
|
+
workflowId: string;
|
|
7895
|
+
status: WorkflowStatus;
|
|
7896
|
+
currentStep: string;
|
|
7897
|
+
context: T;
|
|
7898
|
+
history: HistoryEntry[];
|
|
7899
|
+
startedAt: Date;
|
|
7900
|
+
completedAt?: Date;
|
|
7901
|
+
error?: WorkflowError;
|
|
7902
|
+
metadata?: Record<string, unknown>;
|
|
7903
|
+
}
|
|
7904
|
+
/**
|
|
7905
|
+
* Workflow status
|
|
7906
|
+
*/
|
|
7907
|
+
type WorkflowStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled' | 'paused';
|
|
7908
|
+
/**
|
|
7909
|
+
* Workflow step
|
|
7910
|
+
*/
|
|
7911
|
+
interface WorkflowStep<T = unknown> {
|
|
7912
|
+
id: string;
|
|
7913
|
+
name: string;
|
|
7914
|
+
description?: string;
|
|
7915
|
+
type: StepType;
|
|
7916
|
+
config?: T;
|
|
7917
|
+
timeout?: number;
|
|
7918
|
+
retryPolicy?: RetryPolicy$1;
|
|
7919
|
+
compensation?: string;
|
|
7920
|
+
onSuccess?: string;
|
|
7921
|
+
onFailure?: string;
|
|
7922
|
+
}
|
|
7923
|
+
/**
|
|
7924
|
+
* Step type
|
|
7925
|
+
*/
|
|
7926
|
+
type StepType = 'task' | 'decision' | 'parallel' | 'subworkflow' | 'wait' | 'human' | 'script' | 'http';
|
|
7927
|
+
/**
|
|
7928
|
+
* Step result
|
|
7929
|
+
*/
|
|
7930
|
+
type StepResult<T = unknown> = {
|
|
7931
|
+
success: true;
|
|
7932
|
+
data: T;
|
|
7933
|
+
nextStep?: string;
|
|
7934
|
+
} | {
|
|
7935
|
+
success: false;
|
|
7936
|
+
error: Error;
|
|
7937
|
+
retry?: boolean;
|
|
7938
|
+
compensation?: boolean;
|
|
7939
|
+
};
|
|
7940
|
+
/**
|
|
7941
|
+
* Step status
|
|
7942
|
+
*/
|
|
7943
|
+
type StepStatus$1 = 'waiting' | 'running' | 'success' | 'failure' | 'skipped' | 'compensated';
|
|
7944
|
+
/**
|
|
7945
|
+
* Workflow transition
|
|
7946
|
+
*/
|
|
7947
|
+
interface WorkflowTransition<T = unknown> {
|
|
7948
|
+
from: string;
|
|
7949
|
+
to: string | string[];
|
|
7950
|
+
condition?: TransitionCondition<T>;
|
|
7951
|
+
action?: TransitionAction<T>;
|
|
7952
|
+
priority?: number;
|
|
7953
|
+
}
|
|
7954
|
+
/**
|
|
7955
|
+
* Transition condition
|
|
7956
|
+
*/
|
|
7957
|
+
type TransitionCondition<T = unknown> = (context: T) => boolean;
|
|
7958
|
+
/**
|
|
7959
|
+
* Transition action
|
|
7960
|
+
*/
|
|
7961
|
+
type TransitionAction<T = unknown> = (context: T) => T | Promise<T>;
|
|
7962
|
+
/**
|
|
7963
|
+
* Workflow timeout
|
|
7964
|
+
*/
|
|
7965
|
+
interface WorkflowTimeout {
|
|
7966
|
+
workflow?: number;
|
|
7967
|
+
step?: number;
|
|
7968
|
+
action?: number;
|
|
7969
|
+
}
|
|
7970
|
+
/**
|
|
7971
|
+
* Workflow execution
|
|
7972
|
+
*/
|
|
7973
|
+
interface WorkflowExecution<T = unknown> {
|
|
7974
|
+
id: string;
|
|
7975
|
+
instanceId: string;
|
|
7976
|
+
status: ExecutionStatus;
|
|
7977
|
+
startedAt: Date;
|
|
7978
|
+
completedAt?: Date;
|
|
7979
|
+
duration?: number;
|
|
7980
|
+
steps: ExecutionStep<T>;
|
|
7981
|
+
result?: T;
|
|
7982
|
+
error?: WorkflowError;
|
|
7983
|
+
}
|
|
7984
|
+
/**
|
|
7985
|
+
* Execution status
|
|
7986
|
+
*/
|
|
7987
|
+
type ExecutionStatus = 'pending' | 'running' | 'completed' | 'failed' | 'timeout' | 'cancelled';
|
|
7988
|
+
/**
|
|
7989
|
+
* Execution step
|
|
7990
|
+
*/
|
|
7991
|
+
interface ExecutionStep<T = unknown> {
|
|
7992
|
+
stepId: string;
|
|
7993
|
+
status: StepStatus$1;
|
|
7994
|
+
startedAt: Date;
|
|
7995
|
+
completedAt?: Date;
|
|
7996
|
+
input?: T;
|
|
7997
|
+
output?: T;
|
|
7998
|
+
error?: Error;
|
|
7999
|
+
retryCount: number;
|
|
8000
|
+
}
|
|
8001
|
+
/**
|
|
8002
|
+
* Execution context
|
|
8003
|
+
*/
|
|
8004
|
+
interface ExecutionContext<T = unknown> {
|
|
8005
|
+
workflowId: string;
|
|
8006
|
+
instanceId: string;
|
|
8007
|
+
executionId: string;
|
|
8008
|
+
currentStep: string;
|
|
8009
|
+
context: T;
|
|
8010
|
+
metadata: Record<string, unknown>;
|
|
8011
|
+
variables: Record<string, unknown>;
|
|
8012
|
+
}
|
|
8013
|
+
/**
|
|
8014
|
+
* Execution result
|
|
8015
|
+
*/
|
|
8016
|
+
type ExecutionResult<T = unknown> = {
|
|
8017
|
+
success: true;
|
|
8018
|
+
data: T;
|
|
8019
|
+
completedAt: Date;
|
|
8020
|
+
} | {
|
|
8021
|
+
success: false;
|
|
8022
|
+
error: WorkflowError;
|
|
8023
|
+
completedAt: Date;
|
|
8024
|
+
};
|
|
8025
|
+
/**
|
|
8026
|
+
* Workflow history
|
|
8027
|
+
*/
|
|
8028
|
+
interface WorkflowHistory<T = unknown> {
|
|
8029
|
+
instanceId: string;
|
|
8030
|
+
entries: HistoryEntry<T>[];
|
|
8031
|
+
total: number;
|
|
8032
|
+
}
|
|
8033
|
+
/**
|
|
8034
|
+
* History entry
|
|
8035
|
+
*/
|
|
8036
|
+
interface HistoryEntry<T = unknown> {
|
|
8037
|
+
id: string;
|
|
8038
|
+
timestamp: Date;
|
|
8039
|
+
type: HistoryEventType;
|
|
8040
|
+
stepId?: string;
|
|
8041
|
+
fromStep?: string;
|
|
8042
|
+
toStep?: string;
|
|
8043
|
+
context?: T;
|
|
8044
|
+
result?: StepResult<T>;
|
|
8045
|
+
error?: Error;
|
|
8046
|
+
duration?: number;
|
|
8047
|
+
actor?: string;
|
|
8048
|
+
}
|
|
8049
|
+
/**
|
|
8050
|
+
* History event
|
|
8051
|
+
*/
|
|
8052
|
+
interface HistoryEvent<T = unknown> {
|
|
8053
|
+
type: HistoryEventType;
|
|
8054
|
+
timestamp: Date;
|
|
8055
|
+
data: T;
|
|
8056
|
+
}
|
|
8057
|
+
/**
|
|
8058
|
+
* History event type
|
|
8059
|
+
*/
|
|
8060
|
+
type HistoryEventType = 'workflow_started' | 'workflow_completed' | 'workflow_failed' | 'workflow_cancelled' | 'step_started' | 'step_completed' | 'step_failed' | 'step_skipped' | 'transition' | 'compensation_started' | 'compensation_completed' | 'error' | 'retry' | 'timeout';
|
|
8061
|
+
/**
|
|
8062
|
+
* Workflow error
|
|
8063
|
+
*/
|
|
8064
|
+
interface WorkflowError {
|
|
8065
|
+
code: string;
|
|
8066
|
+
message: string;
|
|
8067
|
+
details?: unknown;
|
|
8068
|
+
stack?: string;
|
|
8069
|
+
retryable: boolean;
|
|
8070
|
+
timestamp: Date;
|
|
8071
|
+
}
|
|
8072
|
+
/**
|
|
8073
|
+
* Workflow error handler
|
|
8074
|
+
*/
|
|
8075
|
+
interface WorkflowErrorHandler<T = unknown> {
|
|
8076
|
+
onError: (error: WorkflowError, context: ExecutionContext<T>) => ErrorHandlerResult;
|
|
8077
|
+
}
|
|
8078
|
+
/**
|
|
8079
|
+
* Error handler result
|
|
8080
|
+
*/
|
|
8081
|
+
type ErrorHandlerResult = {
|
|
8082
|
+
action: 'retry';
|
|
8083
|
+
delay?: number;
|
|
8084
|
+
} | {
|
|
8085
|
+
action: 'compensate';
|
|
8086
|
+
} | {
|
|
8087
|
+
action: 'continue';
|
|
8088
|
+
nextStep: string;
|
|
8089
|
+
} | {
|
|
8090
|
+
action: 'fail';
|
|
8091
|
+
} | {
|
|
8092
|
+
action: 'ignore';
|
|
8093
|
+
};
|
|
8094
|
+
/**
|
|
8095
|
+
* Retry policy
|
|
8096
|
+
*/
|
|
8097
|
+
interface RetryPolicy$1 {
|
|
8098
|
+
maxRetries: number;
|
|
8099
|
+
backoff: 'fixed' | 'exponential' | 'linear';
|
|
8100
|
+
initialDelay: number;
|
|
8101
|
+
maxDelay: number;
|
|
8102
|
+
retryableErrors?: string[];
|
|
8103
|
+
}
|
|
8104
|
+
/**
|
|
8105
|
+
* BPMN process
|
|
8106
|
+
*/
|
|
8107
|
+
type BPMNProcess<T = unknown> = {
|
|
8108
|
+
id: string;
|
|
8109
|
+
name: string;
|
|
8110
|
+
type: BPMNProcessType;
|
|
8111
|
+
lane?: string;
|
|
8112
|
+
documentation?: string;
|
|
8113
|
+
extensionElements?: Record<string, unknown>;
|
|
8114
|
+
} & WorkflowDefinition<T>;
|
|
8115
|
+
/**
|
|
8116
|
+
* BPMN process type
|
|
8117
|
+
*/
|
|
8118
|
+
type BPMNProcessType = 'none' | 'message' | 'timer' | 'signal' | 'conditional' | 'error' | 'escalation' | 'compensation' | 'multiple' | 'parallel';
|
|
8119
|
+
/**
|
|
8120
|
+
* BPMN task
|
|
8121
|
+
*/
|
|
8122
|
+
interface BPMNTask<T = unknown> {
|
|
8123
|
+
id: string;
|
|
8124
|
+
name: string;
|
|
8125
|
+
type: BPMNTaskType;
|
|
8126
|
+
assignee?: string;
|
|
8127
|
+
candidateUsers?: string[];
|
|
8128
|
+
candidateGroups?: string[];
|
|
8129
|
+
priority?: number;
|
|
8130
|
+
dueDate?: Date;
|
|
8131
|
+
formKey?: string;
|
|
8132
|
+
input?: T;
|
|
8133
|
+
output?: T;
|
|
8134
|
+
}
|
|
8135
|
+
/**
|
|
8136
|
+
* BPMN task type
|
|
8137
|
+
*/
|
|
8138
|
+
type BPMNTaskType = 'user' | 'service' | 'script' | 'business-rule' | 'manual' | 'send' | 'receive' | 'abstract';
|
|
8139
|
+
/**
|
|
8140
|
+
* BPMN gateway
|
|
8141
|
+
*/
|
|
8142
|
+
interface BPMNGateway<T = unknown> {
|
|
8143
|
+
id: string;
|
|
8144
|
+
name: string;
|
|
8145
|
+
type: BPMNGatewayType;
|
|
8146
|
+
conditions?: BPMNGatewayCondition<T>[];
|
|
8147
|
+
defaultFlow?: string;
|
|
8148
|
+
}
|
|
8149
|
+
/**
|
|
8150
|
+
* BPMN gateway type
|
|
8151
|
+
*/
|
|
8152
|
+
type BPMNGatewayType = 'exclusive' | 'parallel' | 'inclusive' | 'event-based' | 'complex';
|
|
8153
|
+
/**
|
|
8154
|
+
* BPMN gateway condition
|
|
8155
|
+
*/
|
|
8156
|
+
interface BPMNGatewayCondition<T = unknown> {
|
|
8157
|
+
flowId: string;
|
|
8158
|
+
condition: (context: T) => boolean;
|
|
8159
|
+
expression?: string;
|
|
8160
|
+
}
|
|
8161
|
+
/**
|
|
8162
|
+
* BPMN event
|
|
8163
|
+
*/
|
|
8164
|
+
interface BPMNEvent<T = unknown> {
|
|
8165
|
+
id: string;
|
|
8166
|
+
name: string;
|
|
8167
|
+
type: BPMNEventType;
|
|
8168
|
+
trigger: BPMNEventTrigger;
|
|
8169
|
+
catching: boolean;
|
|
8170
|
+
data?: T;
|
|
8171
|
+
}
|
|
8172
|
+
/**
|
|
8173
|
+
* BPMN event type
|
|
8174
|
+
*/
|
|
8175
|
+
type BPMNEventType = 'start' | 'end' | 'intermediate' | 'boundary';
|
|
8176
|
+
/**
|
|
8177
|
+
* BPMN event trigger
|
|
8178
|
+
*/
|
|
8179
|
+
type BPMNEventTrigger = 'none' | 'message' | 'timer' | 'signal' | 'conditional' | 'error' | 'escalation' | 'compensation' | 'link' | 'terminate' | 'multiple' | 'parallel';
|
|
8180
|
+
/**
|
|
8181
|
+
* Workflow engine
|
|
8182
|
+
*/
|
|
8183
|
+
interface WorkflowEngine<T = unknown> {
|
|
8184
|
+
register: (workflow: Workflow<T>) => void;
|
|
8185
|
+
unregister: (workflowId: string) => void;
|
|
8186
|
+
start: (workflowId: string, input?: T) => Promise<WorkflowInstance>;
|
|
8187
|
+
resume: (instanceId: string) => Promise<WorkflowInstance>;
|
|
8188
|
+
cancel: (instanceId: string) => Promise<void>;
|
|
8189
|
+
pause: (instanceId: string) => Promise<void>;
|
|
8190
|
+
getStatus: (instanceId: string) => Promise<WorkflowInstance | undefined>;
|
|
8191
|
+
getHistory: (instanceId: string) => Promise<WorkflowHistory>;
|
|
8192
|
+
listInstances: (workflowId?: string) => Promise<WorkflowInstance[]>;
|
|
8193
|
+
}
|
|
8194
|
+
/**
|
|
8195
|
+
* Workflow engine configuration
|
|
8196
|
+
*/
|
|
8197
|
+
interface WorkflowEngineConfig {
|
|
8198
|
+
persistence: WorkflowPersistence;
|
|
8199
|
+
executor: WorkflowExecutor;
|
|
8200
|
+
maxConcurrentWorkflows: number;
|
|
8201
|
+
defaultTimeout: number;
|
|
8202
|
+
errorHandling: ErrorHandlingStrategy;
|
|
8203
|
+
}
|
|
8204
|
+
/**
|
|
8205
|
+
* Workflow persistence
|
|
8206
|
+
*/
|
|
8207
|
+
interface WorkflowPersistence {
|
|
8208
|
+
saveInstance: (instance: WorkflowInstance) => Promise<void>;
|
|
8209
|
+
getInstance: (instanceId: string) => Promise<WorkflowInstance | undefined>;
|
|
8210
|
+
deleteInstance: (instanceId: string) => Promise<void>;
|
|
8211
|
+
saveHistory: (instanceId: string, entry: HistoryEntry) => Promise<void>;
|
|
8212
|
+
getHistory: (instanceId: string) => Promise<HistoryEntry[]>;
|
|
8213
|
+
}
|
|
8214
|
+
/**
|
|
8215
|
+
* Workflow executor
|
|
8216
|
+
*/
|
|
8217
|
+
interface WorkflowExecutor {
|
|
8218
|
+
executeStep: <T>(step: WorkflowStep, context: ExecutionContext<T>) => Promise<StepResult>;
|
|
8219
|
+
executeParallel: <T>(steps: WorkflowStep[], context: ExecutionContext<T>) => Promise<StepResult[]>;
|
|
8220
|
+
}
|
|
8221
|
+
/**
|
|
8222
|
+
* Error handling strategy
|
|
8223
|
+
*/
|
|
8224
|
+
type ErrorHandlingStrategy = 'fail-fast' | 'compensate' | 'ignore' | 'manual';
|
|
8225
|
+
//#endregion
|
|
8226
|
+
export { type ABAC, type ABACConfig, type ACL, type ACLEntry, type APIGateway, type ARCCache, type AccessControl, type Action, Add, AddStage, type AggregateEvents, type Alert, type AlertConfig, type AlertReceiver, type AlertRoute, type AlertRule, type AlertSeverity, type AlertStatus, And, AnyGuard, AppendParameter, ArrayElement, ArrayElementGuard, type ArrayFieldValidator, ArrayPaths, Assert, AssertEqual, AssertExtends, AssertHasProperty, AssertKeyof, AssertNotNil, AssertType, AssertionFunction, AsyncFailure, AsyncParameters, AsyncResult, AsyncReturnType, AsyncReturnTypeFromPromise, AsyncSuccess, AtLeastOne, type Attribute, type AttributeValue, type AuthConfig, type AuthorizationOptions, type AuthorizationProvider, Awaited, type BPMNEvent, type BPMNEventTrigger, type BPMNEventType, type BPMNGateway, type BPMNGatewayCondition, type BPMNGatewayType, type BPMNProcess, type BPMNProcessType, type BPMNTask, type BPMNTaskType, type BaseEvent, Between, BinaryTreeNode, type BooleanFieldValidator, Brand, BrandCache, BrandedNumber, BrandedString, BuildStateMachine, Bulkhead, type CORSConfig, type Cache, type CacheAside, type CacheCluster, type CacheCompressionOptions, type CacheDecoratorOptions, type CacheEntry, type CacheInvalidation, type CacheKey, type CacheKeyBuilder, type CacheNode, type CacheOptions, type CacheSerializer, type CacheStats, type CacheStrategy, type CacheValue, Cached, CachedIntersection, CachedKeyOf, CachedProperty, CachedUnion, CachedValue, CamelCase, CamelCaseKeys, CanTransition, CapitalizeAll, Case, ChangeEventHandler, type CircuitBreaker, type CircuitBreakerConfig, type CircuitBreakerState, type CircuitBreakerStats, ColumnOptions, CombinedGuard, type Command, type CommandBus, type CommandHandler, type CommandResult, Compact, CompatibilityReport, CompatibleIntersection, CompatibleKeys, CompatibleMerge, CompatibleWith, ComponentProps, ComponentPropsWithRef, CompositeGuard, CompositeIndex, type ConditionOperator, type Config, type ConfigError, type ConfigField, type ConfigFieldType, type ConfigFileFormat, type ConfigLoader, type ConfigLoaderOptions, type ConfigPriority, type ConfigSchema, type ConfigValidationResult, type ConfigValidator, type ConfigValue, type ConfigWarning, type ConsistentHash, ConstantCase, ConversionMap, ConvertFrom, ConvertTo, type Counter, CreateTable, CurrentState, type CustomValidator, DataOnly, DatabaseConfig, type DateFieldValidator, type DeadLetterQueue, Debounce, DebounceOptions, DebugType, Dec, DeepMerge, DeepMutable, DeepNonNullable, DeepNullable, DeepOmit, DeepOmitPaths, DeepOptional, DeepPartial, DeepPick, DeepPickPaths, DeepReadonly, DeepRequired, DeepRequiredProperties, DeepSimplify, Default, Deferred, DeleteQuery, Dequeue, type DistributedCache, DotCase, type EmailConstraint, EndsWith, Enqueue, type EnvConfig, type EnvMapping, type EnvVar, type ErrorHandlerResult, type ErrorHandlingStrategy, EvaluateExpression, type EventBus, type EventBusConfig, type EventBusHandler, type EventBusMiddleware, type EventEmitter, EventHandler, type EventListenerOptions, type EventMap, type EventPayload, type StepStatus as EventStepStatus, type EventStore, type EventStream, type EventTimestamp, type EventVersion, Exact, ExactType, Exclusive, type ExecutionContext, type ExecutionResult, type ExecutionStatus, type ExecutionStep, ExpandType, ExpectAny, ExpectEqual, ExpectExtends, ExpectFalse, ExpectNever, ExpectNotExtends, ExpectTrue, ExpectUnknown, ExtractPropTypes, ExtractVueProps, type FIFOCache, type FeatureFlag, type FeatureFlagConfig, type FeatureFlagVariant, type FeatureFlags, type FeatureTargeting, FilterKeys, type Find, type FindIndex, FirstParameter, type Flatten, type FlattenDeep, FlattenType, FlushCache, FocusEventHandler, ForEach, ForceEvaluate, FormEventHandler, ForwardRefProps, FromTsToolbelt, FromTypeFest, FromUtilityTypes, Front, FunctionKeys, FunctionOnly, type GatewayConfig, type GatewayMiddleware, type GatewayRoute, type Gauge, GenericTree, Graph, GraphEdge, GraphEdges, GraphHasCycle, GraphNode, GraphNodes, GraphPath, GraphQLArgs, GraphQLContext, GraphQLEnumType, GraphQLFieldResolver, GraphQLFieldTypes, GraphQLFlatSelection, GraphQLFragment, GraphQLInputObjectType, GraphQLInputType, GraphQLInterfaceType, GraphQLMutation, GraphQLObjectType, GraphQLOutputType, GraphQLQuery, GraphQLResolveInfo, GraphQLResolver, GraphQLReturn, GraphQLScalarType, GraphQLSchema, GraphQLSelection, GraphQLSelectionSet, GraphQLSubscription, GraphQLToType, GraphQLType, GraphQLUnionType, GreaterThan, GuardedType, type HTTPStatus, HasExactKeys, HasKeys, HasMethod, HasProperties, HasProperty, HasRuntimeCheck, Head$1 as Head, type HealthCheck, type HealthIndicator, type HealthReport, type Histogram, type HistoryEntry, type HistoryEvent, type HistoryEventType, type HitRate, If, Immutable, Inc, type Includes, IncompatibleKeys, Index, type IndexOf, type InhibitRule, Init, InsertQuery, InspectType, type InstanceStatus, type InvalidationEvent, type InvalidationRule, type InvalidationStrategy, IsAny, IsArray, IsAsyncFunction, IsCompatible, IsEmail, IsEmptyObject, IsEmptyQueue, IsEmptyStack, IsEmptyString, IsEmptyTuple, IsEqual, IsFunction, IsIntersection, IsNever, IsNumeric, IsPromise, IsTerminal, IsTuple, IsURL, IsUUID, IsUnion, IsUnknown, IsValidJSON, IsYupNullable, IsYupOptional, IsYupSchema, IsZodNullable, IsZodOptional, IsZodSchema, Iterate, Join, JoinQuery, KebabCase, KeyboardEventHandler, Keys, KeysByValueType, KeysOfType, type LFUCache, type LRUCache, Last$1 as Last, Lazy, LazyArrayElement, LazyAwaited, LazyChain, LazyConditional, LazyKey, LazyMap, LazyParameters, LazyReturnType, LeafPaths, LessThan, LibraryFeatures, LinkedList, type ListConcat, type ListFilter, type ListFind, ListHead, type ListIncludes, type ListLength, ListNode, type ListReverse, ListTail, Literal$1 as Literal, LiteralBoolean, LiteralNumber, LiteralString, type LivenessCheck, type LoadBalancer, type LoadBalancerStrategy, LockAcquisition, type LogContext, type LogEntry, type LogLevel, type LogTransport, type Logger, type LoggerConfig, type HealthCheckResult as LoggingHealthCheckResult, type LongestCommonPrefix, LoosePartial, LowerCase, MachineConfig, MakeAsync, MakeOptional, type MapDelete, type MapGet, type MapHas, type MapKeys, type MapSet, type MapValues, MarkType, Match, Max, type MaxLength, type MaxValue, Maybe, Memoized, Merge, MergeAll, MergeAllObjects, MergeDefaultProps, type MessageQueue, type Metric, type MetricType, type MetricsRegistry, type Microservice, type Middleware, Migration, MigrationDown, MigrationHistory, MigrationUp, Min, type MinLength, type MinValue, type MissRate, type Monitor, type MonitorResult, type MonitorStatus, MouseEventHandler, Mutable, MutexState, NegateGuard, NextState, NoNullish, NonFunctionKeys, NonNullable$1 as NonNullable, Normalize, NormalizeVueProps, Not, type NotValidator, NthParameter, NullGuard, Nullable, NullishGuard, type NumberFieldValidator, type NumberSanitizer, ObjectEntries, type ObjectFieldValidator, ObjectFilter, ObjectInvert, ObjectMap, ObjectOmitByType, ObjectPath, ObjectPickByType, OmitPartial, OmitRequired, OmitThisParameter, Optional, OptionalKeys, OptionalParameters, OptionalProps, OptionalVueProp, Optionalize, Or, type OrValidator, OrderClause, PadEnd, PadStart, Parameters, ParentPath, ParseCSV, type ParseEnvResult, ParseExpression, ParseJSON, ParseURL, PascalCase, PascalCaseKeys, PathExists, PathLeaf, PathLength, PathParams, PathValue, Paths, type Pattern, Peek, type Permission, type PermissionCheckResult, type PermissionCondition, type PermissionDeny, type PermissionGrant, type PermissionSet, PickNonNullable, PickNullable, PickPartial, PickRequired, Pipeline, PipelineRun, PipelineStage, type Policy, type PolicyCondition, type PolicyContext, type PolicyEffect, type PolicyResult, type PolicyRule, Pop, PrefixKeys, PrependParameter, PrettyType, PrimitiveGuard, PrimitiveGuardMap, PriorityQueue, PrismaAggregateArgs, PrismaCountArgs, PrismaCreateArgs, PrismaCreateInput, PrismaDeleteArgs, PrismaFindFirstArgs, PrismaFindManyArgs, PrismaFindUniqueArgs, PrismaGroupByArgs, PrismaInclude, PrismaModel, PrismaOrderByInput, PrismaPagination, PrismaRelationFields, PrismaScalarFields, PrismaSelect, PrismaUniqueWhere, PrismaUpdateArgs, PrismaUpdateInput, PrismaUpsertArgs, PrismaWhereInput, PromiseFulfilledResult, PromiseRejectedResult, PromiseResult, PromiseSettledResult, PromiseValue, PropsWithChildren, PropsWithClassName, PropsWithStyle, PropsWithStyleAndClassName, PropsWithoutChildren, type PubSub, type PublishOptions, type Publisher, Push, type Query, QueryBuilder, type QueryBus, type QueryHandler, QueryParams, type QueryResult, QueryState, Queue, type QueueConsumer, type QueueMessage, type QueueProducer, QueueSize, type RBAC, type RBACConfig, Range, type RateLimit, RateLimiter, type ReadThroughCache, type ReadableStreamLike, type ReadinessCheck, ReadonlyKeys, type RealTimeChannel, type RealTimeClient, type RealTimeMessage, type RealTimeSubscription, Reduce, ReduceIntersection, ReduceUnion, type RemoteConfigProvider, RemoveSpaces, RenameKeys, Repeat, Replace, ReplaceAll, RequireArray, RequireAtLeastOne, RequireExactlyOne, RequireFunction, RequireKeys, RequireNotNullish, Required$1 as Required, RequiredKeys, RequiredProps, RequiredVueProp, ResolveBrandCache, type Resource, ReturnType$1 as ReturnType, type Reverse, ReverseString, type Role, type RoleHierarchy, type RolePermission, type RoleSet, type Route, RunTypeTest, RuntimeGuard, SQLColumn, SQLType, type Saga, type SagaCompensation, type SagaResult, type SagaStatus, type SagaStep, type SanitizationRule, type SanitizeResult, type Sanitizer, ScheduleOptions, ScheduledJob, Scheduler, type SchemaBuilder, type Secret, type SecretConfig, type SecretOptions, type SecretProvider, SelectQuery, Semaphore, SendEvent, type ServiceClient, type ServiceConfig, type ServiceDiscovery, type ServiceError, type HealthStatus as ServiceHealthStatus, type ServiceInstance, type ServiceRegistry, type ServiceRequest, type ServiceResponse, type RetryPolicy as ServiceRetryPolicy, type SetAdd, type SetDifference, type SetHas, type SetIntersection, type SetIsEmpty, type SetIsSubset, type SetRemove, type SetUnion, Simplify, SkipTest, SnakeCase, SnakeCaseKeys, type Span, type SpanEvent, type SpanKind, type SpanLink, type SpanOptions, type SpanStatus, Split, SplitByComma, SplitPath, Stack, StackSize, StageResult, StartsWith, State, StateHistory, StateMachine, type StepResult, type StepType, type Stream, type StreamChunk, type StreamReader, type StreamWriter, StrictExclude, StrictExtract, type StringFieldValidator, StringLength, type StringSanitizer, StringToArray, StringifyCSV, StringifyJSON, StripNever, StripNull, StripUndefined, type Subscriber, type SubscriptionOptions, Subtract, SuffixKeys, type Summary, TRPCCallerRouter, TRPCClient, TRPCContext, TRPCErrorShape, TRPCExtractProcedureType, TRPCMergeRouters, TRPCMiddleware, TRPCMutations, TRPCProcedureBuilder, TRPCProcedureCaller, TRPCProcedureInput, TRPCProcedureOutput, TRPCProcedureType, TRPCQueries, TRPCRouterRecord, TRPCRouterShape, TRPCSubscriptions, TRPSCaller, type TTLCache, Tail$1 as Tail, type TargetingOperator, Task, TaskError, TaskOptions, TaskPriority, TaskResult, TaskStatus, ThisParameterType, Throttle, ThrottleOptions, Thunk, ToTsToolbelt, ToTypeFest, ToUtilityTypes, ToolbeltDeepPartial, ToolbeltUnionExclude, ToolbeltUnionPick, type Trace, type TraceContext, type TraceStatus, type Tracer, Transaction, type TransformStreamLike, Transition, type TransitionAction, type TransitionCondition, Tree, TreeDepth, TreeFlatten, TreeLeaves, TreeNode, TreePath, Trim, TrimLeft, TrimRight, TupleLength, TypeCache, TypeCategory, TypeComplexity, TypeCoverage, TypeEq, TypeEvery, TypeFestCamelCase, TypeFestSnakeCase, TypeFilter, TypeFind, TypeIdentity, TypeIncludes, TypeInfo, type TypeMap, TypePredicate, type TypeSet, TypeSome, TypeTest, TypeTestResult, TypeTestSuite, TypeToGraphQL, TypeToGuardKey, type TypedEventTarget, type URLConstraint, type UUIDConstraint, Unbrand, UncapitalizeAll, UncoveredTypes, UndefinedGuard, UnionGuard, UnionToIntersection, UnionToTuple, type Unique, UniqueIndex, UnwrapPromise, UpdateQuery, UpperCase, UtilityDeepPartial, UtilityDeepReadonly, UtilityMap, ValidPath, ValidTransitions, type ValidationContext, type ValidationError, type ValidationOptions, type ValidationRule, type Validator, type ValidatorResult, ValueOf, VueComponentInstance, VueComputed, VueEmitType, VueExpose, VueInjectionKey, VueModelProps, VuePropConstructor, VuePropType, VuePropWithDefault, VuePropsToType, VueProvideInjectPair, VueRawProps, VueReactive, VueRef, VueSlot, VueSlots, type WebSocketConfig, type WebSocketEvent, type EventHandler$1 as WebSocketEventHandler, type WebSocketHandler, type WebSocketMessage, type WebSocketOptions, type WebSocketState, WhereBuilder, WhereClause, Worker, WorkerOptions, WorkerPool, WorkerTask, type Workflow, type WorkflowDefinition, type WorkflowEngine, type WorkflowEngineConfig, type WorkflowError, type WorkflowErrorHandler, type WorkflowExecution, type WorkflowExecutor, type WorkflowHistory, type WorkflowInstance, type WorkflowPersistence, type RetryPolicy$1 as WorkflowRetryPolicy, type WorkflowStatus, type WorkflowStep, type StepStatus$1 as WorkflowStepStatus, type WorkflowTimeout, type WorkflowTransition, WrapPromise, WritableKeys, type WritableStreamLike, type WriteBehindCache, type WriteThroughCache, YupArrayElement, YupErrorType, YupFields, YupInput, YupOptionalKeys, YupOutput, YupRequiredKeys, YupSchemaStub, YupTestConfig, YupToType, YupTransform, YupTypeNames, YupUnwrapOptional, ZodArrayElement, ZodDeepPartialInput, ZodErrorType, ZodInput, ZodMapEntry, ZodObjectShapeStub, ZodOmit, ZodOptionalKeys, ZodOutput, ZodPick, ZodRecordValue, ZodRequiredKeys, ZodShape, ZodToType, ZodTypeNames, ZodTypeStub, ZodUnwrapNullable, ZodUnwrapOptional };
|