backfarm 1.0.4 → 1.0.6

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 (176) hide show
  1. package/dist/chunk-22GJTNKR.js +47 -0
  2. package/dist/chunk-22GJTNKR.js.map +1 -0
  3. package/dist/{chunk-XBJ3SJ26.js → chunk-2QNCQ5L5.js} +3 -3
  4. package/dist/chunk-2QNCQ5L5.js.map +1 -0
  5. package/dist/chunk-3DJ6GERS.js +17 -0
  6. package/dist/chunk-3DJ6GERS.js.map +1 -0
  7. package/dist/chunk-452DWS46.js +88 -0
  8. package/dist/chunk-452DWS46.js.map +1 -0
  9. package/dist/{chunk-UWIMSKL5.js → chunk-4L35JPDH.js} +2 -2
  10. package/dist/chunk-4L35JPDH.js.map +1 -0
  11. package/dist/{chunk-VFF4YFA3.js → chunk-5AJKFCEE.js} +3 -3
  12. package/dist/chunk-5AJKFCEE.js.map +1 -0
  13. package/dist/chunk-6BNQOIVA.js +34 -0
  14. package/dist/chunk-6BNQOIVA.js.map +1 -0
  15. package/dist/{chunk-P5XJG7OG.js → chunk-A7GR4LD2.js} +1 -1
  16. package/dist/chunk-A7GR4LD2.js.map +1 -0
  17. package/dist/chunk-EEQ2SXDE.js +32 -0
  18. package/dist/chunk-EEQ2SXDE.js.map +1 -0
  19. package/dist/chunk-EUWCMMGI.js +35 -0
  20. package/dist/chunk-EUWCMMGI.js.map +1 -0
  21. package/dist/chunk-HC4IDQP6.js +89 -0
  22. package/dist/chunk-HC4IDQP6.js.map +1 -0
  23. package/dist/{chunk-QVTKG7FD.js → chunk-HV3IQJH3.js} +3 -3
  24. package/dist/chunk-HV3IQJH3.js.map +1 -0
  25. package/dist/{chunk-X3R3RLXY.js → chunk-IZEPCXYK.js} +1 -1
  26. package/dist/chunk-IZEPCXYK.js.map +1 -0
  27. package/dist/{chunk-YTBSGKGF.js → chunk-J3P6W53K.js} +2 -2
  28. package/dist/chunk-J3P6W53K.js.map +1 -0
  29. package/dist/{chunk-EWQYVPOL.js → chunk-LE2SDA4O.js} +1 -1
  30. package/dist/chunk-LE2SDA4O.js.map +1 -0
  31. package/dist/chunk-M7PVDT2D.js +60 -0
  32. package/dist/chunk-M7PVDT2D.js.map +1 -0
  33. package/dist/chunk-O2ZDXQ2Z.js +44 -0
  34. package/dist/chunk-O2ZDXQ2Z.js.map +1 -0
  35. package/dist/{chunk-MNSQSU7T.js → chunk-O5ILFRFV.js} +2 -2
  36. package/dist/chunk-O5ILFRFV.js.map +1 -0
  37. package/dist/chunk-O76OK6Y7.js +40 -0
  38. package/dist/chunk-O76OK6Y7.js.map +1 -0
  39. package/dist/{chunk-W3W3X2OE.js → chunk-QW2GGDEG.js} +54 -19
  40. package/dist/chunk-QW2GGDEG.js.map +1 -0
  41. package/dist/chunk-RZ7XHAUV.js +74 -0
  42. package/dist/chunk-RZ7XHAUV.js.map +1 -0
  43. package/dist/{chunk-TP3K7DMH.js → chunk-U7BCM2WN.js} +2 -2
  44. package/dist/chunk-U7BCM2WN.js.map +1 -0
  45. package/dist/chunk-UPP2FW3G.js +336 -0
  46. package/dist/chunk-UPP2FW3G.js.map +1 -0
  47. package/dist/chunk-YA3MW2CJ.js +33 -0
  48. package/dist/chunk-YA3MW2CJ.js.map +1 -0
  49. package/dist/{chunk-SSFPGDA3.js → chunk-ZC33GE2U.js} +5 -5
  50. package/dist/chunk-ZC33GE2U.js.map +1 -0
  51. package/dist/{chunk-D7A4TEXY.js → chunk-ZC6ZFZ2J.js} +2 -2
  52. package/dist/chunk-ZC6ZFZ2J.js.map +1 -0
  53. package/dist/{chunk-ZMDJ45KH.js → chunk-ZGOMCU4T.js} +7 -7
  54. package/dist/chunk-ZGOMCU4T.js.map +1 -0
  55. package/dist/chunk-ZTTB4NMA.js +18 -0
  56. package/dist/chunk-ZTTB4NMA.js.map +1 -0
  57. package/dist/engine/cloudBucket/r2Storage.js +3 -3
  58. package/dist/engine/mondoDb/mongoDB.js +3 -3
  59. package/dist/engine/multer/multer_configs.js +2 -2
  60. package/dist/engine/server/server.d.ts +5 -3
  61. package/dist/engine/server/server.js +30 -9
  62. package/dist/engine/sql/mySql.d.ts +2 -2
  63. package/dist/engine/sql/mySql.js +3 -3
  64. package/dist/engine/sql/pgSql.js +3 -3
  65. package/dist/utility/libs/env.js +1 -1
  66. package/dist/utility/libs/index.d.ts +1772 -0
  67. package/dist/utility/libs/index.js +101 -0
  68. package/dist/utility/libs/interface.d.ts +5 -7
  69. package/dist/utility/libs/run-all.js +46 -0
  70. package/dist/utility/libs/run-all.js.map +1 -0
  71. package/dist/{chunk-LFRKRR7G.js → utility/libs/run-bucket.js} +4 -7
  72. package/dist/utility/libs/run-bucket.js.map +1 -0
  73. package/dist/utility/libs/run-node-server.js +35 -0
  74. package/dist/utility/libs/run-node-server.js.map +1 -0
  75. package/dist/utility/libs/types.d.ts +11 -31
  76. package/dist/utility/libs/types.js +1 -1
  77. package/dist/utility/libs/types.js.map +1 -1
  78. package/dist/utility/utilis/cloud_storage/deleteFile.js +7 -54
  79. package/dist/utility/utilis/cloud_storage/deleteFile.js.map +1 -1
  80. package/dist/utility/utilis/cloud_storage/deleteFiles.js +7 -83
  81. package/dist/utility/utilis/cloud_storage/deleteFiles.js.map +1 -1
  82. package/dist/utility/utilis/cloud_storage/downloadFile.js +8 -68
  83. package/dist/utility/utilis/cloud_storage/downloadFile.js.map +1 -1
  84. package/dist/utility/utilis/cloud_storage/downloadFiles.js +8 -82
  85. package/dist/utility/utilis/cloud_storage/downloadFiles.js.map +1 -1
  86. package/dist/utility/utilis/cloud_storage/uploadFile.js +6 -6
  87. package/dist/utility/utilis/cloud_storage/uploadFiles.d.ts +0 -64
  88. package/dist/utility/utilis/cloud_storage/uploadFiles.js +9 -43
  89. package/dist/utility/utilis/cloud_storage/uploadFiles.js.map +1 -1
  90. package/dist/utility/utilis/general/error_handler.js +1 -1
  91. package/dist/utility/utilis/general/file-operations.d.ts +7 -132
  92. package/dist/utility/utilis/general/file-operations.js +6 -4
  93. package/dist/utility/utilis/general/sqlDb.js.d.ts +0 -141
  94. package/dist/utility/utilis/general/sqlDb.js.js +2 -2
  95. package/dist/utility/utilis/general/uuids.d.ts +0 -43
  96. package/dist/utility/utilis/general/uuids.js +1 -1
  97. package/dist/utility/utilis/general/web.d.ts +2 -238
  98. package/dist/utility/utilis/general/web.js +4 -4
  99. package/dist/utility/utilis/mongoDb/buldWrite.d.ts +0 -44
  100. package/dist/utility/utilis/mongoDb/buldWrite.js +6 -28
  101. package/dist/utility/utilis/mongoDb/buldWrite.js.map +1 -1
  102. package/dist/utility/utilis/mongoDb/deleteDocument.d.ts +0 -45
  103. package/dist/utility/utilis/mongoDb/deleteDocument.js +6 -30
  104. package/dist/utility/utilis/mongoDb/deleteDocument.js.map +1 -1
  105. package/dist/utility/utilis/mongoDb/insertField.d.ts +2 -33
  106. package/dist/utility/utilis/mongoDb/insertField.js +7 -30
  107. package/dist/utility/utilis/mongoDb/insertField.js.map +1 -1
  108. package/dist/utility/utilis/mongoDb/insertFields.d.ts +2 -41
  109. package/dist/utility/utilis/mongoDb/insertFields.js +7 -32
  110. package/dist/utility/utilis/mongoDb/insertFields.js.map +1 -1
  111. package/dist/utility/utilis/mongoDb/updateFiled.d.ts +0 -56
  112. package/dist/utility/utilis/mongoDb/updateFiled.js +6 -36
  113. package/dist/utility/utilis/mongoDb/updateFiled.js.map +1 -1
  114. package/dist/utility/utilis/multer/upload_batch.js +5 -12
  115. package/dist/utility/utilis/multer/upload_batch.js.map +1 -1
  116. package/dist/utility/utilis/multer/upload_single.d.ts +41 -0
  117. package/dist/utility/utilis/multer/upload_single.js +5 -11
  118. package/dist/utility/utilis/multer/upload_single.js.map +1 -1
  119. package/dist/utility/utilis/postgres/executeQuery.d.ts +2 -205
  120. package/dist/utility/utilis/postgres/executeQuery.js +11 -41
  121. package/dist/utility/utilis/postgres/executeQuery.js.map +1 -1
  122. package/dist/utility/utilis/postgres/subSqlfiles/executeMySqlQuery.js +4 -4
  123. package/dist/utility/utilis/postgres/subSqlfiles/executePgQuery.js +4 -4
  124. package/dist/utility/utilis/server/app.js +30 -12
  125. package/dist/utility/utilis/server/app.js.map +1 -1
  126. package/dist/utility/utilis/server/server.d.ts +2 -2
  127. package/dist/utility/utilis/server/server.js +30 -20
  128. package/dist/utility/utilis/server/server.js.map +1 -1
  129. package/package.json +55 -56
  130. package/dist/chunk-5A3RVJNT.js +0 -19
  131. package/dist/chunk-5A3RVJNT.js.map +0 -1
  132. package/dist/chunk-D7A4TEXY.js.map +0 -1
  133. package/dist/chunk-EWQYVPOL.js.map +0 -1
  134. package/dist/chunk-ICFMWIIJ.js +0 -53
  135. package/dist/chunk-ICFMWIIJ.js.map +0 -1
  136. package/dist/chunk-LFRKRR7G.js.map +0 -1
  137. package/dist/chunk-MNSQSU7T.js.map +0 -1
  138. package/dist/chunk-NIOLLLJJ.js +0 -44
  139. package/dist/chunk-NIOLLLJJ.js.map +0 -1
  140. package/dist/chunk-P5XJG7OG.js.map +0 -1
  141. package/dist/chunk-QVTKG7FD.js.map +0 -1
  142. package/dist/chunk-SSFPGDA3.js.map +0 -1
  143. package/dist/chunk-TP3K7DMH.js.map +0 -1
  144. package/dist/chunk-UWIMSKL5.js.map +0 -1
  145. package/dist/chunk-VFF4YFA3.js.map +0 -1
  146. package/dist/chunk-W3W3X2OE.js.map +0 -1
  147. package/dist/chunk-X3R3RLXY.js.map +0 -1
  148. package/dist/chunk-XBJ3SJ26.js.map +0 -1
  149. package/dist/chunk-YTBSGKGF.js.map +0 -1
  150. package/dist/chunk-YWFCWT6R.js +0 -23
  151. package/dist/chunk-YWFCWT6R.js.map +0 -1
  152. package/dist/chunk-ZMDJ45KH.js.map +0 -1
  153. package/dist/engine/script/run-all.d.ts +0 -3
  154. package/dist/engine/script/run-all.js +0 -8
  155. package/dist/engine/script/run-bucket.d.ts +0 -3
  156. package/dist/engine/script/run-bucket.js +0 -8
  157. package/dist/engine/script/run-bucket.js.map +0 -1
  158. package/dist/engine/script/run-node-server.d.ts +0 -3
  159. package/dist/engine/script/run-node-server.js +0 -8
  160. package/dist/engine/script/run-node-server.js.map +0 -1
  161. package/dist/engine/server/app.d.ts +0 -5
  162. package/dist/engine/server/app.js +0 -10
  163. package/dist/engine/server/app.js.map +0 -1
  164. package/dist/utility/script/run-all.js +0 -8
  165. package/dist/utility/script/run-all.js.map +0 -1
  166. package/dist/utility/script/run-bucket.js +0 -8
  167. package/dist/utility/script/run-bucket.js.map +0 -1
  168. package/dist/utility/script/run-node-server.js +0 -8
  169. package/dist/utility/script/run-node-server.js.map +0 -1
  170. package/dist/utility/utilis/cloud_storage/s3Client.d.ts +0 -5
  171. package/dist/utility/utilis/cloud_storage/s3Client.js +0 -17
  172. package/dist/utility/utilis/cloud_storage/s3Client.js.map +0 -1
  173. /package/dist/{engine/script/run-all.js.map → utility/libs/index.js.map} +0 -0
  174. /package/dist/utility/{script → libs}/run-all.d.ts +0 -0
  175. /package/dist/utility/{script → libs}/run-bucket.d.ts +0 -0
  176. /package/dist/utility/{script → libs}/run-node-server.d.ts +0 -0
