@uploadista/client-core 0.0.13 → 0.0.15-beta.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.mts +972 -33
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -4
- package/src/index.ts +2 -0
- package/src/managers/__tests__/event-subscription-manager.test.ts +566 -0
- package/src/managers/__tests__/upload-manager.test.ts +588 -0
- package/src/managers/event-subscription-manager.ts +280 -0
- package/src/managers/flow-manager.ts +620 -0
- package/src/managers/index.ts +28 -0
- package/src/managers/upload-manager.ts +353 -0
- package/src/services/service-container.ts +213 -1
- package/src/testing/index.ts +16 -0
- package/src/testing/mock-service-container.ts +629 -0
- package/src/types/flow-upload-options.ts +29 -4
- package/src/types/index.ts +1 -0
- package/src/types/upload-metrics.ts +130 -0
- package/src/types/upload-options.ts +17 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { UploadStrategyNegotiator } from "@uploadista/core/upload";
|
|
2
2
|
import { DataStoreCapabilities, InputFile, UploadEvent, UploadFile } from "@uploadista/core/types";
|
|
3
3
|
import z from "zod";
|
|
4
|
+
import { FlowData, FlowEvent, FlowJob, TypedOutput } from "@uploadista/core/flow";
|
|
4
5
|
import * as _uploadista_core0 from "@uploadista/core";
|
|
5
6
|
import { UploadFile as UploadFile$1 } from "@uploadista/core";
|
|
6
|
-
import { FlowData, FlowEvent, FlowJob } from "@uploadista/core/flow";
|
|
7
7
|
|
|
8
8
|
//#region src/types/buffered-chunk.d.ts
|
|
9
9
|
interface BufferedChunk {
|
|
@@ -1076,11 +1076,11 @@ interface FileSource {
|
|
|
1076
1076
|
slice: (start: number, end: number) => Promise<SliceResult>;
|
|
1077
1077
|
close: () => void;
|
|
1078
1078
|
}
|
|
1079
|
-
interface FileReaderService<UploadInput> {
|
|
1079
|
+
interface FileReaderService<UploadInput$1> {
|
|
1080
1080
|
/**
|
|
1081
1081
|
* Open a file for reading
|
|
1082
1082
|
*/
|
|
1083
|
-
openFile(input: UploadInput, chunkSize: number): Promise<FileSource>;
|
|
1083
|
+
openFile(input: UploadInput$1, chunkSize: number): Promise<FileSource>;
|
|
1084
1084
|
}
|
|
1085
1085
|
interface Base64Service {
|
|
1086
1086
|
/**
|
|
@@ -1094,8 +1094,8 @@ interface Base64Service {
|
|
|
1094
1094
|
}
|
|
1095
1095
|
//#endregion
|
|
1096
1096
|
//#region src/services/fingerprint-service.d.ts
|
|
1097
|
-
interface FingerprintService<UploadInput> {
|
|
1098
|
-
computeFingerprint(file: UploadInput, endpoint: string): Promise<string | null>;
|
|
1097
|
+
interface FingerprintService<UploadInput$1> {
|
|
1098
|
+
computeFingerprint(file: UploadInput$1, endpoint: string): Promise<string | null>;
|
|
1099
1099
|
}
|
|
1100
1100
|
//#endregion
|
|
1101
1101
|
//#region src/services/id-generation-service.d.ts
|
|
@@ -1836,19 +1836,221 @@ declare class UploadistaError extends Error {
|
|
|
1836
1836
|
//#endregion
|
|
1837
1837
|
//#region src/services/service-container.d.ts
|
|
1838
1838
|
/**
|
|
1839
|
-
* Service container for dependency injection
|
|
1839
|
+
* Service container for dependency injection in the Uploadista client.
|
|
1840
|
+
*
|
|
1841
|
+
* This container provides all platform-specific services needed by the upload client.
|
|
1842
|
+
* Different platforms (browser, React Native, Node.js) provide their own implementations
|
|
1843
|
+
* of these services to handle platform-specific APIs and behaviors.
|
|
1844
|
+
*
|
|
1845
|
+
* @template UploadInput - The type of input accepted by the file reader (e.g., File, Blob, string path)
|
|
1846
|
+
*
|
|
1847
|
+
* @example Browser implementation
|
|
1848
|
+
* ```typescript
|
|
1849
|
+
* const services: ServiceContainer<File | Blob> = {
|
|
1850
|
+
* storage: new LocalStorageService(),
|
|
1851
|
+
* idGeneration: new BrowserIdGenerationService(),
|
|
1852
|
+
* httpClient: new FetchHttpClient(),
|
|
1853
|
+
* fileReader: new BrowserFileReaderService(),
|
|
1854
|
+
* base64: new BrowserBase64Service(),
|
|
1855
|
+
* websocket: new BrowserWebSocketFactory(),
|
|
1856
|
+
* abortController: new BrowserAbortControllerFactory(),
|
|
1857
|
+
* platform: new BrowserPlatformService(),
|
|
1858
|
+
* checksumService: new WebCryptoChecksumService(),
|
|
1859
|
+
* fingerprintService: new BrowserFingerprintService(),
|
|
1860
|
+
* };
|
|
1861
|
+
* ```
|
|
1862
|
+
*
|
|
1863
|
+
* @example React Native implementation
|
|
1864
|
+
* ```typescript
|
|
1865
|
+
* const services: ServiceContainer<FilePickResult> = {
|
|
1866
|
+
* storage: new AsyncStorageService(),
|
|
1867
|
+
* idGeneration: new ReactNativeIdGenerationService(),
|
|
1868
|
+
* httpClient: new FetchHttpClient(),
|
|
1869
|
+
* fileReader: new ReactNativeFileReaderService(),
|
|
1870
|
+
* websocket: new ReactNativeWebSocketFactory(),
|
|
1871
|
+
* abortController: new ReactNativeAbortControllerFactory(),
|
|
1872
|
+
* platform: new ReactNativePlatformService(),
|
|
1873
|
+
* checksumService: new ReactNativeChecksumService(),
|
|
1874
|
+
* fingerprintService: new ReactNativeFingerprintService(),
|
|
1875
|
+
* };
|
|
1876
|
+
* ```
|
|
1840
1877
|
*/
|
|
1841
|
-
interface ServiceContainer<UploadInput> {
|
|
1878
|
+
interface ServiceContainer<UploadInput$1> {
|
|
1879
|
+
/**
|
|
1880
|
+
* Storage service for persisting upload state and metadata.
|
|
1881
|
+
*
|
|
1882
|
+
* **Required**: Yes
|
|
1883
|
+
*
|
|
1884
|
+
* **Used for**:
|
|
1885
|
+
* - Storing upload progress for resumption
|
|
1886
|
+
* - Caching upload fingerprints
|
|
1887
|
+
* - Persisting partial upload state across sessions
|
|
1888
|
+
*
|
|
1889
|
+
* **Platform implementations**:
|
|
1890
|
+
* - Browser: `localStorage`, `IndexedDB`
|
|
1891
|
+
* - React Native: `AsyncStorage`, `MMKV`
|
|
1892
|
+
* - Node.js: File system, Redis
|
|
1893
|
+
*/
|
|
1842
1894
|
storage: StorageService;
|
|
1895
|
+
/**
|
|
1896
|
+
* ID generation service for creating unique identifiers.
|
|
1897
|
+
*
|
|
1898
|
+
* **Required**: Yes
|
|
1899
|
+
*
|
|
1900
|
+
* **Used for**:
|
|
1901
|
+
* - Generating upload IDs
|
|
1902
|
+
* - Creating request correlation IDs
|
|
1903
|
+
* - Generating chunk identifiers
|
|
1904
|
+
*
|
|
1905
|
+
* **Platform implementations**:
|
|
1906
|
+
* - Browser: `crypto.randomUUID()` or fallback
|
|
1907
|
+
* - React Native: UUID libraries
|
|
1908
|
+
* - Node.js: `crypto.randomUUID()`
|
|
1909
|
+
*/
|
|
1843
1910
|
idGeneration: IdGenerationService;
|
|
1911
|
+
/**
|
|
1912
|
+
* HTTP client for making upload requests.
|
|
1913
|
+
*
|
|
1914
|
+
* **Required**: Yes
|
|
1915
|
+
*
|
|
1916
|
+
* **Used for**:
|
|
1917
|
+
* - Uploading file chunks
|
|
1918
|
+
* - Making API calls to the upload server
|
|
1919
|
+
* - Fetching upload metadata
|
|
1920
|
+
*
|
|
1921
|
+
* **Platform implementations**:
|
|
1922
|
+
* - Browser: `fetch()` with connection pooling
|
|
1923
|
+
* - React Native: `fetch()` or `XMLHttpRequest`
|
|
1924
|
+
* - Node.js: `node:http`, `node:https`, or libraries like `undici`
|
|
1925
|
+
*
|
|
1926
|
+
* **Important**: Should support connection pooling for optimal performance
|
|
1927
|
+
*/
|
|
1844
1928
|
httpClient: HttpClient;
|
|
1845
|
-
|
|
1929
|
+
/**
|
|
1930
|
+
* File reader service for reading file contents.
|
|
1931
|
+
*
|
|
1932
|
+
* **Required**: Yes
|
|
1933
|
+
*
|
|
1934
|
+
* **Used for**:
|
|
1935
|
+
* - Reading file data for upload
|
|
1936
|
+
* - Slicing files into chunks
|
|
1937
|
+
* - Computing file checksums and fingerprints
|
|
1938
|
+
*
|
|
1939
|
+
* **Platform implementations**:
|
|
1940
|
+
* - Browser: `FileReader` API, `Blob.slice()`
|
|
1941
|
+
* - React Native: Native file system modules, `react-native-fs`
|
|
1942
|
+
* - Node.js: `fs.createReadStream()`, `fs.promises.open()`
|
|
1943
|
+
*
|
|
1944
|
+
* **Generic type**: Accepts platform-specific input types (File, Blob, path string)
|
|
1945
|
+
*/
|
|
1946
|
+
fileReader: FileReaderService<UploadInput$1>;
|
|
1947
|
+
/**
|
|
1948
|
+
* Base64 encoding/decoding service.
|
|
1949
|
+
*
|
|
1950
|
+
* **Required**: No (optional)
|
|
1951
|
+
*
|
|
1952
|
+
* **Used for**:
|
|
1953
|
+
* - Encoding binary data for transport
|
|
1954
|
+
* - Decoding server responses
|
|
1955
|
+
* - Optional data transformations
|
|
1956
|
+
*
|
|
1957
|
+
* **Platform implementations**:
|
|
1958
|
+
* - Browser: `btoa()`, `atob()`
|
|
1959
|
+
* - React Native: `base64-js` or built-in
|
|
1960
|
+
* - Node.js: `Buffer.from().toString('base64')`
|
|
1961
|
+
*
|
|
1962
|
+
* **Note**: Only needed for specific upload protocols that require base64 encoding
|
|
1963
|
+
*/
|
|
1846
1964
|
base64?: Base64Service;
|
|
1965
|
+
/**
|
|
1966
|
+
* WebSocket factory for creating WebSocket connections.
|
|
1967
|
+
*
|
|
1968
|
+
* **Required**: Yes
|
|
1969
|
+
*
|
|
1970
|
+
* **Used for**:
|
|
1971
|
+
* - Real-time upload progress updates
|
|
1972
|
+
* - Server-side event notifications
|
|
1973
|
+
* - Live upload status from server
|
|
1974
|
+
*
|
|
1975
|
+
* **Platform implementations**:
|
|
1976
|
+
* - Browser: Native `WebSocket` API
|
|
1977
|
+
* - React Native: `react-native-websocket` or polyfills
|
|
1978
|
+
* - Node.js: `ws` library
|
|
1979
|
+
*
|
|
1980
|
+
* **Important**: Must support standard WebSocket protocol
|
|
1981
|
+
*/
|
|
1847
1982
|
websocket: WebSocketFactory;
|
|
1983
|
+
/**
|
|
1984
|
+
* Abort controller factory for creating cancellation tokens.
|
|
1985
|
+
*
|
|
1986
|
+
* **Required**: Yes
|
|
1987
|
+
*
|
|
1988
|
+
* **Used for**:
|
|
1989
|
+
* - Aborting in-flight upload requests
|
|
1990
|
+
* - Cancelling file read operations
|
|
1991
|
+
* - Implementing upload timeout logic
|
|
1992
|
+
*
|
|
1993
|
+
* **Platform implementations**:
|
|
1994
|
+
* - Browser: Native `AbortController` API
|
|
1995
|
+
* - React Native: `AbortController` polyfill
|
|
1996
|
+
* - Node.js: Native `AbortController` (Node 15+)
|
|
1997
|
+
*/
|
|
1848
1998
|
abortController: AbortControllerFactory;
|
|
1999
|
+
/**
|
|
2000
|
+
* Platform detection service.
|
|
2001
|
+
*
|
|
2002
|
+
* **Required**: Yes
|
|
2003
|
+
*
|
|
2004
|
+
* **Used for**:
|
|
2005
|
+
* - Detecting runtime environment (browser, React Native, Node.js)
|
|
2006
|
+
* - Applying platform-specific optimizations
|
|
2007
|
+
* - Conditional feature availability
|
|
2008
|
+
*
|
|
2009
|
+
* **Platform implementations**:
|
|
2010
|
+
* - Browser: Checks `window`, `document` availability
|
|
2011
|
+
* - React Native: Checks `navigator.product === 'ReactNative'`
|
|
2012
|
+
* - Node.js: Checks `process` availability
|
|
2013
|
+
*/
|
|
1849
2014
|
platform: PlatformService;
|
|
2015
|
+
/**
|
|
2016
|
+
* Checksum service for computing file checksums.
|
|
2017
|
+
*
|
|
2018
|
+
* **Required**: Yes
|
|
2019
|
+
*
|
|
2020
|
+
* **Used for**:
|
|
2021
|
+
* - Verifying upload integrity
|
|
2022
|
+
* - Detecting corrupted uploads
|
|
2023
|
+
* - Implementing upload deduplication
|
|
2024
|
+
*
|
|
2025
|
+
* **Platform implementations**:
|
|
2026
|
+
* - Browser: `crypto.subtle` Web Crypto API
|
|
2027
|
+
* - React Native: Native crypto modules or JavaScript implementations
|
|
2028
|
+
* - Node.js: `crypto` module
|
|
2029
|
+
*
|
|
2030
|
+
* **Common algorithms**: SHA-256, MD5, CRC32
|
|
2031
|
+
*/
|
|
1850
2032
|
checksumService: ChecksumService;
|
|
1851
|
-
|
|
2033
|
+
/**
|
|
2034
|
+
* Fingerprint service for generating unique file identifiers.
|
|
2035
|
+
*
|
|
2036
|
+
* **Required**: Yes
|
|
2037
|
+
*
|
|
2038
|
+
* **Used for**:
|
|
2039
|
+
* - Upload resumption (matching partial uploads)
|
|
2040
|
+
* - Deduplication (detecting duplicate files)
|
|
2041
|
+
* - Cache key generation
|
|
2042
|
+
*
|
|
2043
|
+
* **Platform implementations**:
|
|
2044
|
+
* - Browser: Combines file metadata (size, name, modified date, first/last bytes)
|
|
2045
|
+
* - React Native: Similar to browser but uses platform-specific file APIs
|
|
2046
|
+
* - Node.js: File stat info + content sampling
|
|
2047
|
+
*
|
|
2048
|
+
* **Generic type**: Accepts platform-specific input types
|
|
2049
|
+
*
|
|
2050
|
+
* **Note**: Fingerprints should be stable (same file = same fingerprint) but
|
|
2051
|
+
* fast to compute (avoid reading entire file if possible)
|
|
2052
|
+
*/
|
|
2053
|
+
fingerprintService: FingerprintService<UploadInput$1>;
|
|
1852
2054
|
}
|
|
1853
2055
|
//#endregion
|
|
1854
2056
|
//#region src/types/upload-response.d.ts
|
|
@@ -2123,7 +2325,7 @@ type UploadistaUploadOptions = {
|
|
|
2123
2325
|
*
|
|
2124
2326
|
* @template UploadInput - The platform-specific file/blob type (e.g., File, Blob, Buffer)
|
|
2125
2327
|
*/
|
|
2126
|
-
type UploadistaClientOptions<UploadInput> = {
|
|
2328
|
+
type UploadistaClientOptions<UploadInput$1> = {
|
|
2127
2329
|
/** Base URL of the Uploadista server (e.g., "https://upload.example.com") */
|
|
2128
2330
|
baseUrl: string;
|
|
2129
2331
|
/** Base path for Uploadista endpoints. Defaults to "uploadista" */
|
|
@@ -2155,11 +2357,11 @@ type UploadistaClientOptions<UploadInput> = {
|
|
|
2155
2357
|
/** Client-side storage for upload resumption data */
|
|
2156
2358
|
clientStorage: ClientStorage;
|
|
2157
2359
|
/** Platform-specific file reading service */
|
|
2158
|
-
fileReader: FileReaderService<UploadInput>;
|
|
2360
|
+
fileReader: FileReaderService<UploadInput$1>;
|
|
2159
2361
|
/** Logger for debugging and monitoring */
|
|
2160
2362
|
logger: Logger;
|
|
2161
2363
|
/** Service for computing file fingerprints for resumption */
|
|
2162
|
-
fingerprintService: FingerprintService<UploadInput>;
|
|
2364
|
+
fingerprintService: FingerprintService<UploadInput$1>;
|
|
2163
2365
|
/** Whether to store fingerprints for upload resumption. Defaults to true */
|
|
2164
2366
|
storeFingerprintForResuming: boolean;
|
|
2165
2367
|
/** Factory for creating WebSocket connections */
|
|
@@ -2325,7 +2527,7 @@ declare const defaultConnectionPoolingConfig: ConnectionPoolConfig;
|
|
|
2325
2527
|
* @see {@link UploadistaClientOptions} for full configuration options
|
|
2326
2528
|
* @see {@link UploadistaUploadOptions} for per-upload options
|
|
2327
2529
|
*/
|
|
2328
|
-
declare function createUploadistaClient<UploadInput>({
|
|
2530
|
+
declare function createUploadistaClient<UploadInput$1>({
|
|
2329
2531
|
baseUrl: _baseUrl,
|
|
2330
2532
|
uploadistaBasePath,
|
|
2331
2533
|
storageId,
|
|
@@ -2350,8 +2552,8 @@ declare function createUploadistaClient<UploadInput>({
|
|
|
2350
2552
|
abortControllerFactory,
|
|
2351
2553
|
platformService,
|
|
2352
2554
|
auth
|
|
2353
|
-
}: UploadistaClientOptions<UploadInput>): {
|
|
2354
|
-
upload: (file: UploadInput, {
|
|
2555
|
+
}: UploadistaClientOptions<UploadInput$1>): {
|
|
2556
|
+
upload: (file: UploadInput$1, {
|
|
2355
2557
|
uploadLengthDeferred,
|
|
2356
2558
|
uploadSize,
|
|
2357
2559
|
onProgress,
|
|
@@ -2362,7 +2564,7 @@ declare function createUploadistaClient<UploadInput>({
|
|
|
2362
2564
|
}?: UploadistaUploadOptions) => Promise<{
|
|
2363
2565
|
abort: () => void;
|
|
2364
2566
|
}>;
|
|
2365
|
-
uploadWithFlow: (file: UploadInput, flowConfig: FlowUploadConfig, {
|
|
2567
|
+
uploadWithFlow: (file: UploadInput$1, flowConfig: FlowUploadConfig, {
|
|
2366
2568
|
onProgress,
|
|
2367
2569
|
onChunkComplete,
|
|
2368
2570
|
onSuccess,
|
|
@@ -2436,12 +2638,12 @@ declare function createUploadistaClient<UploadInput>({
|
|
|
2436
2638
|
connectionOverhead: number;
|
|
2437
2639
|
}>;
|
|
2438
2640
|
resetMetrics: () => Promise<void>;
|
|
2439
|
-
validateConfiguration: (options: UploadistaClientOptions<UploadInput>) => {
|
|
2641
|
+
validateConfiguration: (options: UploadistaClientOptions<UploadInput$1>) => {
|
|
2440
2642
|
valid: boolean;
|
|
2441
2643
|
errors: string[];
|
|
2442
2644
|
warnings: string[];
|
|
2443
2645
|
};
|
|
2444
|
-
validateConfigurationAsync: (options: UploadistaClientOptions<UploadInput>) => Promise<{
|
|
2646
|
+
validateConfigurationAsync: (options: UploadistaClientOptions<UploadInput$1>) => Promise<{
|
|
2445
2647
|
valid: boolean;
|
|
2446
2648
|
errors: string[];
|
|
2447
2649
|
warnings: string[];
|
|
@@ -2502,9 +2704,9 @@ type FlowResult<TOutput = UploadFile> = {
|
|
|
2502
2704
|
/**
|
|
2503
2705
|
* Flow upload item for multi-flow-upload tracking
|
|
2504
2706
|
*/
|
|
2505
|
-
interface FlowUploadItem<UploadInput> {
|
|
2707
|
+
interface FlowUploadItem<UploadInput$1> {
|
|
2506
2708
|
id: string;
|
|
2507
|
-
file: UploadInput;
|
|
2709
|
+
file: UploadInput$1;
|
|
2508
2710
|
status: "pending" | "uploading" | "success" | "error" | "aborted";
|
|
2509
2711
|
progress: number;
|
|
2510
2712
|
bytesUploaded: number;
|
|
@@ -2520,20 +2722,43 @@ interface FlowUploadOptions<TOutput = UploadFile> {
|
|
|
2520
2722
|
* Flow configuration
|
|
2521
2723
|
*/
|
|
2522
2724
|
flowConfig: FlowUploadConfig;
|
|
2725
|
+
/**
|
|
2726
|
+
* Called when the flow job starts
|
|
2727
|
+
* @param jobId - The unique identifier for the flow job
|
|
2728
|
+
*/
|
|
2729
|
+
onJobStart?: (jobId: string) => void;
|
|
2523
2730
|
/**
|
|
2524
2731
|
* Called when upload progress updates
|
|
2732
|
+
*
|
|
2733
|
+
* @param uploadId - The unique identifier for this upload
|
|
2734
|
+
* @param bytesUploaded - Number of bytes uploaded so far
|
|
2735
|
+
* @param totalBytes - Total bytes to upload, null if unknown/deferred
|
|
2525
2736
|
*/
|
|
2526
|
-
onProgress?: (
|
|
2737
|
+
onProgress?: (uploadId: string, bytesUploaded: number, totalBytes: number | null) => void;
|
|
2527
2738
|
/**
|
|
2528
2739
|
* Called when a chunk completes
|
|
2529
2740
|
*/
|
|
2530
2741
|
onChunkComplete?: (chunkSize: number, bytesAccepted: number, bytesTotal: number | null) => void;
|
|
2531
2742
|
/**
|
|
2532
2743
|
* Called when the flow completes successfully (receives full flow outputs)
|
|
2533
|
-
* This is the recommended callback for multi-output flows
|
|
2534
|
-
*
|
|
2744
|
+
* This is the recommended callback for multi-output flows.
|
|
2745
|
+
* Each output includes nodeId, optional nodeType, data, and timestamp.
|
|
2746
|
+
*
|
|
2747
|
+
* @param outputs - Array of typed outputs from all output nodes
|
|
2748
|
+
*
|
|
2749
|
+
* @example
|
|
2750
|
+
* ```typescript
|
|
2751
|
+
* onFlowComplete: (outputs) => {
|
|
2752
|
+
* // Access all outputs with type information
|
|
2753
|
+
* for (const output of outputs) {
|
|
2754
|
+
* if (output.nodeType === 'storage-output-v1') {
|
|
2755
|
+
* console.log('Storage output:', output.data);
|
|
2756
|
+
* }
|
|
2757
|
+
* }
|
|
2758
|
+
* }
|
|
2759
|
+
* ```
|
|
2535
2760
|
*/
|
|
2536
|
-
onFlowComplete?: (outputs:
|
|
2761
|
+
onFlowComplete?: (outputs: TypedOutput[]) => void;
|
|
2537
2762
|
/**
|
|
2538
2763
|
* Called when upload succeeds (legacy, single-output flows)
|
|
2539
2764
|
* For single-output flows, receives the value from the specified outputNodeId
|
|
@@ -2555,7 +2780,7 @@ interface FlowUploadOptions<TOutput = UploadFile> {
|
|
|
2555
2780
|
}
|
|
2556
2781
|
//#endregion
|
|
2557
2782
|
//#region src/types/multi-flow-upload-options.d.ts
|
|
2558
|
-
interface MultiFlowUploadOptions<UploadInput> {
|
|
2783
|
+
interface MultiFlowUploadOptions<UploadInput$1> {
|
|
2559
2784
|
/**
|
|
2560
2785
|
* Flow configuration
|
|
2561
2786
|
*/
|
|
@@ -2567,19 +2792,19 @@ interface MultiFlowUploadOptions<UploadInput> {
|
|
|
2567
2792
|
/**
|
|
2568
2793
|
* Called when an individual upload progresses
|
|
2569
2794
|
*/
|
|
2570
|
-
onItemProgress?: (item: FlowUploadItem<UploadInput>) => void;
|
|
2795
|
+
onItemProgress?: (item: FlowUploadItem<UploadInput$1>) => void;
|
|
2571
2796
|
/**
|
|
2572
2797
|
* Called when an individual upload succeeds
|
|
2573
2798
|
*/
|
|
2574
|
-
onItemSuccess?: (item: FlowUploadItem<UploadInput>) => void;
|
|
2799
|
+
onItemSuccess?: (item: FlowUploadItem<UploadInput$1>) => void;
|
|
2575
2800
|
/**
|
|
2576
2801
|
* Called when an individual upload fails
|
|
2577
2802
|
*/
|
|
2578
|
-
onItemError?: (item: FlowUploadItem<UploadInput>, error: Error) => void;
|
|
2803
|
+
onItemError?: (item: FlowUploadItem<UploadInput$1>, error: Error) => void;
|
|
2579
2804
|
/**
|
|
2580
2805
|
* Called when all uploads complete
|
|
2581
2806
|
*/
|
|
2582
|
-
onComplete?: (items: FlowUploadItem<UploadInput>[]) => void;
|
|
2807
|
+
onComplete?: (items: FlowUploadItem<UploadInput$1>[]) => void;
|
|
2583
2808
|
/**
|
|
2584
2809
|
* Custom retry logic
|
|
2585
2810
|
*/
|
|
@@ -2587,8 +2812,8 @@ interface MultiFlowUploadOptions<UploadInput> {
|
|
|
2587
2812
|
}
|
|
2588
2813
|
//#endregion
|
|
2589
2814
|
//#region src/types/multi-flow-upload-state.d.ts
|
|
2590
|
-
interface MultiFlowUploadState<UploadInput> {
|
|
2591
|
-
items: FlowUploadItem<UploadInput>[];
|
|
2815
|
+
interface MultiFlowUploadState<UploadInput$1> {
|
|
2816
|
+
items: FlowUploadItem<UploadInput$1>[];
|
|
2592
2817
|
totalProgress: number;
|
|
2593
2818
|
activeUploads: number;
|
|
2594
2819
|
completedUploads: number;
|
|
@@ -2611,18 +2836,30 @@ interface UploadOptions {
|
|
|
2611
2836
|
uploadSize?: number;
|
|
2612
2837
|
/**
|
|
2613
2838
|
* Called when upload progress updates
|
|
2839
|
+
*
|
|
2840
|
+
* @param uploadId - The unique identifier for this upload
|
|
2841
|
+
* @param bytesUploaded - Number of bytes uploaded so far
|
|
2842
|
+
* @param totalBytes - Total bytes to upload, null if unknown/deferred
|
|
2614
2843
|
*/
|
|
2615
|
-
onProgress?: (
|
|
2844
|
+
onProgress?: (uploadId: string, bytesUploaded: number, totalBytes: number | null) => void;
|
|
2616
2845
|
/**
|
|
2617
2846
|
* Called when a chunk completes
|
|
2847
|
+
*
|
|
2848
|
+
* @param chunkSize - Size of the completed chunk in bytes
|
|
2849
|
+
* @param bytesAccepted - Total bytes accepted by server so far
|
|
2850
|
+
* @param bytesTotal - Total bytes to upload, null if unknown/deferred
|
|
2618
2851
|
*/
|
|
2619
2852
|
onChunkComplete?: (chunkSize: number, bytesAccepted: number, bytesTotal: number | null) => void;
|
|
2620
2853
|
/**
|
|
2621
2854
|
* Called when upload succeeds
|
|
2855
|
+
*
|
|
2856
|
+
* @param result - The uploaded file result
|
|
2622
2857
|
*/
|
|
2623
2858
|
onSuccess?: (result: UploadFile$1) => void;
|
|
2624
2859
|
/**
|
|
2625
2860
|
* Called when upload fails
|
|
2861
|
+
*
|
|
2862
|
+
* @param error - The error that caused the failure
|
|
2626
2863
|
*/
|
|
2627
2864
|
onError?: (error: Error) => void;
|
|
2628
2865
|
/**
|
|
@@ -2631,10 +2868,137 @@ interface UploadOptions {
|
|
|
2631
2868
|
onAbort?: () => void;
|
|
2632
2869
|
/**
|
|
2633
2870
|
* Custom retry logic
|
|
2871
|
+
*
|
|
2872
|
+
* @param error - The error that triggered the retry check
|
|
2873
|
+
* @param retryAttempt - The current retry attempt number (0-indexed)
|
|
2874
|
+
* @returns true to retry, false to fail
|
|
2634
2875
|
*/
|
|
2635
2876
|
onShouldRetry?: (error: Error, retryAttempt: number) => boolean;
|
|
2636
2877
|
}
|
|
2637
2878
|
//#endregion
|
|
2879
|
+
//#region src/types/upload-metrics.d.ts
|
|
2880
|
+
/**
|
|
2881
|
+
* Comprehensive upload metrics interface
|
|
2882
|
+
*
|
|
2883
|
+
* Provides access to all performance metrics, insights, and network
|
|
2884
|
+
* statistics for upload monitoring and optimization.
|
|
2885
|
+
*
|
|
2886
|
+
* This interface is implemented by all framework packages (React, Vue, React Native)
|
|
2887
|
+
* to ensure consistent metrics API across platforms.
|
|
2888
|
+
*
|
|
2889
|
+
* @example React usage
|
|
2890
|
+
* ```tsx
|
|
2891
|
+
* const upload = useUpload();
|
|
2892
|
+
* const insights = upload.metrics.getInsights();
|
|
2893
|
+
* const metrics = upload.metrics.exportMetrics();
|
|
2894
|
+
* ```
|
|
2895
|
+
*
|
|
2896
|
+
* @example Vue usage
|
|
2897
|
+
* ```vue
|
|
2898
|
+
* <script setup>
|
|
2899
|
+
* const upload = useUpload();
|
|
2900
|
+
* const insights = upload.metrics.getInsights();
|
|
2901
|
+
* </script>
|
|
2902
|
+
* ```
|
|
2903
|
+
*
|
|
2904
|
+
* @example React Native usage
|
|
2905
|
+
* ```tsx
|
|
2906
|
+
* const upload = useUpload();
|
|
2907
|
+
* const networkMetrics = upload.metrics.getNetworkMetrics();
|
|
2908
|
+
* ```
|
|
2909
|
+
*/
|
|
2910
|
+
interface UploadMetrics {
|
|
2911
|
+
/**
|
|
2912
|
+
* Get performance insights from the upload client
|
|
2913
|
+
*
|
|
2914
|
+
* Provides high-level analysis with recommendations for
|
|
2915
|
+
* optimizing upload performance.
|
|
2916
|
+
*
|
|
2917
|
+
* @returns Performance insights including efficiency scores and recommendations
|
|
2918
|
+
*
|
|
2919
|
+
* @example
|
|
2920
|
+
* ```typescript
|
|
2921
|
+
* const insights = metrics.getInsights();
|
|
2922
|
+
* console.log(`Efficiency: ${insights.overallEfficiency}%`);
|
|
2923
|
+
* console.log(`Recommendations:`, insights.recommendations);
|
|
2924
|
+
* ```
|
|
2925
|
+
*/
|
|
2926
|
+
getInsights: () => PerformanceInsights;
|
|
2927
|
+
/**
|
|
2928
|
+
* Export detailed metrics from the upload client
|
|
2929
|
+
*
|
|
2930
|
+
* Returns comprehensive metrics including session data,
|
|
2931
|
+
* per-chunk statistics, and performance insights.
|
|
2932
|
+
*
|
|
2933
|
+
* Useful for analytics, debugging, and performance monitoring.
|
|
2934
|
+
*
|
|
2935
|
+
* @returns Object containing session metrics, chunk metrics, and insights
|
|
2936
|
+
*
|
|
2937
|
+
* @example
|
|
2938
|
+
* ```typescript
|
|
2939
|
+
* const metrics = metrics.exportMetrics();
|
|
2940
|
+
* console.log(`Uploaded ${metrics.session.totalBytesUploaded} bytes`);
|
|
2941
|
+
* console.log(`Average speed: ${metrics.session.averageSpeed} B/s`);
|
|
2942
|
+
* console.log(`Chunks: ${metrics.chunks.length}`);
|
|
2943
|
+
* ```
|
|
2944
|
+
*/
|
|
2945
|
+
exportMetrics: () => {
|
|
2946
|
+
/** Session-level aggregated metrics */
|
|
2947
|
+
session: Partial<UploadSessionMetrics>;
|
|
2948
|
+
/** Per-chunk detailed metrics */
|
|
2949
|
+
chunks: ChunkMetrics[];
|
|
2950
|
+
/** Performance insights and recommendations */
|
|
2951
|
+
insights: PerformanceInsights;
|
|
2952
|
+
};
|
|
2953
|
+
/**
|
|
2954
|
+
* Get current network metrics
|
|
2955
|
+
*
|
|
2956
|
+
* Provides real-time network statistics including speed,
|
|
2957
|
+
* errors, and network condition assessment.
|
|
2958
|
+
*
|
|
2959
|
+
* @returns Current network performance metrics
|
|
2960
|
+
*
|
|
2961
|
+
* @example
|
|
2962
|
+
* ```typescript
|
|
2963
|
+
* const network = metrics.getNetworkMetrics();
|
|
2964
|
+
* console.log(`Speed: ${network.currentSpeed} B/s`);
|
|
2965
|
+
* console.log(`Quality: ${network.condition.quality}`);
|
|
2966
|
+
* ```
|
|
2967
|
+
*/
|
|
2968
|
+
getNetworkMetrics: () => NetworkMetrics;
|
|
2969
|
+
/**
|
|
2970
|
+
* Get current network condition
|
|
2971
|
+
*
|
|
2972
|
+
* Provides assessment of current network quality with
|
|
2973
|
+
* recommendations for adaptive upload strategies.
|
|
2974
|
+
*
|
|
2975
|
+
* @returns Network condition assessment
|
|
2976
|
+
*
|
|
2977
|
+
* @example
|
|
2978
|
+
* ```typescript
|
|
2979
|
+
* const condition = metrics.getNetworkCondition();
|
|
2980
|
+
* if (condition.quality === 'poor') {
|
|
2981
|
+
* console.log('Consider reducing chunk size');
|
|
2982
|
+
* }
|
|
2983
|
+
* ```
|
|
2984
|
+
*/
|
|
2985
|
+
getNetworkCondition: () => NetworkCondition;
|
|
2986
|
+
/**
|
|
2987
|
+
* Reset all metrics
|
|
2988
|
+
*
|
|
2989
|
+
* Clears all accumulated metrics and resets counters.
|
|
2990
|
+
* Useful when starting a new upload session.
|
|
2991
|
+
*
|
|
2992
|
+
* @example
|
|
2993
|
+
* ```typescript
|
|
2994
|
+
* // Reset metrics before starting new upload
|
|
2995
|
+
* metrics.resetMetrics();
|
|
2996
|
+
* upload(newFile);
|
|
2997
|
+
* ```
|
|
2998
|
+
*/
|
|
2999
|
+
resetMetrics: () => void;
|
|
3000
|
+
}
|
|
3001
|
+
//#endregion
|
|
2638
3002
|
//#region src/types/upload-result.d.ts
|
|
2639
3003
|
/**
|
|
2640
3004
|
* Discriminated union representing the result of an upload operation.
|
|
@@ -2692,5 +3056,580 @@ type UploadResult<TOutput = UploadFile$1> = {
|
|
|
2692
3056
|
type: "cancelled";
|
|
2693
3057
|
};
|
|
2694
3058
|
//#endregion
|
|
2695
|
-
|
|
3059
|
+
//#region src/managers/event-subscription-manager.d.ts
|
|
3060
|
+
/**
|
|
3061
|
+
* Generic event type that the subscription manager can handle
|
|
3062
|
+
*/
|
|
3063
|
+
interface GenericEvent {
|
|
3064
|
+
type: string;
|
|
3065
|
+
data?: unknown;
|
|
3066
|
+
}
|
|
3067
|
+
/**
|
|
3068
|
+
* Event handler callback function
|
|
3069
|
+
*/
|
|
3070
|
+
type SubscriptionEventHandler<T = GenericEvent> = (event: T) => void;
|
|
3071
|
+
/**
|
|
3072
|
+
* Unsubscribe function returned from subscriptions
|
|
3073
|
+
*/
|
|
3074
|
+
type UnsubscribeFunction = () => void;
|
|
3075
|
+
/**
|
|
3076
|
+
* Event source that provides subscription capabilities
|
|
3077
|
+
*/
|
|
3078
|
+
interface EventSource<T = GenericEvent> {
|
|
3079
|
+
/**
|
|
3080
|
+
* Subscribe to events from this source
|
|
3081
|
+
* @returns Unsubscribe function to clean up the subscription
|
|
3082
|
+
*/
|
|
3083
|
+
subscribe(handler: SubscriptionEventHandler<T>): UnsubscribeFunction;
|
|
3084
|
+
}
|
|
3085
|
+
/**
|
|
3086
|
+
* Options for event filtering
|
|
3087
|
+
*/
|
|
3088
|
+
interface EventFilterOptions {
|
|
3089
|
+
/**
|
|
3090
|
+
* Filter events by type (exact match)
|
|
3091
|
+
*/
|
|
3092
|
+
eventType?: string;
|
|
3093
|
+
/**
|
|
3094
|
+
* Filter events by upload/job ID
|
|
3095
|
+
* If provided, only events with matching ID will be passed to the handler
|
|
3096
|
+
*/
|
|
3097
|
+
uploadId?: string | null;
|
|
3098
|
+
/**
|
|
3099
|
+
* Custom filter function for advanced filtering
|
|
3100
|
+
* Return true to pass the event to the handler
|
|
3101
|
+
*/
|
|
3102
|
+
customFilter?: (event: GenericEvent) => boolean;
|
|
3103
|
+
}
|
|
3104
|
+
/**
|
|
3105
|
+
* Platform-agnostic event subscription manager that handles event filtering,
|
|
3106
|
+
* subscription tracking, and automatic cleanup.
|
|
3107
|
+
*
|
|
3108
|
+
* This manager simplifies event handling by:
|
|
3109
|
+
* - Filtering events by type and/or ID
|
|
3110
|
+
* - Tracking all active subscriptions
|
|
3111
|
+
* - Providing cleanup methods to unsubscribe from all events
|
|
3112
|
+
* - Supporting custom filter functions for advanced scenarios
|
|
3113
|
+
*
|
|
3114
|
+
* @example Basic event subscription
|
|
3115
|
+
* ```typescript
|
|
3116
|
+
* const manager = new EventSubscriptionManager(eventSource);
|
|
3117
|
+
*
|
|
3118
|
+
* manager.subscribe(
|
|
3119
|
+
* (event) => console.log('Upload progress:', event),
|
|
3120
|
+
* { eventType: 'UPLOAD_PROGRESS', uploadId: 'abc123' }
|
|
3121
|
+
* );
|
|
3122
|
+
*
|
|
3123
|
+
* // Clean up all subscriptions when done
|
|
3124
|
+
* manager.cleanup();
|
|
3125
|
+
* ```
|
|
3126
|
+
*
|
|
3127
|
+
* @example Multiple filtered subscriptions
|
|
3128
|
+
* ```typescript
|
|
3129
|
+
* const manager = new EventSubscriptionManager(eventSource);
|
|
3130
|
+
*
|
|
3131
|
+
* // Subscribe to progress events for specific upload
|
|
3132
|
+
* manager.subscribe(
|
|
3133
|
+
* onProgress,
|
|
3134
|
+
* { eventType: 'UPLOAD_PROGRESS', uploadId: currentUploadId }
|
|
3135
|
+
* );
|
|
3136
|
+
*
|
|
3137
|
+
* // Subscribe to error events for any upload
|
|
3138
|
+
* manager.subscribe(
|
|
3139
|
+
* onError,
|
|
3140
|
+
* { eventType: 'UPLOAD_ERROR' }
|
|
3141
|
+
* );
|
|
3142
|
+
*
|
|
3143
|
+
* // Subscribe to all events with custom filtering
|
|
3144
|
+
* manager.subscribe(
|
|
3145
|
+
* onEvent,
|
|
3146
|
+
* { customFilter: (e) => e.data?.priority === 'high' }
|
|
3147
|
+
* );
|
|
3148
|
+
* ```
|
|
3149
|
+
*/
|
|
3150
|
+
declare class EventSubscriptionManager<T extends GenericEvent = GenericEvent> {
|
|
3151
|
+
private readonly eventSource;
|
|
3152
|
+
private subscriptions;
|
|
3153
|
+
/**
|
|
3154
|
+
* Create a new EventSubscriptionManager
|
|
3155
|
+
*
|
|
3156
|
+
* @param eventSource - Source to subscribe to for events
|
|
3157
|
+
*/
|
|
3158
|
+
constructor(eventSource: EventSource<T>);
|
|
3159
|
+
/**
|
|
3160
|
+
* Subscribe to events with optional filtering
|
|
3161
|
+
*
|
|
3162
|
+
* @param handler - Callback function to invoke when matching events occur
|
|
3163
|
+
* @param filter - Optional filter options to narrow down which events trigger the handler
|
|
3164
|
+
* @returns Unsubscribe function to remove this specific subscription
|
|
3165
|
+
*
|
|
3166
|
+
* @example Subscribe to specific event type
|
|
3167
|
+
* ```typescript
|
|
3168
|
+
* const unsubscribe = manager.subscribe(
|
|
3169
|
+
* (event) => console.log('Progress:', event),
|
|
3170
|
+
* { eventType: 'UPLOAD_PROGRESS' }
|
|
3171
|
+
* );
|
|
3172
|
+
*
|
|
3173
|
+
* // Later, unsubscribe
|
|
3174
|
+
* unsubscribe();
|
|
3175
|
+
* ```
|
|
3176
|
+
*/
|
|
3177
|
+
subscribe(handler: SubscriptionEventHandler<T>, filter?: EventFilterOptions): UnsubscribeFunction;
|
|
3178
|
+
/**
|
|
3179
|
+
* Check if an event matches the filter criteria
|
|
3180
|
+
*
|
|
3181
|
+
* @param event - Event to check
|
|
3182
|
+
* @param filter - Filter options to apply
|
|
3183
|
+
* @returns True if the event passes all filters
|
|
3184
|
+
*/
|
|
3185
|
+
private shouldHandleEvent;
|
|
3186
|
+
/**
|
|
3187
|
+
* Get the number of active subscriptions
|
|
3188
|
+
*
|
|
3189
|
+
* @returns Number of tracked subscriptions
|
|
3190
|
+
*/
|
|
3191
|
+
getSubscriptionCount(): number;
|
|
3192
|
+
/**
|
|
3193
|
+
* Check if there are any active subscriptions
|
|
3194
|
+
*
|
|
3195
|
+
* @returns True if at least one subscription is active
|
|
3196
|
+
*/
|
|
3197
|
+
hasSubscriptions(): boolean;
|
|
3198
|
+
/**
|
|
3199
|
+
* Unsubscribe from all tracked subscriptions and clear the subscription list
|
|
3200
|
+
*
|
|
3201
|
+
* This is typically called when disposing of a component or cleaning up resources.
|
|
3202
|
+
*
|
|
3203
|
+
* @example Cleanup in framework hooks
|
|
3204
|
+
* ```typescript
|
|
3205
|
+
* // React
|
|
3206
|
+
* useEffect(() => {
|
|
3207
|
+
* const manager = new EventSubscriptionManager(eventSource);
|
|
3208
|
+
* manager.subscribe(handler, filter);
|
|
3209
|
+
*
|
|
3210
|
+
* return () => manager.cleanup();
|
|
3211
|
+
* }, []);
|
|
3212
|
+
*
|
|
3213
|
+
* // Vue
|
|
3214
|
+
* onUnmounted(() => {
|
|
3215
|
+
* manager.cleanup();
|
|
3216
|
+
* });
|
|
3217
|
+
* ```
|
|
3218
|
+
*/
|
|
3219
|
+
cleanup(): void;
|
|
3220
|
+
/**
|
|
3221
|
+
* Update the upload ID filter for all subscriptions that have an uploadId filter
|
|
3222
|
+
*
|
|
3223
|
+
* This is useful when the current upload changes and you want to update
|
|
3224
|
+
* all subscriptions to listen for the new upload's events.
|
|
3225
|
+
*
|
|
3226
|
+
* @param newUploadId - New upload ID to filter events by
|
|
3227
|
+
*
|
|
3228
|
+
* @example Update upload ID when starting new upload
|
|
3229
|
+
* ```typescript
|
|
3230
|
+
* const manager = new EventSubscriptionManager(eventSource);
|
|
3231
|
+
* manager.subscribe(onProgress, { eventType: 'UPLOAD_PROGRESS', uploadId: null });
|
|
3232
|
+
*
|
|
3233
|
+
* // When upload starts
|
|
3234
|
+
* manager.updateUploadIdFilter(uploadId);
|
|
3235
|
+
* ```
|
|
3236
|
+
*/
|
|
3237
|
+
updateUploadIdFilter(newUploadId: string | null): void;
|
|
3238
|
+
}
|
|
3239
|
+
//#endregion
|
|
3240
|
+
//#region src/managers/flow-manager.d.ts
|
|
3241
|
+
/**
|
|
3242
|
+
* Flow upload status representing the current state of a flow upload lifecycle.
|
|
3243
|
+
* Flow uploads progress through: idle → uploading → processing → success/error/aborted
|
|
3244
|
+
*/
|
|
3245
|
+
type FlowUploadStatus = "idle" | "uploading" | "processing" | "success" | "error" | "aborted";
|
|
3246
|
+
/**
|
|
3247
|
+
* Complete state information for a flow upload operation.
|
|
3248
|
+
* Tracks both the upload phase (file transfer) and processing phase (flow execution).
|
|
3249
|
+
*
|
|
3250
|
+
* @template TOutput - Type of the final output from the flow (defaults to UploadFile)
|
|
3251
|
+
*/
|
|
3252
|
+
interface FlowUploadState<TOutput = UploadFile> {
|
|
3253
|
+
/** Current upload status */
|
|
3254
|
+
status: FlowUploadStatus;
|
|
3255
|
+
/** Upload progress percentage (0-100) */
|
|
3256
|
+
progress: number;
|
|
3257
|
+
/** Number of bytes uploaded */
|
|
3258
|
+
bytesUploaded: number;
|
|
3259
|
+
/** Total bytes to upload, null if unknown */
|
|
3260
|
+
totalBytes: number | null;
|
|
3261
|
+
/** Error if upload or processing failed */
|
|
3262
|
+
error: Error | null;
|
|
3263
|
+
/** Final output from the flow (available when status is "success") */
|
|
3264
|
+
result: TOutput | null;
|
|
3265
|
+
/** Unique identifier for the flow execution job */
|
|
3266
|
+
jobId: string | null;
|
|
3267
|
+
/** Whether the flow processing has started */
|
|
3268
|
+
flowStarted: boolean;
|
|
3269
|
+
/** Name of the currently executing flow node */
|
|
3270
|
+
currentNodeName: string | null;
|
|
3271
|
+
/** Type of the currently executing flow node */
|
|
3272
|
+
currentNodeType: string | null;
|
|
3273
|
+
/**
|
|
3274
|
+
* Complete typed outputs from all output nodes in the flow.
|
|
3275
|
+
* Each output includes nodeId, optional nodeType, data, and timestamp.
|
|
3276
|
+
* Available when status is "success".
|
|
3277
|
+
*/
|
|
3278
|
+
flowOutputs: TypedOutput[] | null;
|
|
3279
|
+
}
|
|
3280
|
+
/**
|
|
3281
|
+
* Callbacks that FlowManager invokes during the flow upload lifecycle
|
|
3282
|
+
*/
|
|
3283
|
+
interface FlowManagerCallbacks<TOutput = UploadFile> {
|
|
3284
|
+
/**
|
|
3285
|
+
* Called when the flow upload state changes
|
|
3286
|
+
*/
|
|
3287
|
+
onStateChange: (state: FlowUploadState<TOutput>) => void;
|
|
3288
|
+
/**
|
|
3289
|
+
* Called when upload progress updates
|
|
3290
|
+
* @param progress - Progress percentage (0-100)
|
|
3291
|
+
* @param bytesUploaded - Number of bytes uploaded
|
|
3292
|
+
* @param totalBytes - Total bytes to upload, null if unknown
|
|
3293
|
+
*/
|
|
3294
|
+
onProgress?: (uploadId: string, bytesUploaded: number, totalBytes: number | null) => void;
|
|
3295
|
+
/**
|
|
3296
|
+
* Called when a chunk completes
|
|
3297
|
+
* @param chunkSize - Size of the completed chunk
|
|
3298
|
+
* @param bytesAccepted - Total bytes accepted so far
|
|
3299
|
+
* @param bytesTotal - Total bytes to upload, null if unknown
|
|
3300
|
+
*/
|
|
3301
|
+
onChunkComplete?: (chunkSize: number, bytesAccepted: number, bytesTotal: number | null) => void;
|
|
3302
|
+
/**
|
|
3303
|
+
* Called when the flow completes successfully (receives full flow outputs)
|
|
3304
|
+
* Each output includes nodeId, optional nodeType (e.g., "storage-output-v1"), data, and timestamp.
|
|
3305
|
+
*
|
|
3306
|
+
* @param outputs - Array of typed outputs from all output nodes
|
|
3307
|
+
*
|
|
3308
|
+
* @example
|
|
3309
|
+
* ```typescript
|
|
3310
|
+
* onFlowComplete: (outputs) => {
|
|
3311
|
+
* for (const output of outputs) {
|
|
3312
|
+
* console.log(`${output.nodeId} (${output.nodeType}):`, output.data);
|
|
3313
|
+
* }
|
|
3314
|
+
* }
|
|
3315
|
+
* ```
|
|
3316
|
+
*/
|
|
3317
|
+
onFlowComplete?: (outputs: TypedOutput[]) => void;
|
|
3318
|
+
/**
|
|
3319
|
+
* Called when upload succeeds (receives single extracted output)
|
|
3320
|
+
* For single-output flows, receives the value from the specified outputNodeId
|
|
3321
|
+
* or the first output node if outputNodeId is not specified
|
|
3322
|
+
*/
|
|
3323
|
+
onSuccess?: (result: TOutput) => void;
|
|
3324
|
+
/**
|
|
3325
|
+
* Called when upload or flow processing fails with an error
|
|
3326
|
+
* @param error - The error that occurred
|
|
3327
|
+
*/
|
|
3328
|
+
onError?: (error: Error) => void;
|
|
3329
|
+
/**
|
|
3330
|
+
* Called when upload or flow is aborted
|
|
3331
|
+
*/
|
|
3332
|
+
onAbort?: () => void;
|
|
3333
|
+
}
|
|
3334
|
+
/**
|
|
3335
|
+
* Generic flow upload input type - can be any value that the upload client accepts
|
|
3336
|
+
*/
|
|
3337
|
+
type FlowUploadInput = unknown;
|
|
3338
|
+
/**
|
|
3339
|
+
* Flow configuration for upload
|
|
3340
|
+
*/
|
|
3341
|
+
interface FlowConfig {
|
|
3342
|
+
flowId: string;
|
|
3343
|
+
storageId: string;
|
|
3344
|
+
outputNodeId?: string;
|
|
3345
|
+
metadata?: Record<string, string>;
|
|
3346
|
+
}
|
|
3347
|
+
/**
|
|
3348
|
+
* Abort and pause controller interface for canceling/pausing flow uploads
|
|
3349
|
+
*/
|
|
3350
|
+
interface FlowUploadAbortController {
|
|
3351
|
+
abort: () => void | Promise<void>;
|
|
3352
|
+
pause: () => void | Promise<void>;
|
|
3353
|
+
}
|
|
3354
|
+
/**
|
|
3355
|
+
* Internal upload options used by the flow upload function.
|
|
3356
|
+
* The upload phase always returns UploadFile, regardless of the final TOutput type.
|
|
3357
|
+
*/
|
|
3358
|
+
interface InternalFlowUploadOptions {
|
|
3359
|
+
onJobStart?: (jobId: string) => void;
|
|
3360
|
+
onProgress?: (uploadId: string, bytesUploaded: number, totalBytes: number | null) => void;
|
|
3361
|
+
onChunkComplete?: (chunkSize: number, bytesAccepted: number, bytesTotal: number | null) => void;
|
|
3362
|
+
onSuccess?: (result: UploadFile) => void;
|
|
3363
|
+
onError?: (error: Error) => void;
|
|
3364
|
+
onAbort?: () => void;
|
|
3365
|
+
onShouldRetry?: (error: Error, retryAttempt: number) => boolean;
|
|
3366
|
+
}
|
|
3367
|
+
/**
|
|
3368
|
+
* Flow upload function that performs the actual upload with flow processing.
|
|
3369
|
+
* Returns a promise that resolves to an abort controller with pause capability.
|
|
3370
|
+
*
|
|
3371
|
+
* Note: The upload phase onSuccess always receives UploadFile. The final TOutput
|
|
3372
|
+
* result comes from the flow execution and is handled via FlowEnd events.
|
|
3373
|
+
*/
|
|
3374
|
+
type FlowUploadFunction<TInput = FlowUploadInput> = (input: TInput, flowConfig: FlowConfig, options: InternalFlowUploadOptions) => Promise<FlowUploadAbortController>;
|
|
3375
|
+
/**
|
|
3376
|
+
* Platform-agnostic flow upload manager that handles flow upload state machine,
|
|
3377
|
+
* progress tracking, flow event handling, error handling, abort, pause, reset, and retry logic.
|
|
3378
|
+
*
|
|
3379
|
+
* Framework packages (React, Vue, React Native) should wrap this manager
|
|
3380
|
+
* with framework-specific hooks/composables.
|
|
3381
|
+
*
|
|
3382
|
+
* @example
|
|
3383
|
+
* ```typescript
|
|
3384
|
+
* const flowUploadFn = (input, options) => client.uploadWithFlow(input, options.flowConfig, options);
|
|
3385
|
+
* const manager = new FlowManager(flowUploadFn, {
|
|
3386
|
+
* onStateChange: (state) => setState(state),
|
|
3387
|
+
* onProgress: (progress, bytes, total) => console.log(`${progress}%`),
|
|
3388
|
+
* onSuccess: (result) => console.log('Flow complete:', result),
|
|
3389
|
+
* onError: (error) => console.error('Flow failed:', error),
|
|
3390
|
+
* }, {
|
|
3391
|
+
* flowConfig: { flowId: 'my-flow', storageId: 'storage1' }
|
|
3392
|
+
* });
|
|
3393
|
+
*
|
|
3394
|
+
* // Subscribe to events and forward them to the manager
|
|
3395
|
+
* const unsubscribe = client.subscribeToEvents((event) => {
|
|
3396
|
+
* if (isFlowEvent(event)) {
|
|
3397
|
+
* manager.handleFlowEvent(event);
|
|
3398
|
+
* } else if (isUploadProgress(event)) {
|
|
3399
|
+
* manager.handleUploadProgress(event);
|
|
3400
|
+
* }
|
|
3401
|
+
* });
|
|
3402
|
+
*
|
|
3403
|
+
* await manager.upload(file);
|
|
3404
|
+
* ```
|
|
3405
|
+
*/
|
|
3406
|
+
declare class FlowManager<TInput = FlowUploadInput, TOutput = UploadFile> {
|
|
3407
|
+
private readonly flowUploadFn;
|
|
3408
|
+
private readonly callbacks;
|
|
3409
|
+
private readonly options;
|
|
3410
|
+
private state;
|
|
3411
|
+
private abortController;
|
|
3412
|
+
/**
|
|
3413
|
+
* Create a new FlowManager
|
|
3414
|
+
*
|
|
3415
|
+
* @param flowUploadFn - Flow upload function to use for uploads
|
|
3416
|
+
* @param callbacks - Callbacks to invoke during flow upload lifecycle
|
|
3417
|
+
* @param options - Flow upload configuration options
|
|
3418
|
+
*/
|
|
3419
|
+
constructor(flowUploadFn: FlowUploadFunction<TInput>, callbacks: FlowManagerCallbacks<TOutput>, options: FlowUploadOptions<TOutput>);
|
|
3420
|
+
/**
|
|
3421
|
+
* Get the current flow upload state
|
|
3422
|
+
*/
|
|
3423
|
+
getState(): FlowUploadState<TOutput>;
|
|
3424
|
+
/**
|
|
3425
|
+
* Check if an upload or flow is currently active
|
|
3426
|
+
*/
|
|
3427
|
+
isUploading(): boolean;
|
|
3428
|
+
/**
|
|
3429
|
+
* Check if file upload is in progress
|
|
3430
|
+
*/
|
|
3431
|
+
isUploadingFile(): boolean;
|
|
3432
|
+
/**
|
|
3433
|
+
* Check if flow processing is in progress
|
|
3434
|
+
*/
|
|
3435
|
+
isProcessing(): boolean;
|
|
3436
|
+
/**
|
|
3437
|
+
* Get the current job ID
|
|
3438
|
+
*/
|
|
3439
|
+
getJobId(): string | null;
|
|
3440
|
+
/**
|
|
3441
|
+
* Update the internal state and notify callbacks
|
|
3442
|
+
*/
|
|
3443
|
+
private updateState;
|
|
3444
|
+
/**
|
|
3445
|
+
* Handle flow events from the event subscription
|
|
3446
|
+
* This method should be called by the framework wrapper when it receives flow events
|
|
3447
|
+
*
|
|
3448
|
+
* @param event - Flow event to process
|
|
3449
|
+
*/
|
|
3450
|
+
handleFlowEvent(event: FlowEvent): void;
|
|
3451
|
+
/**
|
|
3452
|
+
* Handle upload progress events from the event subscription
|
|
3453
|
+
* This method should be called by the framework wrapper when it receives upload progress events
|
|
3454
|
+
*
|
|
3455
|
+
* @param uploadId - The unique identifier for this upload
|
|
3456
|
+
* @param bytesUploaded - Number of bytes uploaded
|
|
3457
|
+
* @param totalBytes - Total bytes to upload, null if unknown
|
|
3458
|
+
*/
|
|
3459
|
+
handleUploadProgress(uploadId: string, bytesUploaded: number, totalBytes: number | null): void;
|
|
3460
|
+
/**
|
|
3461
|
+
* Start uploading a file through the flow
|
|
3462
|
+
*
|
|
3463
|
+
* @param input - File or input to upload (type depends on platform)
|
|
3464
|
+
*/
|
|
3465
|
+
upload(input: TInput): Promise<void>;
|
|
3466
|
+
/**
|
|
3467
|
+
* Abort the current flow upload
|
|
3468
|
+
*/
|
|
3469
|
+
abort(): void;
|
|
3470
|
+
/**
|
|
3471
|
+
* Pause the current flow upload
|
|
3472
|
+
*/
|
|
3473
|
+
pause(): void;
|
|
3474
|
+
/**
|
|
3475
|
+
* Reset the flow upload state to idle
|
|
3476
|
+
*/
|
|
3477
|
+
reset(): void;
|
|
3478
|
+
/**
|
|
3479
|
+
* Clean up resources (call when disposing the manager)
|
|
3480
|
+
*/
|
|
3481
|
+
cleanup(): void;
|
|
3482
|
+
}
|
|
3483
|
+
//#endregion
|
|
3484
|
+
//#region src/managers/upload-manager.d.ts
|
|
3485
|
+
/**
|
|
3486
|
+
* Upload status representing the current state of an upload
|
|
3487
|
+
*/
|
|
3488
|
+
type UploadStatus = "idle" | "uploading" | "success" | "error" | "aborted";
|
|
3489
|
+
/**
|
|
3490
|
+
* Complete upload state
|
|
3491
|
+
*/
|
|
3492
|
+
interface UploadState {
|
|
3493
|
+
/** Current status of the upload */
|
|
3494
|
+
status: UploadStatus;
|
|
3495
|
+
/** Upload progress percentage (0-100) */
|
|
3496
|
+
progress: number;
|
|
3497
|
+
/** Number of bytes uploaded */
|
|
3498
|
+
bytesUploaded: number;
|
|
3499
|
+
/** Total bytes to upload, null if unknown/deferred */
|
|
3500
|
+
totalBytes: number | null;
|
|
3501
|
+
/** Error if upload failed */
|
|
3502
|
+
error: Error | null;
|
|
3503
|
+
/** Result if upload succeeded */
|
|
3504
|
+
result: UploadFile | null;
|
|
3505
|
+
}
|
|
3506
|
+
/**
|
|
3507
|
+
* Callbacks that UploadManager invokes during the upload lifecycle
|
|
3508
|
+
*/
|
|
3509
|
+
interface UploadManagerCallbacks {
|
|
3510
|
+
/**
|
|
3511
|
+
* Called when the upload state changes
|
|
3512
|
+
*/
|
|
3513
|
+
onStateChange: (state: UploadState) => void;
|
|
3514
|
+
/**
|
|
3515
|
+
* Called when upload progress updates
|
|
3516
|
+
* @param uploadId - The unique identifier for this upload
|
|
3517
|
+
* @param bytesUploaded - Number of bytes uploaded
|
|
3518
|
+
* @param totalBytes - Total bytes to upload, null if unknown
|
|
3519
|
+
*/
|
|
3520
|
+
onProgress?: (uploadId: string, bytesUploaded: number, totalBytes: number | null) => void;
|
|
3521
|
+
/**
|
|
3522
|
+
* Called when a chunk completes
|
|
3523
|
+
* @param chunkSize - Size of the completed chunk
|
|
3524
|
+
* @param bytesAccepted - Total bytes accepted so far
|
|
3525
|
+
* @param bytesTotal - Total bytes to upload, null if unknown
|
|
3526
|
+
*/
|
|
3527
|
+
onChunkComplete?: (chunkSize: number, bytesAccepted: number, bytesTotal: number | null) => void;
|
|
3528
|
+
/**
|
|
3529
|
+
* Called when upload completes successfully
|
|
3530
|
+
* @param result - The uploaded file result
|
|
3531
|
+
*/
|
|
3532
|
+
onSuccess?: (result: UploadFile) => void;
|
|
3533
|
+
/**
|
|
3534
|
+
* Called when upload fails with an error
|
|
3535
|
+
* @param error - The error that occurred
|
|
3536
|
+
*/
|
|
3537
|
+
onError?: (error: Error) => void;
|
|
3538
|
+
/**
|
|
3539
|
+
* Called when upload is aborted
|
|
3540
|
+
*/
|
|
3541
|
+
onAbort?: () => void;
|
|
3542
|
+
}
|
|
3543
|
+
/**
|
|
3544
|
+
* Generic upload input type - can be any value that the upload client accepts
|
|
3545
|
+
*/
|
|
3546
|
+
type UploadInput = unknown;
|
|
3547
|
+
/**
|
|
3548
|
+
* Abort controller interface for canceling uploads
|
|
3549
|
+
*/
|
|
3550
|
+
interface UploadAbortController {
|
|
3551
|
+
abort: () => void;
|
|
3552
|
+
}
|
|
3553
|
+
/**
|
|
3554
|
+
* Upload function that performs the actual upload.
|
|
3555
|
+
* Returns a promise that resolves to an abort controller.
|
|
3556
|
+
*/
|
|
3557
|
+
type UploadFunction<TInput = UploadInput, TOptions extends UploadOptions = UploadOptions> = (input: TInput, options: TOptions) => Promise<UploadAbortController>;
|
|
3558
|
+
/**
|
|
3559
|
+
* Platform-agnostic upload manager that handles upload state machine,
|
|
3560
|
+
* progress tracking, error handling, abort, reset, and retry logic.
|
|
3561
|
+
*
|
|
3562
|
+
* Framework packages (React, Vue, React Native) should wrap this manager
|
|
3563
|
+
* with framework-specific hooks/composables.
|
|
3564
|
+
*
|
|
3565
|
+
* @example
|
|
3566
|
+
* ```typescript
|
|
3567
|
+
* const uploadFn = (input, options) => client.upload(input, options);
|
|
3568
|
+
* const manager = new UploadManager(uploadFn, {
|
|
3569
|
+
* onStateChange: (state) => setState(state),
|
|
3570
|
+
* onProgress: (progress) => console.log(`${progress}%`),
|
|
3571
|
+
* onSuccess: (result) => console.log('Upload complete:', result),
|
|
3572
|
+
* onError: (error) => console.error('Upload failed:', error),
|
|
3573
|
+
* });
|
|
3574
|
+
*
|
|
3575
|
+
* await manager.upload(file);
|
|
3576
|
+
* ```
|
|
3577
|
+
*/
|
|
3578
|
+
declare class UploadManager<TInput = UploadInput, TOptions extends UploadOptions = UploadOptions> {
|
|
3579
|
+
private readonly uploadFn;
|
|
3580
|
+
private readonly callbacks;
|
|
3581
|
+
private readonly options?;
|
|
3582
|
+
private state;
|
|
3583
|
+
private abortController;
|
|
3584
|
+
private lastInput;
|
|
3585
|
+
private uploadId;
|
|
3586
|
+
/**
|
|
3587
|
+
* Create a new UploadManager
|
|
3588
|
+
*
|
|
3589
|
+
* @param uploadFn - Upload function to use for uploads
|
|
3590
|
+
* @param callbacks - Callbacks to invoke during upload lifecycle
|
|
3591
|
+
* @param options - Upload configuration options
|
|
3592
|
+
*/
|
|
3593
|
+
constructor(uploadFn: UploadFunction<TInput, TOptions>, callbacks: UploadManagerCallbacks, options?: TOptions | undefined);
|
|
3594
|
+
/**
|
|
3595
|
+
* Get the current upload state
|
|
3596
|
+
*/
|
|
3597
|
+
getState(): UploadState;
|
|
3598
|
+
/**
|
|
3599
|
+
* Check if an upload is currently active
|
|
3600
|
+
*/
|
|
3601
|
+
isUploading(): boolean;
|
|
3602
|
+
/**
|
|
3603
|
+
* Check if the upload can be retried
|
|
3604
|
+
*/
|
|
3605
|
+
canRetry(): boolean;
|
|
3606
|
+
/**
|
|
3607
|
+
* Update the internal state and notify callbacks
|
|
3608
|
+
*/
|
|
3609
|
+
private updateState;
|
|
3610
|
+
/**
|
|
3611
|
+
* Start uploading a file or input
|
|
3612
|
+
*
|
|
3613
|
+
* @param input - File or input to upload (type depends on platform)
|
|
3614
|
+
*/
|
|
3615
|
+
upload(input: TInput): Promise<void>;
|
|
3616
|
+
/**
|
|
3617
|
+
* Abort the current upload
|
|
3618
|
+
*/
|
|
3619
|
+
abort(): void;
|
|
3620
|
+
/**
|
|
3621
|
+
* Reset the upload state to idle
|
|
3622
|
+
*/
|
|
3623
|
+
reset(): void;
|
|
3624
|
+
/**
|
|
3625
|
+
* Retry the last failed or aborted upload
|
|
3626
|
+
*/
|
|
3627
|
+
retry(): void;
|
|
3628
|
+
/**
|
|
3629
|
+
* Clean up resources (call when disposing the manager)
|
|
3630
|
+
*/
|
|
3631
|
+
cleanup(): void;
|
|
3632
|
+
}
|
|
3633
|
+
//#endregion
|
|
3634
|
+
export { AbortControllerFactory, AbortControllerLike, AbortSignalLike, Base64Service, ChecksumService, ChunkBuffer, ChunkBufferConfig, ChunkMetrics, ClientStorage, ConnectionHealth, ConnectionMetrics, ConnectionPoolConfig, DetailedConnectionMetrics, type EventFilterOptions, type EventSource, EventSubscriptionManager, FileReaderService, FileSource, FingerprintService, type FlowConfig, FlowManager, type FlowManagerCallbacks, FlowResponse, FlowResult, type FlowUploadAbortController, FlowUploadConfig, type FlowUploadFunction, type FlowUploadInput, FlowUploadItem, FlowUploadOptions, type FlowUploadState, type FlowUploadStatus, type GenericEvent, HeadersLike, Http2Info, HttpClient, HttpRequestOptions, HttpResponse, IdGenerationService, type InternalFlowUploadOptions, LogFunction, Logger, MultiFlowUploadOptions, MultiFlowUploadState, NetworkCondition, NetworkMetrics, NetworkMonitor, NetworkMonitorConfig, PerformanceInsights, PlatformService, PreviousUpload, RequestBody, ServiceContainer, SliceResult, StorageService, type SubscriptionEventHandler, Timeout, type UnsubscribeFunction, type UploadAbortController, type UploadFunction, type UploadInput, UploadManager, type UploadManagerCallbacks, UploadMetrics, UploadOptions, UploadResponse, UploadResult, UploadSample, UploadSessionMetrics, type UploadState, type UploadStatus, UploadistaApi, UploadistaClient, UploadistaClientOptions, UploadistaDeleteUploadResponse, UploadistaError, UploadistaErrorName, UploadistaEvent, UploadistaUploadOptions, UploadistaUploadResponse, UploadistaWebSocketEventHandler, UploadistaWebSocketManager, UploadistaWebSocketMessage, WebSocketEventMap, WebSocketFactory, WebSocketLike, createClientStorage, createInMemoryStorageService, createLogger, createUploadistaApi, createUploadistaClient, defaultConnectionPoolingConfig, previousUploadSchema, wait };
|
|
2696
3635
|
//# sourceMappingURL=index.d.mts.map
|