@wlindabla/file_uploader 1.0.0 → 2.0.0

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.
Files changed (109) hide show
  1. package/README.md +51 -20
  2. package/dist/cjs/cache/index.d.ts +198 -0
  3. package/dist/cjs/cache/index.js +318 -0
  4. package/dist/cjs/cache/index.js.map +1 -0
  5. package/dist/cjs/core/index.d.ts +267 -0
  6. package/dist/cjs/core/index.js +753 -0
  7. package/dist/cjs/core/index.js.map +1 -0
  8. package/dist/cjs/events/chunk/index.d.ts +27 -0
  9. package/dist/cjs/events/chunk/index.js +70 -0
  10. package/dist/cjs/events/chunk/index.js.map +1 -0
  11. package/dist/cjs/events/complete/index.d.ts +63 -0
  12. package/dist/cjs/events/complete/index.js +152 -0
  13. package/dist/cjs/events/complete/index.js.map +1 -0
  14. package/dist/cjs/events/index.d.ts +94 -0
  15. package/dist/cjs/events/index.js +85 -0
  16. package/dist/cjs/events/index.js.map +1 -0
  17. package/dist/cjs/events/initialize/index.d.ts +45 -0
  18. package/dist/cjs/events/initialize/index.js +105 -0
  19. package/dist/cjs/events/initialize/index.js.map +1 -0
  20. package/dist/cjs/events/state/index.d.ts +67 -0
  21. package/dist/cjs/events/state/index.js +145 -0
  22. package/dist/cjs/events/state/index.js.map +1 -0
  23. package/dist/cjs/exceptions/index.d.ts +84 -0
  24. package/dist/{exceptions → cjs/exceptions}/index.js +38 -18
  25. package/dist/cjs/exceptions/index.js.map +1 -0
  26. package/dist/cjs/index.d.ts +13 -0
  27. package/dist/cjs/index.js +33 -0
  28. package/dist/cjs/index.js.map +1 -0
  29. package/dist/cjs/subscribers/index.d.ts +33 -0
  30. package/dist/cjs/subscribers/index.js +187 -0
  31. package/dist/cjs/subscribers/index.js.map +1 -0
  32. package/dist/cjs/types/index.d.ts +110 -0
  33. package/dist/cjs/types/index.js +53 -0
  34. package/dist/cjs/types/index.js.map +1 -0
  35. package/dist/cjs/utils/index.d.ts +72 -0
  36. package/dist/cjs/utils/index.js +208 -0
  37. package/dist/cjs/utils/index.js.map +1 -0
  38. package/dist/esm/cache/index.d.mts +198 -0
  39. package/dist/esm/cache/index.js +4 -0
  40. package/dist/{index.js.map → esm/cache/index.js.map} +1 -1
  41. package/dist/{subscribers/index.js → esm/chunk-332NNKOW.js} +36 -34
  42. package/dist/esm/chunk-332NNKOW.js.map +1 -0
  43. package/dist/{events/state/index.js → esm/chunk-6225YMFE.js} +38 -20
  44. package/dist/esm/chunk-6225YMFE.js.map +1 -0
  45. package/dist/{core/index.js → esm/chunk-6DIKDA6J.js} +226 -227
  46. package/dist/esm/chunk-6DIKDA6J.js.map +1 -0
  47. package/dist/esm/chunk-7QVYU63E.js +6 -0
  48. package/dist/esm/chunk-7QVYU63E.js.map +1 -0
  49. package/dist/{events/initialize/index.js → esm/chunk-DN5B6PRW.js} +25 -19
  50. package/dist/esm/chunk-DN5B6PRW.js.map +1 -0
  51. package/dist/{events/index.js → esm/chunk-JDL3U4OX.js} +7 -37
  52. package/dist/esm/chunk-JDL3U4OX.js.map +1 -0
  53. package/dist/{events/chunk/index.js → esm/chunk-LD2DWZRJ.js} +14 -11
  54. package/dist/esm/chunk-LD2DWZRJ.js.map +1 -0
  55. package/dist/{events/complete/index.js → esm/chunk-LTYMA4U4.js} +25 -19
  56. package/dist/{events/complete/index.js.map → esm/chunk-LTYMA4U4.js.map} +1 -1
  57. package/dist/{utils/index.js → esm/chunk-MFYC4PBP.js} +15 -22
  58. package/dist/esm/chunk-MFYC4PBP.js.map +1 -0
  59. package/dist/esm/chunk-NXYS73I4.js +125 -0
  60. package/dist/esm/chunk-NXYS73I4.js.map +1 -0
  61. package/dist/{cache/index.js → esm/chunk-PFALORWQ.js} +10 -11
  62. package/dist/esm/chunk-PFALORWQ.js.map +1 -0
  63. package/dist/{types/index.js → esm/chunk-X757PBC5.js} +5 -7
  64. package/dist/esm/chunk-X757PBC5.js.map +1 -0
  65. package/dist/esm/core/index.d.mts +267 -0
  66. package/dist/esm/core/index.js +12 -0
  67. package/dist/esm/core/index.js.map +1 -0
  68. package/dist/esm/events/chunk/index.d.mts +27 -0
  69. package/dist/esm/events/chunk/index.js +4 -0
  70. package/dist/esm/events/chunk/index.js.map +1 -0
  71. package/dist/esm/events/complete/index.d.mts +63 -0
  72. package/dist/esm/events/complete/index.js +4 -0
  73. package/dist/esm/events/complete/index.js.map +1 -0
  74. package/dist/esm/events/index.d.mts +94 -0
  75. package/dist/esm/events/index.js +8 -0
  76. package/dist/esm/events/index.js.map +1 -0
  77. package/dist/esm/events/initialize/index.d.mts +45 -0
  78. package/dist/esm/events/initialize/index.js +4 -0
  79. package/dist/esm/events/initialize/index.js.map +1 -0
  80. package/dist/esm/events/state/index.d.mts +67 -0
  81. package/dist/esm/events/state/index.js +4 -0
  82. package/dist/esm/events/state/index.js.map +1 -0
  83. package/dist/esm/exceptions/index.d.mts +84 -0
  84. package/dist/esm/exceptions/index.js +4 -0
  85. package/dist/esm/exceptions/index.js.map +1 -0
  86. package/dist/esm/index.d.mts +13 -0
  87. package/dist/esm/index.js +14 -0
  88. package/dist/esm/index.js.map +1 -0
  89. package/dist/esm/subscribers/index.d.mts +33 -0
  90. package/dist/esm/subscribers/index.js +10 -0
  91. package/dist/esm/subscribers/index.js.map +1 -0
  92. package/dist/esm/types/index.d.mts +110 -0
  93. package/dist/esm/types/index.js +4 -0
  94. package/dist/esm/types/index.js.map +1 -0
  95. package/dist/esm/utils/index.d.mts +72 -0
  96. package/dist/esm/utils/index.js +5 -0
  97. package/dist/esm/utils/index.js.map +1 -0
  98. package/package.json +165 -14
  99. package/dist/cache/index.js.map +0 -1
  100. package/dist/core/index.js.map +0 -1
  101. package/dist/events/chunk/index.js.map +0 -1
  102. package/dist/events/index.js.map +0 -1
  103. package/dist/events/initialize/index.js.map +0 -1
  104. package/dist/events/state/index.js.map +0 -1
  105. package/dist/exceptions/index.js.map +0 -1
  106. package/dist/index.js +0 -49
  107. package/dist/subscribers/index.js.map +0 -1
  108. package/dist/types/index.js.map +0 -1
  109. package/dist/utils/index.js.map +0 -1
