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,140 @@
1
+ import { PathOptions } from '../../libs/interface.js';
2
+ import 'mongodb';
3
+ import '../../libs/types.js';
4
+ import 'express';
5
+ import '../../libs/env.js';
6
+
7
+ /**
8
+ * Extracts the file extension from a supported file input.
9
+ *
10
+ * Supports Express Multer files, Web API `File` objects, raw `Buffer` values,
11
+ * and file paths or URLs. For URLs and paths, query parameters and hash
12
+ * fragments are ignored when determining the extension.
13
+ *
14
+ * @param input - The file, buffer, path, or URL from which to extract the extension.
15
+ * @returns The file extension without the leading dot, converted to lowercase.
16
+ * Returns an empty string if no extension can be determined.
17
+ *
18
+ * @example
19
+ * const extension = getFileExtension('https://example.com/files/image.PNG');
20
+ * // Returns: "png"
21
+ *
22
+ * @example
23
+ * const extension = getFileExtension(req.file);
24
+ * // Returns: "pdf"
25
+ *
26
+ * @example
27
+ * const extension = getFileExtension('documents/report.pdf?download=true');
28
+ * // Returns: "pdf"
29
+ *
30
+ * @example
31
+ * const extension = getFileExtension(buffer);
32
+ * // Returns: ""
33
+ */
34
+ declare function getFileExtension(input: Express.Multer.File | File | Buffer | string): string;
35
+ /**
36
+ * Builds a normalized file path from the provided path components.
37
+ *
38
+ * Combines the path prefix, path segments, path postfix, and file name,
39
+ * while removing empty values and normalizing redundant slashes.
40
+ *
41
+ * If `fileName` is a Web API `File` object, its `name` property is used.
42
+ *
43
+ * @param options - The path components used to construct the final path.
44
+ * @param options.path_prefix - An optional prefix to prepend to the path.
45
+ * @param options.path - An array of path segments.
46
+ * @param options.path_postfix - An optional postfix to append before the file name.
47
+ * @param options.fileName - The file name or a Web API `File` object.
48
+ * @returns A normalized path with components separated by a single slash.
49
+ *
50
+ * @example
51
+ * const filePath = buildPath({
52
+ * path_prefix: 'uploads',
53
+ * path: ['documents', 'reports'],
54
+ * fileName: 'report.pdf',
55
+ * });
56
+ * // Returns: "uploads/documents/reports/report.pdf"
57
+ *
58
+ * @example
59
+ * const filePath = buildPath({
60
+ * path: ['documents//', '/reports/'],
61
+ * fileName: 'report.pdf',
62
+ * });
63
+ * // Returns: "documents/reports/report.pdf"
64
+ */
65
+ declare function buildPath({ path_prefix, path, path_postfix, fileName, }: PathOptions): string;
66
+ /**
67
+ * Builds the local file path for a downloaded file.
68
+ *
69
+ * Removes any occurrence of the configured in-app bucket from the provided
70
+ * path to prevent duplicating the bucket name, then constructs the final
71
+ * path using the configured in-app bucket as the path prefix.
72
+ *
73
+ * @param options - The path and file name options used to build the downloaded file path.
74
+ * @param options.path - The path segments leading to the file.
75
+ * @param options.fileName - The name of the file or a Web API `File` object.
76
+ * @returns The complete local path for the downloaded file.
77
+ *
78
+ * @example
79
+ * const filePath = downloadedFilePath({
80
+ * path: ['documents', 'reports'],
81
+ * fileName: 'report.pdf',
82
+ * });
83
+ * // Returns a path prefixed with ENV.IN_APP_BUCKET.
84
+ *
85
+ * @example
86
+ * const filePath = downloadedFilePath({
87
+ * path: [ENV.IN_APP_BUCKET, 'documents'],
88
+ * fileName: file,
89
+ * });
90
+ * // The duplicate bucket segment is removed before building the path.
91
+ */
92
+ declare function downloadedFilePath({ path, fileName }: PathOptions): string;
93
+ /**
94
+ * Determines the MIME content type of a file from its available metadata
95
+ * or, when given a file path or URL, from its file extension.
96
+ *
97
+ * Supports Express Multer files, Web API `File` objects, raw `Buffer` values,
98
+ * and file paths or URLs.
99
+ *
100
+ * @param file - The file, buffer, path, or URL whose content type should be determined.
101
+ * @returns A promise resolving to the detected MIME content type.
102
+ *
103
+ * @example
104
+ * const contentType = await getFileContentType(req.file);
105
+ * // Returns something like: "image/jpeg"
106
+ *
107
+ * @example
108
+ * const contentType = await getFileContentType('/uploads/document.pdf');
109
+ * // Returns: "application/pdf"
110
+ *
111
+ * @example
112
+ * const contentType = await getFileContentType(buffer);
113
+ * // Returns: "application/octet-stream"
114
+ */
115
+ declare const getFileContentType: (file: Express.Multer.File | File | Buffer | string) => Promise<string>;
116
+ /**
117
+ * Determines whether the provided value is a URL or a local/server based file path.
118
+ *
119
+ * If the value is a valid HTTP/HTTPS URL, the configured URL environment
120
+ * value is returned. Otherwise, the configured local path environment value
121
+ * is returned.
122
+ *
123
+ * @param val - The URL or local file path to evaluate.
124
+ * @returns The configured URL or local path based on the input type.
125
+ *
126
+ * @example
127
+ * const basePath = url_or_path('https://example.com/file.png');
128
+ * // Returns ENV.URL
129
+ *
130
+ * @example
131
+ * const basePath = url_or_path('/uploads/file.png');
132
+ * // Returns ENV.PATH
133
+ */
134
+ declare const url_or_path: (val: string) => string;
135
+ /**
136
+ * Safely normalizes Buffer, Express.Multer.File, Web File, or File Path into Uint8Array
137
+ */
138
+ declare function toUint8Array(file: Express.Multer.File | File | Buffer | string): Promise<Uint8Array>;
139
+
140
+ export { buildPath, downloadedFilePath, getFileContentType, getFileExtension, toUint8Array, url_or_path };
@@ -0,0 +1,19 @@
1
+ import {
2
+ buildPath,
3
+ downloadedFilePath,
4
+ getFileContentType,
5
+ getFileExtension,
6
+ toUint8Array,
7
+ url_or_path
8
+ } from "../../../chunk-FMCW72HO.js";
9
+ import "../../../chunk-EWQYVPOL.js";
10
+ import "../../../chunk-7QVYU63E.js";
11
+ export {
12
+ buildPath,
13
+ downloadedFilePath,
14
+ getFileContentType,
15
+ getFileExtension,
16
+ toUint8Array,
17
+ url_or_path
18
+ };
19
+ //# sourceMappingURL=file-operations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,151 @@
1
+ import { DatabaseType } from '../../libs/types.js';
2
+ import 'mongodb';
3
+ import 'express';
4
+ import '../../libs/env.js';
5
+
6
+ /**
7
+ * Detects the SQL database type from a database connection URL.
8
+ *
9
+ * The function supports MySQL and PostgreSQL connection URL schemes,
10
+ * including common driver-specific variants such as `mysql2`,
11
+ * `mysql+pymysql`, `postgresql+psycopg2`, and `postgresql+asyncpg`.
12
+ *
13
+ * If the connection string does not contain a recognized protocol, the
14
+ * function attempts to identify the database using keywords in the
15
+ * connection string or the default database ports:
16
+ *
17
+ * - MySQL: `3306`
18
+ * - PostgreSQL: `5432`
19
+ *
20
+ * Invalid URLs are also checked as raw connection strings before an error
21
+ * is thrown. This allows common connection strings without a protocol to
22
+ * still be detected.
23
+ *
24
+ * @param url - The SQL database connection URL or connection string.
25
+ * @returns `ENV.MY_SQL` for MySQL connections or `ENV.POSTGRES_SQL` for
26
+ * PostgreSQL connections.
27
+ * @throws {Error} If the URL is invalid or the database type cannot be
28
+ * identified as MySQL or PostgreSQL.
29
+ *
30
+ * @example
31
+ * // Detect PostgreSQL from a standard connection URL.
32
+ * const database = detectSQLDatabase(
33
+ * 'postgresql://user:password@localhost:5432/my_database'
34
+ * );
35
+ *
36
+ * // Returns: ENV.POSTGRES_SQL
37
+ *
38
+ * @example
39
+ * // Detect MySQL from a standard connection URL.
40
+ * const database = detectSQLDatabase(
41
+ * 'mysql://user:password@localhost:3306/my_database'
42
+ * );
43
+ *
44
+ * // Returns: ENV.MY_SQL
45
+ *
46
+ * @example
47
+ * // Driver-specific PostgreSQL URLs are also supported.
48
+ * const database = detectSQLDatabase(
49
+ * 'postgresql+psycopg2://user:password@localhost:5432/my_database'
50
+ * );
51
+ *
52
+ * // Returns: ENV.POSTGRES_SQL
53
+ *
54
+ * @example
55
+ * // A connection string without a recognized protocol can be detected
56
+ * // using the default PostgreSQL port.
57
+ * const database = detectSQLDatabase(
58
+ * 'localhost:5432/my_database'
59
+ * );
60
+ *
61
+ * // Returns: ENV.POSTGRES_SQL
62
+ *
63
+ * @example
64
+ * // Throws when the database type cannot be determined.
65
+ * const database = detectSQLDatabase(
66
+ * 'mongodb://localhost:27017/my_database'
67
+ * );
68
+ *
69
+ * // Error: Unsupported or unrecognized database type.
70
+ */
71
+ declare function detectSQLDatabase(url: string): DatabaseType;
72
+ /**
73
+ * Determines whether a database connection URL represents a MySQL database.
74
+ *
75
+ * This function delegates database detection to `detectSQLDatabase()` and
76
+ * compares the detected database type with the configured MySQL database
77
+ * identifier.
78
+ *
79
+ * Any error encountered while parsing or detecting the database type is
80
+ * handled internally, and the function returns `false` instead of throwing.
81
+ * This makes the function safe to use when validating or conditionally
82
+ * selecting a database implementation.
83
+ *
84
+ * @param url - The SQL database connection URL or connection string.
85
+ * @returns `true` if the URL represents a MySQL database; otherwise `false`.
86
+ *
87
+ * @example
88
+ * // Standard MySQL connection URL.
89
+ * const result = isMySQL(
90
+ * 'mysql://user:password@localhost:3306/my_database'
91
+ * );
92
+ *
93
+ * // Returns: true
94
+ *
95
+ * @example
96
+ * // PostgreSQL URL.
97
+ * const result = isMySQL(
98
+ * 'postgresql://user:password@localhost:5432/my_database'
99
+ * );
100
+ *
101
+ * // Returns: false
102
+ *
103
+ * @example
104
+ * // Invalid or unsupported connection URL.
105
+ * const result = isMySQL('invalid-database-url');
106
+ *
107
+ * // Returns: false instead of throwing an error.
108
+ */
109
+ declare function isMySQL(url: string): boolean;
110
+ /**
111
+ * Determines whether a database connection URL represents a PostgreSQL
112
+ * database.
113
+ *
114
+ * This function delegates database detection to `detectSQLDatabase()` and
115
+ * compares the detected database type with the configured PostgreSQL
116
+ * identifier.
117
+ *
118
+ * Any error encountered while parsing or detecting the database type is
119
+ * handled internally, causing the function to return `false` instead of
120
+ * throwing. This makes the function safe to use when conditionally selecting
121
+ * PostgreSQL-specific database logic.
122
+ *
123
+ * @param url - The SQL database connection URL or connection string.
124
+ * @returns `true` if the URL represents a PostgreSQL database; otherwise
125
+ * `false`.
126
+ *
127
+ * @example
128
+ * // Standard PostgreSQL connection URL.
129
+ * const result = isPostgreSQL(
130
+ * 'postgresql://user:password@localhost:5432/my_database'
131
+ * );
132
+ *
133
+ * // Returns: true
134
+ *
135
+ * @example
136
+ * // MySQL connection URL.
137
+ * const result = isPostgreSQL(
138
+ * 'mysql://user:password@localhost:3306/my_database'
139
+ * );
140
+ *
141
+ * // Returns: false
142
+ *
143
+ * @example
144
+ * // Invalid or unsupported connection URL.
145
+ * const result = isPostgreSQL('invalid-database-url');
146
+ *
147
+ * // Returns: false instead of throwing an error.
148
+ */
149
+ declare function isPostgreSQL(url: string): boolean;
150
+
151
+ export { detectSQLDatabase, isMySQL, isPostgreSQL };
@@ -0,0 +1,13 @@
1
+ import {
2
+ detectSQLDatabase,
3
+ isMySQL,
4
+ isPostgreSQL
5
+ } from "../../../chunk-MNSQSU7T.js";
6
+ import "../../../chunk-EWQYVPOL.js";
7
+ import "../../../chunk-7QVYU63E.js";
8
+ export {
9
+ detectSQLDatabase,
10
+ isMySQL,
11
+ isPostgreSQL
12
+ };
13
+ //# sourceMappingURL=sqlDb.js.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,55 @@
1
+ import { GenerateIdOptions } from '../../libs/interface.js';
2
+ import 'mongodb';
3
+ import '../../libs/types.js';
4
+ import 'express';
5
+ import '../../libs/env.js';
6
+
7
+ /**
8
+ * Generates one or more cryptographically secure unique values.
9
+ *
10
+ * Values can be generated using hexadecimal characters or a custom
11
+ * alphanumeric character set. Optional timestamps and prefixes can be
12
+ * included in the generated values.
13
+ *
14
+ * When `count` is provided, multiple unique values are returned as an array.
15
+ * Otherwise, a single string is returned.
16
+ *
17
+ * @param length - The length of the randomly generated portion of each value.
18
+ * @param options - Optional configuration for generating the value(s).
19
+ * @param options.useHex - Whether to generate the random portion using hexadecimal characters.
20
+ * @param options.includeTimestamp - Whether to prepend a hexadecimal timestamp.
21
+ * @param options.prefix - An optional prefix to prepend to the generated value.
22
+ * @param options.count - The number of values to generate. If omitted, one value is returned.
23
+ * @returns A single unique string when `count` is not provided, or an array of unique strings when `count` is specified.
24
+ * @throws {Error} If `length` or `count` is less than or equal to zero.
25
+ *
26
+ * @example
27
+ * const id = generateUniqueValue(16);
28
+ * // Returns: "aZ7_kP2mQ9xL3nBc"
29
+ *
30
+ * @example
31
+ * const id = generateUniqueValue(16, {
32
+ * useHex: true,
33
+ * prefix: 'file',
34
+ * });
35
+ * // Returns: "file-7f3a9c12d84e..."
36
+ *
37
+ * @example
38
+ * const id = generateUniqueValue(12, {
39
+ * includeTimestamp: true,
40
+ * });
41
+ * // Returns: "198a7f3c12a-7Kx9mP..."
42
+ *
43
+ * @example
44
+ * const ids = generateUniqueValue(10, {
45
+ * count: 5,
46
+ * prefix: 'file',
47
+ * });
48
+ * // Returns: ["file-...", "file-...", "file-...", "file-...", "file-..."]
49
+ */
50
+ declare function generateUniqueValue(length: number, options?: GenerateIdOptions): string;
51
+ declare function generateUniqueValue(length: number, options: GenerateIdOptions & {
52
+ count: number;
53
+ }): string[];
54
+
55
+ export { generateUniqueValue };
@@ -0,0 +1,8 @@
1
+ import {
2
+ generateUniqueValue
3
+ } from "../../../chunk-X3R3RLXY.js";
4
+ import "../../../chunk-7QVYU63E.js";
5
+ export {
6
+ generateUniqueValue
7
+ };
8
+ //# sourceMappingURL=uuids.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,247 @@
1
+ import * as express from 'express';
2
+ import { URLOptions } from '../../libs/interface.js';
3
+ import { ResponseInterface } from '../../libs/types.js';
4
+ import 'mongodb';
5
+ import '../../libs/env.js';
6
+
7
+ /**
8
+ * Builds a normalized URL or path from an optional endpoint, path segments,
9
+ * and file name.
10
+ *
11
+ * The function safely combines all provided segments while removing empty
12
+ * values and normalizing slashes between segments. If the endpoint contains
13
+ * an HTTP or HTTPS protocol, the protocol is preserved separately so that
14
+ * slash normalization does not alter it.
15
+ *
16
+ * A `File` object can also be provided as `fileName`; in that case, its
17
+ * original file name is extracted automatically.
18
+ *
19
+ * @param options - Options used to construct the URL.
20
+ * @param options.end_point - Optional base URL or endpoint. Supports
21
+ * `http://` and `https://` protocols.
22
+ * @param options.path - Optional array of path segments to append to the
23
+ * endpoint.
24
+ * @param options.fileName - Optional file name or Web API `File` object.
25
+ *
26
+ * @returns A normalized URL/path containing the provided endpoint, path
27
+ * segments, and file name. Returns an empty string when no valid segments
28
+ * are provided.
29
+ *
30
+ * @example
31
+ * // Build a URL from an endpoint, path, and file name.
32
+ * const url = buildURL({
33
+ * end_point: 'https://storage.example.com',
34
+ * path: ['uploads', 'images'],
35
+ * fileName: 'profile.jpg',
36
+ * });
37
+ *
38
+ * // Returns:
39
+ * // https://storage.example.com/uploads/images/profile.jpg
40
+ *
41
+ * @example
42
+ * // Extra slashes are automatically normalized.
43
+ * const url = buildURL({
44
+ * end_point: 'https://storage.example.com/',
45
+ * path: ['/uploads/', '/images//'],
46
+ * fileName: '/profile.jpg',
47
+ * });
48
+ *
49
+ * // Returns:
50
+ * // https://storage.example.com/uploads/images/profile.jpg
51
+ *
52
+ * @example
53
+ * // A File object can be used as the file name.
54
+ * const url = buildURL({
55
+ * end_point: 'https://storage.example.com',
56
+ * path: ['uploads'],
57
+ * fileName: file,
58
+ * });
59
+ *
60
+ * // If file.name is "document.pdf":
61
+ * // https://storage.example.com/uploads/document.pdf
62
+ *
63
+ * @example
64
+ * // The function can also build a path without a URL endpoint.
65
+ * const path = buildURL({
66
+ * path: ['uploads', 'documents'],
67
+ * fileName: 'report.pdf',
68
+ * });
69
+ *
70
+ * // Returns:
71
+ * // uploads/documents/report.pdf
72
+ *
73
+ * @example
74
+ * // Empty or undefined segments are ignored.
75
+ * const url = buildURL({
76
+ * end_point: 'https://storage.example.com/',
77
+ * path: ['', 'uploads', '', 'documents'],
78
+ * fileName: 'report.pdf',
79
+ * });
80
+ *
81
+ * // Returns:
82
+ * // https://storage.example.com/uploads/documents/report.pdf
83
+ *
84
+ * @example
85
+ * // Returns an empty string when no usable values are provided.
86
+ * const url = buildURL({});
87
+ *
88
+ * // Returns:
89
+ * // ''
90
+ */
91
+ declare function buildURL({ end_point, path, fileName, }: URLOptions): string;
92
+ /**
93
+ * Extracts the object key/path from a full public file URL.
94
+ *
95
+ * This function is intended for files stored in the configured bucket.
96
+ * It parses the URL, extracts the pathname, removes the configured bucket
97
+ * name when it appears as the first path segment, and decodes any
98
+ * URL-encoded characters in the resulting object key.
99
+ *
100
+ * For example, a URL such as:
101
+ *
102
+ * `https://storage.example.com/my-bucket/uploads/images/profile%20photo.jpg`
103
+ *
104
+ * will produce:
105
+ *
106
+ * `uploads/images/profile photo.jpg`
107
+ *
108
+ * @param url - The full public URL of the stored file.
109
+ * @returns The decoded object key/path without the bucket name.
110
+ *
111
+ * @throws {TypeError} If the provided value is not a valid URL.
112
+ *
113
+ * @example
114
+ * // Extract the object key from a bucket URL.
115
+ * const key = getKeyFromUrl(
116
+ * 'https://storage.example.com/my-bucket/uploads/profile.jpg'
117
+ * );
118
+ *
119
+ * // Returns:
120
+ * // 'uploads/profile.jpg'
121
+ *
122
+ * @example
123
+ * // URL-encoded characters are decoded automatically.
124
+ * const key = getKeyFromUrl(
125
+ * 'https://storage.example.com/my-bucket/uploads/profile%20photo.jpg'
126
+ * );
127
+ *
128
+ * // Returns:
129
+ * // 'uploads/profile photo.jpg'
130
+ *
131
+ * @example
132
+ * // Nested directories are preserved.
133
+ * const key = getKeyFromUrl(
134
+ * 'https://storage.example.com/my-bucket/users/123/avatar/image.png'
135
+ * );
136
+ *
137
+ * // Returns:
138
+ * // 'users/123/avatar/image.png'
139
+ */
140
+ declare const getKeyFromUrl: (url: string) => string;
141
+ /**
142
+ * Sends a standardized API response to the client.
143
+ *
144
+ * This function provides a consistent response structure for both successful
145
+ * and failed requests. The `success` property acts as the discriminator
146
+ * between the two response types.
147
+ *
148
+ * For successful responses, the function returns the supplied status,
149
+ * message, data, and metadata. For failed responses, it returns the supplied
150
+ * status, message, error information, and metadata.
151
+ *
152
+ * A response timestamp is automatically generated when one is not already
153
+ * provided through `meta.timestamp`.
154
+ *
155
+ * @param response - Express `Response` object used to send the HTTP response.
156
+ * @param success - Indicates whether the request was successful.
157
+ * @param status - HTTP status code returned to the client.
158
+ * @param message - Optional human-readable response message.
159
+ * @param data - Optional data returned by a successful operation.
160
+ * @param error - Error information returned when the operation fails.
161
+ * @param meta - Optional response metadata such as request ID, timestamp,
162
+ * pagination information, or other request-related information.
163
+ *
164
+ * @returns The Express response containing the standardized API payload.
165
+ *
166
+ * @example
167
+ * // Successful response.
168
+ * return response_to_client({
169
+ * response: res,
170
+ * success: true,
171
+ * status: 200,
172
+ * message: 'User fetched successfully.',
173
+ * data: user,
174
+ * });
175
+ *
176
+ * @example
177
+ * // Successful response with pagination metadata.
178
+ * return response_to_client({
179
+ * response: res,
180
+ * success: true,
181
+ * status: 200,
182
+ * message: 'Users fetched successfully.',
183
+ * data: users,
184
+ * meta: {
185
+ * timestamp: new Date().toISOString(),
186
+ * requestId: 'req_123456',
187
+ * page: 1,
188
+ * limit: 20,
189
+ * totalItems: 100,
190
+ * totalPages: 5,
191
+ * },
192
+ * });
193
+ *
194
+ * @example
195
+ * // Error response.
196
+ * return response_to_client({
197
+ * response: res,
198
+ * success: false,
199
+ * status: 404,
200
+ * message: 'File not found.',
201
+ * error: {
202
+ * code: 'FILE_NOT_FOUND',
203
+ * path: '/files/profile.jpg',
204
+ * },
205
+ * });
206
+ *
207
+ * @example
208
+ * // Validation error with structured details.
209
+ * return response_to_client({
210
+ * response: res,
211
+ * success: false,
212
+ * status: 400,
213
+ * message: 'Validation failed.',
214
+ * error: {
215
+ * code: 'VALIDATION_ERROR',
216
+ * details: [
217
+ * {
218
+ * field: 'email',
219
+ * message: 'Invalid email address.',
220
+ * },
221
+ * {
222
+ * field: 'password',
223
+ * message: 'Password is required.',
224
+ * },
225
+ * ],
226
+ * },
227
+ * });
228
+ *
229
+ * @example
230
+ * // Error response with a request ID for tracing.
231
+ * return response_to_client({
232
+ * response: res,
233
+ * success: false,
234
+ * status: 500,
235
+ * message: 'Internal server error.',
236
+ * error: {
237
+ * code: 'INTERNAL_SERVER_ERROR',
238
+ * },
239
+ * meta: {
240
+ * timestamp: new Date().toISOString(),
241
+ * requestId: 'req_abc123',
242
+ * },
243
+ * });
244
+ */
245
+ declare const response_to_client: ({ response, ...payload }: ResponseInterface) => express.Response<any, Record<string, any>>;
246
+
247
+ export { buildURL, getKeyFromUrl, response_to_client };
@@ -0,0 +1,13 @@
1
+ import {
2
+ buildURL,
3
+ getKeyFromUrl,
4
+ response_to_client
5
+ } from "../../../chunk-SSFPGDA3.js";
6
+ import "../../../chunk-EWQYVPOL.js";
7
+ import "../../../chunk-7QVYU63E.js";
8
+ export {
9
+ buildURL,
10
+ getKeyFromUrl,
11
+ response_to_client
12
+ };
13
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}