backfarm 1.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 (141) hide show
  1. package/dist/chunk-7QVYU63E.js +7 -0
  2. package/dist/chunk-7QVYU63E.js.map +1 -0
  3. package/dist/chunk-BMPUYKJJ.js +148 -0
  4. package/dist/chunk-BMPUYKJJ.js.map +1 -0
  5. package/dist/chunk-EB35KLDE.js +49 -0
  6. package/dist/chunk-EB35KLDE.js.map +1 -0
  7. package/dist/chunk-EWQYVPOL.js +30 -0
  8. package/dist/chunk-EWQYVPOL.js.map +1 -0
  9. package/dist/chunk-FMCW72HO.js +110 -0
  10. package/dist/chunk-FMCW72HO.js.map +1 -0
  11. package/dist/chunk-GBXVVI2R.js +528 -0
  12. package/dist/chunk-GBXVVI2R.js.map +1 -0
  13. package/dist/chunk-HZ4GLSOO.js +91 -0
  14. package/dist/chunk-HZ4GLSOO.js.map +1 -0
  15. package/dist/chunk-I6VD2JKM.js +72 -0
  16. package/dist/chunk-I6VD2JKM.js.map +1 -0
  17. package/dist/chunk-IN3YY526.js +165 -0
  18. package/dist/chunk-IN3YY526.js.map +1 -0
  19. package/dist/chunk-MEQAHLW6.js +135 -0
  20. package/dist/chunk-MEQAHLW6.js.map +1 -0
  21. package/dist/chunk-MNSQSU7T.js +90 -0
  22. package/dist/chunk-MNSQSU7T.js.map +1 -0
  23. package/dist/chunk-NDJVYPUT.js +61 -0
  24. package/dist/chunk-NDJVYPUT.js.map +1 -0
  25. package/dist/chunk-NMNAPTVV.js +91 -0
  26. package/dist/chunk-NMNAPTVV.js.map +1 -0
  27. package/dist/chunk-P5XJG7OG.js +71 -0
  28. package/dist/chunk-P5XJG7OG.js.map +1 -0
  29. package/dist/chunk-SSFPGDA3.js +73 -0
  30. package/dist/chunk-SSFPGDA3.js.map +1 -0
  31. package/dist/chunk-UWIMSKL5.js +35 -0
  32. package/dist/chunk-UWIMSKL5.js.map +1 -0
  33. package/dist/chunk-W2745SOE.js +38 -0
  34. package/dist/chunk-W2745SOE.js.map +1 -0
  35. package/dist/chunk-X3R3RLXY.js +62 -0
  36. package/dist/chunk-X3R3RLXY.js.map +1 -0
  37. package/dist/engine/cloudBucket/r2Storage.d.ts +5 -0
  38. package/dist/engine/cloudBucket/r2Storage.js +10 -0
  39. package/dist/engine/cloudBucket/r2Storage.js.map +1 -0
  40. package/dist/engine/mondoDb/mongoDB.d.ts +6 -0
  41. package/dist/engine/mondoDb/mongoDB.js +11 -0
  42. package/dist/engine/mondoDb/mongoDB.js.map +1 -0
  43. package/dist/engine/multer/multer_configs.d.ts +6 -0
  44. package/dist/engine/multer/multer_configs.js +11 -0
  45. package/dist/engine/multer/multer_configs.js.map +1 -0
  46. package/dist/engine/server/app.d.ts +5 -0
  47. package/dist/engine/server/app.js +8 -0
  48. package/dist/engine/server/app.js.map +1 -0
  49. package/dist/engine/server/server.d.ts +6 -0
  50. package/dist/engine/server/server.js +17 -0
  51. package/dist/engine/server/server.js.map +1 -0
  52. package/dist/engine/sql/mySql.d.ts +7 -0
  53. package/dist/engine/sql/mySql.js +13 -0
  54. package/dist/engine/sql/mySql.js.map +1 -0
  55. package/dist/engine/sql/pgSql.d.ts +7 -0
  56. package/dist/engine/sql/pgSql.js +13 -0
  57. package/dist/engine/sql/pgSql.js.map +1 -0
  58. package/dist/event-streams-PM4LQKAH.js +993 -0
  59. package/dist/event-streams-PM4LQKAH.js.map +1 -0
  60. package/dist/utility/libs/env.d.ts +24 -0
  61. package/dist/utility/libs/env.js +8 -0
  62. package/dist/utility/libs/env.js.map +1 -0
  63. package/dist/utility/libs/interface.d.ts +114 -0
  64. package/dist/utility/libs/interface.js +1 -0
  65. package/dist/utility/libs/interface.js.map +1 -0
  66. package/dist/utility/libs/types.d.ts +207 -0
  67. package/dist/utility/libs/types.js +6 -0
  68. package/dist/utility/libs/types.js.map +1 -0
  69. package/dist/utility/utilis/cloud_storage/deleteFile.d.ts +9 -0
  70. package/dist/utility/utilis/cloud_storage/deleteFile.js +60 -0
  71. package/dist/utility/utilis/cloud_storage/deleteFile.js.map +1 -0
  72. package/dist/utility/utilis/cloud_storage/deleteFiles.d.ts +9 -0
  73. package/dist/utility/utilis/cloud_storage/deleteFiles.js +89 -0
  74. package/dist/utility/utilis/cloud_storage/deleteFiles.js.map +1 -0
  75. package/dist/utility/utilis/cloud_storage/downloadFile.d.ts +9 -0
  76. package/dist/utility/utilis/cloud_storage/downloadFile.js +74 -0
  77. package/dist/utility/utilis/cloud_storage/downloadFile.js.map +1 -0
  78. package/dist/utility/utilis/cloud_storage/downloadFiles.d.ts +9 -0
  79. package/dist/utility/utilis/cloud_storage/downloadFiles.js +88 -0
  80. package/dist/utility/utilis/cloud_storage/downloadFiles.js.map +1 -0
  81. package/dist/utility/utilis/cloud_storage/s3Client.d.ts +5 -0
  82. package/dist/utility/utilis/cloud_storage/s3Client.js +17 -0
  83. package/dist/utility/utilis/cloud_storage/s3Client.js.map +1 -0
  84. package/dist/utility/utilis/cloud_storage/uploadFile.d.ts +51 -0
  85. package/dist/utility/utilis/cloud_storage/uploadFile.js +14 -0
  86. package/dist/utility/utilis/cloud_storage/uploadFile.js.map +1 -0
  87. package/dist/utility/utilis/cloud_storage/uploadFiles.d.ts +73 -0
  88. package/dist/utility/utilis/cloud_storage/uploadFiles.js +49 -0
  89. package/dist/utility/utilis/cloud_storage/uploadFiles.js.map +1 -0
  90. package/dist/utility/utilis/general/error_handler.d.ts +31 -0
  91. package/dist/utility/utilis/general/error_handler.js +8 -0
  92. package/dist/utility/utilis/general/error_handler.js.map +1 -0
  93. package/dist/utility/utilis/general/file-operations.d.ts +140 -0
  94. package/dist/utility/utilis/general/file-operations.js +19 -0
  95. package/dist/utility/utilis/general/file-operations.js.map +1 -0
  96. package/dist/utility/utilis/general/sqlDb.js.d.ts +151 -0
  97. package/dist/utility/utilis/general/sqlDb.js.js +13 -0
  98. package/dist/utility/utilis/general/sqlDb.js.js.map +1 -0
  99. package/dist/utility/utilis/general/uuids.d.ts +55 -0
  100. package/dist/utility/utilis/general/uuids.js +8 -0
  101. package/dist/utility/utilis/general/uuids.js.map +1 -0
  102. package/dist/utility/utilis/general/web.d.ts +247 -0
  103. package/dist/utility/utilis/general/web.js +13 -0
  104. package/dist/utility/utilis/general/web.js.map +1 -0
  105. package/dist/utility/utilis/mongoDb/buldWrite.d.ts +53 -0
  106. package/dist/utility/utilis/mongoDb/buldWrite.js +32 -0
  107. package/dist/utility/utilis/mongoDb/buldWrite.js.map +1 -0
  108. package/dist/utility/utilis/mongoDb/deleteDocument.d.ts +54 -0
  109. package/dist/utility/utilis/mongoDb/deleteDocument.js +34 -0
  110. package/dist/utility/utilis/mongoDb/deleteDocument.js.map +1 -0
  111. package/dist/utility/utilis/mongoDb/insertField.d.ts +40 -0
  112. package/dist/utility/utilis/mongoDb/insertField.js +33 -0
  113. package/dist/utility/utilis/mongoDb/insertField.js.map +1 -0
  114. package/dist/utility/utilis/mongoDb/insertFields.d.ts +48 -0
  115. package/dist/utility/utilis/mongoDb/insertFields.js +35 -0
  116. package/dist/utility/utilis/mongoDb/insertFields.js.map +1 -0
  117. package/dist/utility/utilis/mongoDb/updateFiled.d.ts +65 -0
  118. package/dist/utility/utilis/mongoDb/updateFiled.js +40 -0
  119. package/dist/utility/utilis/mongoDb/updateFiled.js.map +1 -0
  120. package/dist/utility/utilis/multer/upload_batch.d.ts +7 -0
  121. package/dist/utility/utilis/multer/upload_batch.js +17 -0
  122. package/dist/utility/utilis/multer/upload_batch.js.map +1 -0
  123. package/dist/utility/utilis/multer/upload_single.d.ts +7 -0
  124. package/dist/utility/utilis/multer/upload_single.js +16 -0
  125. package/dist/utility/utilis/multer/upload_single.js.map +1 -0
  126. package/dist/utility/utilis/postgres/executeQuery.d.ts +215 -0
  127. package/dist/utility/utilis/postgres/executeQuery.js +46 -0
  128. package/dist/utility/utilis/postgres/executeQuery.js.map +1 -0
  129. package/dist/utility/utilis/postgres/subSqlfiles/executeMySqlQuery.d.ts +9 -0
  130. package/dist/utility/utilis/postgres/subSqlfiles/executeMySqlQuery.js +10 -0
  131. package/dist/utility/utilis/postgres/subSqlfiles/executeMySqlQuery.js.map +1 -0
  132. package/dist/utility/utilis/postgres/subSqlfiles/executePgQuery.d.ts +11 -0
  133. package/dist/utility/utilis/postgres/subSqlfiles/executePgQuery.js +12 -0
  134. package/dist/utility/utilis/postgres/subSqlfiles/executePgQuery.js.map +1 -0
  135. package/dist/utility/utilis/server/app.d.ts +5 -0
  136. package/dist/utility/utilis/server/app.js +15 -0
  137. package/dist/utility/utilis/server/app.js.map +1 -0
  138. package/dist/utility/utilis/server/server.d.ts +5 -0
  139. package/dist/utility/utilis/server/server.js +24 -0
  140. package/dist/utility/utilis/server/server.js.map +1 -0
  141. package/package.json +55 -0
