@trustgraph/react-state 1.5.2 → 1.5.3
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.cjs +548 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +548 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/state/chunked-download.d.ts +56 -0
- package/dist/state/chunked-download.d.ts.map +1 -0
- package/dist/state/chunked-upload.d.ts +84 -0
- package/dist/state/chunked-upload.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export type DownloadStatus = "idle" | "downloading" | "completed" | "error" | "cancelled";
|
|
2
|
+
export interface DownloadProgress {
|
|
3
|
+
/** Total number of chunks (known after first chunk arrives) */
|
|
4
|
+
totalChunks: number;
|
|
5
|
+
/** Number of chunks received */
|
|
6
|
+
chunksReceived: number;
|
|
7
|
+
/** Download percentage (0-100) */
|
|
8
|
+
percentage: number;
|
|
9
|
+
/** Current download status */
|
|
10
|
+
status: DownloadStatus;
|
|
11
|
+
/** Error message if status is 'error' */
|
|
12
|
+
error?: string;
|
|
13
|
+
/** Document ID being downloaded */
|
|
14
|
+
documentId?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ChunkedDownloadOptions {
|
|
17
|
+
/** Chunk size in bytes (default: 1MB) */
|
|
18
|
+
chunkSize?: number;
|
|
19
|
+
/** Progress callback for real-time updates */
|
|
20
|
+
onProgress?: (progress: DownloadProgress) => void;
|
|
21
|
+
/** Called when download completes with the Blob */
|
|
22
|
+
onComplete?: (blob: Blob, documentId: string) => void;
|
|
23
|
+
/** Called on error */
|
|
24
|
+
onError?: (error: string) => void;
|
|
25
|
+
}
|
|
26
|
+
export interface DownloadParams {
|
|
27
|
+
/** Document ID to download */
|
|
28
|
+
documentId: string;
|
|
29
|
+
/** Optional MIME type for the resulting Blob (default: application/octet-stream) */
|
|
30
|
+
mimeType?: string;
|
|
31
|
+
/** Optional filename for browser download (if not provided, returns Blob only) */
|
|
32
|
+
filename?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Hook for managing streamed document downloads with progress tracking
|
|
36
|
+
*
|
|
37
|
+
* Features:
|
|
38
|
+
* - Streams large documents via WebSocket streaming response
|
|
39
|
+
* - Progress tracking (chunks received, percentage)
|
|
40
|
+
* - Cancel support
|
|
41
|
+
* - Returns Blob or triggers browser download
|
|
42
|
+
*
|
|
43
|
+
* @param options - Configuration options for the download
|
|
44
|
+
* @returns Download state and control methods
|
|
45
|
+
*/
|
|
46
|
+
export declare const useChunkedDownload: (options?: ChunkedDownloadOptions) => {
|
|
47
|
+
progress: DownloadProgress;
|
|
48
|
+
download: (params: DownloadParams) => Promise<Blob | null>;
|
|
49
|
+
cancel: () => void;
|
|
50
|
+
reset: () => void;
|
|
51
|
+
isIdle: boolean;
|
|
52
|
+
isDownloading: boolean;
|
|
53
|
+
isCompleted: boolean;
|
|
54
|
+
isError: boolean;
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=chunked-download.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunked-download.d.ts","sourceRoot":"","sources":["../../src/state/chunked-download.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,cAAc,GACtB,MAAM,GACN,aAAa,GACb,WAAW,GACX,OAAO,GACP,WAAW,CAAC;AAEhB,MAAM,WAAW,gBAAgB;IAC/B,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,8BAA8B;IAC9B,MAAM,EAAE,cAAc,CAAC;IACvB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,sBAAsB;IACrC,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8CAA8C;IAC9C,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAClD,mDAAmD;IACnD,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IACtD,sBAAsB;IACtB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,cAAc;IAC7B,8BAA8B;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,oFAAoF;IACpF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kFAAkF;IAClF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AA4BD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAS,sBAA2B;;uBAwC1D,cAAc,KAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;;;;;;;CA2JjD,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export type UploadStatus = "idle" | "preparing" | "uploading" | "paused" | "completing" | "completed" | "error" | "cancelled";
|
|
2
|
+
export interface UploadProgress {
|
|
3
|
+
/** Total bytes to upload */
|
|
4
|
+
totalBytes: number;
|
|
5
|
+
/** Bytes uploaded so far */
|
|
6
|
+
bytesUploaded: number;
|
|
7
|
+
/** Upload percentage (0-100) */
|
|
8
|
+
percentage: number;
|
|
9
|
+
/** Total number of chunks */
|
|
10
|
+
totalChunks: number;
|
|
11
|
+
/** Number of chunks uploaded */
|
|
12
|
+
chunksUploaded: number;
|
|
13
|
+
/** Indices of chunks still pending */
|
|
14
|
+
pendingChunks: number[];
|
|
15
|
+
/** Current upload status */
|
|
16
|
+
status: UploadStatus;
|
|
17
|
+
/** Error message if status is 'error' */
|
|
18
|
+
error?: string;
|
|
19
|
+
/** Upload ID from server (for resume) */
|
|
20
|
+
uploadId?: string;
|
|
21
|
+
/** Document ID after completion */
|
|
22
|
+
documentId?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ChunkedUploadOptions {
|
|
25
|
+
/** Chunk size in bytes (default: 5MB) */
|
|
26
|
+
chunkSize?: number;
|
|
27
|
+
/** Number of parallel chunk uploads (default: 3) */
|
|
28
|
+
parallelUploads?: number;
|
|
29
|
+
/** Progress callback for real-time updates */
|
|
30
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
31
|
+
/** Called when upload completes successfully */
|
|
32
|
+
onComplete?: (documentId: string) => void;
|
|
33
|
+
/** Called on error */
|
|
34
|
+
onError?: (error: string) => void;
|
|
35
|
+
}
|
|
36
|
+
export interface ChunkedUploadParams {
|
|
37
|
+
/** File to upload */
|
|
38
|
+
file: File;
|
|
39
|
+
/** Document title */
|
|
40
|
+
title: string;
|
|
41
|
+
/** Optional comments/description */
|
|
42
|
+
comments?: string;
|
|
43
|
+
/** Optional tags for categorization */
|
|
44
|
+
tags?: string[];
|
|
45
|
+
/** Optional collection name */
|
|
46
|
+
collection?: string;
|
|
47
|
+
/** Optional document ID (auto-generated if not provided) */
|
|
48
|
+
documentId?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ResumeUploadParams {
|
|
51
|
+
/** Upload ID from a previous session */
|
|
52
|
+
uploadId: string;
|
|
53
|
+
/** File to resume uploading (must match original) */
|
|
54
|
+
file: File;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Hook for managing chunked document uploads with progress tracking
|
|
58
|
+
*
|
|
59
|
+
* Features:
|
|
60
|
+
* - Automatic chunking of large files
|
|
61
|
+
* - Parallel chunk uploads for performance
|
|
62
|
+
* - Progress tracking (bytes, percentage, chunks)
|
|
63
|
+
* - Pause/resume support
|
|
64
|
+
* - Cancel support
|
|
65
|
+
* - Resumability after interruption
|
|
66
|
+
*
|
|
67
|
+
* @param options - Configuration options for the upload
|
|
68
|
+
* @returns Upload state and control methods
|
|
69
|
+
*/
|
|
70
|
+
export declare const useChunkedUpload: (options?: ChunkedUploadOptions) => {
|
|
71
|
+
progress: UploadProgress;
|
|
72
|
+
upload: (params: ChunkedUploadParams) => Promise<string | null>;
|
|
73
|
+
resume: (params: ResumeUploadParams) => Promise<string | null>;
|
|
74
|
+
pause: () => void;
|
|
75
|
+
unpause: () => void;
|
|
76
|
+
cancel: () => Promise<void>;
|
|
77
|
+
reset: () => void;
|
|
78
|
+
isIdle: boolean;
|
|
79
|
+
isUploading: boolean;
|
|
80
|
+
isPaused: boolean;
|
|
81
|
+
isCompleted: boolean;
|
|
82
|
+
isError: boolean;
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=chunked-upload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunked-upload.d.ts","sourceRoot":"","sources":["../../src/state/chunked-upload.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,WAAW,GACX,WAAW,GACX,QAAQ,GACR,YAAY,GACZ,WAAW,GACX,OAAO,GACP,WAAW,CAAC;AAEhB,MAAM,WAAW,cAAc;IAC7B,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,4BAA4B;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,sCAAsC;IACtC,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,4BAA4B;IAC5B,MAAM,EAAE,YAAY,CAAC;IACrB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,yCAAyC;IACzC,SAA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