@@ -0,0 +1,1772 @@
1
+ import * as node_http from 'node:http';
2
+ import * as mysql2_promise from 'mysql2/promise';
3
+ import * as pg from 'pg';
4
+ import * as qs from 'qs';
5
+ import * as express_serve_static_core from 'express-serve-static-core';
6
+ import * as express from 'express';
7
+ import { URLOptions, DeleteFile, DeleteFiles, DownloadFileParams, DownloadedFile, DownloadFilesParams, QueryItems, GenerateIdOptions, DownloadablePath, CustomErrorTemplate, BulkWriteInterface, DeleteDocuments, InsertOneInterface, InsertManyInterface, UpdateDocument, UploadFileInput, UploadFilesInput, FilesUploadedResponseData } from './interface.js';
8
+ import { S3Client } from '@aws-sdk/client-s3';
9
+ import { PathOptions, DatabaseType, CustomBulkWriteResult, CustomDeleteResult, CustomInsertOneResult, CustomInsertManyResult, CustomUpdateResult, ResponseInterface, FileUploadedResponseData } from './types.js';
10
+ import 'mongodb';
11
+ import './env.js';
12
+
13
+ /**
14
+ * Deletes a file from either remote object storage or the local filesystem.
15
+ *
16
+ * The function determines whether the provided file reference is a URL or
17
+ * a local filesystem path using `url_or_path()`.
18
+ *
19
+ * For remote URLs, the corresponding object key is extracted from the URL
20
+ * and the object is deleted from the configured bucket using the S3-compatible
21
+ * storage client.
22
+ *
23
+ * For local paths, the function first checks whether the file exists and
24
+ * removes it using the asynchronous filesystem API. If the local file does
25
+ * not exist, the operation is still considered successful.
26
+ *
27
+ * Errors encountered during either remote or local deletion are caught and
28
+ * returned as part of the result instead of being thrown.
29
+ *
30
+ * @param item_file - Full URL of the remote file or local filesystem path
31
+ * of the file to delete.
32
+ *
33
+ * @returns A promise resolving to a `DeleteFile` result containing the
34
+ * original file URL/path, the deletion status, and the error when the
35
+ * operation fails.
36
+ *
37
+ * @example
38
+ * // Delete a file stored in the remote bucket.
39
+ * const result = await deleteFile(
40
+ * 'https://storage.example.com/my-bucket/uploads/profile.jpg'
41
+ * );
42
+ *
43
+ * // Returns:
44
+ * // {
45
+ * // status: true,
46
+ * // url_or_path:
47
+ * // 'https://storage.example.com/my-bucket/uploads/profile.jpg'
48
+ * // }
49
+ *
50
+ * @example
51
+ * // Delete a locally stored file.
52
+ * const result = await deleteFile(
53
+ * './uploads/profile.jpg'
54
+ * );
55
+ *
56
+ * // Returns:
57
+ * // {
58
+ * // status: true,
59
+ * // url_or_path: './uploads/profile.jpg'
60
+ * // }
61
+ *
62
+ * @example
63
+ * // A local file that does not exist is treated as successfully deleted.
64
+ * const result = await deleteFile(
65
+ * './uploads/missing-file.jpg'
66
+ * );
67
+ *
68
+ * // Returns:
69
+ * // {
70
+ * // status: true,
71
+ * // url_or_path: './uploads/missing-file.jpg'
72
+ * // }
73
+ *
74
+ * @example
75
+ * // Handle the deletion result.
76
+ * const result = await deleteFile(filePath);
77
+ *
78
+ * if (result.status) {
79
+ * console.log('File deleted successfully:', result.url_or_path);
80
+ * } else {
81
+ * console.error('Failed to delete file:', result.error);
82
+ * }
83
+ */
84
+ declare const deleteFile: (item_file: string) => Promise<DeleteFile>;
85
+ /**
86
+ * Deletes multiple files from either remote object storage or the local
87
+ * filesystem.
88
+ *
89
+ * Each file is automatically classified as either a remote URL or a local
90
+ * filesystem path using `url_or_path()`. Remote files are deleted from the
91
+ * configured S3-compatible bucket, while local files are removed from the
92
+ * filesystem.
93
+ *
94
+ * The function is designed to be idempotent for local files: if a local
95
+ * file does not exist, that file is still reported as successfully deleted.
96
+ *
97
+ * Duplicate file references are removed before processing to prevent the
98
+ * same file from being deleted more than once.
99
+ *
100
+ * Files are processed in batches of up to 50 items at a time to limit
101
+ * concurrent filesystem and object-storage operations. Each batch is
102
+ * processed concurrently, while subsequent batches wait for the previous
103
+ * batch to complete.
104
+ *
105
+ * Individual deletion failures do not stop the remaining files from being
106
+ * processed. Every file receives its own result describing whether the
107
+ * deletion succeeded or failed.
108
+ *
109
+ * @param item_files - Array of remote file URLs or local filesystem paths
110
+ * to delete.
111
+ *
112
+ * @returns A promise resolving to a `DeleteFiles` object containing the
113
+ * deletion result for each unique file.
114
+ *
115
+ * @example
116
+ * // Delete multiple remote files.
117
+ * const result = await deleteFiles([
118
+ * 'https://storage.example.com/my-bucket/uploads/image1.jpg',
119
+ * 'https://storage.example.com/my-bucket/uploads/image2.jpg',
120
+ * 'https://storage.example.com/my-bucket/uploads/document.pdf',
121
+ * ]);
122
+ *
123
+ * // Returns:
124
+ * // {
125
+ * // items: [
126
+ * // {
127
+ * // url_or_path: 'https://storage.example.com/my-bucket/uploads/image1.jpg',
128
+ * // status: true
129
+ * // },
130
+ * // {
131
+ * // url_or_path: 'https://storage.example.com/my-bucket/uploads/image2.jpg',
132
+ * // status: true
133
+ * // },
134
+ * {
135
+ * url_or_path: 'https://storage.example.com/my-bucket/uploads/document.pdf',
136
+ * status: true
137
+ * }
138
+ * ]
139
+ * // }
140
+ *
141
+ * @example
142
+ * // Delete multiple local files.
143
+ * const result = await deleteFiles([
144
+ * './uploads/image1.jpg',
145
+ * './uploads/image2.jpg',
146
+ * './uploads/document.pdf',
147
+ * ]);
148
+ *
149
+ * @example
150
+ * // Remote URLs and local paths can be mixed in the same request.
151
+ * const result = await deleteFiles([
152
+ * 'https://storage.example.com/my-bucket/uploads/avatar.jpg',
153
+ * './uploads/temp-file.pdf',
154
+ * ]);
155
+ *
156
+ * @example
157
+ * // Duplicate file references are automatically removed.
158
+ * const result = await deleteFiles([
159
+ * './uploads/image.jpg',
160
+ * './uploads/image.jpg',
161
+ * './uploads/document.pdf',
162
+ * ]);
163
+ *
164
+ * // The image is processed only once.
165
+ *
166
+ * @example
167
+ * // Individual failures are returned without stopping other deletions.
168
+ * const result = await deleteFiles([
169
+ * './uploads/existing.jpg',
170
+ * './uploads/missing.jpg',
171
+ * 'invalid-file-reference',
172
+ * ]);
173
+ *
174
+ * // Example result:
175
+ * // {
176
+ * // items: [
177
+ * // {
178
+ * // url_or_path: './uploads/existing.jpg',
179
+ * status: true
180
+ * },
181
+ * {
182
+ * url_or_path: './uploads/missing.jpg',
183
+ * status: true
184
+ * },
185
+ * {
186
+ * url_or_path: 'invalid-file-reference',
187
+ * status: false
188
+ * }
189
+ * ]
190
+ * // }
191
+ *
192
+ * @example
193
+ * // An empty array returns immediately without performing any operations.
194
+ * const result = await deleteFiles([]);
195
+ *
196
+ * // Returns:
197
+ * // {
198
+ * // items: []
199
+ * // }
200
+ */
201
+ declare const deleteFiles: (item_files: string[]) => Promise<DeleteFiles>;
202
+ /**
203
+ * Downloads a file from the configured S3-compatible object storage and
204
+ * saves it to the application's local in-app bucket.
205
+ *
206
+ * The object key is extracted from the provided file URL using
207
+ * `getKeyFromUrl()`. The file is then retrieved from the configured bucket
208
+ * using `GetObjectCommand`.
209
+ *
210
+ * A unique file name is generated while preserving the original file
211
+ * extension. The resulting file is stored under the path specified by
212
+ * `outputPath`, with `ENV.IN_APP_BUCKET` automatically used as the root
213
+ * directory.
214
+ *
215
+ * The required directory structure is created automatically if it does not
216
+ * already exist. The downloaded object is streamed directly to the local
217
+ * filesystem rather than loading the entire file into memory.
218
+ *
219
+ * @param params - Parameters required to download the file.
220
+ * @param params.url - Full URL of the file stored in the S3-compatible
221
+ * object storage.
222
+ * @param params.outputPath - Optional array of directory segments where
223
+ * the downloaded file should be stored inside the in-app bucket.
224
+ *
225
+ * @returns A promise resolving to a `DownloadedFile` containing the original
226
+ * URL, the local file path when successful, and an error when the operation
227
+ * fails.
228
+ *
229
+ * @example
230
+ * // Download a file into the default in-app bucket directory.
231
+ * const result = await downloadFile({
232
+ * url: 'https://storage.example.com/my-bucket/uploads/profile.jpg',
233
+ * });
234
+ *
235
+ * // Example result:
236
+ * // {
237
+ * // status: true,
238
+ * // url: 'https://storage.example.com/my-bucket/uploads/profile.jpg',
239
+ * path: 'in_app_bucket/a8f91c2e4b7d91f2.jpg'
240
+ * // }
241
+ *
242
+ * @example
243
+ * // Download a file into a specific directory.
244
+ * const result = await downloadFile({
245
+ * url: 'https://storage.example.com/my-bucket/documents/report.pdf',
246
+ * outputPath: ['temporary_files', 'documents'],
247
+ * });
248
+ *
249
+ * // Example result:
250
+ * // {
251
+ * // status: true,
252
+ * // url: 'https://storage.example.com/my-bucket/documents/report.pdf',
253
+ * path: 'in_app_bucket/temporary_files/documents/b71d92ac31f04e21.pdf'
254
+ * // }
255
+ *
256
+ * @example
257
+ * // Handle a failed download.
258
+ * const result = await downloadFile({
259
+ * url: 'https://storage.example.com/my-bucket/missing.jpg',
260
+ * outputPath: ['temporary_files'],
261
+ * });
262
+ *
263
+ * if (!result.status) {
264
+ * console.error('Download failed:', result.error);
265
+ * }
266
+ *
267
+ * @example
268
+ * // The downloaded file keeps the original extension while receiving
269
+ * // a newly generated unique file name.
270
+ * const result = await downloadFile({
271
+ * url: 'https://storage.example.com/my-bucket/images/avatar.png',
272
+ * outputPath: ['images'],
273
+ * });
274
+ *
275
+ * // The resulting file will have a structure similar to:
276
+ * // in_app_bucket/images/<unique-id>.png
277
+ */
278
+ declare const downloadFile: ({ url, outputPath }: DownloadFileParams) => Promise<DownloadedFile>;
279
+ /**
280
+ * Downloads multiple files from the configured S3-compatible object storage
281
+ * and saves them to the local in-app bucket.
282
+ *
283
+ * Each file is downloaded independently and processed concurrently. The
284
+ * object key for each file is extracted from its URL using `getKeyFromUrl()`,
285
+ * and the file is streamed directly to the local filesystem.
286
+ *
287
+ * A unique file name is generated for every downloaded file while preserving
288
+ * its original file extension. The target directory is created automatically
289
+ * when it does not already exist.
290
+ *
291
+ * A global output path can be provided for all files, or each file can define
292
+ * its own output path. These two options cannot be used together.
293
+ *
294
+ * Unlike a batch operation that stops when one file fails, each download is
295
+ * handled independently. A failure for one file does not prevent the
296
+ * remaining files from being downloaded.
297
+ *
298
+ * @param params - Parameters containing the files to download and an
299
+ * optional common output path.
300
+ * @param params.files - Array of file download configurations. Each file
301
+ * contains its remote URL and may optionally specify its own output path.
302
+ * @param params.globalPath - Optional common output path used for every file.
303
+ * Cannot be used when any individual file specifies `outputPath`.
304
+ *
305
+ * @returns A promise resolving to an array of `DownloadedFile` results.
306
+ * Each result represents the success or failure of its corresponding
307
+ * download.
308
+ *
309
+ * @example
310
+ * // Download multiple files into the default in-app bucket directory.
311
+ * const results = await downloadFiles({
312
+ * files: [
313
+ * {
314
+ * url: 'https://storage.example.com/my-bucket/images/profile.jpg',
315
+ * },
316
+ * {
317
+ * url: 'https://storage.example.com/my-bucket/documents/report.pdf',
318
+ * },
319
+ * ],
320
+ * });
321
+ *
322
+ * @example
323
+ * // Download multiple files into the same directory.
324
+ * const results = await downloadFiles({
325
+ * files: [
326
+ * {
327
+ * url: 'https://storage.example.com/my-bucket/images/profile.jpg',
328
+ * },
329
+ * {
330
+ * url: 'https://storage.example.com/my-bucket/images/banner.png',
331
+ * },
332
+ * ],
333
+ * globalPath: 'temporary_files',
334
+ * });
335
+ *
336
+ * // Resulting paths will be similar to:
337
+ * // in_app_bucket/temporary_files/<unique-id>.jpg
338
+ * // in_app_bucket/temporary_files/<unique-id>.png
339
+ *
340
+ * @example
341
+ * // Each file can have its own output directory.
342
+ * const results = await downloadFiles({
343
+ * files: [
344
+ * {
345
+ * url: 'https://storage.example.com/my-bucket/images/profile.jpg',
346
+ * outputPath: ['users', 'images'],
347
+ * },
348
+ * {
349
+ * url: 'https://storage.example.com/my-bucket/documents/report.pdf',
350
+ * outputPath: ['users', 'documents'],
351
+ * },
352
+ * ],
353
+ * });
354
+ *
355
+ * @example
356
+ * // Check the result of each download independently.
357
+ * const results = await downloadFiles({
358
+ * files: [
359
+ * {
360
+ * url: 'https://storage.example.com/my-bucket/image1.jpg',
361
+ * },
362
+ * {
363
+ * url: 'https://storage.example.com/my-bucket/image2.jpg',
364
+ * },
365
+ * ],
366
+ * globalPath: 'downloads',
367
+ * });
368
+ *
369
+ * results.forEach((result) => {
370
+ * if (result.status) {
371
+ * console.log('Downloaded:', result.path);
372
+ * } else {
373
+ * console.error('Download failed:', result.url, result.error);
374
+ * }
375
+ * });
376
+ *
377
+ * @example
378
+ * // Invalid: globalPath and individual outputPath cannot be used together.
379
+ * const results = await downloadFiles({
380
+ * files: [
381
+ * {
382
+ * url: 'https://storage.example.com/my-bucket/image.jpg',
383
+ * outputPath: ['images'],
384
+ * },
385
+ * ],
386
+ * globalPath: 'downloads',
387
+ * });
388
+ *
389
+ * // Throws:
390
+ * // Error: Conflict: Cannot specify both 'globalPath' and
391
+ * // 'individual outputPath' on files.
392
+ */
393
+ declare const downloadFiles: ({ files, globalPath, }: DownloadFilesParams) => Promise<DownloadedFile[]>;
394
+ declare const upload_file: ({ file, path }: UploadFileInput) => Promise<FileUploadedResponseData>;
395
+ /**
396
+ * Uploads multiple files to the configured S3-compatible storage bucket
397
+ * concurrently with a configurable concurrency limit.
398
+ *
399
+ * Each file is uploaded using the `upload_file` function. A global path can
400
+ * be applied to all files, or each file can specify its own individual path,
401
+ * but both options cannot be used at the same time.
402
+ *
403
+ * Failed uploads are collected separately from successful uploads, allowing
404
+ * the caller to inspect the result of every individual file without stopping
405
+ * the entire batch operation.
406
+ *
407
+ * @param params - Configuration options for the batch upload.
408
+ * @param params.files - The files to upload along with their optional paths.
409
+ * @param params.globalPath - An optional path applied to all files that do
410
+ * not specify an individual path.
411
+ * @param params.concurrency - The maximum number of files uploaded
412
+ * concurrently. Defaults to `5`.
413
+ * @returns A promise resolving to a `FilesUploadedResponseData` containing
414
+ * separate arrays of successfully uploaded and failed files.
415
+ * @throws {Error} If both `globalPath` and an individual file `path` are
416
+ * provided.
417
+ *
418
+ * @example
419
+ * const result = await upload_files({
420
+ * files: [
421
+ * { file: file1 },
422
+ * { file: file2 },
423
+ * { file: file3 },
424
+ * ],
425
+ * globalPath: ['temporary_files'],
426
+ * concurrency: 5,
427
+ * });
428
+ *
429
+ * console.log('Successful uploads:', result.successFiles);
430
+ * console.log('Failed uploads:', result.failedFiles);
431
+ *
432
+ * @example
433
+ * const result = await upload_files({
434
+ * files: [
435
+ * {
436
+ * file: file1,
437
+ * path: ['documents', 'reports'],
438
+ * },
439
+ * {
440
+ * file: file2,
441
+ * path: ['documents', 'images'],
442
+ * },
443
+ * ],
444
+ * concurrency: 10,
445
+ * });
446
+ *
447
+ * @example
448
+ * // This throws because globalPath and an individual path cannot be used together.
449
+ * const result = await upload_files({
450
+ * files: [
451
+ * {
452
+ * file: file1,
453
+ * path: ['documents'],
454
+ * },
455
+ * ],
456
+ * globalPath: ['temporary_files'],
457
+ * });
458
+ */
459
+ declare const upload_files: ({ files, globalPath, concurrency }: UploadFilesInput) => Promise<FilesUploadedResponseData>;
460
+ /**
461
+ * Returns the configured S3-compatible storage client.
462
+ *
463
+ * This function provides access to the shared `S3Client` instance configured
464
+ * by the application's cloud storage engine. The client can be used for
465
+ * operations such as uploading, downloading, deleting, and managing objects
466
+ * in an S3-compatible storage service.
467
+ *
468
+ * The function returns the existing client instance rather than creating a
469
+ * new client, allowing the application to reuse the same connection
470
+ * configuration across storage operations.
471
+ *
472
+ * @returns A promise resolving to the configured `S3Client` instance.
473
+ *
474
+ * @example
475
+ * // Get the configured S3 client.
476
+ * const s3Client = await getS3Client();
477
+ *
478
+ * // Use the client for an S3 operation.
479
+ * const result = await s3Client.send(
480
+ * new GetObjectCommand({
481
+ * Bucket: ENV.BUCKET_NAME,
482
+ * Key: 'temporary_files/example.jpg',
483
+ * })
484
+ * );
485
+ *
486
+ * @example
487
+ * // The same configured client can be reused for multiple operations.
488
+ * const s3Client = await getS3Client();
489
+ *
490
+ * await s3Client.send(uploadCommand);
491
+ * await s3Client.send(downloadCommand);
492
+ * await s3Client.send(deleteCommand);
493
+ */
494
+ declare const getS3Client: () => Promise<S3Client>;
495
+ /**
496
+ * Normalizes and logs an error with optional contextual information.
497
+ *
498
+ * Formats the error for both terminal and browser environments, displaying
499
+ * its type, message, timestamp, context, stack trace, and raw error object.
500
+ * The normalized error is returned after being logged.
501
+ *
502
+ * @param err - The unknown error value to normalize and handle.
503
+ * @param context - Optional context describing where the error occurred.
504
+ * @returns The normalized error as a `CustomErrorTemplate`.
505
+ *
506
+ * @example
507
+ * const error = handleError(error, 'File Upload');
508
+ * // Logs the normalized error and returns a CustomErrorTemplate.
509
+ *
510
+ * @example
511
+ * try {
512
+ * await upload_file(file);
513
+ * } catch (error) {
514
+ * handleError(error, 'MinIO Upload');
515
+ * }
516
+ */
517
+ declare function handleError(err: unknown, context?: string): CustomErrorTemplate;
518
+ /**
519
+ * Asynchronously checks whether a file or path exists and is accessible.
520
+ *
521
+ * The function uses the filesystem access check to determine whether the
522
+ * specified path can be accessed. It resolves to `true` when the path is
523
+ * accessible and `false` when the access check fails.
524
+ *
525
+ * Any filesystem error is handled internally, so the function does not
526
+ * throw when the file or directory does not exist.
527
+ *
528
+ * @param filePath - The filesystem path to check.
529
+ *
530
+ * @returns A promise resolving to `true` if the path exists and is
531
+ * accessible, otherwise `false`.
532
+ *
533
+ * @example
534
+ * // Check whether a file exists.
535
+ * const exists = await fileExistsAsync('./uploads/profile.jpg');
536
+ *
537
+ * if (exists) {
538
+ * console.log('File exists.');
539
+ * }
540
+ *
541
+ * @example
542
+ * // Use the result before reading a file.
543
+ * const filePath = './uploads/document.pdf';
544
+ *
545
+ * if (await fileExistsAsync(filePath)) {
546
+ * const file = await fs.readFile(filePath);
547
+ * console.log('File loaded successfully.');
548
+ * }
549
+ *
550
+ * @example
551
+ * // A missing file returns false instead of throwing an error.
552
+ * const exists = await fileExistsAsync('./uploads/missing.jpg');
553
+ *
554
+ * // Returns:
555
+ * // false
556
+ */
557
+ declare function fileExistsAsync(filePath: string): Promise<boolean>;
558
+ /**
559
+ * Synchronously checks whether a file or filesystem path exists and is
560
+ * accessible.
561
+ *
562
+ * The function uses Node.js's synchronous filesystem access check to
563
+ * determine whether the specified path can be accessed. It returns `true`
564
+ * when the path is accessible and `false` when the access check fails.
565
+ *
566
+ * Any filesystem error is handled internally, so the function does not
567
+ * throw when the file or directory does not exist.
568
+ *
569
+ * @param filePath - The filesystem path to check.
570
+ *
571
+ * @returns `true` if the path exists and is accessible; otherwise `false`.
572
+ *
573
+ * @example
574
+ * // Check whether a file exists.
575
+ * const exists = fileExistsSync('./uploads/profile.jpg');
576
+ *
577
+ * if (exists) {
578
+ * console.log('File exists.');
579
+ * }
580
+ *
581
+ * @example
582
+ * // Check before performing a synchronous file operation.
583
+ * const filePath = './uploads/document.pdf';
584
+ *
585
+ * if (fileExistsSync(filePath)) {
586
+ * const file = fsSync.readFileSync(filePath);
587
+ * console.log('File loaded successfully.');
588
+ * }
589
+ *
590
+ * @example
591
+ * // A missing file returns false instead of throwing an error.
592
+ * const exists = fileExistsSync('./uploads/missing.jpg');
593
+ *
594
+ * // Returns:
595
+ * // false
596
+ */
597
+ declare function fileExistsSync(filePath: string): boolean;
598
+ /**
599
+ * Extracts the file extension from a supported file input.
600
+ *
601
+ * Supports Express Multer files, Web API `File` objects, raw `Buffer` values,
602
+ * and file paths or URLs. For URLs and paths, query parameters and hash
603
+ * fragments are ignored when determining the extension.
604
+ *
605
+ * @param input - The file, buffer, path, or URL from which to extract the extension.
606
+ * @returns The file extension without the leading dot, converted to lowercase.
607
+ * Returns an empty string if no extension can be determined.
608
+ *
609
+ * @example
610
+ * const extension = getFileExtension('https://example.com/files/image.PNG');
611
+ * // Returns: "png"
612
+ *
613
+ * @example
614
+ * const extension = getFileExtension(req.file);
615
+ * // Returns: "pdf"
616
+ *
617
+ * @example
618
+ * const extension = getFileExtension('documents/report.pdf?download=true');
619
+ * // Returns: "pdf"
620
+ *
621
+ * @example
622
+ * const extension = getFileExtension(buffer);
623
+ * // Returns: ""
624
+ */
625
+ declare function getFileExtension(input: Express.Multer.File | File | Buffer | string): string;
626
+ /**
627
+ * Determines whether the provided value is a URL or a local/server based file path.
628
+ *
629
+ * If the value is a valid HTTP/HTTPS URL, the configured URL environment
630
+ * value is returned. Otherwise, the configured local path environment value
631
+ * is returned.
632
+ *
633
+ * @param val - The URL or local file path to evaluate.
634
+ * @returns The configured URL or local path based on the input type.
635
+ *
636
+ * @example
637
+ * const basePath = url_or_path('https://example.com/file.png');
638
+ * // Returns ENV.URL
639
+ *
640
+ * @example
641
+ * const basePath = url_or_path('/uploads/file.png');
642
+ * // Returns ENV.PATH
643
+ */
644
+ declare const url_or_path: (val: string) => "url" | "path";
645
+ /**
646
+ * Safely normalizes Buffer, Express.Multer.File, Web File, or File Path into Uint8Array
647
+ */
648
+ declare function toUint8Array(file: Express.Multer.File | File | Buffer | string): Promise<Uint8Array>;
649
+ /**
650
+ * Builds a normalized file path from the provided path components.
651
+ *
652
+ * Combines the path prefix, path segments, path postfix, and file name,
653
+ * while removing empty values and normalizing redundant slashes.
654
+ *
655
+ * If `fileName` is a Web API `File` object, its `name` property is used.
656
+ *
657
+ * @param options - The path components used to construct the final path.
658
+ * @param options.path_prefix - An optional prefix to prepend to the path.
659
+ * @param options.path - An array of path segments.
660
+ * @param options.path_postfix - An optional postfix to append before the file name.
661
+ * @param options.fileName - The file name or a Web API `File` object.
662
+ * @returns A normalized path with components separated by a single slash.
663
+ *
664
+ * @example
665
+ * const filePath = buildPath({
666
+ * path_prefix: 'uploads',
667
+ * path: ['documents', 'reports'],
668
+ * fileName: 'report.pdf',
669
+ * });
670
+ * // Returns: "uploads/documents/reports/report.pdf"
671
+ *
672
+ * @example
673
+ * const filePath = buildPath({
674
+ * path: ['documents//', '/reports/'],
675
+ * fileName: 'report.pdf',
676
+ * });
677
+ * // Returns: "documents/reports/report.pdf"
678
+ */
679
+ declare function buildPath(options: PathOptions): string;
680
+ /**
681
+ * Determines the MIME content type of a file from its available metadata
682
+ * or, when given a file path or URL, from its file extension.
683
+ *
684
+ * Supports Express Multer files, Web API `File` objects, raw `Buffer` values,
685
+ * and file paths or URLs.
686
+ *
687
+ * @param file - The file, buffer, path, or URL whose content type should be determined.
688
+ * @returns A promise resolving to the detected MIME content type.
689
+ *
690
+ * @example
691
+ * const contentType = await getFileContentType(req.file);
692
+ * // Returns something like: "image/jpeg"
693
+ *
694
+ * @example
695
+ * const contentType = await getFileContentType('/uploads/document.pdf');
696
+ * // Returns: "application/pdf"
697
+ *
698
+ * @example
699
+ * const contentType = await getFileContentType(buffer);
700
+ * // Returns: "application/octet-stream"
701
+ */
702
+ declare const getFileContentType: (file: Express.Multer.File | File | Buffer | string) => Promise<string>;
703
+ /**
704
+ * Builds the download path for a file stored in the application's
705
+ * in-app bucket.
706
+ *
707
+ * The configured `ENV.IN_APP_BUCKET` value is automatically used as the
708
+ * path prefix. If the bucket name is already present in the supplied
709
+ * segments, it is removed first to prevent the bucket name from being
710
+ * duplicated in the resulting path.
711
+ *
712
+ * The function supports an optional file name or file-like input. When a
713
+ * `File` or `Express.Multer.File` is provided, the underlying file name is
714
+ * resolved by `buildPath()`.
715
+ *
716
+ * @param options - Options used to construct the in-app bucket path.
717
+ * @param options.segments - Optional path segments representing directories
718
+ * within the in-app bucket.
719
+ * @param options.fileName - Optional file to append to the generated path.
720
+ * Supports `Express.Multer.File`, Web API `File`, `Buffer`, or a string
721
+ * path/file name.
722
+ *
723
+ * @returns A normalized path beginning with `ENV.IN_APP_BUCKET`.
724
+ *
725
+ * @example
726
+ * // Build a path for a file inside the in-app bucket.
727
+ * const path = getInAppBucketDownloadPath({
728
+ * segments: ['temporary_files', 'images'],
729
+ * fileName: 'profile.jpg',
730
+ * });
731
+ *
732
+ * // Returns:
733
+ * // <IN_APP_BUCKET>/temporary_files/images/profile.jpg
734
+ *
735
+ * @example
736
+ * // The bucket name is automatically removed if it is already
737
+ * // included in the provided segments.
738
+ * const path = getInAppBucketDownloadPath({
739
+ * segments: [
740
+ * ENV.IN_APP_BUCKET,
741
+ * 'temporary_files',
742
+ * 'images',
743
+ * ],
744
+ * fileName: 'profile.jpg',
745
+ * });
746
+ *
747
+ * // Returns:
748
+ * // <IN_APP_BUCKET>/temporary_files/images/profile.jpg
749
+ *
750
+ * @example
751
+ * // A Multer file can be supplied directly.
752
+ * const path = getInAppBucketDownloadPath({
753
+ * segments: ['temporary_files'],
754
+ * fileName: req.file,
755
+ * });
756
+ *
757
+ * @example
758
+ * // A path can be generated without a file name.
759
+ * const path = getInAppBucketDownloadPath({
760
+ * segments: ['temporary_files', 'images'],
761
+ * });
762
+ *
763
+ * // Returns:
764
+ * // <IN_APP_BUCKET>/temporary_files/images
765
+ */
766
+ declare function getInAppBucketDownloadPath({ segments, fileName }?: DownloadablePath): string;
767
+ /**
768
+ * Detects the SQL database type from a database connection URL.
769
+ *
770
+ * The function supports MySQL and PostgreSQL connection URL schemes,
771
+ * including common driver-specific variants such as `mysql2`,
772
+ * `mysql+pymysql`, `postgresql+psycopg2`, and `postgresql+asyncpg`.
773
+ *
774
+ * If the connection string does not contain a recognized protocol, the
775
+ * function attempts to identify the database using keywords in the
776
+ * connection string or the default database ports:
777
+ *
778
+ * - MySQL: `3306`
779
+ * - PostgreSQL: `5432`
780
+ *
781
+ * Invalid URLs are also checked as raw connection strings before an error
782
+ * is thrown. This allows common connection strings without a protocol to
783
+ * still be detected.
784
+ *
785
+ * @param url - The SQL database connection URL or connection string.
786
+ * @returns `ENV.MY_SQL` for MySQL connections or `ENV.POSTGRES_SQL` for
787
+ * PostgreSQL connections.
788
+ * @throws {Error} If the URL is invalid or the database type cannot be
789
+ * identified as MySQL or PostgreSQL.
790
+ *
791
+ * @example
792
+ * // Detect PostgreSQL from a standard connection URL.
793
+ * const database = detectSQLDatabase(
794
+ * 'postgresql://user:password@localhost:5432/my_database'
795
+ * );
796
+ *
797
+ * // Returns: ENV.POSTGRES_SQL
798
+ *
799
+ * @example
800
+ * // Detect MySQL from a standard connection URL.
801
+ * const database = detectSQLDatabase(
802
+ * 'mysql://user:password@localhost:3306/my_database'
803
+ * );
804
+ *
805
+ * // Returns: ENV.MY_SQL
806
+ *
807
+ * @example
808
+ * // Driver-specific PostgreSQL URLs are also supported.
809
+ * const database = detectSQLDatabase(
810
+ * 'postgresql+psycopg2://user:password@localhost:5432/my_database'
811
+ * );
812
+ *
813
+ * // Returns: ENV.POSTGRES_SQL
814
+ *
815
+ * @example
816
+ * // A connection string without a recognized protocol can be detected
817
+ * // using the default PostgreSQL port.
818
+ * const database = detectSQLDatabase(
819
+ * 'localhost:5432/my_database'
820
+ * );
821
+ *
822
+ * // Returns: ENV.POSTGRES_SQL
823
+ *
824
+ * @example
825
+ * // Throws when the database type cannot be determined.
826
+ * const database = detectSQLDatabase(
827
+ * 'mongodb://localhost:27017/my_database'
828
+ * );
829
+ *
830
+ * // Error: Unsupported or unrecognized database type.
831
+ */
832
+ declare function detectSQLDatabase(url: string): DatabaseType;
833
+ /**
834
+ * Determines whether a database connection URL represents a MySQL database.
835
+ *
836
+ * This function delegates database detection to `detectSQLDatabase()` and
837
+ * compares the detected database type with the configured MySQL database
838
+ * identifier.
839
+ *
840
+ * Any error encountered while parsing or detecting the database type is
841
+ * handled internally, and the function returns `false` instead of throwing.
842
+ * This makes the function safe to use when validating or conditionally
843
+ * selecting a database implementation.
844
+ *
845
+ * @param url - The SQL database connection URL or connection string.
846
+ * @returns `true` if the URL represents a MySQL database; otherwise `false`.
847
+ *
848
+ * @example
849
+ * // Standard MySQL connection URL.
850
+ * const result = isMySQL(
851
+ * 'mysql://user:password@localhost:3306/my_database'
852
+ * );
853
+ *
854
+ * // Returns: true
855
+ *
856
+ * @example
857
+ * // PostgreSQL URL.
858
+ * const result = isMySQL(
859
+ * 'postgresql://user:password@localhost:5432/my_database'
860
+ * );
861
+ *
862
+ * // Returns: false
863
+ *
864
+ * @example
865
+ * // Invalid or unsupported connection URL.
866
+ * const result = isMySQL('invalid-database-url');
867
+ *
868
+ * // Returns: false instead of throwing an error.
869
+ */
870
+ declare function isMySQL(url: string): boolean;
871
+ /**
872
+ * Determines whether a database connection URL represents a PostgreSQL
873
+ * database.
874
+ *
875
+ * This function delegates database detection to `detectSQLDatabase()` and
876
+ * compares the detected database type with the configured PostgreSQL
877
+ * identifier.
878
+ *
879
+ * Any error encountered while parsing or detecting the database type is
880
+ * handled internally, causing the function to return `false` instead of
881
+ * throwing. This makes the function safe to use when conditionally selecting
882
+ * PostgreSQL-specific database logic.
883
+ *
884
+ * @param url - The SQL database connection URL or connection string.
885
+ * @returns `true` if the URL represents a PostgreSQL database; otherwise
886
+ * `false`.
887
+ *
888
+ * @example
889
+ * // Standard PostgreSQL connection URL.
890
+ * const result = isPostgreSQL(
891
+ * 'postgresql://user:password@localhost:5432/my_database'
892
+ * );
893
+ *
894
+ * // Returns: true
895
+ *
896
+ * @example
897
+ * // MySQL connection URL.
898
+ * const result = isPostgreSQL(
899
+ * 'mysql://user:password@localhost:3306/my_database'
900
+ * );
901
+ *
902
+ * // Returns: false
903
+ *
904
+ * @example
905
+ * // Invalid or unsupported connection URL.
906
+ * const result = isPostgreSQL('invalid-database-url');
907
+ *
908
+ * // Returns: false instead of throwing an error.
909
+ */
910
+ declare function isPostgreSQL(url: string): boolean;
911
+ /**
912
+ * Generates one or more cryptographically secure unique values.
913
+ *
914
+ * Values can be generated using hexadecimal characters or a custom
915
+ * alphanumeric character set. Optional timestamps and prefixes can be
916
+ * included in the generated values.
917
+ *
918
+ * When `count` is provided, multiple unique values are returned as an array.
919
+ * Otherwise, a single string is returned.
920
+ *
921
+ * @param length - The length of the randomly generated portion of each value.
922
+ * @param options - Optional configuration for generating the value(s).
923
+ * @param options.useHex - Whether to generate the random portion using hexadecimal characters.
924
+ * @param options.includeTimestamp - Whether to prepend a hexadecimal timestamp.
925
+ * @param options.prefix - An optional prefix to prepend to the generated value.
926
+ * @param options.count - The number of values to generate. If omitted, one value is returned.
927
+ * @returns A single unique string when `count` is not provided, or an array of unique strings when `count` is specified.
928
+ * @throws {Error} If `length` or `count` is less than or equal to zero.
929
+ *
930
+ * @example
931
+ * const id = generateUniqueValue(16);
932
+ * // Returns: "aZ7_kP2mQ9xL3nBc"
933
+ *
934
+ * @example
935
+ * const id = generateUniqueValue(16, {
936
+ * useHex: true,
937
+ * prefix: 'file',
938
+ * });
939
+ * // Returns: "file-7f3a9c12d84e..."
940
+ *
941
+ * @example
942
+ * const id = generateUniqueValue(12, {
943
+ * includeTimestamp: true,
944
+ * });
945
+ * // Returns: "198a7f3c12a-7Kx9mP..."
946
+ *
947
+ * @example
948
+ * const ids = generateUniqueValue(10, {
949
+ * count: 5,
950
+ * prefix: 'file',
951
+ * });
952
+ * // Returns: ["file-...", "file-...", "file-...", "file-...", "file-..."]
953
+ */
954
+ declare function generateUniqueValue(length: number, options?: GenerateIdOptions): string;
955
+ declare function generateUniqueValue(length: number, options: GenerateIdOptions & {
956
+ count: number;
957
+ }): string[];
958
+ /**
959
+ * Builds a normalized URL or path from an optional endpoint, path segments,
960
+ * and file name.
961
+ *
962
+ * The function safely combines all provided segments while removing empty
963
+ * values and normalizing slashes between segments. If the endpoint contains
964
+ * an HTTP or HTTPS protocol, the protocol is preserved separately so that
965
+ * slash normalization does not alter it.
966
+ *
967
+ * A `File` object can also be provided as `fileName`; in that case, its
968
+ * original file name is extracted automatically.
969
+ *
970
+ * @param options - Options used to construct the URL.
971
+ * @param options.end_point - Optional base URL or endpoint. Supports
972
+ * `http://` and `https://` protocols.
973
+ * @param options.path - Optional array of path segments to append to the
974
+ * endpoint.
975
+ * @param options.fileName - Optional file name or Web API `File` object.
976
+ *
977
+ * @returns A normalized URL/path containing the provided endpoint, path
978
+ * segments, and file name. Returns an empty string when no valid segments
979
+ * are provided.
980
+ *
981
+ * @example
982
+ * // Build a URL from an endpoint, path, and file name.
983
+ * const url = buildURL({
984
+ * end_point: 'https://storage.example.com',
985
+ * path: ['uploads', 'images'],
986
+ * fileName: 'profile.jpg',
987
+ * });
988
+ *
989
+ * // Returns:
990
+ * // https://storage.example.com/uploads/images/profile.jpg
991
+ *
992
+ * @example
993
+ * // Extra slashes are automatically normalized.
994
+ * const url = buildURL({
995
+ * end_point: 'https://storage.example.com/',
996
+ * path: ['/uploads/', '/images//'],
997
+ * fileName: '/profile.jpg',
998
+ * });
999
+ *
1000
+ * // Returns:
1001
+ * // https://storage.example.com/uploads/images/profile.jpg
1002
+ *
1003
+ * @example
1004
+ * // A File object can be used as the file name.
1005
+ * const url = buildURL({
1006
+ * end_point: 'https://storage.example.com',
1007
+ * path: ['uploads'],
1008
+ * fileName: file,
1009
+ * });
1010
+ *
1011
+ * // If file.name is "document.pdf":
1012
+ * // https://storage.example.com/uploads/document.pdf
1013
+ *
1014
+ * @example
1015
+ * // The function can also build a path without a URL endpoint.
1016
+ * const path = buildURL({
1017
+ * path: ['uploads', 'documents'],
1018
+ * fileName: 'report.pdf',
1019
+ * });
1020
+ *
1021
+ * // Returns:
1022
+ * // uploads/documents/report.pdf
1023
+ *
1024
+ * @example
1025
+ * // Empty or undefined segments are ignored.
1026
+ * const url = buildURL({
1027
+ * end_point: 'https://storage.example.com/',
1028
+ * path: ['', 'uploads', '', 'documents'],
1029
+ * fileName: 'report.pdf',
1030
+ * });
1031
+ *
1032
+ * // Returns:
1033
+ * // https://storage.example.com/uploads/documents/report.pdf
1034
+ *
1035
+ * @example
1036
+ * // Returns an empty string when no usable values are provided.
1037
+ * const url = buildURL({});
1038
+ *
1039
+ * // Returns:
1040
+ * // ''
1041
+ */
1042
+ declare function buildURL({ end_point, path, fileName }: URLOptions): string;
1043
+ /**
1044
+ * Extracts the object key/path from a full public file URL.
1045
+ *
1046
+ * This function is intended for files stored in the configured bucket.
1047
+ * It parses the URL, extracts the pathname, removes the configured bucket
1048
+ * name when it appears as the first path segment, and decodes any
1049
+ * URL-encoded characters in the resulting object key.
1050
+ *
1051
+ * For example, a URL such as:
1052
+ *
1053
+ * `https://storage.example.com/my-bucket/uploads/images/profile%20photo.jpg`
1054
+ *
1055
+ * will produce:
1056
+ *
1057
+ * `uploads/images/profile photo.jpg`
1058
+ *
1059
+ * @param url - The full public URL of the stored file.
1060
+ * @returns The decoded object key/path without the bucket name.
1061
+ *
1062
+ * @throws {TypeError} If the provided value is not a valid URL.
1063
+ *
1064
+ * @example
1065
+ * // Extract the object key from a bucket URL.
1066
+ * const key = getKeyFromUrl(
1067
+ * 'https://storage.example.com/my-bucket/uploads/profile.jpg'
1068
+ * );
1069
+ *
1070
+ * // Returns:
1071
+ * // 'uploads/profile.jpg'
1072
+ *
1073
+ * @example
1074
+ * // URL-encoded characters are decoded automatically.
1075
+ * const key = getKeyFromUrl(
1076
+ * 'https://storage.example.com/my-bucket/uploads/profile%20photo.jpg'
1077
+ * );
1078
+ *
1079
+ * // Returns:
1080
+ * // 'uploads/profile photo.jpg'
1081
+ *
1082
+ * @example
1083
+ * // Nested directories are preserved.
1084
+ * const key = getKeyFromUrl(
1085
+ * 'https://storage.example.com/my-bucket/users/123/avatar/image.png'
1086
+ * );
1087
+ *
1088
+ * // Returns:
1089
+ * // 'users/123/avatar/image.png'
1090
+ */
1091
+ declare const getKeyFromUrl: (url: string) => string;
1092
+ /**
1093
+ * Sends a standardized API response to the client.
1094
+ *
1095
+ * This function provides a consistent response structure for both successful
1096
+ * and failed requests. The `success` property acts as the discriminator
1097
+ * between the two response types.
1098
+ *
1099
+ * For successful responses, the function returns the supplied status,
1100
+ * message, data, and metadata. For failed responses, it returns the supplied
1101
+ * status, message, error information, and metadata.
1102
+ *
1103
+ * A response timestamp is automatically generated when one is not already
1104
+ * provided through `meta.timestamp`.
1105
+ *
1106
+ * @param response - Express `Response` object used to send the HTTP response.
1107
+ * @param success - Indicates whether the request was successful.
1108
+ * @param status - HTTP status code returned to the client.
1109
+ * @param message - Optional human-readable response message.
1110
+ * @param data - Optional data returned by a successful operation.
1111
+ * @param error - Error information returned when the operation fails.
1112
+ * @param meta - Optional response metadata such as request ID, timestamp,
1113
+ * pagination information, or other request-related information.
1114
+ *
1115
+ * @returns The Express response containing the standardized API payload.
1116
+ *
1117
+ * @example
1118
+ * // Successful response.
1119
+ * return response_to_client({
1120
+ * response: res,
1121
+ * success: true,
1122
+ * status: 200,
1123
+ * message: 'User fetched successfully.',
1124
+ * data: user,
1125
+ * });
1126
+ *
1127
+ * @example
1128
+ * // Successful response with pagination metadata.
1129
+ * return response_to_client({
1130
+ * response: res,
1131
+ * success: true,
1132
+ * status: 200,
1133
+ * message: 'Users fetched successfully.',
1134
+ * data: users,
1135
+ * meta: {
1136
+ * timestamp: new Date().toISOString(),
1137
+ * requestId: 'req_123456',
1138
+ * page: 1,
1139
+ * limit: 20,
1140
+ * totalItems: 100,
1141
+ * totalPages: 5,
1142
+ * },
1143
+ * });
1144
+ *
1145
+ * @example
1146
+ * // Error response.
1147
+ * return response_to_client({
1148
+ * response: res,
1149
+ * success: false,
1150
+ * status: 404,
1151
+ * message: 'File not found.',
1152
+ * error: {
1153
+ * code: 'FILE_NOT_FOUND',
1154
+ * path: '/files/profile.jpg',
1155
+ * },
1156
+ * });
1157
+ *
1158
+ * @example
1159
+ * // Validation error with structured details.
1160
+ * return response_to_client({
1161
+ * response: res,
1162
+ * success: false,
1163
+ * status: 400,
1164
+ * message: 'Validation failed.',
1165
+ * error: {
1166
+ * code: 'VALIDATION_ERROR',
1167
+ * details: [
1168
+ * {
1169
+ * field: 'email',
1170
+ * message: 'Invalid email address.',
1171
+ * },
1172
+ * {
1173
+ * field: 'password',
1174
+ * message: 'Password is required.',
1175
+ * },
1176
+ * ],
1177
+ * },
1178
+ * });
1179
+ *
1180
+ * @example
1181
+ * // Error response with a request ID for tracing.
1182
+ * return response_to_client({
1183
+ * response: res,
1184
+ * success: false,
1185
+ * status: 500,
1186
+ * message: 'Internal server error.',
1187
+ * error: {
1188
+ * code: 'INTERNAL_SERVER_ERROR',
1189
+ * },
1190
+ * meta: {
1191
+ * timestamp: new Date().toISOString(),
1192
+ * requestId: 'req_abc123',
1193
+ * },
1194
+ * });
1195
+ */
1196
+ declare const responseToClient: ({ response, ...payload }: ResponseInterface) => express.Response<any, Record<string, any>>;
1197
+ /**
1198
+ * Executes multiple write operations against a MongoDB collection in a single
1199
+ * bulk operation.
1200
+ *
1201
+ * The function connects to the specified database and collection, executes
1202
+ * the provided bulk write operations, and returns a standardized result
1203
+ * indicating whether the operation succeeded or failed.
1204
+ *
1205
+ * @param params - Configuration and operations required for the bulk write.
1206
+ * @param params.dbName - The name of the MongoDB database.
1207
+ * @param params.collectionName - The name of the collection to modify.
1208
+ * @param params.writable - An array of MongoDB bulk write operations to execute.
1209
+ * @param params.options - Optional MongoDB bulk write configuration.
1210
+ * @returns A promise resolving to a `CustomBulkWriteResult` containing either
1211
+ * the `BulkWriteResult` on success or an `Error` on failure.
1212
+ *
1213
+ * @example
1214
+ * const result = await bulkWrite({
1215
+ * dbName: 'my_database',
1216
+ * collectionName: 'users',
1217
+ * writable: [
1218
+ * {
1219
+ * insertOne: {
1220
+ * document: {
1221
+ * name: 'John',
1222
+ * email: 'john@example.com',
1223
+ * },
1224
+ * },
1225
+ * },
1226
+ * {
1227
+ * updateOne: {
1228
+ * filter: { name: 'Jane' },
1229
+ * update: { $set: { active: true } },
1230
+ * },
1231
+ * },
1232
+ * ],
1233
+ * });
1234
+ *
1235
+ * if (result.status) {
1236
+ * console.log(result.result);
1237
+ * } else {
1238
+ * console.error(result.error);
1239
+ * }
1240
+ */
1241
+ declare const mongoBulkWrite: (params: BulkWriteInterface) => Promise<CustomBulkWriteResult>;
1242
+ /**
1243
+ * Deletes one or more documents from a MongoDB collection.
1244
+ *
1245
+ * By default, the function deletes a single document matching the provided
1246
+ * query. When `deleteMany` is set to `true`, all documents matching the query
1247
+ * are deleted.
1248
+ *
1249
+ * @param params - Configuration options for the delete operation.
1250
+ * @param params.dbName - The name of the MongoDB database.
1251
+ * @param params.collection - The name of the collection to delete from.
1252
+ * @param params.query - The MongoDB filter used to identify the documents.
1253
+ * @param params.deleteMany - Whether to delete all matching documents instead
1254
+ * of only the first matching document. Defaults to `false`.
1255
+ * @param params.options - Optional MongoDB delete operation options.
1256
+ * @returns A promise resolving to a `CustomDeleteResult` containing the
1257
+ * `DeleteResult` and number of deleted documents on success, or an `Error`
1258
+ * on failure.
1259
+ *
1260
+ * @example
1261
+ * const result = await deleteDocument({
1262
+ * dbName: 'my_database',
1263
+ * collection: 'users',
1264
+ * query: {
1265
+ * email: 'john@example.com',
1266
+ * },
1267
+ * });
1268
+ *
1269
+ * if (result.status) {
1270
+ * console.log(`Deleted ${result.deletedCount} document(s)`);
1271
+ * } else {
1272
+ * console.error(result.error);
1273
+ * }
1274
+ *
1275
+ * @example
1276
+ * const result = await deleteDocument({
1277
+ * dbName: 'my_database',
1278
+ * collection: 'users',
1279
+ * query: {
1280
+ * active: false,
1281
+ * },
1282
+ * deleteMany: true,
1283
+ * });
1284
+ *
1285
+ * // Deletes all inactive users matching the query.
1286
+ */
1287
+ declare const mongoDeleteDocument: (params: DeleteDocuments) => Promise<CustomDeleteResult>;
1288
+ /**
1289
+ * Inserts a single document into a MongoDB collection.
1290
+ *
1291
+ * The document is inserted into the specified database and collection using
1292
+ * the provided MongoDB insertion options. The generic type `T` allows the
1293
+ * inserted document and resulting operation to remain type-safe.
1294
+ *
1295
+ * @param params - Configuration options for the insert operation.
1296
+ * @param params.dbName - The name of the MongoDB database.
1297
+ * @param params.collectionName - The name of the collection to insert into.
1298
+ * @param params.field - The document to insert.
1299
+ * @param params.options - Optional MongoDB insert operation options.
1300
+ * @returns A promise resolving to a `CustomInsertOneResult<T>` containing the
1301
+ * `InsertOneResult` on success or an `Error` on failure.
1302
+ *
1303
+ * @example
1304
+ * const result = await insertOneField({
1305
+ * dbName: 'my_database',
1306
+ * collectionName: 'users',
1307
+ * field: {
1308
+ * name: 'John Doe',
1309
+ * email: 'john@example.com',
1310
+ * },
1311
+ * });
1312
+ *
1313
+ * if (result.status) {
1314
+ * console.log('Inserted ID:', result.result.insertedId);
1315
+ * } else {
1316
+ * console.error(result.error);
1317
+ * }
1318
+ */
1319
+ declare const mongoInsertField: <T>(params: InsertOneInterface<T>) => Promise<CustomInsertOneResult<T>>;
1320
+ /**
1321
+ * Inserts multiple documents into a MongoDB collection.
1322
+ *
1323
+ * The documents are inserted into the specified database and collection
1324
+ * using the provided MongoDB insertion options. The generic type `T`
1325
+ * ensures that the inserted documents and resulting operation remain
1326
+ * type-safe.
1327
+ *
1328
+ * @param params - Configuration options for the bulk insert operation.
1329
+ * @param params.dbName - The name of the MongoDB database.
1330
+ * @param params.collectionName - The name of the collection to insert into.
1331
+ * @param params.fields - An array of documents to insert.
1332
+ * @param params.options - Optional MongoDB bulk write options.
1333
+ * @returns A promise resolving to a `CustomInsertManyResult<T>` containing
1334
+ * the `InsertManyResult` and number of inserted documents on success, or
1335
+ * an `Error` on failure.
1336
+ *
1337
+ * @example
1338
+ * const result = await insertManyFields({
1339
+ * dbName: 'my_database',
1340
+ * collectionName: 'users',
1341
+ * fields: [
1342
+ * {
1343
+ * name: 'John Doe',
1344
+ * email: 'john@example.com',
1345
+ * },
1346
+ * {
1347
+ * name: 'Jane Doe',
1348
+ * email: 'jane@example.com',
1349
+ * },
1350
+ * ],
1351
+ * });
1352
+ *
1353
+ * if (result.status) {
1354
+ * console.log(`Inserted ${result.insertedCount} documents`);
1355
+ * } else {
1356
+ * console.error(result.error);
1357
+ * }
1358
+ */
1359
+ declare const mongoInsertFields: <T>(params: InsertManyInterface<T>) => Promise<CustomInsertManyResult<T>>;
1360
+ /**
1361
+ * Updates one or more documents in a MongoDB collection.
1362
+ *
1363
+ * By default, the function updates a single document matching the provided
1364
+ * query. When `updateMany` is set to `true`, all documents matching the query
1365
+ * are updated.
1366
+ *
1367
+ * @param params - Configuration options for the update operation.
1368
+ * @param params.dbName - The name of the MongoDB database.
1369
+ * @param params.collectionName - The name of the collection to update.
1370
+ * @param params.query - The MongoDB filter used to identify the documents.
1371
+ * @param params.updatable - The update operations or update pipeline to apply
1372
+ * to the matching documents.
1373
+ * @param params.updateMany - Whether to update all matching documents instead
1374
+ * of only the first matching document. Defaults to `false`.
1375
+ * @param params.options - Optional MongoDB update operation options.
1376
+ * @returns A promise resolving to a `CustomUpdateResult` containing the
1377
+ * `UpdateResult` on success or an `Error` on failure.
1378
+ *
1379
+ * @example
1380
+ * const result = await updateField({
1381
+ * dbName: 'my_database',
1382
+ * collectionName: 'users',
1383
+ * query: {
1384
+ * email: 'john@example.com',
1385
+ * },
1386
+ * updatable: {
1387
+ * $set: {
1388
+ * active: true,
1389
+ * },
1390
+ * },
1391
+ * });
1392
+ *
1393
+ * if (result.status) {
1394
+ * console.log('User updated successfully');
1395
+ * } else {
1396
+ * console.error(result.error);
1397
+ * }
1398
+ *
1399
+ * @example
1400
+ * const result = await updateField({
1401
+ * dbName: 'my_database',
1402
+ * collectionName: 'users',
1403
+ * query: {
1404
+ * active: false,
1405
+ * },
1406
+ * updatable: {
1407
+ * $set: {
1408
+ * status: 'inactive',
1409
+ * },
1410
+ * },
1411
+ * updateMany: true,
1412
+ * });
1413
+ *
1414
+ * // Updates all users matching the query.
1415
+ */
1416
+ declare const mongoUpdateField: (params: UpdateDocument) => Promise<CustomUpdateResult>;
1417
+ /**
1418
+ * Creates Multer middleware for handling multiple file uploads from a
1419
+ * single form field.
1420
+ *
1421
+ * The middleware accepts multiple files using the specified field name and
1422
+ * limits the maximum number of uploaded files to the provided count.
1423
+ *
1424
+ * If no field name is supplied, `ENV.FILES` is used as the default field
1425
+ * name. Likewise, `MAX_BATCH_FILES` is used as the default maximum number
1426
+ * of files.
1427
+ *
1428
+ * @param fieldName - Name of the multipart/form-data field containing the
1429
+ * uploaded files.
1430
+ * @param maxCount - Maximum number of files that can be uploaded in a
1431
+ * single request.
1432
+ *
1433
+ * @returns Multer middleware configured to process an array of uploaded
1434
+ * files.
1435
+ *
1436
+ * @example
1437
+ * // Use the default field name and maximum file count.
1438
+ * router.post('/upload', upload_batch(), uploadBatchFilesApi);
1439
+ *
1440
+ * @example
1441
+ * // Accept up to 10 files from the "files" field.
1442
+ * router.post(
1443
+ * '/upload',
1444
+ * upload_batch('files', 10),
1445
+ * uploadBatchFilesApi
1446
+ * );
1447
+ *
1448
+ * @example
1449
+ * // Use a custom field name with the configured maximum file count.
1450
+ * router.post(
1451
+ * '/images',
1452
+ * upload_batch('images'),
1453
+ * uploadBatchFilesApi
1454
+ * );
1455
+ */
1456
+ declare const upload_batch: (fieldName?: string, maxCount?: number) => express.RequestHandler<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>;
1457
+ /**
1458
+ * Creates Multer middleware for handling a single file upload.
1459
+ *
1460
+ * The middleware expects one uploaded file from the specified
1461
+ * `multipart/form-data` field and makes the uploaded file available through
1462
+ * `req.file`.
1463
+ *
1464
+ * If no field name is provided, `ENV.FILE` is used as the default field name.
1465
+ *
1466
+ * @param fieldName - Name of the multipart/form-data field containing the
1467
+ * uploaded file.
1468
+ *
1469
+ * @returns Multer middleware configured to process a single uploaded file.
1470
+ *
1471
+ * @example
1472
+ * // Use the default field name.
1473
+ * router.post(
1474
+ * '/upload',
1475
+ * upload_single(),
1476
+ * uploadSingleFileApi
1477
+ * );
1478
+ *
1479
+ * @example
1480
+ * // Accept a single file from the "file" field.
1481
+ * router.post(
1482
+ * '/upload',
1483
+ * upload_single('file'),
1484
+ * uploadSingleFileApi
1485
+ * );
1486
+ *
1487
+ * @example
1488
+ * // Use a custom field name.
1489
+ * router.post(
1490
+ * '/profile-picture',
1491
+ * upload_single('profilePicture'),
1492
+ * uploadSingleFileApi
1493
+ * );
1494
+ *
1495
+ * // The uploaded file will be available as:
1496
+ * // req.file
1497
+ */
1498
+ declare const upload_single: (fieldName?: string) => express.RequestHandler<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>;
1499
+ /**
1500
+ * Executes one or more SQL queries using the database configured through
1501
+ * the `SQL_DB_URL` environment variable.
1502
+ *
1503
+ * The function automatically detects whether the configured database is
1504
+ * PostgreSQL or MySQL and delegates execution to the appropriate database
1505
+ * implementation.
1506
+ *
1507
+ * Supports structured CRUD operations (`insert_one`, `insert_many`, `select`,
1508
+ * `update`, and `delete`) as well as custom raw SQL queries.
1509
+ *
1510
+ * Parameterized conditions and raw queries are supported. The placeholder
1511
+ * syntax must match the configured database engine:
1512
+ *
1513
+ * - MySQL uses `?` placeholders.
1514
+ * - PostgreSQL uses `$1`, `$2`, `$3`, etc.
1515
+ *
1516
+ * The corresponding values are supplied through `conditionalParams` for
1517
+ * structured CRUD operations or `params` for raw SQL queries.
1518
+ *
1519
+ * @param query - The SQL operations to execute.
1520
+ * @param query.crud - Optional array of structured CRUD operations.
1521
+ * @param query.custom - Optional raw SQL query or array of raw SQL queries.
1522
+ *
1523
+ * @returns A promise resolving to the result returned by the PostgreSQL or
1524
+ * MySQL query executor. If the configured `SQL_DB_URL` does not represent a
1525
+ * supported database, an `Error` is returned.
1526
+ *
1527
+ * @example
1528
+ * // Insert a user.
1529
+ * //
1530
+ * // This operation is database-independent because the values are passed
1531
+ * // as an object and the underlying executor generates the appropriate SQL.
1532
+ * await executeQuery({
1533
+ * crud: [
1534
+ * {
1535
+ * insert_one: {
1536
+ * table: CONSTANTS.USER_INFOS,
1537
+ * item: {
1538
+ * [CONSTANTS.USER_PRIMARY_ID]: generateUniqueValue(32),
1539
+ * [CONSTANTS.USER_NAME]: 'Divyanshu',
1540
+ * [CONSTANTS.USER_EMAIL]: 'div@example.com',
1541
+ * [CONSTANTS.USER_GENDER]: CONSTANTS.GENDER_TYPE.MALE,
1542
+ * },
1543
+ * },
1544
+ * },
1545
+ * ],
1546
+ * });
1547
+ *
1548
+ * @example
1549
+ * // Select a user by email.
1550
+ * //
1551
+ * // MySQL:
1552
+ * // condition: 'user_email = ?'
1553
+ * //
1554
+ * // PostgreSQL:
1555
+ * // condition: 'user_email = $1'
1556
+ * //
1557
+ * // The value is supplied separately through conditionalParams.
1558
+ * await executeQuery({
1559
+ * crud: [
1560
+ * {
1561
+ * select: {
1562
+ * table: CONSTANTS.USER_INFOS,
1563
+ * columns: [
1564
+ * CONSTANTS.USER_PRIMARY_ID,
1565
+ * CONSTANTS.USER_NAME,
1566
+ * CONSTANTS.USER_EMAIL,
1567
+ * ],
1568
+ * condition: 'user_email = ?',
1569
+ * conditionalParams: ['div@example.com'],
1570
+ * },
1571
+ * },
1572
+ * ],
1573
+ * });
1574
+ *
1575
+ * @example
1576
+ * // Update a user's information.
1577
+ * //
1578
+ * // MySQL:
1579
+ * // condition: 'user_primary_id = ?'
1580
+ * //
1581
+ * // PostgreSQL:
1582
+ * // condition: 'user_primary_id = $1'
1583
+ * await executeQuery({
1584
+ * crud: [
1585
+ * {
1586
+ * update: {
1587
+ * table: CONSTANTS.USER_INFOS,
1588
+ * item: {
1589
+ * [CONSTANTS.USER_NAME]: 'Div',
1590
+ * [CONSTANTS.USER_PHONE_NUMBER]: '+1234567890',
1591
+ * },
1592
+ * condition: 'user_primary_id = ?',
1593
+ * conditionalParams: [
1594
+ * '550e8400-e29b-41d4-a716-446655440000',
1595
+ * ],
1596
+ * },
1597
+ * },
1598
+ * ],
1599
+ * });
1600
+ *
1601
+ * @example
1602
+ * // Delete a user.
1603
+ * //
1604
+ * // Replace `?` with `$1` when using PostgreSQL.
1605
+ * await executeQuery({
1606
+ * crud: [
1607
+ * {
1608
+ * delete: {
1609
+ * table: CONSTANTS.USER_INFOS,
1610
+ * condition: 'user_primary_id = ?',
1611
+ * conditionalParams: [
1612
+ * '550e8400-e29b-41d4-a716-446655440000',
1613
+ * ],
1614
+ * },
1615
+ * },
1616
+ * ],
1617
+ * });
1618
+ *
1619
+ * @example
1620
+ * // Execute a raw SQL query.
1621
+ * //
1622
+ * // MySQL:
1623
+ * // query: 'SELECT * FROM user_infos WHERE user_email = ?'
1624
+ * //
1625
+ * // PostgreSQL:
1626
+ * // query: 'SELECT * FROM user_infos WHERE user_email = $1'
1627
+ * await executeQuery({
1628
+ * custom: {
1629
+ * query: 'SELECT * FROM user_infos WHERE user_email = ?',
1630
+ * params: ['div@example.com'],
1631
+ * },
1632
+ * });
1633
+ *
1634
+ * @example
1635
+ * // Execute multiple operations in one call.
1636
+ * //
1637
+ * // The underlying executor handles the operations according to the
1638
+ * // configured database engine.
1639
+ * await executeQuery({
1640
+ * crud: [
1641
+ * {
1642
+ * insert_one: {
1643
+ * table: CONSTANTS.USER_INFOS,
1644
+ * item: {
1645
+ * [CONSTANTS.USER_PRIMARY_ID]: generateUniqueValue(32),
1646
+ * [CONSTANTS.USER_NAME]: 'Alice',
1647
+ * [CONSTANTS.USER_EMAIL]: 'alice@example.com',
1648
+ * },
1649
+ * },
1650
+ * },
1651
+ * {
1652
+ * update: {
1653
+ * table: CONSTANTS.USER_INFOS,
1654
+ * item: {
1655
+ * status: 'active',
1656
+ * },
1657
+ * condition: 'user_email = ?',
1658
+ * conditionalParams: ['alice@example.com'],
1659
+ * },
1660
+ * },
1661
+ * ],
1662
+ * });
1663
+ */
1664
+ declare const executeQuery: (query: QueryItems) => Promise<any[] | Error>;
1665
+ /**
1666
+ * Returns the connection pool for the SQL database configured through
1667
+ * the `SQL_DB_URL` environment variable.
1668
+ *
1669
+ * The database type is detected automatically from the connection URL.
1670
+ * If the URL represents a PostgreSQL database, the PostgreSQL connection
1671
+ * pool is returned. If it represents a MySQL database, the MySQL connection
1672
+ * pool is returned.
1673
+ *
1674
+ * This function acts as the database-agnostic entry point for obtaining
1675
+ * the application's SQL connection pool. Callers do not need to know
1676
+ * whether the application is currently using PostgreSQL or MySQL.
1677
+ *
1678
+ * The underlying pool is created lazily and reused across subsequent
1679
+ * calls through `getPgSqlPool()` or `getMySqlPool()`.
1680
+ *
1681
+ * @returns A promise resolving to the PostgreSQL or MySQL connection pool,
1682
+ * depending on the configured `SQL_DB_URL`. Returns `undefined` if the
1683
+ * configured database URL does not match a supported SQL database.
1684
+ *
1685
+ * @example
1686
+ * // Get the configured SQL connection pool.
1687
+ * const pool = await getPool();
1688
+ *
1689
+ * if (!pool) {
1690
+ * throw new Error('Unsupported SQL database configuration.');
1691
+ * }
1692
+ *
1693
+ * @example
1694
+ * // The same function works regardless of whether the application
1695
+ * // is configured to use PostgreSQL or MySQL.
1696
+ * const pool = await getPool();
1697
+ *
1698
+ * if (pool) {
1699
+ * // Use the returned pool with the appropriate database layer.
1700
+ * console.log('Database pool is ready.');
1701
+ * }
1702
+ */
1703
+ declare const getPool: () => Promise<pg.Pool | mysql2_promise.Pool | undefined>;
1704
+ /**
1705
+ * Returns the application's configured Express instance.
1706
+ *
1707
+ * This function provides access to the shared Express application created
1708
+ * by the application entry point. It returns the existing instance rather
1709
+ * than creating a new Express application.
1710
+ *
1711
+ * The returned instance can be used to configure middleware, routes,
1712
+ * error handlers, and other Express application settings.
1713
+ *
1714
+ * @returns The shared Express `Application` instance.
1715
+ *
1716
+ * @example
1717
+ * // Get the Express application instance.
1718
+ * const app = getApp();
1719
+ *
1720
+ * // Register a route.
1721
+ * app.get('/health', (req, res) => {
1722
+ * res.json({ status: 'ok' });
1723
+ * });
1724
+ *
1725
+ * @example
1726
+ * // Use the shared application when configuring middleware.
1727
+ * const app = getApp();
1728
+ *
1729
+ * app.use(express.json());
1730
+ *
1731
+ * @example
1732
+ * // Export the configured application for use by a server entry point.
1733
+ * const app = getApp();
1734
+ *
1735
+ * app.listen(PORT, () => {
1736
+ * console.log(`Server running on port ${PORT}`);
1737
+ * });
1738
+ */
1739
+ declare const getApp: () => express.Application;
1740
+ /**
1741
+ * Returns the application's underlying HTTP server.
1742
+ *
1743
+ * This function provides access to the shared Node.js HTTP server created
1744
+ * using the configured Express application. The same server instance is
1745
+ * returned each time instead of creating a new server.
1746
+ *
1747
+ * The HTTP server can be used for operations that require access to the
1748
+ * underlying Node.js server, such as attaching WebSocket servers or
1749
+ * handling
1750
+ * low-level HTTP server events.
1751
+ *
1752
+ * @returns The shared Node.js `http.Server` instance.
1753
+ *
1754
+ * @example
1755
+ * // Attach a WebSocket server to the HTTP server.
1756
+ * const server = getServer();
1757
+ *
1758
+ * const wsServer = new WebSocket.Server({
1759
+ * server,
1760
+ * });
1761
+ *
1762
+ * @example
1763
+ * // Listen for server-level errors.
1764
+ * const server = getServer();
1765
+ *
1766
+ * server.on('error', (error) => {
1767
+ * console.error('HTTP server error:', error);
1768
+ * });
1769
+ */
1770
+ declare const getServer: () => node_http.Server<typeof node_http.IncomingMessage, typeof node_http.ServerResponse>;
1771
+
1772
+ export { buildPath, buildURL, deleteFile, deleteFiles, detectSQLDatabase, downloadFile, downloadFiles, executeQuery, fileExistsAsync, fileExistsSync, generateUniqueValue, getApp, getFileContentType, getFileExtension, getInAppBucketDownloadPath, getKeyFromUrl, getPool, getS3Client, getServer, handleError, isMySQL, isPostgreSQL, mongoBulkWrite, mongoDeleteDocument, mongoInsertField, mongoInsertFields, mongoUpdateField, responseToClient, toUint8Array, upload_batch, upload_file, upload_files, upload_single, url_or_path };