@uploadista/client-core 0.0.13 → 0.0.14

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.
@@ -0,0 +1,130 @@
1
+ import type { NetworkCondition, NetworkMetrics } from "../network-monitor";
2
+ import type { ChunkMetrics } from "./chunk-metrics";
3
+ import type { PerformanceInsights } from "./performance-insights";
4
+ import type { UploadSessionMetrics } from "./upload-session-metrics";
5
+
6
+ /**
7
+ * Comprehensive upload metrics interface
8
+ *
9
+ * Provides access to all performance metrics, insights, and network
10
+ * statistics for upload monitoring and optimization.
11
+ *
12
+ * This interface is implemented by all framework packages (React, Vue, React Native)
13
+ * to ensure consistent metrics API across platforms.
14
+ *
15
+ * @example React usage
16
+ * ```tsx
17
+ * const upload = useUpload();
18
+ * const insights = upload.metrics.getInsights();
19
+ * const metrics = upload.metrics.exportMetrics();
20
+ * ```
21
+ *
22
+ * @example Vue usage
23
+ * ```vue
24
+ * <script setup>
25
+ * const upload = useUpload();
26
+ * const insights = upload.metrics.getInsights();
27
+ * </script>
28
+ * ```
29
+ *
30
+ * @example React Native usage
31
+ * ```tsx
32
+ * const upload = useUpload();
33
+ * const networkMetrics = upload.metrics.getNetworkMetrics();
34
+ * ```
35
+ */
36
+ export interface UploadMetrics {
37
+ /**
38
+ * Get performance insights from the upload client
39
+ *
40
+ * Provides high-level analysis with recommendations for
41
+ * optimizing upload performance.
42
+ *
43
+ * @returns Performance insights including efficiency scores and recommendations
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const insights = metrics.getInsights();
48
+ * console.log(`Efficiency: ${insights.overallEfficiency}%`);
49
+ * console.log(`Recommendations:`, insights.recommendations);
50
+ * ```
51
+ */
52
+ getInsights: () => PerformanceInsights;
53
+
54
+ /**
55
+ * Export detailed metrics from the upload client
56
+ *
57
+ * Returns comprehensive metrics including session data,
58
+ * per-chunk statistics, and performance insights.
59
+ *
60
+ * Useful for analytics, debugging, and performance monitoring.
61
+ *
62
+ * @returns Object containing session metrics, chunk metrics, and insights
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const metrics = metrics.exportMetrics();
67
+ * console.log(`Uploaded ${metrics.session.totalBytesUploaded} bytes`);
68
+ * console.log(`Average speed: ${metrics.session.averageSpeed} B/s`);
69
+ * console.log(`Chunks: ${metrics.chunks.length}`);
70
+ * ```
71
+ */
72
+ exportMetrics: () => {
73
+ /** Session-level aggregated metrics */
74
+ session: Partial<UploadSessionMetrics>;
75
+ /** Per-chunk detailed metrics */
76
+ chunks: ChunkMetrics[];
77
+ /** Performance insights and recommendations */
78
+ insights: PerformanceInsights;
79
+ };
80
+
81
+ /**
82
+ * Get current network metrics
83
+ *
84
+ * Provides real-time network statistics including speed,
85
+ * errors, and network condition assessment.
86
+ *
87
+ * @returns Current network performance metrics
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const network = metrics.getNetworkMetrics();
92
+ * console.log(`Speed: ${network.currentSpeed} B/s`);
93
+ * console.log(`Quality: ${network.condition.quality}`);
94
+ * ```
95
+ */
96
+ getNetworkMetrics: () => NetworkMetrics;
97
+
98
+ /**
99
+ * Get current network condition
100
+ *
101
+ * Provides assessment of current network quality with
102
+ * recommendations for adaptive upload strategies.
103
+ *
104
+ * @returns Network condition assessment
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const condition = metrics.getNetworkCondition();
109
+ * if (condition.quality === 'poor') {
110
+ * console.log('Consider reducing chunk size');
111
+ * }
112
+ * ```
113
+ */
114
+ getNetworkCondition: () => NetworkCondition;
115
+
116
+ /**
117
+ * Reset all metrics
118
+ *
119
+ * Clears all accumulated metrics and resets counters.
120
+ * Useful when starting a new upload session.
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * // Reset metrics before starting new upload
125
+ * metrics.resetMetrics();
126
+ * upload(newFile);
127
+ * ```
128
+ */
129
+ resetMetrics: () => void;
130
+ }
@@ -18,15 +18,23 @@ export interface UploadOptions {
18
18
 
19
19
  /**
20
20
  * Called when upload progress updates
21
+ *
22
+ * @param uploadId - The unique identifier for this upload
23
+ * @param bytesUploaded - Number of bytes uploaded so far
24
+ * @param totalBytes - Total bytes to upload, null if unknown/deferred
21
25
  */
22
26
  onProgress?: (
23
- progress: number,
27
+ uploadId: string,
24
28
  bytesUploaded: number,
25
29
  totalBytes: number | null,
26
30
  ) => void;
27
31
 
28
32
  /**
29
33
  * Called when a chunk completes
34
+ *
35
+ * @param chunkSize - Size of the completed chunk in bytes
36
+ * @param bytesAccepted - Total bytes accepted by server so far
37
+ * @param bytesTotal - Total bytes to upload, null if unknown/deferred
30
38
  */
31
39
  onChunkComplete?: (
32
40
  chunkSize: number,
@@ -36,11 +44,15 @@ export interface UploadOptions {
36
44
 
37
45
  /**
38
46
  * Called when upload succeeds
47
+ *
48
+ * @param result - The uploaded file result
39
49
  */
40
50
  onSuccess?: (result: UploadFile) => void;
41
51
 
42
52
  /**
43
53
  * Called when upload fails
54
+ *
55
+ * @param error - The error that caused the failure
44
56
  */
45
57
  onError?: (error: Error) => void;
46
58
 
@@ -51,6 +63,10 @@ export interface UploadOptions {
51
63
 
52
64
  /**
53
65
  * Custom retry logic
66
+ *
67
+ * @param error - The error that triggered the retry check
68
+ * @param retryAttempt - The current retry attempt number (0-indexed)
69
+ * @returns true to retry, false to fail
54
70
  */
55
71
  onShouldRetry?: (error: Error, retryAttempt: number) => boolean;
56
72
  }