@plyaz/types 1.6.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/types.d.ts +20 -53
- package/dist/auth/types.d.ts +3 -20
- package/dist/common/types.d.ts +1567 -3
- package/dist/errors/types.d.ts +4 -39
- package/dist/events/payload.d.ts +2 -3
- package/dist/events/types.d.ts +17 -78
- package/dist/features/cache/types.d.ts +7 -23
- package/dist/features/community/blog/providers/wordpress/types.d.ts +2 -3
- package/dist/features/community/blog/types.d.ts +6 -8
- package/dist/features/feature-flag/types.d.ts +37 -156
- package/dist/index.js.map +1 -1
- package/dist/testing/common/assertions/types.d.ts +16 -35
- package/dist/testing/common/factories/types.d.ts +35 -144
- package/dist/testing/common/mocks/types.d.ts +23 -66
- package/dist/testing/common/patterns/types.d.ts +13 -26
- package/dist/testing/common/utils/types.d.ts +174 -285
- package/dist/testing/common/wrappers/types.d.ts +14 -29
- package/dist/testing/features/cache/types.d.ts +6 -6
- package/dist/testing/features/feature-flags/types.d.ts +20 -31
- package/dist/web3/types.d.ts +3 -12
- package/package.json +2 -1
package/dist/errors/types.d.ts
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
1
|
+
import type { WithStatusCode, WithErrorCode, WithMessage, WithCorrelationId, WithTimestamp, WithValidationError } from '../common/types';
|
|
1
2
|
/**
|
|
2
3
|
* Represents the structure of an error response returned by the application.
|
|
3
4
|
* @template ErrorDetails - The type of the `errors` array, defaults to `ErrorDetailsList`.
|
|
4
5
|
*/
|
|
5
|
-
export interface ErrorResponse<ErrorDetails = ErrorDetailsList> {
|
|
6
|
-
/**
|
|
7
|
-
* HTTP status code (e.g., 400, 404, 500).
|
|
8
|
-
*/
|
|
9
|
-
readonly statusCode: number;
|
|
10
|
-
/**
|
|
11
|
-
* Application-specific error code used for programmatic handling.
|
|
12
|
-
*/
|
|
13
|
-
readonly errorCode: string;
|
|
14
|
-
/**
|
|
15
|
-
* Human-readable message describing the error.
|
|
16
|
-
*/
|
|
17
|
-
readonly message: string;
|
|
6
|
+
export interface ErrorResponse<ErrorDetails = ErrorDetailsList> extends WithStatusCode, WithErrorCode, WithMessage, Partial<WithCorrelationId>, WithTimestamp {
|
|
18
7
|
/**
|
|
19
8
|
* Array of detailed errors, typically used for validation failures.
|
|
20
9
|
*/
|
|
21
10
|
readonly errors: ErrorDetails;
|
|
22
|
-
/**
|
|
23
|
-
* Optional unique identifier for tracing the request across systems.
|
|
24
|
-
*/
|
|
25
|
-
readonly correlationId?: string;
|
|
26
|
-
/**
|
|
27
|
-
* ISO 8601 timestamp indicating when the error occurred.
|
|
28
|
-
*/
|
|
29
|
-
readonly timestamp: string;
|
|
30
11
|
}
|
|
31
12
|
/**
|
|
32
13
|
* Additional context information about a validation error.
|
|
@@ -50,28 +31,12 @@ export interface ErrorDetailContext<ValueGiven, AllowedValues, Constraints> {
|
|
|
50
31
|
}
|
|
51
32
|
/**
|
|
52
33
|
* Represents a specific validation or business logic error related to a particular field.
|
|
34
|
+
* Uses WithValidationError for consistent validation error structure.
|
|
53
35
|
* @template ValueGiven - Type of the value that caused the error.
|
|
54
36
|
* @template AllowedValues - Type of acceptable values for the field.
|
|
55
37
|
* @template Constraints - Type of any validation constraints.
|
|
56
38
|
*/
|
|
57
|
-
export
|
|
58
|
-
/**
|
|
59
|
-
* The name of the field that caused the error (optional).
|
|
60
|
-
*/
|
|
61
|
-
readonly field?: string;
|
|
62
|
-
/**
|
|
63
|
-
* Human-readable error message for this specific field or rule.
|
|
64
|
-
*/
|
|
65
|
-
readonly message: string;
|
|
66
|
-
/**
|
|
67
|
-
* Specific application-defined error code for this error.
|
|
68
|
-
*/
|
|
69
|
-
readonly errorCode: string;
|
|
70
|
-
/**
|
|
71
|
-
* Additional context information about the error.
|
|
72
|
-
*/
|
|
73
|
-
readonly context?: ErrorDetailContext<ValueGiven, AllowedValues, Constraints>;
|
|
74
|
-
}
|
|
39
|
+
export type ErrorDetail<ValueGiven, AllowedValues, Constraints> = WithValidationError<ErrorDetailContext<ValueGiven, AllowedValues, Constraints>>;
|
|
75
40
|
/**
|
|
76
41
|
* Error Details Array.
|
|
77
42
|
* @description A flexible list of error details that can contain string, number, or boolean values along with structured allowed values and constraints.
|
package/dist/events/payload.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* User Payloads.
|
|
3
3
|
*/
|
|
4
|
+
import type { WithUuid } from '../common/types';
|
|
4
5
|
/**
|
|
5
6
|
* Payload for user update events.
|
|
6
7
|
* Contains the unique identifier of the user that was updated.
|
|
@@ -12,7 +13,5 @@
|
|
|
12
13
|
* };
|
|
13
14
|
* ```
|
|
14
15
|
*/
|
|
15
|
-
export interface UserUpdatePayload {
|
|
16
|
-
/** The unique identifier of the updated user */
|
|
17
|
-
readonly uuid: string;
|
|
16
|
+
export interface UserUpdatePayload extends WithUuid {
|
|
18
17
|
}
|
package/dist/events/types.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
+
import type { Promisable, SetOptional } from 'type-fest';
|
|
1
2
|
import type { EVENT_PRIORITY, EVENT_STATUS, EVENT_TYPE } from './enums';
|
|
3
|
+
import type { Identifiable, WithUserId, WithSessionId, WithUserAgent, WithRetryTracking, WithTimestamp, WithCorrelationId, Versioned, WithSource, WithStatus, WithPriority, WithMetadata, WithIpAddress, WithPayload, SubscriptionWithHandler } from '../common/types';
|
|
2
4
|
/**
|
|
3
5
|
* Event Details.
|
|
4
6
|
* @description Represents a typed event published and consumed via the event bus.
|
|
5
7
|
* @template T - The payload type carried by the event.
|
|
6
8
|
*/
|
|
7
|
-
export interface Event<T> {
|
|
8
|
-
/**
|
|
9
|
-
* Unique identifier for the event instance.
|
|
10
|
-
*/
|
|
11
|
-
readonly id: string;
|
|
9
|
+
export interface Event<T> extends Identifiable, WithTimestamp, Partial<WithCorrelationId>, Versioned, WithSource, WithStatus<typeof EVENT_STATUS>, WithPriority<typeof EVENT_PRIORITY>, Partial<WithMetadata<EventMetadata>>, WithPayload<T> {
|
|
12
10
|
/**
|
|
13
11
|
* Type of the event, used to categorize behavior.
|
|
14
12
|
*/
|
|
@@ -17,103 +15,42 @@ export interface Event<T> {
|
|
|
17
15
|
* Topic used for event routing and subscription.
|
|
18
16
|
*/
|
|
19
17
|
readonly topic: string;
|
|
20
|
-
/**
|
|
21
|
-
* ISO timestamp of when the event was created.
|
|
22
|
-
*/
|
|
23
|
-
readonly timestamp: string;
|
|
24
|
-
/**
|
|
25
|
-
* Payload data associated with the event.
|
|
26
|
-
*/
|
|
27
|
-
readonly payload: T;
|
|
28
|
-
/**
|
|
29
|
-
* Origin or service that published the event.
|
|
30
|
-
*/
|
|
31
|
-
readonly source: string;
|
|
32
|
-
/**
|
|
33
|
-
* Optional correlation ID used for tracing distributed flows.
|
|
34
|
-
*/
|
|
35
|
-
readonly correlationId?: string;
|
|
36
|
-
/**
|
|
37
|
-
* Version number of the event structure or schema.
|
|
38
|
-
*/
|
|
39
|
-
readonly version: number;
|
|
40
|
-
/**
|
|
41
|
-
* Priority level of the event.
|
|
42
|
-
*/
|
|
43
|
-
readonly priority: typeof EVENT_PRIORITY;
|
|
44
|
-
/**
|
|
45
|
-
* Current processing status of the event.
|
|
46
|
-
*/
|
|
47
|
-
readonly status: typeof EVENT_STATUS;
|
|
48
|
-
/**
|
|
49
|
-
* Optional metadata providing contextual details about the event.
|
|
50
|
-
*/
|
|
51
|
-
readonly metadata?: EventMetadata;
|
|
52
18
|
}
|
|
53
19
|
/**
|
|
54
20
|
* Additional contextual data for an event.
|
|
55
21
|
* @description This is often populated with session/user data and retry tracking.
|
|
56
22
|
*/
|
|
57
|
-
export
|
|
58
|
-
/**
|
|
59
|
-
* Optional user identifier associated with the event.
|
|
60
|
-
*/
|
|
61
|
-
readonly userId?: string;
|
|
62
|
-
/**
|
|
63
|
-
* Optional session identifier, typically from a browser or mobile session.
|
|
64
|
-
*/
|
|
65
|
-
readonly sessionId?: string;
|
|
66
|
-
/**
|
|
67
|
-
* User-agent string from the origin of the event.
|
|
68
|
-
*/
|
|
69
|
-
readonly userAgent?: string;
|
|
70
|
-
/**
|
|
71
|
-
* IP address of the origin that triggered the event.
|
|
72
|
-
*/
|
|
73
|
-
readonly ipAddress?: string;
|
|
74
|
-
/**
|
|
75
|
-
* Current retry attempt count for the event.
|
|
76
|
-
*/
|
|
77
|
-
readonly retryCount?: number;
|
|
78
|
-
/**
|
|
79
|
-
* Maximum allowed retries for this event.
|
|
80
|
-
*/
|
|
81
|
-
readonly maxRetries?: number;
|
|
23
|
+
export type EventMetadata = SetOptional<WithUserId & WithSessionId & WithUserAgent & WithRetryTracking & WithIpAddress, 'userId' | 'sessionId' | 'userAgent' | 'retryCount' | 'maxRetries' | 'ip'> & {
|
|
82
24
|
/**
|
|
83
25
|
* Additional metadata as key-value pairs.
|
|
84
26
|
*/
|
|
85
27
|
readonly [key: string]: unknown;
|
|
86
|
-
}
|
|
28
|
+
};
|
|
87
29
|
/**
|
|
88
30
|
* Event Handler.
|
|
89
31
|
* @description A handler function that processes an event of type `T`.
|
|
90
32
|
* @template T - The event payload type.
|
|
91
33
|
*/
|
|
92
|
-
export type EventHandler<T = unknown> = (event: Event<T>) =>
|
|
34
|
+
export type EventHandler<T = unknown> = (event: Event<T>) => Promisable<void>;
|
|
93
35
|
/**
|
|
94
36
|
* Represents a subscription to a specific topic on the event bus.
|
|
37
|
+
* Uses the common SubscriptionWithHandler pattern with EventHandler type.
|
|
95
38
|
*/
|
|
96
|
-
export
|
|
97
|
-
/**
|
|
98
|
-
* Unique ID for the subscription.
|
|
99
|
-
*/
|
|
100
|
-
readonly id: string;
|
|
101
|
-
/**
|
|
102
|
-
* Topic the handler is subscribed to.
|
|
103
|
-
*/
|
|
104
|
-
readonly topic: string;
|
|
39
|
+
export type Subscription = SubscriptionWithHandler<Event<unknown>> & {
|
|
105
40
|
/**
|
|
106
41
|
* Handler function to invoke when an event is published on the topic.
|
|
107
42
|
*/
|
|
108
43
|
readonly handler: EventHandler;
|
|
109
|
-
|
|
110
|
-
* Function to cancel the subscription.
|
|
111
|
-
*/
|
|
112
|
-
readonly unsubscribe: () => void;
|
|
113
|
-
}
|
|
44
|
+
};
|
|
114
45
|
/**
|
|
115
46
|
* Interface for a publish-subscribe event bus system.
|
|
116
47
|
* @description Allows services to publish events and listen to specific topics.
|
|
48
|
+
*
|
|
49
|
+
* While this doesn't directly extend WithTopicSubscribe due to different signatures
|
|
50
|
+
* (EventBus uses EventHandler instead of a generic callback), it follows the same
|
|
51
|
+
* conceptual pattern of topic-based pub/sub.
|
|
52
|
+
*
|
|
53
|
+
* For simpler pub/sub patterns, see WithTopicPubSub or WithSubscribable in common/types.
|
|
117
54
|
*/
|
|
118
55
|
export interface EventBus {
|
|
119
56
|
/**
|
|
@@ -123,6 +60,7 @@ export interface EventBus {
|
|
|
123
60
|
readonly publish: <T>(event: Event<T>) => Promise<void>;
|
|
124
61
|
/**
|
|
125
62
|
* Subscribes a handler function to a specific topic.
|
|
63
|
+
* Similar to WithTopicSubscribe but uses EventHandler for type safety.
|
|
126
64
|
* @param topic - The topic to subscribe to.
|
|
127
65
|
* @param handler - The function to call when events are published to the topic.
|
|
128
66
|
* @returns A `Subscription` object for managing the listener.
|
|
@@ -130,6 +68,7 @@ export interface EventBus {
|
|
|
130
68
|
readonly subscribe: <T>(topic: string, handler: EventHandler<T>) => Subscription;
|
|
131
69
|
/**
|
|
132
70
|
* Unsubscribes a handler by its subscription ID.
|
|
71
|
+
* Matches the pattern in WithTopicSubscribe.
|
|
133
72
|
* @param subscriptionId - The unique ID of the subscription to remove.
|
|
134
73
|
*/
|
|
135
74
|
readonly unsubscribe: (subscriptionId: string) => void;
|
|
@@ -10,15 +10,11 @@
|
|
|
10
10
|
/**
|
|
11
11
|
* Cache entry structure that wraps cached data with metadata.
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
import type { UnknownRecord } from 'type-fest';
|
|
14
|
+
import type { Configurable, WithExpiration, WithMetadata, Enabled, WithUrl, Timestamped } from '../../common/types';
|
|
15
|
+
export interface CacheEntry<T = unknown> extends Partial<WithMetadata<UnknownRecord>>, WithExpiration<number>, Pick<Timestamped<number, number>, 'createdAt'> {
|
|
14
16
|
/** The cached data */
|
|
15
17
|
data: T;
|
|
16
|
-
/** When the entry expires (timestamp in milliseconds) */
|
|
17
|
-
expiresAt: number;
|
|
18
|
-
/** When the entry was created (timestamp in milliseconds) */
|
|
19
|
-
createdAt: number;
|
|
20
|
-
/** Optional metadata for the cache entry */
|
|
21
|
-
meta?: Record<string, unknown>;
|
|
22
18
|
}
|
|
23
19
|
/**
|
|
24
20
|
* Cache statistics for monitoring and debugging.
|
|
@@ -40,9 +36,7 @@ export interface CacheStats {
|
|
|
40
36
|
/**
|
|
41
37
|
* Configuration for cache strategies.
|
|
42
38
|
*/
|
|
43
|
-
export interface CacheConfig {
|
|
44
|
-
/** Whether caching is enabled */
|
|
45
|
-
isEnabled: boolean;
|
|
39
|
+
export interface CacheConfig extends Configurable, Enabled {
|
|
46
40
|
/** Default TTL in seconds */
|
|
47
41
|
ttl: number;
|
|
48
42
|
/** Cache strategy to use */
|
|
@@ -50,14 +44,7 @@ export interface CacheConfig {
|
|
|
50
44
|
/** Redis-specific configuration */
|
|
51
45
|
redisConfig?: RedisCacheConfig;
|
|
52
46
|
/** Memory cache specific configuration */
|
|
53
|
-
memoryConfig?:
|
|
54
|
-
/** Maximum number of entries to store */
|
|
55
|
-
maxSize?: number;
|
|
56
|
-
/** Maximum number of entries to store (alias for maxSize) */
|
|
57
|
-
maxEntries?: number;
|
|
58
|
-
/** Check for expired entries every N milliseconds */
|
|
59
|
-
cleanupInterval?: number;
|
|
60
|
-
};
|
|
47
|
+
memoryConfig?: MemoryCacheConfig;
|
|
61
48
|
}
|
|
62
49
|
/**
|
|
63
50
|
* Configuration for memory cache strategy.
|
|
@@ -75,9 +62,7 @@ export interface MemoryCacheConfig {
|
|
|
75
62
|
/**
|
|
76
63
|
* Configuration for Redis cache strategy.
|
|
77
64
|
*/
|
|
78
|
-
export interface RedisCacheConfig {
|
|
79
|
-
/** Redis connection URL */
|
|
80
|
-
url: string;
|
|
65
|
+
export interface RedisCacheConfig extends WithUrl {
|
|
81
66
|
/** Redis password for authentication */
|
|
82
67
|
password?: string;
|
|
83
68
|
/** Redis database number */
|
|
@@ -92,8 +77,7 @@ export interface RedisCacheConfig {
|
|
|
92
77
|
/**
|
|
93
78
|
* Cache manager statistics interface.
|
|
94
79
|
*/
|
|
95
|
-
export
|
|
96
|
-
}
|
|
80
|
+
export type CacheManagerStats = CacheStats;
|
|
97
81
|
/**
|
|
98
82
|
* Interface that all cache strategies must implement.
|
|
99
83
|
*/
|
|
@@ -6,10 +6,9 @@
|
|
|
6
6
|
* @fileoverview WordPress provider type definitions
|
|
7
7
|
* @version 1.0.0
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
import type { Named, Sluggable } from '../../../../../common';
|
|
10
|
+
export interface WPPostRaw extends Sluggable, Named {
|
|
11
11
|
date: string;
|
|
12
|
-
slug: string;
|
|
13
12
|
title: {
|
|
14
13
|
rendered: string;
|
|
15
14
|
};
|
|
@@ -6,23 +6,21 @@
|
|
|
6
6
|
* @fileoverview Blog domain type definitions
|
|
7
7
|
* @version 1.0.0
|
|
8
8
|
*/
|
|
9
|
+
import type { Identifiable, Named, Sluggable, WithCategories } from '../../../common/types';
|
|
10
|
+
export interface Author extends Named {
|
|
11
|
+
avatar?: string;
|
|
12
|
+
}
|
|
9
13
|
/**
|
|
10
14
|
* Blog post interface
|
|
11
15
|
* @description This interface defines the properties of a blog post.
|
|
12
16
|
*/
|
|
13
|
-
export interface BlogPost {
|
|
14
|
-
id: number;
|
|
17
|
+
export interface BlogPost extends Identifiable<number>, Sluggable, WithCategories {
|
|
15
18
|
title: string;
|
|
16
19
|
excerpt: string;
|
|
17
20
|
content: string;
|
|
18
21
|
date: string;
|
|
19
|
-
slug: string;
|
|
20
22
|
featuredImage?: string;
|
|
21
|
-
author:
|
|
22
|
-
name: string;
|
|
23
|
-
avatar?: string;
|
|
24
|
-
};
|
|
25
|
-
categories: string[];
|
|
23
|
+
author: Author;
|
|
26
24
|
readingTime: number;
|
|
27
25
|
}
|
|
28
26
|
/**
|