@@ -0,0 +1,125 @@
1
+ import { __name } from './chunk-7QVYU63E.js';
2
+
3
+ // src/exceptions/index.ts
4
+ var InitializeUploadFailureException = class _InitializeUploadFailureException extends Error {
5
+ constructor(responseData, message) {
6
+ super(message);
7
+ this.responseData = responseData;
8
+ this.name = "InitializeUploadFailureException";
9
+ if (Error.captureStackTrace) {
10
+ Error.captureStackTrace(this, _InitializeUploadFailureException);
11
+ }
12
+ }
13
+ responseData;
14
+ static {
15
+ __name(this, "InitializeUploadFailureException");
16
+ }
17
+ };
18
+ var ChunkUploadHttpErrorException = class _ChunkUploadHttpErrorException extends Error {
19
+ constructor(errorPayload, statusResponse) {
20
+ super();
21
+ this.errorPayload = errorPayload;
22
+ this.statusResponse = statusResponse;
23
+ this.name = "ChunkUploadHttpErrorException";
24
+ if (Error.captureStackTrace) {
25
+ Error.captureStackTrace(this, _ChunkUploadHttpErrorException);
26
+ }
27
+ }
28
+ errorPayload;
29
+ statusResponse;
30
+ static {
31
+ __name(this, "ChunkUploadHttpErrorException");
32
+ }
33
+ };
34
+ var FileUploadChunkError = class _FileUploadChunkError extends Error {
35
+ static {
36
+ __name(this, "FileUploadChunkError");
37
+ }
38
+ /**
39
+ * The detailed chunk error information
40
+ */
41
+ chunkError;
42
+ /**
43
+ * Creates a new FileUploadChunkError
44
+ *
45
+ * @param message - Human-readable error message
46
+ * @param chunkError - Detailed information about the chunk failure
47
+ */
48
+ constructor(message, chunkError) {
49
+ super(message, { cause: chunkError.error });
50
+ this.name = "FileUploadChunkError";
51
+ this.chunkError = chunkError;
52
+ if (Error.captureStackTrace) {
53
+ Error.captureStackTrace(this, _FileUploadChunkError);
54
+ }
55
+ }
56
+ /**
57
+ * Gets the index of the chunk that failed
58
+ */
59
+ get chunkIndex() {
60
+ return this.chunkError.chunk.index;
61
+ }
62
+ /**
63
+ * Gets the attempt number when the chunk failed
64
+ */
65
+ get attemptNumber() {
66
+ return this.chunkError.attempt;
67
+ }
68
+ /**
69
+ * Indicates whether a retry will be attempted
70
+ */
71
+ get willRetry() {
72
+ return this.chunkError.willRetry;
73
+ }
74
+ /**
75
+ * Gets the underlying error that caused the chunk upload to fail
76
+ */
77
+ get underlyingError() {
78
+ return this.chunkError.error;
79
+ }
80
+ /**
81
+ * Gets the full chunk information
82
+ */
83
+ get chunk() {
84
+ return this.chunkError.chunk;
85
+ }
86
+ /**
87
+ * Returns a JSON representation of the error
88
+ */
89
+ toJSON() {
90
+ return {
91
+ name: this.name,
92
+ message: this.message,
93
+ chunkIndex: this.chunkIndex,
94
+ attempt: this.attemptNumber,
95
+ willRetry: this.willRetry,
96
+ underlyingError: {
97
+ name: this.underlyingError.name,
98
+ message: this.underlyingError.message
99
+ },
100
+ stack: this.stack
101
+ };
102
+ }
103
+ };
104
+ var UploadCancelledException = class _UploadCancelledException extends Error {
105
+ constructor(chunkIndex, totalChunks, uploadedBytes, message) {
106
+ super(message);
107
+ this.chunkIndex = chunkIndex;
108
+ this.totalChunks = totalChunks;
109
+ this.uploadedBytes = uploadedBytes;
110
+ this.name = "UploadCancelledException";
111
+ if (Error.captureStackTrace) {
112
+ Error.captureStackTrace(this, _UploadCancelledException);
113
+ }
114
+ }
115
+ chunkIndex;
116
+ totalChunks;
117
+ uploadedBytes;
118
+ static {
119
+ __name(this, "UploadCancelledException");
120
+ }
121
+ };
122
+
123
+ export { ChunkUploadHttpErrorException, FileUploadChunkError, InitializeUploadFailureException, UploadCancelledException };
124
+ //# sourceMappingURL=chunk-NXYS73I4.js.map
125
+ //# sourceMappingURL=chunk-NXYS73I4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/exceptions/index.ts"],"names":[],"mappings":";;;AAaO,IAAM,gCAAA,GAAN,MAAM,iCAAA,SAAyC,KAAA,CAAM;AAAA,EACxD,WAAA,CAA4B,cAAmB,OAAA,EAAiB;AAC5D,IAAA,KAAA,CAAM,OAAO,CAAA;AADW,IAAA,IAAA,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A,UAAA;AACA,IAAA,IAAA,CAAA,WAAA,GAAA,WAAA;AACA,IAAA,IAAA,CAAA,aAAA,GAAA,aAAA;AAIhB,IAAA,IAAA,CAAK,IAAA,GAAO,0BAAA;AAEZ,IAAA,IAAI,MAAM,iBAAA,EAAmB;AACzB,MAAA,KAAA,CAAM,iBAAA,CAAkB,MAAM,yBAAwB,CAAA;AAAA,IAC1D;AAAA,EACJ;AAAA,EAXoB,UAAA;AAAA,EACA,WAAA;AAAA,EACA,aAAA;AAAA,EAtJxB;AAkJoD,IAAA,MAAA,CAAA,IAAA,EAAA,0BAAA,CAAA;AAAA;AAcpD","file":"chunk-NXYS73I4.js","sourcesContent":["/*\n * This file is part of the project by AGBOKOUDJO Franck.\n *\n * (c) AGBOKOUDJO Franck <internationaleswebservices@gmail.com>\n * Phone: +229 0167 25 18 86\n * LinkedIn: https://www.linkedin.com/in/internationales-web-apps-services-120520193/\n * Company: INTERNATIONALES WEB APPS & SERVICES\n *\n * For more information, please feel free to contact the author.\n */\n\nimport { ChunkInfo, ChunkError } from \"../types\";\n\nexport class InitializeUploadFailureException extends Error {\n constructor(public readonly responseData: any, message: string) {\n super(message);\n this.name = \"InitializeUploadFailureException\";\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, InitializeUploadFailureException);\n }\n }\n}\n\n/**\n * Exception data for MEDIA_CHUNK_UPLOAD_HTTP_ERROR_RESPONSE\n */\nexport class ChunkUploadHttpErrorException extends Error {\n constructor(\n public readonly errorPayload: string | Record<string, string | unknown> | unknown,\n public readonly statusResponse: number\n ) {\n super();\n\n this.name = \"ChunkUploadHttpErrorException\";\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, ChunkUploadHttpErrorException);\n }\n }\n}\n\n/**\n * Custom error thrown during chunked file upload operations.\n * \n * This error provides detailed information about which chunk failed,\n * the underlying error, and whether a retry will be attempted.\n * \n * @example\n * ```typescript\n * try {\n * await uploadChunk(chunk);\n * } catch (error) {\n * throw new FileUploadChunkError(\n * `Failed to upload chunk ${chunkIndex}`,\n * chunkError\n * );\n * }\n * \n * // Later in error handler\n * if (error instanceof FileUploadChunkError) {\n * console.log(`Chunk ${error.chunkIndex} failed`);\n * console.log(`Will retry: ${error.willRetry}`);\n * }\n * ```\n */\nexport class FileUploadChunkError extends Error {\n\n /**\n * The detailed chunk error information\n */\n public readonly chunkError: ChunkError;\n\n /**\n * Creates a new FileUploadChunkError\n * \n * @param message - Human-readable error message\n * @param chunkError - Detailed information about the chunk failure\n */\n constructor(message: string, chunkError: ChunkError) {\n super(message, { cause: chunkError.error });\n\n this.name = \"FileUploadChunkError\";\n this.chunkError = chunkError;\n\n // Maintain proper stack trace in V8 engines (Chrome, Node.js)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, FileUploadChunkError);\n }\n }\n\n /**\n * Gets the index of the chunk that failed\n */\n get chunkIndex(): number {\n return this.chunkError.chunk.index;\n }\n\n /**\n * Gets the attempt number when the chunk failed\n */\n get attemptNumber(): number {\n return this.chunkError.attempt;\n }\n\n /**\n * Indicates whether a retry will be attempted\n */\n get willRetry(): boolean {\n return this.chunkError.willRetry;\n }\n\n /**\n * Gets the underlying error that caused the chunk upload to fail\n */\n get underlyingError(): Error {\n return this.chunkError.error;\n }\n\n /**\n * Gets the full chunk information\n */\n get chunk(): ChunkInfo {\n return this.chunkError.chunk;\n }\n \n /**\n * Returns a JSON representation of the error\n */\n toJSON(): object {\n return {\n name: this.name,\n message: this.message,\n chunkIndex: this.chunkIndex,\n attempt: this.attemptNumber,\n willRetry: this.willRetry,\n underlyingError: {\n name: this.underlyingError.name,\n message: this.underlyingError.message\n },\n stack: this.stack\n };\n }\n}\n\n\nexport class UploadCancelledException extends Error {\n constructor(\n public readonly chunkIndex: number,\n public readonly totalChunks: number,\n public readonly uploadedBytes: number,\n message: string\n ) {\n super(message);\n this.name = \"UploadCancelledException\";\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, UploadCancelledException);\n }\n }\n}"]}
@@ -1,8 +1,7 @@
1
- 'use strict';
1
+ import { __name } from './chunk-7QVYU63E.js';
2
2
 
