@plyaz/types 1.5.5 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
+ import type { Simplify } from 'type-fest';
2
+ import type { WithTimestamp, WithCorrelationId, Pageable, Versioned, NavigablePaginationMetadata, WithRequestId, WithItems } from '../common/types';
1
3
  /**
2
4
  * Standard structure for API responses.
3
5
  * @template Data - The main payload/data returned by the API.
@@ -17,66 +19,31 @@ export interface ApiResponse<Data, Meta = Record<string, string>> {
17
19
  * Metadata included in API responses.
18
20
  * @description Provides useful context such as timestamps, request tracking, and API versioning.
19
21
  */
20
- export interface ApiResponseMeta {
21
- /**
22
- * ISO timestamp indicating when the response was generated.
23
- */
24
- readonly timestamp: string;
25
- /**
26
- * Semantic version or release version of the API.
27
- */
28
- readonly version: string;
29
- /**
30
- * Unique identifier for tracing the API request.
31
- */
32
- readonly requestId: string;
33
- }
22
+ export type ApiResponseMeta = WithTimestamp & Versioned & WithCorrelationId & WithRequestId;
34
23
  /**
35
24
  * Generic structure for paginated API responses.
36
25
  * @template Item - The type of items in the paginated result.
37
26
  */
38
- export interface PaginatedResponse<Item> {
39
- /**
40
- * The current page's list of items.
41
- */
42
- readonly items: readonly Item[];
43
- /**
44
- * Total number of items across all pages.
45
- */
46
- readonly totalCount: number;
47
- /**
48
- * Number of items per page.
49
- */
50
- readonly pageSize: number;
51
- /**
52
- * Current page number (starting from 1).
53
- */
54
- readonly currentPage: number;
55
- /**
56
- * Total number of available pages.
57
- */
58
- readonly totalPages: number;
59
- /**
60
- * Indicates whether there is a next page.
61
- */
62
- readonly hasNextPage: boolean;
63
- /**
64
- * Indicates whether there is a previous page.
65
- */
66
- readonly hasPreviousPage: boolean;
67
- }
27
+ /**
28
+ * Common pagination information shared by paginated API results.
29
+ * Type alias for NavigablePaginationMetadata to maintain consistency.
30
+ */
31
+ export type PaginationInfo = NavigablePaginationMetadata;
32
+ /**
33
+ * Items wrapper used in paginated results.
34
+ * Extends WithItems with readonly array for API immutability.
35
+ */
36
+ export type Paginated<Item> = WithItems<Item>;
37
+ /**
38
+ * Generic structure for paginated API responses.
39
+ * Combines items with pagination metadata.
40
+ * @template Item - The type of items in the paginated result.
41
+ */
42
+ export type PaginatedResponse<Item> = Simplify<Paginated<Item> & PaginationInfo>;
68
43
  /**
69
44
  * Parameters used to control pagination in API requests.
70
45
  */
71
- export interface PaginationParameters {
72
- /**
73
- * Page number to retrieve (starting from 1).
74
- */
75
- readonly page?: number;
76
- /**
77
- * Maximum number of items per page.
78
- */
79
- readonly limit?: number;
46
+ export interface PaginationParameters extends Partial<Pageable> {
80
47
  /**
81
48
  * Optional cursor string for cursor-based pagination.
82
49
  */
@@ -1,32 +1,15 @@
1
+ import type { WithUuid, WithExpiration, WithAuthTokens } from '../common/types';
1
2
  /**
2
3
  * Represents a simplified user model.
3
4
  * @description Typically used for identification purposes within auth or session logic.
4
5
  */
5
- export interface User {
6
- /**
7
- * Universally unique identifier (UUID) for the user.
8
- * @example "f47ac10b-58cc-4372-a567-0e02b2c3d479"
9
- */
10
- readonly uuid: string;
6
+ export interface User extends WithUuid {
11
7
  }
12
8
  /**
13
9
  * AuthToken Interface.
14
10
  * @description Represents an authentication token set returned after a successful login or refresh.
15
11
  */
16
- export interface AuthToken {
17
- /**
18
- * JWT or opaque access token used for authenticating API requests.
19
- */
20
- readonly accessToken: string;
21
- /**
22
- * Token used to obtain a new access token when the current one expires.
23
- */
24
- readonly refreshToken: string;
25
- /**
26
- * ISO timestamp indicating when the access token will expire.
27
- * @example "2025-06-15T12:00:00Z"
28
- */
29
- readonly expiresAt: string;
12
+ export interface AuthToken extends WithExpiration, WithAuthTokens {
30
13
  /**
31
14
  * Token type, typically "Bearer" for OAuth2-style tokens.
32
15
  */