@qlover/fe-corekit 1.2.10 → 1.3.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/index.d.ts CHANGED
@@ -542,409 +542,6 @@ declare abstract class Executor<ExecutorConfig = unknown> {
542
542
  abstract execNoError<Result, Params = unknown>(data: unknown, task: Task<Result, Params>): Promise<Result | ExecutorError> | Result | ExecutorError;
543
543
  }
544
544
 
545
- /**
546
- * Request adapter configuration
547
- *
548
- * This type defines the configuration options for a request adapter.
549
- * It includes properties for URL, method, headers, and other request details.
550
- * The main purpose is to provide a flexible structure for configuring HTTP requests.
551
- *
552
- * @since 1.0.14
553
- */
554
- interface RequestAdapterConfig<RequestData = unknown> {
555
- /**
556
- * Request URL path
557
- * Will be combined with baseURL if provided
558
- *
559
- * Processed by FetchURLPlugin during request
560
- *
561
- * @todo Change to URL | Request, add attribute `input`
562
- * @example
563
- * ```typescript
564
- * url: '/users/1'
565
- * ```
566
- */
567
- url?: string;
568
- /**
569
- * HTTP request methods supported by the executor
570
- * Follows standard HTTP method definitions
571
- *
572
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
573
- * @example
574
- * ```typescript
575
- * method: 'GET'
576
- * ```
577
- */
578
- method?: string;
579
- /**
580
- * Base URL for all requests
581
- * Will be prepended to the request URL
582
- *
583
- * @example
584
- * ```typescript
585
- * baseURL: 'https://api.example.com'
586
- * // url = /users/1 => https://api.example.com/users/1
587
- * // url = users/1 => https://api.example.com/users/1
588
- * ```
589
- */
590
- baseURL?: string;
591
- /**
592
- * Request body data
593
- *
594
- * Mapping fetch `body`
595
- *
596
- * @typeParam RequestData - The type of the request body data.
597
- * @example
598
- * ```typescript
599
- * data: { name: 'John Doe' }
600
- * ```
601
- */
602
- data?: RequestData;
603
- /**
604
- * URL query parameters
605
- * Will be serialized and appended to the URL
606
- *
607
- * @example
608
- * ```typescript
609
- * params: { search: 'query' }
610
- * ```
611
- */
612
- params?: Record<string, unknown>;
613
- /**
614
- * Request headers
615
- *
616
- * @example
617
- * ```typescript
618
- * headers: { 'Content-Type': 'application/json' }
619
- * ```
620
- */
621
- headers?: {
622
- [key: string]: unknown;
623
- };
624
- /**
625
- * Response type
626
- *
627
- * Specifies the type of data that the server will respond with.
628
- *
629
- * @example
630
- * ```typescript
631
- * responseType: 'json'
632
- * ```
633
- */
634
- responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream' | 'formdata';
635
- /**
636
- * Request ID, used to identify the request in the abort plugin.
637
- */
638
- requestId?: string;
639
- [key: string]: any;
640
- }
641
- /**
642
- * Request adapter response
643
- *
644
- * This type defines the structure of a response from a request adapter.
645
- * It includes the response data, status, headers, and the original request configuration.
646
- *
647
- * @typeParam Req - The type of the request data.
648
- * @typeParam Res - The type of the response data.
649
- */
650
- interface RequestAdapterResponse<Req = unknown, Res = unknown> {
651
- data: Res;
652
- status: number;
653
- statusText: string;
654
- headers: {
655
- [key: string]: unknown;
656
- };
657
- config: RequestAdapterConfig<Req>;
658
- response: Response;
659
- [key: string]: unknown;
660
- }
661
- /**
662
- * Request adapter interface
663
- *
664
- * This interface defines the contract for request adapters.
665
- * Adapters are responsible for handling the specific details of a request,
666
- * such as URL construction, headers, and response handling.
667
- *
668
- */
669
- interface RequestAdapterInterface<Config extends RequestAdapterConfig> {
670
- /**
671
- * The configuration for the request adapter.
672
- *
673
- * @type {Config}
674
- */
675
- readonly config: Config;
676
- /**
677
- * Sends a request using the specified options and returns a promise with the response.
678
- *
679
- * @typeParam Request - The type of the request data.
680
- * @typeParam Response - The type of the response data.
681
- * @param options - The configuration options for the request.
682
- * @returns A promise that resolves to the response of the request.
683
- * @example
684
- * ```typescript
685
- * adapter.request({ url: '/users', method: 'GET' }).then(response => console.log(response));
686
- * ```
687
- */
688
- request<Request, Response>(options: RequestAdapterConfig<Request>): Promise<RequestAdapterResponse<Request, Response>>;
689
- /**
690
- * Retrieves the current configuration of the request adapter.
691
- *
692
- * @returns The current configuration.
693
- * @example
694
- * ```typescript
695
- * const config = adapter.getConfig();
696
- * ```
697
- */
698
- getConfig: () => Config;
699
- }
700
-
701
- /**
702
- * Represents a custom error class for handling request-related errors in the application
703
- *
704
- * RequestError extends the base ExecutorError class to provide specific error handling
705
- * for HTTP requests and fetch operations. It works in conjunction with RequestErrorID
706
- * to categorize different types of request failures.
707
- *
708
- * @since 1.0.14
709
- *
710
- * @example
711
- * ```typescript
712
- * try {
713
- * await fetchData(url);
714
- * } catch (error) {
715
- * if (error instanceof RequestError) {
716
- * // Handle request specific error
717
- * console.error('Request failed:', error.message);
718
- * }
719
- * }
720
- * ```
721
- */
722
- declare class RequestError extends ExecutorError {
723
- }
724
- /**
725
- * Error IDs for different fetch request failure scenarios
726
- * Used to identify specific error types in error handling
727
- *
728
- * @description
729
- * This enum provides a standardized set of error identifiers that can be used
730
- * to categorize and handle different types of request failures in a consistent manner.
731
- * Each error ID represents a specific failure scenario that might occur during HTTP requests.
732
- *
733
- * @example
734
- * ```typescript
735
- * if (error.id === RequestErrorID.RESPONSE_NOT_OK) {
736
- * // Handle non-200 response
737
- * } else if (error.id === RequestErrorID.ABORT_ERROR) {
738
- * // Handle aborted request
739
- * }
740
- * ```
741
- */
742
- declare enum RequestErrorID {
743
- /** Generic fetch request error */
744
- REQUEST_ERROR = "REQUEST_ERROR",
745
- /** Environment doesn't support fetch API */
746
- ENV_FETCH_NOT_SUPPORT = "ENV_FETCH_NOT_SUPPORT",
747
- /** No fetcher function provided */
748
- FETCHER_NONE = "FETCHER_NONE",
749
- /** Response status is not OK (not in 200-299 range) */
750
- RESPONSE_NOT_OK = "RESPONSE_NOT_OK",
751
- /** Request was aborted */
752
- ABORT_ERROR = "ABORT_ERROR",
753
- /** URL is not provided */
754
- URL_NONE = "URL_NONE"
755
- }
756
-
757
- /**
758
- * Represents a transaction for a request.
759
- *
760
- * This interface defines a transaction that contains a request and a response.
761
- * It can be used to track the request and response of a transaction.
762
- *
763
- * @since 1.2.2
764
- */
765
- interface RequestTransactionInterface<Request, Response> {
766
- /**
767
- * The request object
768
- */
769
- request: Request;
770
- /**
771
- * The response object
772
- */
773
- response: Response;
774
- }
775
-
776
- /**
777
- * Generic interface for data serialization/deserialization operations
778
- * Provides a standard contract for implementing serialization strategies
779
- *
780
- * This is a generic interface, you can implement it with different serialization strategies
781
- *
782
- * @template T - Type of data to serialize/deserialize, defaults to any
783
- * @template R - Type of serialized result, defaults to string
784
- *
785
- * @since 1.0.10
786
- *
787
- * @example
788
- * ```typescript
789
- * // JSON serialization implementation
790
- * class JSONSerializer implements Serializer {
791
- * serialize(data: any): string {
792
- * return JSON.stringify(data);
793
- * }
794
- *
795
- * deserialize(data: string): any {
796
- * return JSON.parse(data);
797
- * }
798
- * }
799
- * ```
800
- */
801
- interface Serializer<T = unknown, R = string> {
802
- /**
803
- * Serializes data into a target format
804
- * @since 1.0.10
805
- * @param data - Data to serialize
806
- * @returns Serialized representation
807
- */
808
- serialize(data: T): R;
809
- /**
810
- * Deserializes data from target format back to original form
811
- * @since 1.0.10
812
- * @param data - Data to deserialize
813
- * @param defaultValue - Optional default value to return if deserialization fails
814
- * @returns Original data structure
815
- */
816
- deserialize(data: R, defaultValue?: T): T;
817
- }
818
-
819
- /**
820
- * Interface representing a synchronous storage mechanism.
821
- *
822
- * @template Key - The type of keys used to identify stored values.
823
- * @template ValueType - The type of values stored, defaults to unknown.
824
- *
825
- * @example
826
- * ```typescript
827
- * const storage: SyncStorage<string, number> = ...;
828
- * storage.setItem('key', 123);
829
- * const value = storage.getItem('key', 0);
830
- * ```
831
- */
832
- interface SyncStorage<Key, ValueType = unknown> {
833
- /**
834
- * The number of items stored.
835
- */
836
- readonly length: number;
837
- /**
838
- * Stores a value with the specified key.
839
- *
840
- * @param key - The key to identify the stored value.
841
- * @param value - The value to store.
842
- * @param options - Optional parameters for storage.
843
- */
844
- setItem<T>(key: Key, value: T, options?: unknown): void;
845
- /**
846
- * Retrieves a value by key.
847
- *
848
- * @param key - The key of the value to retrieve.
849
- * @param defaultValue - The default value to return if the key is not found.
850
- * @param options - Optional parameters for retrieval.
851
- * @returns The value associated with the key, or the default value if not found.
852
- */
853
- getItem<T extends ValueType>(key: Key, defaultValue?: T, options?: unknown): T | null;
854
- /**
855
- * Removes a value by key.
856
- *
857
- * @param key - The key of the value to remove.
858
- * @param options - Optional parameters for removal.
859
- */
860
- removeItem(key: Key, options?: unknown): void;
861
- /**
862
- * Clears all stored values.
863
- */
864
- clear(): void;
865
- }
866
- /**
867
- * Interface representing an asynchronous storage mechanism.
868
- *
869
- * @template Key - The type of keys used to identify stored values.
870
- * @template ValueType - The type of values stored, defaults to unknown.
871
- *
872
- * @example
873
- *
874
- * ```typescript
875
- * const storage: AsyncStorage<string, number> = ...;
876
- * await storage.setItem('key', 123);
877
- * const value = await storage.getItem('key', 0);
878
- * ```
879
- *
880
- */
881
- interface AsyncStorage<Key, ValueType = unknown> {
882
- /**
883
- * The number of items stored.
884
- */
885
- readonly length: number;
886
- /**
887
- * Asynchronously stores a value with the specified key.
888
- *
889
- * @param key - The key to identify the stored value.
890
- * @param value - The value to store.
891
- * @param options - Optional parameters for storage.
892
- * @returns A promise that resolves when the value is stored.
893
- */
894
- setItem<T>(key: Key, value: T, options?: unknown): Promise<void>;
895
- /**
896
- * Asynchronously retrieves a value by key.
897
- *
898
- * @param key - The key of the value to retrieve.
899
- * @param defaultValue - The default value to return if the key is not found.
900
- * @param options - Optional parameters for retrieval.
901
- * @returns A promise that resolves to the value associated with the key, or the default value if not found.
902
- */
903
- getItem<T extends ValueType>(key: Key, defaultValue?: T, options?: unknown): Promise<T | null>;
904
- /**
905
- * Asynchronously removes a value by key.
906
- *
907
- * @param key - The key of the value to remove.
908
- * @param options - Optional parameters for removal.
909
- * @returns A promise that resolves when the value is removed.
910
- */
911
- removeItem(key: Key, options?: unknown): Promise<void>;
912
- /**
913
- * Asynchronously clears all stored values.
914
- *
915
- * @returns A promise that resolves when all values are cleared.
916
- */
917
- clear(): Promise<void>;
918
- }
919
-
920
- /**
921
- * Get the value type of an object
922
- *
923
- * @since 1.0.14
924
- *
925
- * @example
926
- * ```ts
927
- * type T = { a: number; b: string };
928
- * type V = ValueOf<T>; // V is number | string
929
- * ```
930
- */
931
- type ValueOf<T> = T[keyof T];
932
- /**
933
- * Get the intersection type of two types
934
- *
935
- * @since 1.0.14
936
- *
937
- * @example
938
- * ```ts
939
- * type T1 = { a: number; b: string };
940
- * type T2 = { a: number; c: boolean };
941
- * type I = Intersection<T1, T2>; // I is { a: number }
942
- * ```
943
- */
944
- type Intersection<T1, T2> = {
945
- [P in keyof T1 & keyof T2]: T1[P] | T2[P];
946
- };
947
-
948
545
  /**
949
546
  * Asynchronous implementation of the Executor pattern
950
547
  *
@@ -1496,202 +1093,234 @@ declare class RetryPlugin implements ExecutorPlugin {
1496
1093
  }
1497
1094
 
1498
1095
  /**
1499
- * Available log levels
1500
- * Used to categorize and control log output
1501
- */
1502
- declare const LEVELS: {
1503
- readonly LOG: "LOG";
1504
- readonly INFO: "INFO";
1505
- readonly ERROR: "ERROR";
1506
- readonly WARN: "WARN";
1507
- readonly DEBUG: "DEBUG";
1508
- };
1509
- type LogLevel = (typeof LEVELS)[keyof typeof LEVELS];
1510
- type LogArgument = unknown;
1511
- /**
1512
- * Options for execution logging
1513
- * @interface ExecOptions
1514
- */
1515
- type ExecOptions = {
1516
- /** When true, commands are only logged but not executed */
1517
- isDryRun?: boolean;
1518
- /** When true, indicates the command is from an external source */
1519
- isExternal?: boolean;
1520
- };
1521
- /**
1522
- * Logger class providing various logging methods
1523
- *
1524
- * The Logger class supports multiple log levels and can be configured
1525
- * to operate in different environments such as CI, dry run, debug, and silent modes.
1526
- *
1527
- * - Core Idea: Provide a flexible and configurable logging utility.
1528
- * - Main Function: Log messages at different levels with optional environment-specific behavior.
1529
- * - Main Purpose: Facilitate debugging and monitoring by providing structured log output.
1096
+ * Request adapter configuration
1530
1097
  *
1531
- * @class Logger
1532
- * @example
1533
- * ```typescript
1534
- * // Create a logger instance
1535
- * const logger = new Logger({ debug: true });
1098
+ * This type defines the configuration options for a request adapter.
1099
+ * It includes properties for URL, method, headers, and other request details.
1100
+ * The main purpose is to provide a flexible structure for configuring HTTP requests.
1536
1101
  *
1537
- * // Log messages at different levels
1538
- * logger.info('This is an info message');
1539
- * logger.error('This is an error message');
1540
- * logger.debug('This is a debug message');
1541
- * ```
1102
+ * @since 1.0.14
1542
1103
  */
