@plyaz/types 1.3.1 → 1.3.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plyaz/types",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "author": "Redeemer Pace",
5
5
  "license": "ISC",
6
6
  "description": "Provides shared TypeScript types and schema utilities for validation and parsing in the @playz ecosystem.",
@@ -105,7 +105,7 @@
105
105
  "scripts": {
106
106
  "build": "pnpm clean && pnpm build:js && pnpm build:types",
107
107
  "build:js": "tsup",
108
- "build:types": "tsc src/index.ts --emitDeclarationOnly --outDir dist --declaration",
108
+ "build:types": "tsc -p tsconfig.build.json",
109
109
  "build:watch": "tsup --watch",
110
110
  "dev": "tsup --watch",
111
111
  "lint": "eslint ./src",
@@ -1 +0,0 @@
1
- export type * from './types';
@@ -1,84 +0,0 @@
1
- /**
2
- * Standard structure for API responses.
3
- * @template Data - The main payload/data returned by the API.
4
- * @template Meta - Optional metadata object extending the default {@link ApiResponseMeta}.
5
- */
6
- export interface ApiResponse<Data, Meta = Record<string, string>> {
7
- /**
8
- * The core data returned by the API.
9
- */
10
- readonly data: Data;
11
- /**
12
- * Optional metadata object containing request-related information.
13
- */
14
- readonly meta?: ApiResponseMeta & Meta;
15
- }
16
- /**
17
- * Metadata included in API responses.
18
- * @description Provides useful context such as timestamps, request tracking, and API versioning.
19
- */
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
- }
34
- /**
35
- * Generic structure for paginated API responses.
36
- * @template Item - The type of items in the paginated result.
37
- */
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
- }
68
- /**
69
- * Parameters used to control pagination in API requests.
70
- */
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;
80
- /**
81
- * Optional cursor string for cursor-based pagination.
82
- */
83
- readonly cursor?: string;
84
- }
@@ -1,32 +0,0 @@
1
- /**
2
- * Enum representing the different roles a user can have within the system.
3
- * @description Roles are used to determine access levels, permissions, and user-specific experiences.
4
- */
5
- export declare const USER_ROLE: {
6
- readonly Athlete: "athlete";
7
- readonly Scout: "scout";
8
- readonly Agent: "agent";
9
- readonly Club: "club";
10
- readonly Fan: "fan";
11
- readonly Admin: "admin";
12
- readonly SuperAdmin: "super.admin";
13
- };
14
- /**
15
- * Enum representing the current status of a user account.
16
- * @description Statuses are used to determine login availability, visibility, and user flow.
17
- */
18
- export declare const USER_STATUS: {
19
- readonly Active: "active";
20
- readonly Inactive: "inactive";
21
- readonly Pending: "pending";
22
- readonly Suspended: "suspended";
23
- readonly Banned: "banned";
24
- };
25
- /**
26
- * Enum representing the supported authentication providers for user login.
27
- * @description Auth Providers allowed such as Email, Wallet, etc.
28
- */
29
- export declare const AUTH_PROVIDER: {
30
- readonly Email: "email";
31
- readonly Wallet: "wallet";
32
- };
@@ -1,3 +0,0 @@
1
- export * from './enums';
2
- export type * from './schemas';
3
- export type * from './types';
@@ -1,27 +0,0 @@
1
- import { z } from 'zod';
2
- /**
3
- * Zod schema for validating user login credentials.
4
- * @description Ensures the input object contains a valid email address and a password string.
5
- * @example
6
- * ```ts
7
- * LoginCredentialsSchema.parse({
8
- * email: "user@example.com",
9
- * password: ""
10
- * });
11
- * ```
12
- */
13
- export declare const loginCredentialsSchema: z.ZodObject<{
14
- email: z.ZodString;
15
- password: z.ZodString;
16
- }, "strip", z.ZodTypeAny, {
17
- email?: string;
18
- password?: string;
19
- }, {
20
- email?: string;
21
- password?: string;
22
- }>;
23
- /**
24
- * Type inferred from {@link loginCredentialsSchema}.
25
- * @description Represents the shape of validated login credentials input.
26
- */
27
- export type LoginCredentialsInput = z.infer<typeof loginCredentialsSchema>;
@@ -1,34 +0,0 @@
1
- /**
2
- * Represents a simplified user model.
3
- * @description Typically used for identification purposes within auth or session logic.
4
- */
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;
11
- }
12
- /**
13
- * AuthToken Interface.
14
- * @description Represents an authentication token set returned after a successful login or refresh.
15
- */
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;
30
- /**
31
- * Token type, typically "Bearer" for OAuth2-style tokens.
32
- */
33
- readonly tokenType: 'Bearer';
34
- }
@@ -1,2 +0,0 @@
1
- export type * from './types';
2
- export type * from 'type-fest';
@@ -1,22 +0,0 @@
1
- /**
2
- * A utility type used to create branded types for stronger type safety.
3
- * @description Branded types allow distinguishing between primitive types that share the same shape (e.g., two different string IDs), preventing accidental mixing of values that are technically the same base type.
4
- * @template T - The base type (e.g., `string`, `number`).
5
- * @template B - The unique brand label (typically a string literal).
6
- * @example
7
- * ```ts
8
- * type UserId = Brand<string, "UserID">;
9
- * type PostId = Brand<string, "PostID">;
10
- *
11
- * function getUser(id: UserId) { ... }
12
- * // getUser("abc") // ❌ Type error
13
- * ```
14
- */
15
- export type Brand<T, B> = T & {
16
- readonly _brand: B;
17
- };
18
- /**
19
- * Branded `string` type representing a unique identifier.
20
- * @description This is used to avoid mixing generic strings with semantically significant IDs in function arguments and data structures.
21
- */
22
- export type ID = Brand<string, 'ID'>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,33 +0,0 @@
1
- /**
2
- * Enum representing standardized error types used across the application.
3
- * @description These error types help classify different categories of errors such as validation issues and system-level failures.
4
- */
5
- export declare const ERROR_TYPE: {
6
- readonly ValidationError: "validation.error";
7
- readonly SchemaValidationError: "validation.schema.error";
8
- readonly InternalError: "system.internal.error";
9
- readonly ServiceUnavailable: "system.service.unavailable";
10
- readonly TimeoutError: "system.timeout";
11
- readonly RateLimitExceeded: "system.rate.limit.exceeded";
12
- };
13
- /**
14
- * Enum representing the severity level of an error.
15
- * @description This allows categorization of errors by their potential impact on the system or user.
16
- */
17
- export declare const ERROR_SEVERITY: {
18
- readonly Low: "low";
19
- readonly Medium: "medium";
20
- readonly High: "high";
21
- readonly Critical: "critical";
22
- };
23
- /**
24
- * Enum representing the category or origin of an error.
25
- * @description Useful for filtering or logging errors based on their source or nature.
26
- */
27
- export declare const ERROR_CATEGORY: {
28
- readonly Client: "client";
29
- readonly Server: "server";
30
- readonly Network: "network";
31
- readonly Blockchain: "blockchain";
32
- readonly Validation: "validation";
33
- };
@@ -1,2 +0,0 @@
1
- export * from './enums';
2
- export type * from './types';
@@ -1,79 +0,0 @@
1
- /**
2
- * Represents the structure of an error response returned by the application.
3
- * @template ErrorDetails - The type of the `errors` array, defaults to `ErrorDetailsList`.
4
- */
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;
18
- /**
19
- * Array of detailed errors, typically used for validation failures.
20
- */
21
- 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
- }
31
- /**
32
- * Additional context information about a validation error.
33
- * @template ValueGiven - Type of the value that caused the error.
34
- * @template AllowedValues - Type of acceptable values for the field.
35
- * @template Constraints - Type of any validation constraints.
36
- */
37
- export interface ErrorDetailContext<ValueGiven, AllowedValues, Constraints> {
38
- /**
39
- * The value that was provided and caused the error.
40
- */
41
- readonly valueGiven?: ValueGiven;
42
- /**
43
- * Acceptable values for the field, if applicable.
44
- */
45
- readonly allowedValues?: AllowedValues;
46
- /**
47
- * Validation constraints that were violated (e.g., min/max, regex).
48
- */
49
- readonly constraints?: Constraints;
50
- }
51
- /**
52
- * Represents a specific validation or business logic error related to a particular field.
53
- * @template ValueGiven - Type of the value that caused the error.
54
- * @template AllowedValues - Type of acceptable values for the field.
55
- * @template Constraints - Type of any validation constraints.
56
- */
57
- export interface ErrorDetail<ValueGiven, AllowedValues, Constraints> {
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
- }
75
- /**
76
- * Error Details Array.
77
- * @description A flexible list of error details that can contain string, number, or boolean values along with structured allowed values and constraints.
78
- */
79
- export type ErrorDetailsList = readonly ErrorDetail<string | number | boolean, Record<string, string>, Record<string, string>>[];
@@ -1,25 +0,0 @@
1
- /**
2
- * Enum representing the types of events in the application.
3
- */
4
- export declare const EVENT_TYPE: {
5
- readonly AppInit: "app.init";
6
- };
7
- /**
8
- * Const representing the priority levels for events.
9
- */
10
- export declare const EVENT_PRIORITY: {
11
- readonly Low: "low";
12
- readonly Normal: "normal";
13
- readonly High: "high";
14
- readonly Critical: "critical";
15
- };
16
- /**
17
- * Const representing the status of an event.
18
- */
19
- export declare const EVENT_STATUS: {
20
- readonly Pending: "pending";
21
- readonly Processing: "processing";
22
- readonly Completed: "completed";
23
- readonly Failed: "failed";
24
- readonly Retrying: "retrying";
25
- };
@@ -1,3 +0,0 @@
1
- export * from './enums';
2
- export type * from './payload';
3
- export type * from './types';
@@ -1,6 +0,0 @@
1
- /**
2
- * User Payloads.
3
- */
4
- export interface UserUpdatePayload {
5
- readonly uuid: string;
6
- }
@@ -1,136 +0,0 @@
1
- import type { EVENT_PRIORITY, EVENT_STATUS, EVENT_TYPE } from './enums';
2
- /**
3
- * Event Details.
4
- * @description Represents a typed event published and consumed via the event bus.
5
- * @template T - The payload type carried by the event.
6
- */
7
- export interface Event<T> {
8
- /**
9
- * Unique identifier for the event instance.
10
- */
11
- readonly id: string;
12
- /**
13
- * Type of the event, used to categorize behavior.
14
- */
15
- readonly type: typeof EVENT_TYPE;
16
- /**
17
- * Topic used for event routing and subscription.
18
- */
19
- 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
- }
53
- /**
54
- * Additional contextual data for an event.
55
- * @description This is often populated with session/user data and retry tracking.
56
- */
57
- export interface EventMetadata {
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;
82
- /**
83
- * Additional metadata as key-value pairs.
84
- */
85
- readonly [key: string]: unknown;
86
- }
87
- /**
88
- * Event Handler.
89
- * @description A handler function that processes an event of type `T`.
90
- * @template T - The event payload type.
91
- */
92
- export type EventHandler<T = unknown> = (event: Event<T>) => void | Promise<void>;
93
- /**
94
- * Represents a subscription to a specific topic on the event bus.
95
- */
96
- export interface Subscription {
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;
105
- /**
106
- * Handler function to invoke when an event is published on the topic.
107
- */
108
- readonly handler: EventHandler;
109
- /**
110
- * Function to cancel the subscription.
111
- */
112
- readonly unsubscribe: () => void;
113
- }
114
- /**
115
- * Interface for a publish-subscribe event bus system.
116
- * @description Allows services to publish events and listen to specific topics.
117
- */
118
- export interface EventBus {
119
- /**
120
- * Publishes an event to all subscribed handlers for its topic.
121
- * @param event - The event object to publish.
122
- */
123
- readonly publish: <T>(event: Event<T>) => Promise<void>;
124
- /**
125
- * Subscribes a handler function to a specific topic.
126
- * @param topic - The topic to subscribe to.
127
- * @param handler - The function to call when events are published to the topic.
128
- * @returns A `Subscription` object for managing the listener.
129
- */
130
- readonly subscribe: <T>(topic: string, handler: EventHandler<T>) => Subscription;
131
- /**
132
- * Unsubscribes a handler by its subscription ID.
133
- * @param subscriptionId - The unique ID of the subscription to remove.
134
- */
135
- readonly unsubscribe: (subscriptionId: string) => void;
136
- }
@@ -1 +0,0 @@
1
- export type * from './types';
@@ -1,142 +0,0 @@
1
- /**
2
- * Cache Types and Interfaces
3
- *
4
- * Type definitions for the caching layer.
5
- * This will be moved to @plyaz/core when the package structure is finalized.
6
- *
7
- * @fileoverview Cache type definitions
8
- * @version 1.0.0
9
- */
10
- /**
11
- * Cache entry structure that wraps cached data with metadata.
12
- */
13
- export interface CacheEntry<T = unknown> {
14
- /** The cached data */
15
- 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
- }
23
- /**
24
- * Cache statistics for monitoring and debugging.
25
- */
26
- export interface CacheStats {
27
- /** Total number of cache hits */
28
- hits: number;
29
- /** Total number of cache misses */
30
- misses: number;
31
- /** Total number of set operations */
32
- sets: number;
33
- /** Total number of delete operations */
34
- deletes: number;
35
- /** Number of entries currently in cache */
36
- size: number;
37
- /** Cache hit ratio (hits / (hits + misses)) */
38
- hitRatio?: number;
39
- }
40
- /**
41
- * Configuration for cache strategies.
42
- */
43
- export interface CacheConfig {
44
- /** Whether caching is enabled */
45
- isEnabled: boolean;
46
- /** Default TTL in seconds */
47
- ttl: number;
48
- /** Cache strategy to use */
49
- strategy: 'memory' | 'redis';
50
- /** Redis-specific configuration */
51
- redisConfig?: RedisCacheConfig;
52
- /** 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
- };
61
- }
62
- /**
63
- * Configuration for memory cache strategy.
64
- */
65
- export interface MemoryCacheConfig {
66
- /** Maximum number of entries to store (default: 1000) */
67
- maxSize?: number;
68
- /** Maximum number of entries to store (alias for maxSize) */
69
- maxEntries?: number;
70
- /** Check for expired entries every N milliseconds (default: 60000) */
71
- cleanupInterval?: number;
72
- /** Callback when entry is evicted */
73
- onEvict?: (key: string, entry: CacheEntry) => void;
74
- }
75
- /**
76
- * Configuration for Redis cache strategy.
77
- */
78
- export interface RedisCacheConfig {
79
- /** Redis connection URL */
80
- url: string;
81
- /** Redis password for authentication */
82
- password?: string;
83
- /** Redis database number */
84
- db?: number;
85
- /** Key prefix for Redis keys */
86
- keyPrefix?: string;
87
- /** Connection timeout in milliseconds */
88
- connectTimeout?: number;
89
- /** Command timeout in milliseconds */
90
- commandTimeout?: number;
91
- }
92
- /**
93
- * Cache manager statistics interface.
94
- */
95
- export interface CacheManagerStats extends CacheStats {
96
- }
97
- /**
98
- * Interface that all cache strategies must implement.
99
- */
100
- export interface CacheStrategy {
101
- /**
102
- * Stores a cache entry.
103
- *
104
- * @param key - Cache key
105
- * @param entry - Cache entry to store
106
- * @returns Promise that resolves when entry is stored
107
- */
108
- set<T>(key: string, entry: CacheEntry<T>): Promise<void>;
109
- /**
110
- * Retrieves a cache entry.
111
- *
112
- * @param key - Cache key
113
- * @returns Promise that resolves to cache entry or null if not found
114
- */
115
- get<T>(key: string): Promise<CacheEntry<T> | null>;
116
- /**
117
- * Removes a cache entry.
118
- *
119
- * @param key - Cache key to remove
120
- * @returns Promise that resolves when entry is removed
121
- */
122
- delete(key: string): Promise<void>;
123
- /**
124
- * Clears all cache entries.
125
- *
126
- * @returns Promise that resolves when cache is cleared
127
- */
128
- clear(): Promise<void>;
129
- /**
130
- * Gets cache statistics.
131
- *
132
- * @returns Promise that resolves to cache statistics
133
- */
134
- getStats(): Promise<CacheStats>;
135
- /**
136
- * Disposes of the cache strategy and cleans up resources.
137
- * Optional method for cleanup.
138
- *
139
- * @returns Promise that resolves when cleanup is complete
140
- */
141
- dispose?(): Promise<void>;
142
- }
@@ -1 +0,0 @@
1
- export type * from './types';