@@ -0,0 +1,89 @@
1
+ import {
2
+ url_or_path
3
+ } from "../../../chunk-FMCW72HO.js";
4
+ import {
5
+ getKeyFromUrl
6
+ } from "../../../chunk-SSFPGDA3.js";
7
+ import {
8
+ s3Client
9
+ } from "../../../chunk-GBXVVI2R.js";
10
+ import "../../../chunk-IN3YY526.js";
11
+ import {
12
+ ENV
13
+ } from "../../../chunk-EWQYVPOL.js";
14
+ import {
15
+ __name
16
+ } from "../../../chunk-7QVYU63E.js";
17
+
18
+ // src/utility/utilis/cloud_storage/deleteFiles.ts
19
+ import { DeleteObjectCommand } from "@aws-sdk/client-s3";
20
+ import * as fs from "fs";
21
+ var deleteFiles = /* @__PURE__ */ __name(async (item_files) => {
22
+ if (!item_files || item_files.length === 0) {
23
+ return { items: [] };
24
+ }
25
+ const uniqueFiles = [...new Set(item_files)];
26
+ const BATCH_SIZE = 50;
27
+ const results = [];
28
+ const deleteSingleFile = /* @__PURE__ */ __name(async (item_file) => {
29
+ try {
30
+ const fileType = url_or_path(item_file);
31
+ if (fileType === ENV.URL) {
32
+ const key = getKeyFromUrl(item_file);
33
+ const command = new DeleteObjectCommand({
34
+ Bucket: ENV.BUCKET_NAME,
35
+ Key: key
36
+ });
37
+ await s3Client.send(command);
38
+ return {
39
+ url_or_path: item_file,
40
+ status: true
41
+ };
42
+ }
43
+ if (fileType === ENV.PATH) {
44
+ try {
45
+ await fs.promises.access(item_file);
46
+ await fs.promises.unlink(item_file);
47
+ } catch (accessError) {
48
+ }
49
+ return {
50
+ url_or_path: item_file,
51
+ status: true
52
+ };
53
+ }
54
+ return {
55
+ url_or_path: item_file,
56
+ status: false
57
+ };
58
+ } catch (error) {
59
+ return {
60
+ url_or_path: item_file,
61
+ status: false,
62
+ error
63
+ };
64
+ }
65
+ }, "deleteSingleFile");
66
+ for (let i = 0; i < uniqueFiles.length; i += BATCH_SIZE) {
67
+ const batch = uniqueFiles.slice(i, i + BATCH_SIZE);
68
+ const batchResults = await Promise.allSettled(
69
+ batch.map((file) => deleteSingleFile(file))
70
+ );
71
+ batchResults.forEach((result, index) => {
72
+ if (result.status === "fulfilled") {
73
+ results.push(result.value);
74
+ } else {
75
+ results.push({
76
+ url_or_path: batch[index] || "unknown",
77
+ // Provide fallback
78
+ status: false,
79
+ error: result.reason
80
+ });
81
+ }
82
+ });
83
+ }
84
+ return { items: results };
85
+ }, "deleteFiles");
86
+ export {
87
+ deleteFiles
88
+ };
89
+ //# sourceMappingURL=deleteFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/deleteFiles.ts"],"sourcesContent":["import {ENV} from \"../../libs/env.js\";\r\nimport {url_or_path} from \"../general/file-operations.js\";\r\nimport {getKeyFromUrl} from \"../general/web.js\";\r\nimport {DeleteObjectCommand} from \"@aws-sdk/client-s3\";\r\nimport * as fs from \"node:fs\";\r\nimport type {DeleteFiles} from \"../../libs/interface.js\";\r\nimport {s3Client} from \"../../../engine/cloudBucket/r2Storage.js\";\r\n\r\nexport const deleteFiles = async (item_files: string[]): Promise<DeleteFiles> => {\r\n // Early return for empty array\r\n if (!item_files || item_files.length === 0) {\r\n return { items: [] };\r\n }\r\n\r\n // Optional: Deduplicate files to avoid redundant operations\r\n const uniqueFiles = [...new Set(item_files)];\r\n\r\n // Optional: Limit concurrency to avoid overwhelming the system\r\n const BATCH_SIZE = 50; // Adjust based on your needs\r\n const results: DeleteFiles['items'] = [];\r\n\r\n const deleteSingleFile = async (item_file: string): Promise<DeleteFiles['items'][0]> => {\r\n try {\r\n const fileType = url_or_path(item_file);\r\n\r\n if (fileType === ENV.URL) {\r\n const key = getKeyFromUrl(item_file);\r\n const command = new DeleteObjectCommand({\r\n Bucket: ENV.BUCKET_NAME,\r\n Key: key,\r\n });\r\n await s3Client.send(command);\r\n return {\r\n url_or_path: item_file,\r\n status: true,\r\n };\r\n }\r\n\r\n if (fileType === ENV.PATH) {\r\n try {\r\n await fs.promises.access(item_file);\r\n await fs.promises.unlink(item_file);\r\n } catch (accessError) {\r\n // File doesn't exist - consider this a success (idempotent)\r\n }\r\n return {\r\n url_or_path: item_file,\r\n status: true,\r\n };\r\n }\r\n\r\n return {\r\n url_or_path: item_file,\r\n status: false,\r\n };\r\n } catch (error) {\r\n return {\r\n url_or_path: item_file,\r\n status: false,\r\n error: error,\r\n };\r\n }\r\n };\r\n\r\n // Process in batches to control memory/connection usage\r\n for (let i = 0; i < uniqueFiles.length; i += BATCH_SIZE) {\r\n const batch = uniqueFiles.slice(i, i + BATCH_SIZE);\r\n const batchResults = await Promise.allSettled(\r\n batch.map(file => deleteSingleFile(file))\r\n );\r\n\r\n batchResults.forEach((result, index) => {\r\n if (result.status === 'fulfilled') {\r\n results.push(result.value);\r\n } else {\r\n // result.reason should never happen with allSettled, but handle it anyway\r\n results.push({\r\n url_or_path: batch[index] || 'unknown', // Provide fallback\r\n status: false,\r\n error: result.reason,\r\n });\r\n }\r\n });\r\n }\r\n\r\n return { items: results };\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;AAGA,SAAQ,2BAA0B;AAClC,YAAY,QAAQ;AAIb,IAAM,cAAc,8BAAO,eAA+C;AAE7E,MAAI,CAAC,cAAc,WAAW,WAAW,GAAG;AACxC,WAAO,EAAE,OAAO,CAAC,EAAE;AAAA,EACvB;AAGA,QAAM,cAAc,CAAC,GAAG,IAAI,IAAI,UAAU,CAAC;AAG3C,QAAM,aAAa;AACnB,QAAM,UAAgC,CAAC;AAEvC,QAAM,mBAAmB,8BAAO,cAAwD;AACpF,QAAI;AACA,YAAM,WAAW,YAAY,SAAS;AAEtC,UAAI,aAAa,IAAI,KAAK;AACtB,cAAM,MAAM,cAAc,SAAS;AACnC,cAAM,UAAU,IAAI,oBAAoB;AAAA,UACpC,QAAQ,IAAI;AAAA,UACZ,KAAK;AAAA,QACT,CAAC;AACD,cAAM,SAAS,KAAK,OAAO;AAC3B,eAAO;AAAA,UACH,aAAa;AAAA,UACb,QAAQ;AAAA,QACZ;AAAA,MACJ;AAEA,UAAI,aAAa,IAAI,MAAM;AACvB,YAAI;AACA,gBAAS,YAAS,OAAO,SAAS;AAClC,gBAAS,YAAS,OAAO,SAAS;AAAA,QACtC,SAAS,aAAa;AAAA,QAEtB;AACA,eAAO;AAAA,UACH,aAAa;AAAA,UACb,QAAQ;AAAA,QACZ;AAAA,MACJ;AAEA,aAAO;AAAA,QACH,aAAa;AAAA,QACb,QAAQ;AAAA,MACZ;AAAA,IACJ,SAAS,OAAO;AACZ,aAAO;AAAA,QACH,aAAa;AAAA,QACb,QAAQ;AAAA,QACR;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ,GAzCyB;AA4CzB,WAAS,IAAI,GAAG,IAAI,YAAY,QAAQ,KAAK,YAAY;AACrD,UAAM,QAAQ,YAAY,MAAM,GAAG,IAAI,UAAU;AACjD,UAAM,eAAe,MAAM,QAAQ;AAAA,MAC/B,MAAM,IAAI,UAAQ,iBAAiB,IAAI,CAAC;AAAA,IAC5C;AAEA,iBAAa,QAAQ,CAAC,QAAQ,UAAU;AACpC,UAAI,OAAO,WAAW,aAAa;AAC/B,gBAAQ,KAAK,OAAO,KAAK;AAAA,MAC7B,OAAO;AAEH,gBAAQ,KAAK;AAAA,UACT,aAAa,MAAM,KAAK,KAAK;AAAA;AAAA,UAC7B,QAAQ;AAAA,UACR,OAAO,OAAO;AAAA,QAClB,CAAC;AAAA,MACL;AAAA,IACJ,CAAC;AAAA,EACL;AAEA,SAAO,EAAE,OAAO,QAAQ;AAC5B,GA9E2B;","names":[]}
@@ -0,0 +1,9 @@
1
+ import { DownloadFileParams, DownloadedFile } from '../../libs/interface.js';
2
+ import 'mongodb';
3
+ import '../../libs/types.js';
4
+ import 'express';
5
+ import '../../libs/env.js';
6
+
7
+ declare const downloadFile: ({ url, outputPath, }: DownloadFileParams) => Promise<DownloadedFile>;
8
+
9
+ export { downloadFile };
@@ -0,0 +1,74 @@
1
+ import {
2
+ downloadedFilePath,
3
+ getFileExtension
4
+ } from "../../../chunk-FMCW72HO.js";
5
+ import {
6
+ generateUniqueValue
7
+ } from "../../../chunk-X3R3RLXY.js";
8
+ import {
9
+ getKeyFromUrl
10
+ } from "../../../chunk-SSFPGDA3.js";
11
+ import {
12
+ s3Client
13
+ } from "../../../chunk-GBXVVI2R.js";
14
+ import "../../../chunk-IN3YY526.js";
15
+ import {
16
+ ENV
17
+ } from "../../../chunk-EWQYVPOL.js";
18
+ import {
19
+ __name
20
+ } from "../../../chunk-7QVYU63E.js";
21
+
22
+ // src/utility/utilis/cloud_storage/downloadFile.ts
23
+ import { GetObjectCommand } from "@aws-sdk/client-s3";
24
+ import { pipeline } from "stream/promises";
25
+ import path from "path";
26
+ import fsPromises from "fs/promises";
27
+ import * as fs from "fs";
28
+ var downloadFile = /* @__PURE__ */ __name(async ({
29
+ url,
30
+ outputPath
31
+ }) => {
32
+ try {
33
+ const key = getKeyFromUrl(url);
34
+ const command = new GetObjectCommand({
35
+ Bucket: ENV.BUCKET_NAME,
36
+ Key: key
37
+ });
38
+ const response = await s3Client.send(command);
39
+ if (!response.Body) {
40
+ console.log(response);
41
+ return {
42
+ status: true,
43
+ url,
44
+ error: new Error(`Empty response body received for key: ${key}`)
45
+ };
46
+ }
47
+ const fileExtension = getFileExtension(url);
48
+ const fileName = generateUniqueValue(16);
49
+ const finalFileName = `${fileName}.${fileExtension}`;
50
+ const targetPath = downloadedFilePath({ path: outputPath || [], fileName: finalFileName });
51
+ const dir = path.dirname(targetPath);
52
+ if (!fs.existsSync(dir)) {
53
+ await fsPromises.mkdir(dir, { recursive: true });
54
+ }
55
+ const stream = response.Body;
56
+ await pipeline(stream, fs.createWriteStream(targetPath));
57
+ return {
58
+ status: true,
59
+ url,
60
+ path: targetPath
61
+ };
62
+ } catch (error) {
63
+ console.error(error);
64
+ return {
65
+ status: false,
66
+ url,
67
+ error: error instanceof Error ? error : new Error(String(error))
68
+ };
69
+ }
70
+ }, "downloadFile");
71
+ export {
72
+ downloadFile
73
+ };
74
+ //# sourceMappingURL=downloadFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/downloadFile.ts"],"sourcesContent":["import {GetObjectCommand} from \"@aws-sdk/client-s3\";\r\nimport {getKeyFromUrl} from \"../general/web.js\";\r\nimport { pipeline } from \"stream/promises\";\r\nimport path from 'node:path'\r\nimport fsPromises from 'fs/promises';\r\nimport * as fs from \"node:fs\";\r\nimport type {DownloadedFile, DownloadFileParams} from \"../../libs/interface.js\";\r\nimport {ENV} from \"../../libs/env.js\";\r\nimport {downloadedFilePath, getFileExtension} from \"../general/file-operations.js\";\r\nimport {generateUniqueValue} from \"../general/uuids.js\";\r\nimport {s3Client} from \"../../../engine/cloudBucket/r2Storage.js\";\r\n\r\n\r\n\r\nexport const downloadFile = async ({\r\n url,\r\n outputPath,\r\n }: DownloadFileParams): Promise<DownloadedFile> => {\r\n try {\r\n const key = getKeyFromUrl(url);\r\n\r\n const command = new GetObjectCommand({\r\n Bucket: ENV.BUCKET_NAME,\r\n Key: key,\r\n });\r\n\r\n const response = await s3Client.send(command);\r\n\r\n if (!response.Body) {\r\n console.log(response);\r\n return {\r\n status: true,\r\n url: url,\r\n error: new Error(`Empty response body received for key: ${key}`),\r\n };\r\n }\r\n\r\n const fileExtension = getFileExtension(url);\r\n const fileName = generateUniqueValue(16);\r\n const finalFileName = `${fileName}.${fileExtension}`;\r\n const targetPath = downloadedFilePath({ path: outputPath || [], fileName: finalFileName });\r\n\r\n // Ensure directory structure exists for targetPath\r\n const dir = path.dirname(targetPath);\r\n if (!fs.existsSync(dir)) {\r\n await fsPromises.mkdir(dir, { recursive: true });\r\n }\r\n\r\n // Cast stream to NodeJS.ReadableStream for pipeline overload\r\n const stream = response.Body as NodeJS.ReadableStream;\r\n await pipeline(stream, fs.createWriteStream(targetPath));\r\n\r\n return {\r\n status: true,\r\n url: url,\r\n path: targetPath,\r\n };\r\n\r\n } catch (error) {\r\n console.error(error);\r\n return {\r\n status: false,\r\n url: url,\r\n error: error instanceof Error ? error : new Error(String(error)),\r\n };\r\n }\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAQ,wBAAuB;AAE/B,SAAS,gBAAgB;AACzB,OAAO,UAAU;AACjB,OAAO,gBAAgB;AACvB,YAAY,QAAQ;AASb,IAAM,eAAe,8BAAO;AAAA,EACI;AAAA,EACA;AACJ,MAAmD;AAClF,MAAI;AACA,UAAM,MAAM,cAAc,GAAG;AAE7B,UAAM,UAAU,IAAI,iBAAiB;AAAA,MACjC,QAAQ,IAAI;AAAA,MACZ,KAAK;AAAA,IACT,CAAC;AAED,UAAM,WAAW,MAAM,SAAS,KAAK,OAAO;AAE5C,QAAI,CAAC,SAAS,MAAM;AAChB,cAAQ,IAAI,QAAQ;AACpB,aAAO;AAAA,QACH,QAAQ;AAAA,QACR;AAAA,QACA,OAAO,IAAI,MAAM,yCAAyC,GAAG,EAAE;AAAA,MACnE;AAAA,IACJ;AAEA,UAAM,gBAAgB,iBAAiB,GAAG;AAC1C,UAAM,WAAW,oBAAoB,EAAE;AACvC,UAAM,gBAAgB,GAAG,QAAQ,IAAI,aAAa;AAClD,UAAM,aAAa,mBAAmB,EAAE,MAAM,cAAc,CAAC,GAAG,UAAU,cAAc,CAAC;AAGzF,UAAM,MAAM,KAAK,QAAQ,UAAU;AACnC,QAAI,CAAI,cAAW,GAAG,GAAG;AACrB,YAAM,WAAW,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACnD;AAGA,UAAM,SAAS,SAAS;AACxB,UAAM,SAAS,QAAW,qBAAkB,UAAU,CAAC;AAEvD,WAAO;AAAA,MACH,QAAQ;AAAA,MACR;AAAA,MACA,MAAM;AAAA,IACV;AAAA,EAEJ,SAAS,OAAO;AACZ,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,MACH,QAAQ;AAAA,MACR;AAAA,MACA,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AAAA,IACnE;AAAA,EACJ;AACJ,GApD4B;","names":[]}
@@ -0,0 +1,9 @@
1
+ import { DownloadFilesParams, DownloadedFile } from '../../libs/interface.js';
2
+ import 'mongodb';
3
+ import '../../libs/types.js';
4
+ import 'express';
5
+ import '../../libs/env.js';
6
+
7
+ declare const downloadFiles: ({ files, globalPath, }: DownloadFilesParams) => Promise<DownloadedFile[]>;
8
+
9
+ export { downloadFiles };
@@ -0,0 +1,88 @@
1
+ import {
2
+ downloadedFilePath,
3
+ getFileExtension
4
+ } from "../../../chunk-FMCW72HO.js";
5
+ import {
6
+ generateUniqueValue
7
+ } from "../../../chunk-X3R3RLXY.js";
8
+ import {
9
+ getKeyFromUrl
10
+ } from "../../../chunk-SSFPGDA3.js";
11
+ import {
12
+ s3Client
13
+ } from "../../../chunk-GBXVVI2R.js";
14
+ import "../../../chunk-IN3YY526.js";
15
+ import {
16
+ ENV
17
+ } from "../../../chunk-EWQYVPOL.js";
18
+ import {
19
+ __name
20
+ } from "../../../chunk-7QVYU63E.js";
21
+
22
+ // src/utility/utilis/cloud_storage/downloadFiles.ts
23
+ import { GetObjectCommand } from "@aws-sdk/client-s3";
24
+ import path from "path";
25
+ import fsPromises from "fs/promises";
26
+ import * as fs from "fs";
27
+ import { pipeline } from "stream/promises";
28
+ var downloadFiles = /* @__PURE__ */ __name(async ({
29
+ files,
30
+ globalPath
31
+ }) => {
32
+ const hasIndividualOutputPath = files.some(
33
+ (file) => file.outputPath && file.outputPath.length > 0
34
+ );
35
+ if (globalPath && hasIndividualOutputPath) {
36
+ throw new Error(
37
+ "Conflict: Cannot specify both 'globalPath' and individual 'outputPath' on files."
38
+ );
39
+ }
40
+ const downloadPromises = files.map(async (file) => {
41
+ const { url, outputPath } = file;
42
+ try {
43
+ const key = getKeyFromUrl(url);
44
+ const command = new GetObjectCommand({
45
+ Bucket: ENV.BUCKET_NAME,
46
+ Key: key
47
+ });
48
+ const response = await s3Client.send(command);
49
+ if (!response.Body) {
50
+ return {
51
+ status: false,
52
+ url,
53
+ error: new Error(`Empty response body received for key: ${key}`)
54
+ };
55
+ }
56
+ const fileExtension = getFileExtension(url);
57
+ const fileName = generateUniqueValue(16);
58
+ const finalFileName = `${fileName}.${fileExtension}`;
59
+ const resolvedPathSegments = outputPath || (globalPath ? [globalPath] : []);
60
+ const targetPath = downloadedFilePath({
61
+ path: resolvedPathSegments,
62
+ fileName: finalFileName
63
+ });
64
+ const dir = path.dirname(targetPath);
65
+ if (!fs.existsSync(dir)) {
66
+ await fsPromises.mkdir(dir, { recursive: true });
67
+ }
68
+ const stream = response.Body;
69
+ await pipeline(stream, fs.createWriteStream(targetPath));
70
+ return {
71
+ status: true,
72
+ url,
73
+ path: targetPath
74
+ };
75
+ } catch (error) {
76
+ return {
77
+ status: false,
78
+ url,
79
+ error: error instanceof Error ? error : new Error(String(error))
80
+ };
81
+ }
82
+ });
83
+ return Promise.all(downloadPromises);
84
+ }, "downloadFiles");
85
+ export {
86
+ downloadFiles
87
+ };
88
+ //# sourceMappingURL=downloadFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/downloadFiles.ts"],"sourcesContent":["import type {DownloadedFile, DownloadFilesParams} from \"../../libs/interface.js\";\r\nimport {getKeyFromUrl} from \"../general/web.js\";\r\nimport {GetObjectCommand} from \"@aws-sdk/client-s3\";\r\nimport {ENV} from \"../../libs/env.js\";\r\nimport {downloadedFilePath, getFileExtension} from \"../general/file-operations.js\";\r\nimport path from \"node:path\";\r\nimport fsPromises from \"fs/promises\";\r\nimport * as fs from \"node:fs\";\r\nimport {pipeline} from \"stream/promises\";\r\nimport {generateUniqueValue} from \"../general/uuids.js\";\r\nimport {s3Client} from \"../../../engine/cloudBucket/r2Storage.js\";\r\n\r\nexport const downloadFiles = async ({\r\n files,\r\n globalPath,\r\n }: DownloadFilesParams): Promise<DownloadedFile[]> => {\r\n // 1. Validate path conflict rule upfront\r\n const hasIndividualOutputPath = files.some(\r\n (file) => file.outputPath && file.outputPath.length > 0\r\n );\r\n\r\n if (globalPath && hasIndividualOutputPath) {\r\n throw new Error(\r\n \"Conflict: Cannot specify both 'globalPath' and individual 'outputPath' on files.\"\r\n );\r\n }\r\n\r\n // 2. Process all files independently in parallel\r\n const downloadPromises = files.map(async (file): Promise<DownloadedFile> => {\r\n const { url, outputPath } = file;\r\n\r\n try {\r\n const key = getKeyFromUrl(url);\r\n\r\n const command = new GetObjectCommand({\r\n Bucket: ENV.BUCKET_NAME,\r\n Key: key,\r\n });\r\n\r\n const response = await s3Client.send(command);\r\n\r\n if (!response.Body) {\r\n return {\r\n status: false,\r\n url: url,\r\n error: new Error(`Empty response body received for key: ${key}`),\r\n };\r\n }\r\n\r\n const fileExtension = getFileExtension(url);\r\n const fileName = generateUniqueValue(16);\r\n const finalFileName = `${fileName}.${fileExtension}`;\r\n\r\n // Resolve target path using either file's outputPath or globalPath\r\n const resolvedPathSegments = outputPath || (globalPath ? [globalPath] : []);\r\n const targetPath = downloadedFilePath({\r\n path: resolvedPathSegments,\r\n fileName: finalFileName,\r\n });\r\n\r\n // Ensure output folder structure exists\r\n const dir = path.dirname(targetPath);\r\n if (!fs.existsSync(dir)) {\r\n await fsPromises.mkdir(dir, { recursive: true });\r\n }\r\n\r\n // Stream response body directly to file\r\n const stream = response.Body as NodeJS.ReadableStream;\r\n await pipeline(stream, fs.createWriteStream(targetPath));\r\n\r\n return {\r\n status: true,\r\n url: url,\r\n path: targetPath,\r\n };\r\n } catch (error) {\r\n return {\r\n status: false,\r\n url: url,\r\n error: error instanceof Error ? error : new Error(String(error)),\r\n };\r\n }\r\n });\r\n\r\n return Promise.all(downloadPromises);\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAEA,SAAQ,wBAAuB;AAG/B,OAAO,UAAU;AACjB,OAAO,gBAAgB;AACvB,YAAY,QAAQ;AACpB,SAAQ,gBAAe;AAIhB,IAAM,gBAAgB,8BAAO;AAAA,EACI;AAAA,EACA;AACJ,MAAsD;AAEtF,QAAM,0BAA0B,MAAM;AAAA,IAClC,CAAC,SAAS,KAAK,cAAc,KAAK,WAAW,SAAS;AAAA,EAC1D;AAEA,MAAI,cAAc,yBAAyB;AACvC,UAAM,IAAI;AAAA,MACN;AAAA,IACJ;AAAA,EACJ;AAGA,QAAM,mBAAmB,MAAM,IAAI,OAAO,SAAkC;AACxE,UAAM,EAAE,KAAK,WAAW,IAAI;AAE5B,QAAI;AACA,YAAM,MAAM,cAAc,GAAG;AAE7B,YAAM,UAAU,IAAI,iBAAiB;AAAA,QACjC,QAAQ,IAAI;AAAA,QACZ,KAAK;AAAA,MACT,CAAC;AAED,YAAM,WAAW,MAAM,SAAS,KAAK,OAAO;AAE5C,UAAI,CAAC,SAAS,MAAM;AAChB,eAAO;AAAA,UACH,QAAQ;AAAA,UACR;AAAA,UACA,OAAO,IAAI,MAAM,yCAAyC,GAAG,EAAE;AAAA,QACnE;AAAA,MACJ;AAEA,YAAM,gBAAgB,iBAAiB,GAAG;AAC1C,YAAM,WAAW,oBAAoB,EAAE;AACvC,YAAM,gBAAgB,GAAG,QAAQ,IAAI,aAAa;AAGlD,YAAM,uBAAuB,eAAe,aAAa,CAAC,UAAU,IAAI,CAAC;AACzE,YAAM,aAAa,mBAAmB;AAAA,QAClC,MAAM;AAAA,QACN,UAAU;AAAA,MACd,CAAC;AAGD,YAAM,MAAM,KAAK,QAAQ,UAAU;AACnC,UAAI,CAAI,cAAW,GAAG,GAAG;AACrB,cAAM,WAAW,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,MACnD;AAGA,YAAM,SAAS,SAAS;AACxB,YAAM,SAAS,QAAW,qBAAkB,UAAU,CAAC;AAEvD,aAAO;AAAA,QACH,QAAQ;AAAA,QACR;AAAA,QACA,MAAM;AAAA,MACV;AAAA,IACJ,SAAS,OAAO;AACZ,aAAO;AAAA,QACH,QAAQ;AAAA,QACR;AAAA,QACA,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AAAA,MACnE;AAAA,IACJ;AAAA,EACJ,CAAC;AAED,SAAO,QAAQ,IAAI,gBAAgB;AACvC,GAzE6B;","names":[]}
@@ -0,0 +1,5 @@
1
+ import { S3Client } from '@aws-sdk/client-s3';
2
+
3
+ declare const getS3Client: () => Promise<S3Client>;
4
+
5
+ export { getS3Client };
@@ -0,0 +1,17 @@
1
+ import {
2
+ s3Client
3
+ } from "../../../chunk-GBXVVI2R.js";
4
+ import "../../../chunk-IN3YY526.js";
5
+ import "../../../chunk-EWQYVPOL.js";
6
+ import {
7
+ __name
8
+ } from "../../../chunk-7QVYU63E.js";
9
+
10
+ // src/utility/utilis/cloud_storage/s3Client.ts
11
+ var getS3Client = /* @__PURE__ */ __name(async () => {
12
+ return s3Client;
13
+ }, "getS3Client");
14
+ export {
15
+ getS3Client
16
+ };
17
+ //# sourceMappingURL=s3Client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/s3Client.ts"],"sourcesContent":["import {s3Client as sss} from \"../../../engine/cloudBucket/r2Storage.js\";\r\nimport type {S3Client} from \"@aws-sdk/client-s3\";\r\n\r\nexport const getS3Client = async (): Promise<S3Client> => {\r\n return sss;\r\n}\r\n"],"mappings":";;;;;;;;;;AAGO,IAAM,cAAc,mCAA+B;AACtD,SAAO;AACX,GAF2B;","names":[]}
@@ -0,0 +1,51 @@
1
+ import { UploadFileInput } from '../../libs/interface.js';
2
+ import { FileUploadedResponseData } from '../../libs/types.js';
3
+ import 'mongodb';
4
+ import 'express';
5
+ import '../../libs/env.js';
6
+
7
+ /**
8
+ * Uploads a single file to the configured S3-compatible storage bucket.
9
+ *
10
+ * The function accepts a Multer file, Web API `File`, raw `Buffer`, or file
11
+ * path/URL. A unique file name is generated while preserving the original
12
+ * file extension. The file is then converted to a byte array, its content
13
+ * type is detected, and it is uploaded to the configured bucket.
14
+ *
15
+ * On successful upload, the function returns the generated storage path and
16
+ * public URL along with the original file data when applicable. If the upload
17
+ * fails, it returns the encountered error and the original file data when
18
+ * available.
19
+ *
20
+ * @param params - The file and optional storage path used for the upload.
21
+ * @param params.file - The file, buffer, or file path/URL to upload.
22
+ * @param params.path - Optional array of path segments under which the file
23
+ * should be stored.
24
+ * @returns A promise resolving to a `FileUploadedResponseData` containing
25
+ * either the uploaded file information or the encountered error.
26
+ *
27
+ * @example
28
+ * const result = await upload_file({
29
+ * file: req.file,
30
+ * path: ['temporary_files'],
31
+ * });
32
+ *
33
+ * if ('error' in result) {
34
+ * console.error('Upload failed:', result.error);
35
+ * } else {
36
+ * console.log('File uploaded:', result.url);
37
+ * }
38
+ *
39
+ * @example
40
+ * const result = await upload_file({
41
+ * file: buffer,
42
+ * path: ['documents', 'reports'],
43
+ * });
44
+ *
45
+ * if (!result.error) {
46
+ * console.log('Uploaded to:', result.path);
47
+ * }
48
+ */
49
+ declare const upload_file: ({ file, path }: UploadFileInput) => Promise<FileUploadedResponseData>;
50
+
51
+ export { upload_file };
@@ -0,0 +1,14 @@
1
+ import {
2
+ upload_file
3
+ } from "../../../chunk-I6VD2JKM.js";
4
+ import "../../../chunk-FMCW72HO.js";
5
+ import "../../../chunk-X3R3RLXY.js";
6
+ import "../../../chunk-SSFPGDA3.js";
7
+ import "../../../chunk-GBXVVI2R.js";
8
+ import "../../../chunk-IN3YY526.js";
9
+ import "../../../chunk-EWQYVPOL.js";
10
+ import "../../../chunk-7QVYU63E.js";
11
+ export {
12
+ upload_file
13
+ };
14
+ //# sourceMappingURL=uploadFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,73 @@
1
+ import { UploadFilesInput, FilesUploadedResponseData } from '../../libs/interface.js';
2
+ import 'mongodb';
3
+ import '../../libs/types.js';
4
+ import 'express';
5
+ import '../../libs/env.js';
6
+
7
+ /**
8
+ * Uploads multiple files to the configured S3-compatible storage bucket
9
+ * concurrently with a configurable concurrency limit.
10
+ *
11
+ * Each file is uploaded using the `upload_file` function. A global path can
12
+ * be applied to all files, or each file can specify its own individual path,
13
+ * but both options cannot be used at the same time.
14
+ *
15
+ * Failed uploads are collected separately from successful uploads, allowing
16
+ * the caller to inspect the result of every individual file without stopping
17
+ * the entire batch operation.
18
+ *
19
+ * @param params - Configuration options for the batch upload.
20
+ * @param params.files - The files to upload along with their optional paths.
21
+ * @param params.globalPath - An optional path applied to all files that do
22
+ * not specify an individual path.
23
+ * @param params.concurrency - The maximum number of files uploaded
24
+ * concurrently. Defaults to `5`.
25
+ * @returns A promise resolving to a `FilesUploadedResponseData` containing
26
+ * separate arrays of successfully uploaded and failed files.
27
+ * @throws {Error} If both `globalPath` and an individual file `path` are
28
+ * provided.
29
+ *
30
+ * @example
31
+ * const result = await upload_files({
32
+ * files: [
33
+ * { file: file1 },
34
+ * { file: file2 },
35
+ * { file: file3 },
36
+ * ],
37
+ * globalPath: ['temporary_files'],
38
+ * concurrency: 5,
39
+ * });
40
+ *
41
+ * console.log('Successful uploads:', result.successFiles);
42
+ * console.log('Failed uploads:', result.failedFiles);
43
+ *
44
+ * @example
45
+ * const result = await upload_files({
46
+ * files: [
47
+ * {
48
+ * file: file1,
49
+ * path: ['documents', 'reports'],
50
+ * },
51
+ * {
52
+ * file: file2,
53
+ * path: ['documents', 'images'],
54
+ * },
55
+ * ],
56
+ * concurrency: 10,
57
+ * });
58
+ *
59
+ * @example
60
+ * // This throws because globalPath and an individual path cannot be used together.
61
+ * const result = await upload_files({
62
+ * files: [
63
+ * {
64
+ * file: file1,
65
+ * path: ['documents'],
66
+ * },
67
+ * ],
68
+ * globalPath: ['temporary_files'],
69
+ * });
70
+ */
71
+ declare const upload_files: ({ files, globalPath, concurrency }: UploadFilesInput) => Promise<FilesUploadedResponseData>;
72
+
73
+ export { upload_files };
@@ -0,0 +1,49 @@
1
+ import {
2
+ upload_file
3
+ } from "../../../chunk-I6VD2JKM.js";
4
+ import "../../../chunk-FMCW72HO.js";
5
+ import "../../../chunk-X3R3RLXY.js";
6
+ import "../../../chunk-SSFPGDA3.js";
7
+ import "../../../chunk-GBXVVI2R.js";
8
+ import "../../../chunk-IN3YY526.js";
9
+ import "../../../chunk-EWQYVPOL.js";
10
+ import {
11
+ __name
12
+ } from "../../../chunk-7QVYU63E.js";
13
+
14
+ // src/utility/utilis/cloud_storage/uploadFiles.ts
15
+ import pLimit from "p-limit";
16
+ var upload_files = /* @__PURE__ */ __name(async ({
17
+ files,
18
+ globalPath,
19
+ concurrency = 5
20
+ }) => {
21
+ if (globalPath && files.some((item) => item.path && item.path.length > 0)) {
22
+ throw new Error("Invalid options: 'globalPath' and individual 'path' cannot both exist.");
23
+ }
24
+ const limiter = pLimit(concurrency);
25
+ const returnData = {
26
+ successFiles: [],
27
+ failedFiles: []
28
+ };
29
+ const uploadTasks = files.map(
30
+ ({ file, path }) => limiter(async () => {
31
+ const resolvedPath = path ?? (globalPath?.length ? globalPath : void 0);
32
+ const result = await upload_file({
33
+ file,
34
+ path: resolvedPath
35
+ });
36
+ if ("error" in result && result.error) {
37
+ returnData.failedFiles.push(result);
38
+ } else {
39
+ returnData.successFiles.push(result);
40
+ }
41
+ })
42
+ );
43
+ await Promise.all(uploadTasks);
44
+ return returnData;
45
+ }, "upload_files");
46
+ export {
47
+ upload_files
48
+ };
49
+ //# sourceMappingURL=uploadFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/uploadFiles.ts"],"sourcesContent":["import type {FilesUploadedResponseData, UploadFilesInput} from \"../../libs/interface.js\";\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nimport pLimit from 'p-limit';\r\nimport {upload_file} from \"./uploadFile.js\";\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n/**\r\n * Uploads multiple files to the configured S3-compatible storage bucket\r\n * concurrently with a configurable concurrency limit.\r\n *\r\n * Each file is uploaded using the `upload_file` function. A global path can\r\n * be applied to all files, or each file can specify its own individual path,\r\n * but both options cannot be used at the same time.\r\n *\r\n * Failed uploads are collected separately from successful uploads, allowing\r\n * the caller to inspect the result of every individual file without stopping\r\n * the entire batch operation.\r\n *\r\n * @param params - Configuration options for the batch upload.\r\n * @param params.files - The files to upload along with their optional paths.\r\n * @param params.globalPath - An optional path applied to all files that do\r\n * not specify an individual path.\r\n * @param params.concurrency - The maximum number of files uploaded\r\n * concurrently. Defaults to `5`.\r\n * @returns A promise resolving to a `FilesUploadedResponseData` containing\r\n * separate arrays of successfully uploaded and failed files.\r\n * @throws {Error} If both `globalPath` and an individual file `path` are\r\n * provided.\r\n *\r\n * @example\r\n * const result = await upload_files({\r\n * files: [\r\n * { file: file1 },\r\n * { file: file2 },\r\n * { file: file3 },\r\n * ],\r\n * globalPath: ['temporary_files'],\r\n * concurrency: 5,\r\n * });\r\n *\r\n * console.log('Successful uploads:', result.successFiles);\r\n * console.log('Failed uploads:', result.failedFiles);\r\n *\r\n * @example\r\n * const result = await upload_files({\r\n * files: [\r\n * {\r\n * file: file1,\r\n * path: ['documents', 'reports'],\r\n * },\r\n * {\r\n * file: file2,\r\n * path: ['documents', 'images'],\r\n * },\r\n * ],\r\n * concurrency: 10,\r\n * });\r\n *\r\n * @example\r\n * // This throws because globalPath and an individual path cannot be used together.\r\n * const result = await upload_files({\r\n * files: [\r\n * {\r\n * file: file1,\r\n * path: ['documents'],\r\n * },\r\n * ],\r\n * globalPath: ['temporary_files'],\r\n * });\r\n */\r\nexport const upload_files = async ({\r\n files,\r\n globalPath,\r\n concurrency = 5\r\n }: UploadFilesInput): Promise<FilesUploadedResponseData> => {\r\n\r\n // 1. Validate: Throw error immediately if globalPath coexists with any item's individual path\r\n if (globalPath && files.some((item) => item.path && item.path.length > 0)) {\r\n throw new Error(\"Invalid options: 'globalPath' and individual 'path' cannot both exist.\");\r\n }\r\n\r\n const limiter = pLimit(concurrency);\r\n const returnData: FilesUploadedResponseData = {\r\n successFiles: [],\r\n failedFiles: []\r\n };\r\n\r\n // 2. Map and run concurrent uploads inside limiter tasks\r\n const uploadTasks = files.map(({ file, path }) =>\r\n limiter(async () => {\r\n // Resolve target path (use item's path if available, otherwise globalPath array)\r\n const resolvedPath = path ?? (globalPath?.length ? globalPath : undefined);\r\n\r\n // Delegate single file upload logic to upload_file function\r\n const result = await upload_file({\r\n file,\r\n path: resolvedPath\r\n });\r\n\r\n // Aggregate results based on whether an error occurred on the single file upload\r\n if ('error' in result && result.error) {\r\n returnData.failedFiles.push(result);\r\n } else {\r\n returnData.successFiles.push(result);\r\n }\r\n })\r\n );\r\n\r\n // 3. Wait for all concurrent uploads to settle\r\n await Promise.all(uploadTasks);\r\n\r\n return returnData;\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;AAQA,OAAO,YAAY;AAyEZ,IAAM,eAAe,8BAAO;AAAA,EACI;AAAA,EACA;AAAA,EACA,cAAc;AAClB,MAA4D;AAG3F,MAAI,cAAc,MAAM,KAAK,CAAC,SAAS,KAAK,QAAQ,KAAK,KAAK,SAAS,CAAC,GAAG;AACvE,UAAM,IAAI,MAAM,wEAAwE;AAAA,EAC5F;AAEA,QAAM,UAAU,OAAO,WAAW;AAClC,QAAM,aAAwC;AAAA,IAC1C,cAAc,CAAC;AAAA,IACf,aAAa,CAAC;AAAA,EAClB;AAGA,QAAM,cAAc,MAAM;AAAA,IAAI,CAAC,EAAE,MAAM,KAAK,MACxC,QAAQ,YAAY;AAEhB,YAAM,eAAe,SAAS,YAAY,SAAS,aAAa;AAGhE,YAAM,SAAS,MAAM,YAAY;AAAA,QAC7B;AAAA,QACA,MAAM;AAAA,MACV,CAAC;AAGD,UAAI,WAAW,UAAU,OAAO,OAAO;AACnC,mBAAW,YAAY,KAAK,MAAM;AAAA,MACtC,OAAO;AACH,mBAAW,aAAa,KAAK,MAAM;AAAA,MACvC;AAAA,IACJ,CAAC;AAAA,EACL;AAGA,QAAM,QAAQ,IAAI,WAAW;AAE7B,SAAO;AACX,GA1C4B;","names":[]}
@@ -0,0 +1,31 @@
1
+ import { CustomErrorTemplate } from '../../libs/interface.js';
2
+ import 'mongodb';
3
+ import '../../libs/types.js';
4
+ import 'express';
5
+ import '../../libs/env.js';
6
+
7
+ /**
8
+ * Normalizes and logs an error with optional contextual information.
9
+ *
10
+ * Formats the error for both terminal and browser environments, displaying
11
+ * its type, message, timestamp, context, stack trace, and raw error object.
12
+ * The normalized error is returned after being logged.
13
+ *
14
+ * @param err - The unknown error value to normalize and handle.
15
+ * @param context - Optional context describing where the error occurred.
16
+ * @returns The normalized error as a `CustomErrorTemplate`.
17
+ *
18
+ * @example
19
+ * const error = handleError(error, 'File Upload');
20
+ * // Logs the normalized error and returns a CustomErrorTemplate.
21
+ *
22
+ * @example
23
+ * try {
24
+ * await upload_file(file);
25
+ * } catch (error) {
26
+ * handleError(error, 'MinIO Upload');
27
+ * }
28
+ */
29
+ declare function handleError(err: unknown, context?: string): CustomErrorTemplate;
30
+
31
+ export { handleError };
@@ -0,0 +1,8 @@
1
+ import {
2
+ handleError
3
+ } from "../../../chunk-P5XJG7OG.js";
4
+ import "../../../chunk-7QVYU63E.js";
5
+ export {
6
+ handleError
7
+ };
8
+ //# sourceMappingURL=error_handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}