1543
- declare class Logger {
1544
- protected isCI: boolean;
1545
- protected isDryRun: boolean;
1546
- protected isDebug: boolean;
1547
- protected isSilent: boolean;
1104
+ interface RequestAdapterConfig<RequestData = unknown> {
1548
1105
  /**
1549
- * Creates a new Logger instance
1550
- *
1551
- * This constructor initializes the Logger with configuration options
1552
- * that determine its behavior in different environments.
1106
+ * Request URL path
1107
+ * Will be combined with baseURL if provided
1553
1108
  *
1554
- * @param options - Logger configuration options
1555
- * @param {boolean} options.isCI - Whether running in CI environment
1556
- * @param {boolean} options.dryRun - Whether to perform dry run only
1557
- * @param {boolean} options.debug - Whether to enable debug output
1558
- * @param {boolean} options.silent - Whether to suppress all output
1109
+ * Processed by FetchURLPlugin during request
1559
1110
  *
1111
+ * @todo Change to URL | Request, add attribute `input`
1560
1112
  * @example
1561
1113
  * ```typescript
1562
- * const logger = new Logger({ isCI: true, debug: true });
1114
+ * url: '/users/1'
1563
1115
  * ```
1564
1116
  */
1565
- constructor({ isCI, dryRun, debug, silent }?: {
1566
- isCI?: boolean | undefined;
1567
- dryRun?: boolean | undefined;
1568
- debug?: boolean | undefined;
1569
- silent?: boolean | undefined;
1570
- });
1117
+ url?: string;
1571
1118
  /**
1572
- * Core logging method
1573
- * Handles actual console output based on configuration
1574
- *
1575
- * @param level - Log level for the message
1576
- * @param args - Arguments to log
1119
+ * HTTP request methods supported by the executor
1120
+ * Follows standard HTTP method definitions
1577
1121
  *
1122
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
1578
1123
  * @example
1579
1124
  * ```typescript
1580
- * this.print(LEVELS.INFO, 'Information message');
1125
+ * method: 'GET'
1581
1126
  * ```
1582
1127
  */
1583
- protected print(_level: LogLevel, ...args: LogArgument[]): void;
1128
+ method?: string;
1584
1129
  /**
1585
- * Adds prefix to log messages
1586
- * Can be overridden to customize log format
1587
- *
1588
- * @param value - The prefix value
1589
- * @param _level - Log level (optional)
1590
- * @returns Formatted prefix string or array
1130
+ * Base URL for all requests
1131
+ * Will be prepended to the request URL
1591
1132
  *
1592
1133
  * @example
1593
1134
  * ```typescript
1594
- * const prefix = this.prefix('INFO');
1135
+ * baseURL: 'https://api.example.com'
1136
+ * // url = /users/1 => https://api.example.com/users/1
1137
+ * // url = users/1 => https://api.example.com/users/1
1595
1138
  * ```
1596
1139
  */
1597
- prefix(value: string, _level?: LogLevel): string | string[];
1140
+ baseURL?: string;
1598
1141
  /**
1599
- * Basic log output
1142
+ * Request body data
1600
1143
  *
1601
- * @param args - Values to log
1144
+ * Mapping fetch `body`
1602
1145
  *
1146
+ * @typeParam RequestData - The type of the request body data.
1603
1147
  * @example
1604
1148
  * ```typescript
1605
- * logger.log('This is a log message');
1149
+ * data: { name: 'John Doe' }
1606
1150
  * ```
1607
1151
  */
1608
- log(...args: LogArgument[]): void;
1152
+ data?: RequestData;
1609
1153
  /**
1610
- * Informational log output
1611
- *
1612
- * @param args - Values to log
1154
+ * URL query parameters
1155
+ * Will be serialized and appended to the URL
1613
1156
  *
1614
1157
  * @example
1615
1158
  * ```typescript
1616
- * logger.info('This is an info message');
1159
+ * params: { search: 'query' }
1617
1160
  * ```
1618
1161
  */
1619
- info(...args: LogArgument[]): void;
1162
+ params?: Record<string, unknown>;
1620
1163
  /**
1621
- * Warning log output
1622
- *
1623
- * @param args - Values to log
1164
+ * Request headers
1624
1165
  *
1625
1166
  * @example
1626
1167
  * ```typescript
1627
- * logger.warn('This is a warning message');
1168
+ * headers: { 'Content-Type': 'application/json' }
1628
1169
  * ```
1629
1170
  */
1630
- warn(...args: LogArgument[]): void;
1171
+ headers?: {
1172
+ [key: string]: unknown;
1173
+ };
1631
1174
  /**
1632
- * Error log output
1175
+ * Response type
1633
1176
  *
1634
- * @param args - Values to log
1177
+ * Specifies the type of data that the server will respond with.
1635
1178
  *
1636
1179
  * @example
1637
1180
  * ```typescript
1638
- * logger.error('This is an error message');
1181
+ * responseType: 'json'
1639
1182
  * ```
1640
1183
  */
1641
- error(...args: LogArgument[]): void;
1184
+ responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream' | 'formdata';
1642
1185
  /**
1643
- * Debug log output
1644
- *
1645
- * - Only active when debug mode is enabled
1646
- * - Formats objects as JSON strings
1647
- *
1648
- * @param args - Values to log
1649
- *
1650
- * @example
1651
- * ```typescript
1652
- * logger.debug('This is a debug message');
1653
- * ```
1186
+ * Request ID, used to identify the request in the abort plugin.
1654
1187
  */
1655
- debug(...args: LogArgument[]): void;
1188
+ requestId?: string;
1189
+ [key: string]: any;
1190
+ }
1191
+ /**
1192
+ * Request adapter response
1193
+ *
1194
+ * This type defines the structure of a response from a request adapter.
1195
+ * It includes the response data, status, headers, and the original request configuration.
1196
+ *
1197
+ * @typeParam Req - The type of the request data.
1198
+ * @typeParam Res - The type of the response data.
1199
+ */
1200
+ interface RequestAdapterResponse<Req = unknown, Res = unknown> {
1201
+ data: Res;
1202
+ status: number;
1203
+ statusText: string;
1204
+ headers: {
1205
+ [key: string]: unknown;
1206
+ };
1207
+ config: RequestAdapterConfig<Req>;
1208
+ response: Response;
1209
+ [key: string]: unknown;
1210
+ }
1211
+ /**
1212
+ * Request adapter interface
1213
+ *
1214
+ * This interface defines the contract for request adapters.
1215
+ * Adapters are responsible for handling the specific details of a request,
1216
+ * such as URL construction, headers, and response handling.
1217
+ *
1218
+ */
1219
+ interface RequestAdapterInterface<Config extends RequestAdapterConfig> {
1656
1220
  /**
1657
- * Verbose log output
1658
- *
1659
- * - Only active when debug mode is enabled
1660
- * - Uses purple color for output
1661
- *
1662
- * @param args - Values to log
1221
+ * The configuration for the request adapter.
1663
1222
  *
1664
- * @example
1665
- * ```typescript
1666
- * logger.verbose('This is a verbose message');
1667
- * ```
1223
+ * @type {Config}
1668
1224
  */
1669
- verbose(...args: LogArgument[]): void;
1225
+ readonly config: Config;
1670
1226
  /**
1671
- * Command execution logging
1672
- * Supports dry run mode and external command indication
1673
- *
1674
- * @param args - Command arguments and options
1227
+ * Sends a request using the specified options and returns a promise with the response.
1675
1228
  *
1229
+ * @typeParam Request - The type of the request data.
1230
+ * @typeParam Response - The type of the response data.
1231
+ * @param options - The configuration options for the request.
1232
+ * @returns A promise that resolves to the response of the request.
1676
1233
  * @example
1677
1234
  * ```typescript
1678
- * logger.exec('npm', 'install', { isDryRun: true });
1679
- * logger.exec(['git', 'commit', '-m', 'feat: update'], { isExternal: true });
1235
+ * adapter.request({ url: '/users', method: 'GET' }).then(response => console.log(response));
1680
1236
  * ```
1681
1237
  */
1682
- exec(...args: (LogArgument | ExecOptions)[]): void;
1238
+ request<Request, Response>(options: RequestAdapterConfig<Request>): Promise<RequestAdapterResponse<Request, Response>>;
1683
1239
  /**
1684
- * Obtrusive log output
1685
- * Adds extra line breaks in non-CI environments
1686
- *
1687
- * @param args - Values to log
1240
+ * Retrieves the current configuration of the request adapter.
1688
1241
  *
1242
+ * @returns The current configuration.
1689
1243
  * @example
1690
1244
  * ```typescript
1691
- * logger.obtrusive('This is an important message');
1245
+ * const config = adapter.getConfig();
1692
1246
  * ```
1693
1247
  */
1694
- obtrusive(...args: LogArgument[]): void;
1248
+ getConfig: () => Config;
1249
+ }
1250
+
1251
+ /**
1252
+ * Represents a custom error class for handling request-related errors in the application
1253
+ *
1254
+ * RequestError extends the base ExecutorError class to provide specific error handling
1255
+ * for HTTP requests and fetch operations. It works in conjunction with RequestErrorID
1256
+ * to categorize different types of request failures.
1257
+ *
1258
+ * @since 1.0.14
1259
+ *
1260
+ * @example
1261
+ * ```typescript
1262
+ * try {
1263
+ * await fetchData(url);
1264
+ * } catch (error) {
1265
+ * if (error instanceof RequestError) {
1266
+ * // Handle request specific error
1267
+ * console.error('Request failed:', error.message);
1268
+ * }
1269
+ * }
1270
+ * ```
1271
+ */
1272
+ declare class RequestError extends ExecutorError {
1273
+ }
1274
+ /**
1275
+ * Error IDs for different fetch request failure scenarios
1276
+ * Used to identify specific error types in error handling
1277
+ *
1278
+ * @description
1279
+ * This enum provides a standardized set of error identifiers that can be used
1280
+ * to categorize and handle different types of request failures in a consistent manner.
1281
+ * Each error ID represents a specific failure scenario that might occur during HTTP requests.
1282
+ *
1283
+ * @example
1284
+ * ```typescript
1285
+ * if (error.id === RequestErrorID.RESPONSE_NOT_OK) {
1286
+ * // Handle non-200 response
1287
+ * } else if (error.id === RequestErrorID.ABORT_ERROR) {
1288
+ * // Handle aborted request
1289
+ * }
1290
+ * ```
1291
+ */
1292
+ declare enum RequestErrorID {
1293
+ /** Generic fetch request error */
1294
+ REQUEST_ERROR = "REQUEST_ERROR",
1295
+ /** Environment doesn't support fetch API */
1296
+ ENV_FETCH_NOT_SUPPORT = "ENV_FETCH_NOT_SUPPORT",
1297
+ /** No fetcher function provided */
1298
+ FETCHER_NONE = "FETCHER_NONE",
1299
+ /** Response status is not OK (not in 200-299 range) */
1300
+ RESPONSE_NOT_OK = "RESPONSE_NOT_OK",
1301
+ /** Request was aborted */
1302
+ ABORT_ERROR = "ABORT_ERROR",
1303
+ /** URL is not provided */
1304
+ URL_NONE = "URL_NONE"
1305
+ }
1306
+
1307
+ /**
1308
+ * Represents a transaction for a request.
1309
+ *
1310
+ * This interface defines a transaction that contains a request and a response.
1311
+ * It can be used to track the request and response of a transaction.
1312
+ *
1313
+ * @since 1.2.2
1314
+ */
1315
+ interface RequestTransactionInterface<Request, Response> {
1316
+ /**
1317
+ * The request object
1318
+ */
1319
+ request: Request;
1320
+ /**
1321
+ * The response object
1322
+ */
1323
+ response: Response;
1695
1324
  }
1696
1325
 
1697
1326
  /**
@@ -2455,6 +2084,49 @@ declare class RequestTransaction<Config extends RequestAdapterConfig<unknown>> e
2455
2084
  patch<Transaction = unknown>(url: string, data?: Transaction extends RequestTransactionInterface<Config, unknown> ? Transaction['request']['data'] : Config['data'], config?: Omit<Config, 'url' | 'method' | 'data'>): Promise<Transaction extends RequestTransactionInterface<Config, unknown> ? Transaction['response'] : RequestAdapterResponse<unknown, Transaction>>;
2456
2085
  }
2457
2086
 
2087
+ /**
2088
+ * Generic interface for data serialization/deserialization operations
2089
+ * Provides a standard contract for implementing serialization strategies
2090
+ *
2091
+ * This is a generic interface, you can implement it with different serialization strategies
2092
+ *
2093
+ * @template T - Type of data to serialize/deserialize, defaults to any
2094
+ * @template R - Type of serialized result, defaults to string
2095
+ *
2096
+ * @since 1.0.10
2097
+ *
2098
+ * @example
2099
+ * ```typescript
2100
+ * // JSON serialization implementation
2101
+ * class JSONSerializer implements Serializer {
2102
+ * serialize(data: any): string {
2103
+ * return JSON.stringify(data);
2104
+ * }
2105
+ *
2106
+ * deserialize(data: string): any {
2107
+ * return JSON.parse(data);
2108
+ * }
2109
+ * }
2110
+ * ```
2111
+ */
2112
+ interface Serializer<T = unknown, R = string> {
2113
+ /**
2114
+ * Serializes data into a target format
2115
+ * @since 1.0.10
2116
+ * @param data - Data to serialize
2117
+ * @returns Serialized representation
2118
+ */
2119
+ serialize(data: T): R;
2120
+ /**
2121
+ * Deserializes data from target format back to original form
2122
+ * @since 1.0.10
2123
+ * @param data - Data to deserialize
2124
+ * @param defaultValue - Optional default value to return if deserialization fails
2125
+ * @returns Original data structure
2126
+ */
2127
+ deserialize(data: R, defaultValue?: T): T;
2128
+ }
2129
+
2458
2130
  /**
2459
2131
  * Enhanced JSON serialization implementation that combines standard JSON API with additional features
2460
2132
  *
@@ -2697,6 +2369,107 @@ declare class Base64Serializer implements Serializer<string, string> {
2697
2369
  private makeUrlUnsafe;
2698
2370
  }
2699
2371
 
2372
+ /**
2373
+ * Interface representing a synchronous storage mechanism.
2374
+ *
2375
+ * @template Key - The type of keys used to identify stored values.
2376
+ * @template ValueType - The type of values stored, defaults to unknown.
2377
+ *
2378
+ * @example
2379
+ * ```typescript
2380
+ * const storage: SyncStorage<string, number> = ...;
2381
+ * storage.setItem('key', 123);
2382
+ * const value = storage.getItem('key', 0);
2383
+ * ```
2384
+ */
2385
+ interface SyncStorage<Key, ValueType = unknown> {
2386
+ /**
2387
+ * The number of items stored.
2388
+ */
2389
+ readonly length: number;
2390
+ /**
2391
+ * Stores a value with the specified key.
2392
+ *
2393
+ * @param key - The key to identify the stored value.
2394
+ * @param value - The value to store.
2395
+ * @param options - Optional parameters for storage.
2396
+ */
2397
+ setItem<T>(key: Key, value: T, options?: unknown): void;
2398
+ /**
2399
+ * Retrieves a value by key.
2400
+ *
2401
+ * @param key - The key of the value to retrieve.
2402
+ * @param defaultValue - The default value to return if the key is not found.
2403
+ * @param options - Optional parameters for retrieval.
2404
+ * @returns The value associated with the key, or the default value if not found.
2405
+ */
2406
+ getItem<T extends ValueType>(key: Key, defaultValue?: T, options?: unknown): T | null;
2407
+ /**
2408
+ * Removes a value by key.
2409
+ *
2410
+ * @param key - The key of the value to remove.
2411
+ * @param options - Optional parameters for removal.
2412
+ */
2413
+ removeItem(key: Key, options?: unknown): void;
2414
+ /**
2415
+ * Clears all stored values.
2416
+ */
2417
+ clear(): void;
2418
+ }
2419
+ /**
2420
+ * Interface representing an asynchronous storage mechanism.
2421
+ *
2422
+ * @template Key - The type of keys used to identify stored values.
2423
+ * @template ValueType - The type of values stored, defaults to unknown.
2424
+ *
2425
+ * @example
2426
+ *
2427
+ * ```typescript
2428
+ * const storage: AsyncStorage<string, number> = ...;
2429
+ * await storage.setItem('key', 123);
2430
+ * const value = await storage.getItem('key', 0);
2431
+ * ```
2432
+ *
2433
+ */
2434
+ interface AsyncStorage<Key, ValueType = unknown> {
2435
+ /**
2436
+ * The number of items stored.
2437
+ */
2438
+ readonly length: number;
2439
+ /**
2440
+ * Asynchronously stores a value with the specified key.
2441
+ *
2442
+ * @param key - The key to identify the stored value.
2443
+ * @param value - The value to store.
2444
+ * @param options - Optional parameters for storage.
2445
+ * @returns A promise that resolves when the value is stored.
2446
+ */
2447
+ setItem<T>(key: Key, value: T, options?: unknown): Promise<void>;
2448
+ /**
2449
+ * Asynchronously retrieves a value by key.
2450
+ *
2451
+ * @param key - The key of the value to retrieve.
2452
+ * @param defaultValue - The default value to return if the key is not found.
2453
+ * @param options - Optional parameters for retrieval.
2454
+ * @returns A promise that resolves to the value associated with the key, or the default value if not found.
2455
+ */
2456
+ getItem<T extends ValueType>(key: Key, defaultValue?: T, options?: unknown): Promise<T | null>;
2457
+ /**
2458
+ * Asynchronously removes a value by key.
2459
+ *
2460
+ * @param key - The key of the value to remove.
2461
+ * @param options - Optional parameters for removal.
2462
+ * @returns A promise that resolves when the value is removed.
2463
+ */
2464
+ removeItem(key: Key, options?: unknown): Promise<void>;
2465
+ /**
2466
+ * Asynchronously clears all stored values.
2467
+ *
2468
+ * @returns A promise that resolves when all values are cleared.
2469
+ */
2470
+ clear(): Promise<void>;
2471
+ }
2472
+
2700
2473
  /**
2701
2474
  * Represents a storage mechanism for JSON-serializable data.
2702
2475
  *
@@ -2833,5 +2606,33 @@ declare class JSONStorage implements SyncStorage<string> {
2833
2606
  clear(): void;
2834
2607
  }
2835
2608
 
2836
- export { AsyncExecutor, Base64Serializer, Executor, ExecutorError, FetchAbortPlugin, FetchURLPlugin, JSONSerializer, JSONStorage, LEVELS, Logger, RequestAdapterAxios, RequestAdapterFetch, RequestError, RequestErrorID, RequestManager, RequestScheduler, RequestTransaction, RetryPlugin, SyncExecutor };
2837
- export type { AsyncStorage, Encryptor, ExecOptions, ExecutorContext, ExecutorPlugin, HookRuntimes, Intersection, LogArgument, LogLevel, PromiseTask, RequestAdapterConfig, RequestAdapterFetchConfig, RequestAdapterInterface, RequestAdapterResponse, RequestTransactionInterface, RetryOptions, Serializer, SyncStorage, SyncTask, Task, ValueOf };
2609
+ /**
2610
+ * Get the value type of an object
2611
+ *
2612
+ * @since 1.0.14
2613
+ *
2614
+ * @example
2615
+ * ```ts
2616
+ * type T = { a: number; b: string };
2617
+ * type V = ValueOf<T>; // V is number | string
2618
+ * ```
2619
+ */
2620
+ type ValueOf<T> = T[keyof T];
2621
+ /**
2622
+ * Get the intersection type of two types
2623
+ *
2624
+ * @since 1.0.14
2625
+ *
2626
+ * @example
2627
+ * ```ts
2628
+ * type T1 = { a: number; b: string };
2629
+ * type T2 = { a: number; c: boolean };
2630
+ * type I = Intersection<T1, T2>; // I is { a: number }
2631
+ * ```
2632
+ */
2633
+ type Intersection<T1, T2> = {
2634
+ [P in keyof T1 & keyof T2]: T1[P] | T2[P];
2635
+ };
2636
+
2637
+ export { AsyncExecutor, Base64Serializer, Executor, ExecutorError, FetchAbortPlugin, FetchURLPlugin, JSONSerializer, JSONStorage, RequestAdapterAxios, RequestAdapterFetch, RequestError, RequestErrorID, RequestManager, RequestScheduler, RequestTransaction, RetryPlugin, SyncExecutor };
2638
+ export type { AsyncStorage, Encryptor, ExecutorContext, ExecutorPlugin, HookRuntimes, Intersection, PromiseTask, RequestAdapterConfig, RequestAdapterFetchConfig, RequestAdapterInterface, RequestAdapterResponse, RequestTransactionInterface, RetryOptions, Serializer, SyncStorage, SyncTask, Task, ValueOf };