3
- var __defProp = Object.defineProperty;
4
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
- class DefaultUploadResumeCacheAdapter {
3
+ // src/cache/index.ts
4
+ var DefaultUploadResumeCacheAdapter = class {
6
5
  static {
7
6
  __name(this, "DefaultUploadResumeCacheAdapter");
8
7
  }
@@ -277,19 +276,19 @@ class DefaultUploadResumeCacheAdapter {
277
276
  get usage() {
278
277
  return this.cache.size / this.maxCacheSize * 100;
279
278
  }
280
- }
281
- class UploadCacheError extends Error {
279
+ };
280
+ var UploadCacheError = class extends Error {
282
281
  constructor(message, code) {
283
282
  super(message);
284
283
  this.code = code;
285
284
  this.name = "UploadCacheError";
286
285
  }
286
+ code;
287
287
  static {
288
288
  __name(this, "UploadCacheError");
289
289
  }
290
- }
290
+ };
291
291
 
292
- exports.DefaultUploadResumeCacheAdapter = DefaultUploadResumeCacheAdapter;
293
- exports.UploadCacheError = UploadCacheError;
294
- //# sourceMappingURL=index.js.map
295
- //# sourceMappingURL=index.js.map
292
+ export { DefaultUploadResumeCacheAdapter, UploadCacheError };
293
+ //# sourceMappingURL=chunk-PFALORWQ.js.map
294
+ //# sourceMappingURL=chunk-PFALORWQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/cache/index.ts"],"names":[],"mappings":";;;AA+FO,IAAM,kCAAN,MAA4E;AAAA,EA/FnF;AA+FmF,IAAA,MAAA,CAAA,IAAA,EAAA,iCAAA,CAAA;AAAA;AAAA,EAEvE,KAAA,uBAAqC,GAAA,EAAI;AAAA,EAChC,YAAA,GAAuB,GAAA;AAAA,EAExC,WAAA,GAAc;AACV,IAAA,IAAA,CAAK,mBAAA,EAAoB;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,mBAAA,GAA4B;AAChC,IAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AAC/B,MAAA,OAAA,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AAK,IAAA,GAAO,kBAAA;AAAA,EAChB;AAAA,EAJoB,IAAA;AAAA,EAjaxB;AA8Z4C,IAAA,MAAA,CAAA,IAAA,EAAA,kBAAA,CAAA;AAAA;AAQ5C","file":"chunk-PFALORWQ.js","sourcesContent":["/*\n * This file is part of the project by AGBOKOUDJO Franck.\n *\n * (c) AGBOKOUDJO Franck <internationaleswebservices@gmail.com>\n * Phone: +229 0167 25 18 86\n * LinkedIn: https://www.linkedin.com/in/internationales-web-apps-services-120520193/\n * Company: INTERNATIONALES WEB APPS & SERVICES\n *\n * For more information, please feel free to contact the author.\n */\n\nimport { ResumeData } from \"../types\"\n\n/**\n * Interface for caching upload resume data.\n * \n * This interface extends the base cache functionality to specifically\n * handle resume data for file uploads, allowing uploads to be paused\n * and resumed across browser sessions.\n * \n * \n * @example\n * ```typescript\n * const cache: UploadResumeCacheInterface = new LocalStorageUploadResumeCache();\n * \n * // Save progress\n * await cache.setItem('video.mp4', {\n * uploadedChunks: 45,\n * totalChunks: 100,\n * lastBytePosition: 47185920\n * });\n * \n * // Resume later\n * const data = await cache.getItem('video.mp4');\n * console.log(`Resume from chunk ${data.uploadedChunks}`);\n * ```\n */\nexport interface UploadResumeCacheInterface {\n /**\n * Retrieves cached resume data for a specific upload.\n * \n * @param key - Unique identifier for the upload (typically filename or file hash)\n * @returns Promise resolving to the cached resume data\n * @throws {Error} If the key doesn't exist or data is corrupted\n */\n getItem(key: string): Promise<ResumeData>;\n\n /**\n * Stores resume data for an upload session.\n * \n * @param key - Unique identifier for the upload\n * @param data - Resume data containing upload progress information\n * @returns Promise that resolves when data is successfully cached\n * @throws {Error} If storage quota is exceeded or data is invalid\n */\n setItem(key: string, data: ResumeData): Promise<void>;\n}\n\n/**\n * Default adapter for caching resume data during file uploads.\n * \n * Implements an in-memory storage strategy with secure serialization,\n * strict data validation, and comprehensive error handling.\n * \n * This implementation serves as a foundation for specialized adapters\n * (localStorage, IndexedDB, sessionStorage, etc.).\n * \n * @implements {UploadResumeCacheInterface}\n * \n * @example\n * ```typescript\n * const adapter = new DefaultUploadResumeCacheAdapter();\n * \n * // Save resume data\n * await adapter.setItem('upload-123', {\n * fileId: 'file-abc',\n * fileName: 'document.pdf',\n * fileSize: 5242880,\n * uploadedChunks: 12,\n * lastChunkIndex: 11,\n * lastBytePosition: 1258291,\n * chunkSize: 1048576\n * });\n * \n * // Retrieve and resume\n * const resumeData = await adapter.getItem('upload-123');\n * console.log(`Resume from chunk ${resumeData.uploadedChunks}`);\n * \n * // Remove specific item\n * await adapter.removeItem('upload-123');\n * \n * // Clear all cache\n * await adapter.clear();\n * ```\n */\nexport class DefaultUploadResumeCacheAdapter implements UploadResumeCacheInterface {\n\n private cache: Map<string, ResumeData> = new Map();\n private readonly maxCacheSize: number = 100;\n\n constructor() {\n this.validateEnvironment();\n }\n\n /**\n * Validates that the runtime environment is appropriate.\n * \n * @private\n * @throws {UploadCacheError} If the environment is incompatible\n */\n private validateEnvironment(): void {\n if (typeof window === 'undefined') {\n console.warn(\n '[UploadResumeCacheAdapter] Server-side execution detected. ' +\n 'Consider a server-compatible adapter for persistent storage.'\n );\n }\n }\n\n /**\n * Validates resume data according to strict criteria.\n * \n * @private\n * @param data - The data to validate\n * @throws {UploadCacheError} If the data is invalid\n */\n private validateResumeData(data: ResumeData): void {\n if (!data || typeof data !== 'object') {\n throw new UploadCacheError(\n 'Resume data must be a valid object',\n 'INVALID_DATA'\n );\n }\n\n // Validate required fields\n const requiredFields: (keyof ResumeData)[] = [\n 'fileId',\n 'fileName',\n 'fileSize',\n 'uploadedChunks',\n 'lastChunkIndex',\n 'lastBytePosition',\n 'chunkSize'\n ];\n\n for (const field of requiredFields) {\n if (!(field in data)) {\n throw new UploadCacheError(\n `Required field '${field}' is missing`,\n 'MISSING_FIELD'\n );\n }\n }\n\n // Validate types\n if (typeof data.fileId !== 'string' || !data.fileId.trim()) {\n throw new UploadCacheError(\n 'fileId must be a non-empty string',\n 'INVALID_FILE_ID'\n );\n }\n\n if (typeof data.fileName !== 'string' || !data.fileName.trim()) {\n throw new UploadCacheError(\n 'fileName must be a non-empty string',\n 'INVALID_FILE_NAME'\n );\n }\n\n // Validate numbers\n if (!Number.isFinite(data.fileSize) || data.fileSize <= 0) {\n throw new UploadCacheError(\n 'fileSize must be a positive number',\n 'INVALID_FILE_SIZE'\n );\n }\n\n if (!Number.isFinite(data.chunkSize) || data.chunkSize <= 0) {\n throw new UploadCacheError(\n 'chunkSize must be a positive number',\n 'INVALID_CHUNK_SIZE'\n );\n }\n\n if (!Number.isInteger(data.uploadedChunks) || data.uploadedChunks < 0) {\n throw new UploadCacheError(\n 'uploadedChunks must be a non-negative integer',\n 'INVALID_UPLOADED_CHUNKS'\n );\n }\n\n if (!Number.isInteger(data.lastChunkIndex) || data.lastChunkIndex < -1) {\n throw new UploadCacheError(\n 'lastChunkIndex must be an integer >= -1',\n 'INVALID_LAST_CHUNK_INDEX'\n );\n }\n\n if (!Number.isFinite(data.lastBytePosition) || data.lastBytePosition < 0) {\n throw new UploadCacheError(\n 'lastBytePosition must be a non-negative number',\n 'INVALID_BYTE_POSITION'\n );\n }\n\n // Validate logical consistency\n if (data.uploadedChunks > 0 && data.lastBytePosition === 0) {\n throw new UploadCacheError(\n 'lastBytePosition cannot be 0 if chunks have been uploaded',\n 'INCONSISTENT_DATA'\n );\n }\n\n const expectedMaxChunks = Math.ceil(data.fileSize / data.chunkSize);\n if (data.uploadedChunks > expectedMaxChunks) {\n throw new UploadCacheError(\n `uploadedChunks (${data.uploadedChunks}) exceeds maximum expected (${expectedMaxChunks})`,\n 'INCONSISTENT_DATA'\n );\n }\n }\n\n /**\n * Retrieves resume data for a specific upload.\n * \n * @param key - Unique identifier for the upload\n * @returns Promise resolved with the resume data\n * @throws {UploadCacheError} If the key does not exist or data is corrupted\n * \n * @example\n * ```typescript\n * try {\n * const data = await adapter.getItem('upload-123');\n * console.log(`${data.uploadedChunks}/${Math.ceil(data.fileSize / data.chunkSize)} chunks`);\n * } catch (error) {\n * console.error('Failed to retrieve data:', error.message);\n * }\n * ```\n */\n async getItem(key: string): Promise<ResumeData> {\n return new Promise((resolve, reject) => {\n try {\n if (!key || typeof key !== 'string') {\n reject(new UploadCacheError(\n 'Key must be a non-empty string',\n 'INVALID_KEY'\n ));\n return;\n }\n\n const data = this.cache.get(key);\n\n if (!data) {\n reject(new UploadCacheError(\n `Resume data for key '${key}' was not found`,\n 'NOT_FOUND'\n ));\n return;\n }\n\n // Return a deep copy to prevent external mutations\n resolve(JSON.parse(JSON.stringify(data)));\n } catch (error) {\n reject(new UploadCacheError(\n `Error retrieving data: ${error instanceof Error ? error.message : String(error)}`,\n 'RETRIEVAL_ERROR'\n ));\n }\n });\n }\n\n /**\n * Stores resume data for an upload session.\n * \n * @param key - Unique identifier for the upload\n * @param data - Resume data containing upload progress information\n * @returns Promise resolved when data is successfully cached\n * @throws {UploadCacheError} If quota is exceeded or data is invalid\n * \n * @example\n * ```typescript\n * try {\n * await adapter.setItem('upload-123', {\n * fileId: 'file-abc',\n * fileName: 'video.mp4',\n * fileSize: 10737418240,\n * uploadedChunks: 45,\n * lastChunkIndex: 44,\n * lastBytePosition: 47185920,\n * chunkSize: 1048576\n * });\n * console.log('Data successfully saved');\n * } catch (error) {\n * console.error('Storage error:', error.message);\n * }\n * ```\n */\n async setItem(key: string, data: ResumeData): Promise<void> {\n return new Promise((resolve, reject) => {\n try {\n if (!key || typeof key !== 'string') {\n reject(new UploadCacheError(\n 'Key must be a non-empty string',\n 'INVALID_KEY'\n ));\n return;\n }\n\n this.validateResumeData(data);\n\n // Check cache limit\n if (this.cache.size >= this.maxCacheSize && !this.cache.has(key)) {\n reject(new UploadCacheError(\n `Cache limit (${this.maxCacheSize} entries) has been reached. ` +\n 'Remove obsolete entries or use an adapter with persistent storage.',\n 'CACHE_LIMIT_EXCEEDED'\n ));\n return;\n }\n\n // Store a deep copy\n this.cache.set(key, JSON.parse(JSON.stringify(data)));\n resolve();\n } catch (error) {\n if (error instanceof UploadCacheError) {\n reject(error);\n } else {\n reject(new UploadCacheError(\n `Error storing data: ${error instanceof Error ? error.message : String(error)}`,\n 'STORAGE_ERROR'\n ));\n }\n }\n });\n }\n\n /**\n * Removes resume data for a specific upload.\n * \n * @param key - Unique identifier for the upload\n * @returns Promise resolved after removal\n * \n * @example\n * ```typescript\n * await adapter.removeItem('upload-123');\n * ```\n */\n async removeItem(key: string): Promise<void> {\n return new Promise((resolve, reject) => {\n try {\n if (!key || typeof key !== 'string') {\n reject(new UploadCacheError(\n 'Key must be a non-empty string',\n 'INVALID_KEY'\n ));\n return;\n }\n\n this.cache.delete(key);\n resolve();\n } catch (error) {\n reject(new UploadCacheError(\n `Error removing data: ${error instanceof Error ? error.message : String(error)}`,\n 'DELETION_ERROR'\n ));\n }\n });\n }\n\n /**\n * Clears all cached resume data.\n * \n * @returns Promise resolved after complete cleanup\n * \n * @example\n * ```typescript\n * await adapter.clear();\n * console.log('Cache cleared');\n * ```\n */\n async clear(): Promise<void> {\n return new Promise((resolve) => {\n this.cache.clear();\n resolve();\n });\n }\n\n /**\n * Returns the number of entries currently in cache.\n * \n * @returns Number of cache entries\n */\n get size(): number {\n return this.cache.size;\n }\n\n /**\n * Returns cache usage as a percentage.\n * \n * @returns Usage percentage (0-100)\n */\n get usage(): number {\n return (this.cache.size / this.maxCacheSize) * 100;\n }\n}\n\n/**\n * Custom error for upload cache operations.\n * \n * @example\n * ```typescript\n * throw new UploadCacheError('Resume data not found', 'NOT_FOUND');\n * ```\n */\nexport class UploadCacheError extends Error {\n constructor(\n message: string,\n public readonly code: string\n ) {\n super(message);\n this.name = 'UploadCacheError';\n }\n}\n"]}
@@ -1,5 +1,4 @@
1
- 'use strict';
2
-
1
+ // src/types/index.ts
3
2
  var UploadState = /* @__PURE__ */ ((UploadState2) => {
4
3
  UploadState2["IDLE"] = "idle";
5
4
  UploadState2["INITIALIZING"] = "initializing";
@@ -11,7 +10,7 @@ var UploadState = /* @__PURE__ */ ((UploadState2) => {
11
10
  UploadState2["FAILED"] = "failed";
12
11
  return UploadState2;
13
12
  })(UploadState || {});
14
- const DEFAULT_CONFIG = Object.freeze({
13
+ var DEFAULT_CONFIG = Object.freeze({
15
14
  defaultChunkSizeMB: 50,
16
15
  slowSpeedThresholdMbps: 5,
17
16
  slowSpeedChunkSizeMB: 2,
@@ -24,7 +23,6 @@ const DEFAULT_CONFIG = Object.freeze({
24
23
  ]
25
24
  });
26
25
 
27
- exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
28
- exports.UploadState = UploadState;
29
- //# sourceMappingURL=index.js.map
30
- //# sourceMappingURL=index.js.map
26
+ export { DEFAULT_CONFIG, UploadState };
27
+ //# sourceMappingURL=chunk-X757PBC5.js.map
28
+ //# sourceMappingURL=chunk-X757PBC5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/index.ts"],"names":["UploadState"],"mappings":";AAkEO,IAAK,WAAA,qBAAAA,YAAAA,KAAL;AACH,EAAAA,aAAA,MAAA,CAAA,GAAO,MAAA;AACP,EAAAA,aAAA,cAAA,CAAA,GAAe,cAAA;AACf,EAAAA,aAAA,WAAA,CAAA,GAAY,WAAA;AACZ,EAAAA,aAAA,QAAA,CAAA,GAAS,QAAA;AACT,EAAAA,aAAA,WAAA,CAAA,GAAY,WAAA;AACZ,EAAAA,aAAA,YAAA,CAAA,GAAa,YAAA;AACb,EAAAA,aAAA,WAAA,CAAA,GAAY,WAAA;AACZ,EAAAA,aAAA,QAAA,CAAA,GAAS,QAAA;AARD,EAAA,OAAAA,YAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA;AAiCL,IAAM,cAAA,GAA4C,OAAO,MAAA,CAAO;AAAA,EACnE,kBAAA,EAAoB,EAAA;AAAA,EACpB,sBAAA,EAAwB,CAAA;AAAA,EACxB,oBAAA,EAAsB,CAAA;AAAA,EACtB,kBAAA,EAAoB;AAAA,IAChB,EAAE,SAAA,EAAW,GAAA,EAAK,WAAA,EAAa,EAAA,EAAG;AAAA,IAClC,EAAE,SAAA,EAAW,GAAA,EAAK,WAAA,EAAa,GAAA,EAAI;AAAA,IACnC,EAAE,SAAA,EAAW,GAAA,EAAK,WAAA,EAAa,GAAA,EAAI;AAAA,IACnC,EAAE,SAAA,EAAW,GAAA,EAAM,WAAA,EAAa,GAAA,EAAI;AAAA,IACpC,EAAE,SAAA,EAAW,QAAA,EAAU,WAAA,EAAa,GAAA;AAAI;AAEhD,CAAC","file":"chunk-X757PBC5.js","sourcesContent":["/*\n * This file is part of the project by AGBOKOUDJO Franck.\n *\n * (c) AGBOKOUDJO Franck <internationaleswebservices@gmail.com>\n * Phone: +229 0167 25 18 86\n * LinkedIn: https://www.linkedin.com/in/internationales-web-apps-services-120520193/\n * Company: INTERNATIONALES WEB APPS & SERVICES\n *\n * For more information, please feel free to contact the author.\n */\n\nimport { FetchResponseInterface } from \"@wlindabla/http_client\";\n\nexport interface UploadOptions {\n autoSave?: boolean,\n chunkSize?: number;\n speedMbps?: number;\n config?: ChunkSizeConfig;\n headers?: HeadersInit;\n chunkOtherData?: Record<string, any>;\n metadata?: Record<string, any>;\n maxRetries?: number;\n timeout?: number;\n initTimeout?: number;\n headerInitialzingUpload?: HeadersInit;\n headerFinalezingUpload?: HeadersInit;\n concurrency?: number; // Default: 3\n}\n\nexport interface InitializeUploadOptions{\n metadata?: Record<string, any>;\n fileHash: string;\n fileName: string;\n fileSize: number;\n fileType: string;\n endpointInit: string | URL;\n headers?: HeadersInit;\n}\n\nexport interface UploadEndpoints{\n init: string | URL;\n upload: string | URL;\n finalize: string | URL;\n}\n\nexport interface ChunkSizeConfig {\n defaultChunkSizeMB: number;\n slowSpeedThresholdMbps: number;\n slowSpeedChunkSizeMB: number;\n fileSizeThresholds: Array<{\n maxSizeMB: number;\n chunkSizeMB: number;\n }>;\n}\n\nexport type UploadStatus = 'pending' | 'uploading' | 'success' | 'error';\n\nexport interface ChunkInfo {\n index: number;\n start: number;\n end: number;\n size: number;\n attempt: number;\n status: UploadStatus;\n}\n\nexport enum UploadState {\n IDLE = 'idle',\n INITIALIZING = 'initializing',\n UPLOADING = 'uploading',\n PAUSED = 'paused',\n CANCELLED = 'cancelled',\n FINALIZING = 'finalizing',\n COMPLETED = 'completed',\n FAILED = 'failed'\n}\n\nexport interface UploadResult {\n success: boolean;\n fileId?: string;\n totalChunks: number;\n totalBytes: number;\n duration: number;\n averageSpeed: number;\n finalizeUploadResponse?: FetchResponseInterface | null;\n statusResponse?: number;\n}\n\nexport interface ResumeData {\n fileId: string;\n fileName: string;\n fileSize: number;\n uploadedChunks: number;\n lastChunkIndex: number;\n lastBytePosition: number;\n chunkSize: number;\n concurrency: number;\n}\n\nexport const DEFAULT_CONFIG: Readonly<ChunkSizeConfig> = Object.freeze({\n defaultChunkSizeMB: 50,\n slowSpeedThresholdMbps: 5,\n slowSpeedChunkSizeMB: 2,\n fileSizeThresholds: [\n { maxSizeMB: 200, chunkSizeMB: 50 },\n { maxSizeMB: 400, chunkSizeMB: 100 },\n { maxSizeMB: 800, chunkSizeMB: 300 },\n { maxSizeMB: 1000, chunkSizeMB: 500 },\n { maxSizeMB: Infinity, chunkSizeMB: 700 }\n ]\n});\n\nexport interface UploadProgress {\n uploadedChunks: number;\n totalChunks: number;\n uploadedBytes: number;\n totalBytes: number;\n percentage: number;\n currentChunk: number;\n speed?: number; // bytes per second\n estimatedTimeRemaining?: number | null; // seconds\n elapsed: number;// secondes écoulées\n}\nexport interface ChunkError {\n chunk: ChunkInfo;\n error: Error;\n attempt: number;\n willRetry: boolean;\n}\n\n/**\n * Expected response structure from initialize endpoint\n */\nexport interface InitializeUploadResponse {\n mediaIdFromServer?: string | number;\n sessionId?: string | number;\n uploadId?: string | number;\n mediaId?: string | number;\n message?: string | number;\n [key: string]: any; // Allow extra fields\n}"]}
@@ -0,0 +1,267 @@
1
+ import { EventDispatcherInterface } from '@wlindabla/event_dispatcher';
2
+ import { UploadOptions, UploadEndpoints, UploadState, ResumeData } from '../types/index.mjs';
3
+ import { UploadResumeCacheInterface } from '../cache/index.mjs';
4
+ import '@wlindabla/http_client';
5
+
6
+ /**
7
+ * ChunkedFileUploader
8
+ *
9
+ * A production-ready, event-driven chunked file upload engine for Browser and Node.js.
10
+ *
11
+ * Designed and developed by **AGBOKOUDJO Franck** at
12
+ * **INTERNATIONALES WEB APPS & SERVICES**, this class provides a robust,
13
+ * framework-agnostic solution for uploading large files to a remote server
14
+ * by splitting them into smaller chunks and sending them in parallel with
15
+ * configurable concurrency control.
16
+ *
17
+ * ---
18
+ *
19
+ * ### How It Works
20
+ *
21
+ * The upload process follows a strict three-phase lifecycle:
22
+ *
23
+ * 1. **Initialization** — A session is opened with the server via the `init` endpoint.
24
+ * The file is identified by its name, size, type, and a SHA-256 hash of its
25
+ * first megabyte. The server returns a unique `mediaId` that identifies the session.
26
+ *
27
+ * 2. **Chunk Upload** — The file is sliced into fixed-size chunks and uploaded
28
+ * concurrently using `p-limit`. Each chunk carries its index, the total number
29
+ * of chunks, and the session `mediaId`. Failed chunks are retried automatically
30
+ * with exponential backoff up to `maxRetries` attempts.
31
+ *
32
+ * 3. **Finalization** — Once all chunks are successfully uploaded, the `finalize`
33
+ * endpoint is called to instruct the server to assemble the chunks into the
34
+ * final file.
35
+ *
36
+ * ---
37
+ *
38
+ * ### Event-Driven Architecture
39
+ *
40
+ * This class follows the **Symfony EventDispatcher pattern** via
41
+ * `@wlindabla/event_dispatcher`. Every meaningful moment in the upload
42
+ * lifecycle emits a typed event that your application can listen to:
43
+ *
44
+ * ```
45
+ * IDLE → INITIALIZING → UPLOADING → FINALIZING → COMPLETED
46
+ * ↓ ↓
47
+ * FAILED PAUSED ↔ UPLOADING
48
+ * ↓
49
+ * CANCELLED
50
+ * ```
51
+ *
52
+ * All event name constants are centralized in {@link HttpFileUploaderEvents}.
53
+ *
54
+ * ---
55
+ *
56
+ * ### Subscriber Registration (Required)
57
+ *
58
+ * Before calling `.upload()`, you **must** register the two built-in subscribers
59
+ * on your dispatcher. They handle the HTTP communication for the init and finalize phases:
60
+ *
61
+ * ```typescript
62
+ * // Browser
63
+ * const dispatcher = new BrowserEventDispatcher(document);
64
+ * dispatcher.addSubscriber(new InitializeUploadSubscriber(dispatcher));
65
+ * dispatcher.addSubscriber(new FinalizeUploadSubscriber(dispatcher));
66
+ *
67
+ * // Node.js
68
+ * const dispatcher = new NodeEventDispatcher();
69
+ * dispatcher.addSubscriber(new InitializeUploadSubscriber(dispatcher));
70
+ * dispatcher.addSubscriber(new FinalizeUploadSubscriber(dispatcher));
71
+ * ```
72
+ *
73
+ * ---
74
+ *
75
+ * ### Fluent Builder API
76
+ *
77
+ * The class exposes a fluent API to configure the upload before starting:
78
+ *
79
+ * ```typescript
80
+ * const uploader = new ChunkedFileUploader(dispatcher, cache, options);
81
+ *
82
+ * await uploader
83
+ * .withFile(file)
84
+ * .withEndpoints({
85
+ * init: 'https://api.example.com/upload/init',
86
+ * upload: 'https://api.example.com/upload/chunk',
87
+ * finalize: 'https://api.example.com/upload/finalize'
88
+ * })
89
+ * .upload();
90
+ * ```
91
+ *
92
+ * ---
93
+ *
94
+ * ### Resumable Uploads
95
+ *
96
+ * When `autoSave: true` is set in options, the upload progress is persisted
97
+ * after each successful chunk via the {@link UploadResumeCacheInterface}.
98
+ * A failed or interrupted upload can be resumed later:
99
+ *
100
+ * ```typescript
101
+ * const resumeData = await uploader.loadResumeData(file.name);
102
+ *
103
+ * if (resumeData) {
104
+ * await uploader
105
+ * .withFile(file)
106
+ * .withEndpoints(endpoints)
107
+ * .resumeUpload(resumeData);
108
+ * }
109
+ * ```
110
+ *
111
+ * ---
112
+ *
113
+ * ### Concurrency
114
+ *
115
+ * Multiple chunks can be uploaded simultaneously. The `concurrency` option
116
+ * controls how many parallel uploads are active at any given time.
117
+ * The default value is `3`, which provides a good balance between speed
118
+ * and server/network load:
119
+ *
120
+ * ```typescript
121
+ * // Upload 5 chunks in parallel
122
+ * new ChunkedFileUploader(dispatcher, cache, { concurrency: 5 });
123
+ * ```
124
+ *
125
+ * ---
126
+ *
127
+ * ### Pause, Resume and Cancel
128
+ *
129
+ * The upload can be paused, resumed, or cancelled at any time:
130
+ *
131
+ * ```typescript
132
+ * uploader.pause(); // Pauses after the current chunk finishes
133
+ * uploader.resume(); // Resumes from where it was paused
134
+ * uploader.cancel(); // Aborts immediately via AbortController
135
+ * ```
136
+ *
137
+ * ---
138
+ *
139
+ * ### Cache
140
+ *
141
+ * The library does **not** provide a built-in cache implementation to stay
142
+ * lightweight and environment-agnostic. You must implement
143
+ * {@link UploadResumeCacheInterface} with your preferred storage backend
144
+ * (localStorage, IndexedDB, Redis, filesystem, etc.).
145
+ *
146
+ * ---
147
+ *
148
+ * @author AGBOKOUDJO Franck <internationaleswebservices@gmail.com>
149
+ * @company INTERNATIONALES WEB APPS & SERVICES
150
+ * @phone +229 0167 25 18 86
151
+ * @linkedin https://www.linkedin.com/in/internationales-web-apps-services-120520193/
152
+ * @github https://github.com/Agbokoudjo/file_uploader
153
+ *
154
+ * @version 1.0.0
155
+ * @since 1.0.0
156
+ * @license MIT
157
+ *
158
+ * @see {@link HttpFileUploaderEvents} All event name constants
159
+ * @see {@link UploadResumeCacheInterface} Cache interface to implement
160
+ * @see {@link InitializeUploadSubscriber} Handles the init HTTP phase
161
+ * @see {@link FinalizeUploadSubscriber} Handles the finalize HTTP phase
162
+ * @see {@link UploadOptions} Full configuration reference
163
+ * @see {@link https://github.com/Agbokoudjo/file_uploader | GitHub Repository}
164
+ */
165
+ declare class ChunkedFileUploader {
166
+ private readonly _uploadEventDispatcher;
167
+ private readonly uploadResumeData;
168
+ private options;
169
+ private _file;
170
+ private _endpoints;
171
+ private isPaused;
172
+ private startTime;
173
+ private uploadedBytes;
174
+ private abortController;
175
+ private state;
176
+ private totalChunks;
177
+ private percentage;
178
+ private uploadedChunks;
179
+ private lastUploadedChunkIndex;
180
+ constructor(_uploadEventDispatcher: EventDispatcherInterface | undefined, //or new NodeJSEventDispatcher() if you have an environment NodeJs
181
+ uploadResumeData: UploadResumeCacheInterface, options: UploadOptions);
182
+ /**
183
+ * Starts the chunked file upload process.
184
+ *
185
+ * @throws {Error} If file or endpoints are not set
186
+ * @throws {InitializeUploadFailureException} If server initialization fails
187
+ * @throws {FileUploadChunkError} If a chunk fails after all retries
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * const uploader = new ChunkedFileUploader(dispatcher, cache, options);
192
+ *
193
+ * uploader
194
+ * .withFile(file)
195
+ * .withEndpoints({ init, upload, finalize });
196
+ *
197
+ * await uploader.upload();
198
+ * ```
199
+ */
200
+ upload(): Promise<void>;
201
+ withFile(file: File): this;
202
+ withEndpoints(endpoints: UploadEndpoints): this;
203
+ private get endPointOptions();
204
+ private get file();
205
+ /**
206
+ * Upload all chunks with concurrency control using p-limit
207
+ *
208
+ * @param file - File to upload
209
+ * @param chunkSize - Size of each chunk
210
+ * @param fileId - Server file ID
211
+ * @param fileHash - File hash
212
+ * @param maxRetries - Max retry attempts per chunk
213
+ * @param concurrency - Number of concurrent uploads (default: 3)
214
+ */
215
+ private uploadChunksWithConcurrency;
216
+ /**
217
+ * Process a single chunk: slice, upload with retry, and save progress.
218
+ *
219
+ * @param file - The file being uploaded
220
+ * @param currentChunkIndex - Index of the current chunk (0-based)
221
+ * @param chunkSize - Size of each chunk in bytes
222
+ * @param fileId - Server-provided file/session ID
223
+ * @param fileHash - SHA-256 hash of the file
224
+ * @param maxRetries - Maximum number of retry attempts
225
+ *
226
+ * @throws {UploadCancelledException} If upload is cancelled
227
+ * @throws {FileUploadChunkError} If chunk upload fails after all retries
228
+ */
229
+ private processChunk;
230
+ private uploadChunkWithRetry;
231
+ private uploadChunk;
232
+ private createChunkAbortSignal;
233
+ private notifyProgress;
234
+ private sleep;
235
+ /**
236
+ * Save current upload progress to cache for resume capability
237
+ *
238
+ * @param fileId - Server-provided file/session ID
239
+ * @param chunkSize - Size of each chunk in bytes
240
+ * @returns Saved resume data
241
+ */
242
+ private saveResumeData;
243
+ private setState;
244
+ getState(): UploadState;
245
+ private handleUploadFailure;
246
+ cancel(): void;
247
+ pause(): void;
248
+ resume(): void;
249
+ /**
250
+ * Load previously saved resume data
251
+ *
252
+ * @param fileName - Name of the file to resume
253
+ * @returns Resume data or null if not found
254
+ */
255
+ loadResumeData(fileName: string): Promise<ResumeData | null>;
256
+ /**
257
+ * Resume upload from saved state
258
+ *
259
+ * @param resumeData - Previously saved resume data
260
+ * @returns Upload result
261
+ */
262
+ resumeUpload(resumeData: ResumeData): Promise<void>;
263
+ private updateProgress;
264
+ private finalizeUpload;
265
+ }
266
+
267
+ export { ChunkedFileUploader };
@@ -0,0 +1,12 @@
1
+ export { ChunkedFileUploader } from '../chunk-6DIKDA6J.js';
2
+ import '../chunk-NXYS73I4.js';
3
+ import '../chunk-MFYC4PBP.js';
4
+ import '../chunk-X757PBC5.js';
5
+ import '../chunk-JDL3U4OX.js';
6
+ import '../chunk-LD2DWZRJ.js';
7
+ import '../chunk-LTYMA4U4.js';
8
+ import '../chunk-DN5B6PRW.js';
9
+ import '../chunk-6225YMFE.js';
10
+ import '../chunk-7QVYU63E.js';
11
+ //# sourceMappingURL=index.js.map
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,27 @@
1
+ import { ChunkInfo, UploadStatus } from '../../types/index.mjs';
2
+ import '@wlindabla/http_client';
3
+
4
+ /**
5
+ * Event data for MEDIA_CHUNK_UPLOAD_HTTP_ERROR_RESPONSE
6
+ */
7
+ declare class ChunkUploadHttpErrorResponseEvent {
8
+ readonly errorPayload: string | Record<string, string | unknown> | unknown;
9
+ readonly statusResponse: number;
10
+ readonly urlEndpoint: string | URL | Request;
11
+ readonly chunkInfo: ChunkInfo;
12
+ constructor(errorPayload: string | Record<string, string | unknown> | unknown, statusResponse: number, urlEndpoint: string | URL | Request, chunkInfo: ChunkInfo);
13
+ get chunkIndex(): number;
14
+ }
15
+ /**
16
+ * Event data for MEDIA_CHUNK_UPLOAD_STARTED
17
+ */
18
+ declare class UploadChunkStartedEvent {
19
+ private readonly _chunkInfo;
20
+ constructor(_chunkInfo: ChunkInfo);
21
+ get start(): number;
22
+ get end(): number;
23
+ get uploadStatus(): UploadStatus;
24
+ get chunkIndex(): number;
25
+ }
26
+
27
+ export { ChunkUploadHttpErrorResponseEvent, UploadChunkStartedEvent };
@@ -0,0 +1,4 @@
1
+ export { ChunkUploadHttpErrorResponseEvent, UploadChunkStartedEvent } from '../../chunk-LD2DWZRJ.js';
2
+ import '../../chunk-7QVYU63E.js';
3
+ //# sourceMappingURL=index.js.map
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,63 @@
1
+ import { BaseEvent } from '@wlindabla/event_dispatcher';
2
+ import { ResumeData, UploadResult } from '../../types/index.mjs';
3
+ import { ResponseEventInterface, FetchResponseInterface } from '@wlindabla/http_client';
4
+
5
+ /**
6
+ * Event data for MEDIA_CHUNK_UPLOAD_RESUME
7
+ */
8
+ declare class ResumeUploadEvent {
9
+ private readonly __resumeData;
10
+ readonly message: string;
11
+ constructor(__resumeData: ResumeData, message: string);
12
+ get mediaId(): string | number;
13
+ get fileName(): string;
14
+ get uploadedChunks(): number;
15
+ get lastChunkIndex(): number;
16
+ get lastBytePosition(): number;
17
+ get chunkSize(): number;
18
+ get fileSize(): number;
19
+ }
20
+ /**
21
+ * Event data for DOWNLOAD_MEDIA_COMPLETE
22
+ */
23
+ declare class UploadMediaCompleteEvent {
24
+ private readonly _uploadResult;
25
+ constructor(_uploadResult: UploadResult);
26
+ get success(): boolean;
27
+ get mediaId(): string | number;
28
+ get totalBytes(): number;
29
+ get totalChunks(): number;
30
+ get finalizeUploadHttpResponse(): any;
31
+ get operationDuration(): number;
32
+ get averageSpeed(): number;
33
+ }
34
+ declare class FinalizeUploadFailureEvent extends BaseEvent {
35
+ readonly error: Error;
36
+ readonly status?: number | undefined;
37
+ readonly errorData?: any | undefined;
38
+ readonly responseData?: any | undefined;
39
+ readonly isNetworkError?: boolean | undefined;
40
+ constructor(error: Error, status?: number | undefined, errorData?: any | undefined, responseData?: any | undefined, isNetworkError?: boolean | undefined);
41
+ }
42
+ declare class FinalizeUploadEvent extends BaseEvent implements ResponseEventInterface {
43
+ readonly endPoint: string | URL;
44
+ readonly mediaId: string;
45
+ readonly mediaHash: string;
46
+ readonly headers?: HeadersInit | undefined;
47
+ private fetchResponse;
48
+ constructor(endPoint: string | URL, mediaId: string, mediaHash: string, headers?: HeadersInit | undefined);
49
+ /**
50
+ * Returns the response
51
+ */
52
+ getResponse(): FetchResponseInterface | null;
53
+ /**
54
+ * Sets the response
55
+ */
56
+ setResponse(response: FetchResponseInterface): void;
57
+ /**
58
+ * Returns whether a response was set
59
+ */
60
+ hasResponse(): boolean;
61
+ }
62
+
63
+ export { FinalizeUploadEvent, FinalizeUploadFailureEvent, ResumeUploadEvent, UploadMediaCompleteEvent };
@@ -0,0 +1,4 @@
1
+ export { FinalizeUploadEvent, FinalizeUploadFailureEvent, ResumeUploadEvent, UploadMediaCompleteEvent } from '../../chunk-LTYMA4U4.js';
2
+ import '../../chunk-7QVYU63E.js';
3
+ //# sourceMappingURL=index.js.map
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}