backfarm 1.0.4 → 1.0.5

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 (157) hide show
  1. package/dist/{chunk-QVTKG7FD.js → chunk-2RFTNIPS.js} +2 -2
  2. package/dist/{chunk-X3R3RLXY.js → chunk-3IO4NPP3.js} +1 -1
  3. package/dist/chunk-3IO4NPP3.js.map +1 -0
  4. package/dist/chunk-ATY3REI3.js +89 -0
  5. package/dist/chunk-ATY3REI3.js.map +1 -0
  6. package/dist/{chunk-W3W3X2OE.js → chunk-CBTP2HOO.js} +53 -18
  7. package/dist/chunk-CBTP2HOO.js.map +1 -0
  8. package/dist/chunk-CPECHQJJ.js +18 -0
  9. package/dist/chunk-CPECHQJJ.js.map +1 -0
  10. package/dist/{chunk-TP3K7DMH.js → chunk-DRLEV7OW.js} +2 -2
  11. package/dist/chunk-E2NNDV4O.js +40 -0
  12. package/dist/chunk-E2NNDV4O.js.map +1 -0
  13. package/dist/{chunk-XBJ3SJ26.js → chunk-ECIP24BN.js} +2 -2
  14. package/dist/chunk-ES6AHESH.js +17 -0
  15. package/dist/chunk-ES6AHESH.js.map +1 -0
  16. package/dist/chunk-FNFFY5LD.js +44 -0
  17. package/dist/chunk-FNFFY5LD.js.map +1 -0
  18. package/dist/{chunk-YTBSGKGF.js → chunk-IAQMTSGP.js} +2 -2
  19. package/dist/chunk-LNFYUCA3.js +32 -0
  20. package/dist/chunk-LNFYUCA3.js.map +1 -0
  21. package/dist/chunk-LW246RDT.js +33 -0
  22. package/dist/chunk-LW246RDT.js.map +1 -0
  23. package/dist/chunk-M2C6HHRK.js +34 -0
  24. package/dist/chunk-M2C6HHRK.js.map +1 -0
  25. package/dist/chunk-MKS3GPZY.js +74 -0
  26. package/dist/chunk-MKS3GPZY.js.map +1 -0
  27. package/dist/chunk-O42S6QIG.js +88 -0
  28. package/dist/chunk-O42S6QIG.js.map +1 -0
  29. package/dist/chunk-OHDZYSL3.js +60 -0
  30. package/dist/chunk-OHDZYSL3.js.map +1 -0
  31. package/dist/chunk-P4FWSZ43.js +47 -0
  32. package/dist/chunk-P4FWSZ43.js.map +1 -0
  33. package/dist/{chunk-SSFPGDA3.js → chunk-QBBF6LZZ.js} +4 -4
  34. package/dist/chunk-QBBF6LZZ.js.map +1 -0
  35. package/dist/chunk-QS4MDB5H.js +336 -0
  36. package/dist/chunk-QS4MDB5H.js.map +1 -0
  37. package/dist/{chunk-D7A4TEXY.js → chunk-QUZPQJRE.js} +2 -2
  38. package/dist/chunk-RIBTACPE.js +35 -0
  39. package/dist/chunk-RIBTACPE.js.map +1 -0
  40. package/dist/{chunk-VFF4YFA3.js → chunk-SOZL76ZM.js} +2 -2
  41. package/dist/{chunk-MNSQSU7T.js → chunk-T4KN3FCF.js} +1 -1
  42. package/dist/chunk-T4KN3FCF.js.map +1 -0
  43. package/dist/{chunk-ZMDJ45KH.js → chunk-WLJV5O6C.js} +6 -6
  44. package/dist/chunk-WLJV5O6C.js.map +1 -0
  45. package/dist/engine/cloudBucket/r2Storage.js +2 -2
  46. package/dist/engine/mondoDb/mongoDB.js +2 -2
  47. package/dist/engine/server/server.d.ts +5 -3
  48. package/dist/engine/server/server.js +28 -7
  49. package/dist/engine/sql/mySql.d.ts +2 -2
  50. package/dist/engine/sql/mySql.js +2 -2
  51. package/dist/engine/sql/pgSql.js +2 -2
  52. package/dist/utility/libs/index.d.ts +1772 -0
  53. package/dist/utility/libs/index.js +101 -0
  54. package/dist/utility/libs/interface.d.ts +5 -7
  55. package/dist/utility/libs/run-all.js +46 -0
  56. package/dist/utility/libs/run-all.js.map +1 -0
  57. package/dist/{chunk-LFRKRR7G.js → utility/libs/run-bucket.js} +4 -7
  58. package/dist/utility/libs/run-bucket.js.map +1 -0
  59. package/dist/utility/libs/run-node-server.js +35 -0
  60. package/dist/utility/libs/run-node-server.js.map +1 -0
  61. package/dist/utility/libs/types.d.ts +11 -31
  62. package/dist/utility/libs/types.js.map +1 -1
  63. package/dist/utility/utilis/cloud_storage/deleteFile.js +7 -54
  64. package/dist/utility/utilis/cloud_storage/deleteFile.js.map +1 -1
  65. package/dist/utility/utilis/cloud_storage/deleteFiles.js +7 -83
  66. package/dist/utility/utilis/cloud_storage/deleteFiles.js.map +1 -1
  67. package/dist/utility/utilis/cloud_storage/downloadFile.js +8 -68
  68. package/dist/utility/utilis/cloud_storage/downloadFile.js.map +1 -1
  69. package/dist/utility/utilis/cloud_storage/downloadFiles.js +8 -82
  70. package/dist/utility/utilis/cloud_storage/downloadFiles.js.map +1 -1
  71. package/dist/utility/utilis/cloud_storage/uploadFile.js +5 -5
  72. package/dist/utility/utilis/cloud_storage/uploadFiles.d.ts +0 -64
  73. package/dist/utility/utilis/cloud_storage/uploadFiles.js +8 -42
  74. package/dist/utility/utilis/cloud_storage/uploadFiles.js.map +1 -1
  75. package/dist/utility/utilis/general/file-operations.d.ts +7 -132
  76. package/dist/utility/utilis/general/file-operations.js +5 -3
  77. package/dist/utility/utilis/general/sqlDb.js.d.ts +0 -141
  78. package/dist/utility/utilis/general/sqlDb.js.js +1 -1
  79. package/dist/utility/utilis/general/uuids.d.ts +0 -43
  80. package/dist/utility/utilis/general/uuids.js +1 -1
  81. package/dist/utility/utilis/general/web.d.ts +2 -238
  82. package/dist/utility/utilis/general/web.js +3 -3
  83. package/dist/utility/utilis/mongoDb/buldWrite.d.ts +0 -44
  84. package/dist/utility/utilis/mongoDb/buldWrite.js +5 -27
  85. package/dist/utility/utilis/mongoDb/buldWrite.js.map +1 -1
  86. package/dist/utility/utilis/mongoDb/deleteDocument.d.ts +0 -45
  87. package/dist/utility/utilis/mongoDb/deleteDocument.js +5 -29
  88. package/dist/utility/utilis/mongoDb/deleteDocument.js.map +1 -1
  89. package/dist/utility/utilis/mongoDb/insertField.d.ts +2 -33
  90. package/dist/utility/utilis/mongoDb/insertField.js +6 -29
  91. package/dist/utility/utilis/mongoDb/insertField.js.map +1 -1
  92. package/dist/utility/utilis/mongoDb/insertFields.d.ts +2 -41
  93. package/dist/utility/utilis/mongoDb/insertFields.js +6 -31
  94. package/dist/utility/utilis/mongoDb/insertFields.js.map +1 -1
  95. package/dist/utility/utilis/mongoDb/updateFiled.d.ts +0 -56
  96. package/dist/utility/utilis/mongoDb/updateFiled.js +5 -35
  97. package/dist/utility/utilis/mongoDb/updateFiled.js.map +1 -1
  98. package/dist/utility/utilis/multer/upload_batch.js +5 -12
  99. package/dist/utility/utilis/multer/upload_batch.js.map +1 -1
  100. package/dist/utility/utilis/multer/upload_single.d.ts +41 -0
  101. package/dist/utility/utilis/multer/upload_single.js +5 -11
  102. package/dist/utility/utilis/multer/upload_single.js.map +1 -1
  103. package/dist/utility/utilis/postgres/executeQuery.d.ts +2 -205
  104. package/dist/utility/utilis/postgres/executeQuery.js +11 -41
  105. package/dist/utility/utilis/postgres/executeQuery.js.map +1 -1
  106. package/dist/utility/utilis/postgres/subSqlfiles/executeMySqlQuery.js +3 -3
  107. package/dist/utility/utilis/postgres/subSqlfiles/executePgQuery.js +3 -3
  108. package/dist/utility/utilis/server/app.js +29 -11
  109. package/dist/utility/utilis/server/app.js.map +1 -1
  110. package/dist/utility/utilis/server/server.d.ts +2 -2
  111. package/dist/utility/utilis/server/server.js +28 -18
  112. package/dist/utility/utilis/server/server.js.map +1 -1
  113. package/package.json +7 -8
  114. package/dist/chunk-5A3RVJNT.js +0 -19
  115. package/dist/chunk-5A3RVJNT.js.map +0 -1
  116. package/dist/chunk-ICFMWIIJ.js +0 -53
  117. package/dist/chunk-ICFMWIIJ.js.map +0 -1
  118. package/dist/chunk-LFRKRR7G.js.map +0 -1
  119. package/dist/chunk-MNSQSU7T.js.map +0 -1
  120. package/dist/chunk-NIOLLLJJ.js +0 -44
  121. package/dist/chunk-NIOLLLJJ.js.map +0 -1
  122. package/dist/chunk-SSFPGDA3.js.map +0 -1
  123. package/dist/chunk-W3W3X2OE.js.map +0 -1
  124. package/dist/chunk-X3R3RLXY.js.map +0 -1
  125. package/dist/chunk-YWFCWT6R.js +0 -23
  126. package/dist/chunk-YWFCWT6R.js.map +0 -1
  127. package/dist/chunk-ZMDJ45KH.js.map +0 -1
  128. package/dist/engine/script/run-all.d.ts +0 -3
  129. package/dist/engine/script/run-all.js +0 -8
  130. package/dist/engine/script/run-bucket.d.ts +0 -3
  131. package/dist/engine/script/run-bucket.js +0 -8
  132. package/dist/engine/script/run-bucket.js.map +0 -1
  133. package/dist/engine/script/run-node-server.d.ts +0 -3
  134. package/dist/engine/script/run-node-server.js +0 -8
  135. package/dist/engine/script/run-node-server.js.map +0 -1
  136. package/dist/engine/server/app.d.ts +0 -5
  137. package/dist/engine/server/app.js +0 -10
  138. package/dist/engine/server/app.js.map +0 -1
  139. package/dist/utility/script/run-all.js +0 -8
  140. package/dist/utility/script/run-all.js.map +0 -1
  141. package/dist/utility/script/run-bucket.js +0 -8
  142. package/dist/utility/script/run-bucket.js.map +0 -1
  143. package/dist/utility/script/run-node-server.js +0 -8
  144. package/dist/utility/script/run-node-server.js.map +0 -1
  145. package/dist/utility/utilis/cloud_storage/s3Client.d.ts +0 -5
  146. package/dist/utility/utilis/cloud_storage/s3Client.js +0 -17
  147. package/dist/utility/utilis/cloud_storage/s3Client.js.map +0 -1
  148. /package/dist/{chunk-QVTKG7FD.js.map → chunk-2RFTNIPS.js.map} +0 -0
  149. /package/dist/{chunk-TP3K7DMH.js.map → chunk-DRLEV7OW.js.map} +0 -0
  150. /package/dist/{chunk-XBJ3SJ26.js.map → chunk-ECIP24BN.js.map} +0 -0
  151. /package/dist/{chunk-YTBSGKGF.js.map → chunk-IAQMTSGP.js.map} +0 -0
  152. /package/dist/{chunk-D7A4TEXY.js.map → chunk-QUZPQJRE.js.map} +0 -0
  153. /package/dist/{chunk-VFF4YFA3.js.map → chunk-SOZL76ZM.js.map} +0 -0
  154. /package/dist/{engine/script/run-all.js.map → utility/libs/index.js.map} +0 -0
  155. /package/dist/utility/{script → libs}/run-all.d.ts +0 -0
  156. /package/dist/utility/{script → libs}/run-bucket.d.ts +0 -0
  157. /package/dist/utility/{script → libs}/run-node-server.d.ts +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/utility/utilis/server/server.ts"],"sourcesContent":["import {HTTP_SERVER, startServer} from \"../../../engine/server/server.js\";\r\n\r\n\r\nawait startServer();\r\n\r\n\r\nexport const getServer = () => {return HTTP_SERVER}\r\n"],"mappings":";;;;;;;;;;;;;;;;;AAGA,MAAM,YAAY;AAGX,IAAM,YAAa,6BAAO;AAAC,SAAO;AAAW,GAA1B;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "backfarm",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "Divyanshu Jha",
7
7
  "license": "ISC",
8
8
  "type": "module",
9
9
  "scripts": {
10
- "all": "tsx src/utility/script/run-all.ts",
11
- "bucket": "tsx src/utility/script/run-bucket.ts",
12
- "node": "tsx src/utility/script/run-node-server.ts",
10
+ "all": "tsx src/utility/libs/run-all.ts",
11
+ "bucket": "tsx src/utility/libs/run-bucket.ts",
12
+ "node": "tsx src/utility/libs/run-node-server.ts",
13
13
  "build": "tsup",
14
14
  "prepublishOnly": "npm run build",
15
15
  "start": "node dist/server.js",
@@ -20,14 +20,13 @@
20
20
  ],
21
21
  "exports": {
22
22
  "./*": {
23
- "types": "./dist/utility/*.d.ts",
24
- "import": "./dist/utility/*.js",
25
- "require": "./dist/utility/*.js"
23
+ "types": "./dist/utility/libs/*.d.ts",
24
+ "import": "./dist/utility/libs/*.js",
25
+ "require": "./dist/utility/libs/*.js"
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
29
  "@aws-sdk/client-s3": "^3.1080.0",
30
- "backfarm": "^1.0.1",
31
30
  "dotenv": "^17.4.2",
32
31
  "express": "^5.2.1",
33
32
  "mongodb": "^7.4.0",
@@ -1,19 +0,0 @@
1
- import {
2
- __name
3
- } from "./chunk-7QVYU63E.js";
4
-
5
- // src/engine/script/run-node-server.ts
6
- import { execSync } from "child_process";
7
- import path from "path";
8
- function runNodeServer() {
9
- execSync("tsx " + path.join(process.cwd(), "node_modules/backfarm/dist/utility/utilis/server/server.js"), {
10
- cwd: process.cwd(),
11
- stdio: "inherit"
12
- });
13
- }
14
- __name(runNodeServer, "runNodeServer");
15
-
16
- export {
17
- runNodeServer
18
- };
19
- //# sourceMappingURL=chunk-5A3RVJNT.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/engine/script/run-node-server.ts"],"sourcesContent":["import {execSync} from \"node:child_process\";\r\nimport path from \"node:path\";\r\n\r\nexport function runNodeServer () {\r\n execSync(\"tsx \" + path.join(process.cwd() , \"node_modules/backfarm/dist/utility/utilis/server/server.js\"), {\r\n cwd: process.cwd(),\r\n stdio: \"inherit\",\r\n })\r\n}\r\n\r\n"],"mappings":";;;;;AAAA,SAAQ,gBAAe;AACvB,OAAO,UAAU;AAEV,SAAS,gBAAmB;AAC/B,WAAS,SAAS,KAAK,KAAK,QAAQ,IAAI,GAAI,4DAA4D,GAAG;AAAA,IACvG,KAAK,QAAQ,IAAI;AAAA,IACjB,OAAO;AAAA,EACX,CAAC;AACL;AALgB;","names":[]}
@@ -1,53 +0,0 @@
1
- import {
2
- isMySQL,
3
- isPostgreSQL
4
- } from "./chunk-MNSQSU7T.js";
5
- import {
6
- handleError
7
- } from "./chunk-P5XJG7OG.js";
8
- import {
9
- app_default
10
- } from "./chunk-NIOLLLJJ.js";
11
- import {
12
- runMySqlScript
13
- } from "./chunk-QVTKG7FD.js";
14
- import {
15
- runPgSqlScript
16
- } from "./chunk-VFF4YFA3.js";
17
- import {
18
- connectToMongo
19
- } from "./chunk-XBJ3SJ26.js";
20
- import {
21
- ENV
22
- } from "./chunk-EWQYVPOL.js";
23
- import {
24
- __name
25
- } from "./chunk-7QVYU63E.js";
26
-
27
- // src/engine/server/server.ts
28
- import * as http from "http";
29
- var PORT = ENV.SERVER_PORT;
30
- var SQL_URL = ENV.SQL_DB_URL;
31
- var HTTP_SERVER = http.createServer(app_default);
32
- var startServer = /* @__PURE__ */ __name(async () => {
33
- try {
34
- if (isPostgreSQL(SQL_URL)) {
35
- await runPgSqlScript();
36
- }
37
- if (isMySQL(SQL_URL)) {
38
- await runMySqlScript();
39
- }
40
- await connectToMongo();
41
- HTTP_SERVER.listen(PORT, () => {
42
- console.log(`Server running on port ${PORT}`);
43
- });
44
- } catch (err) {
45
- handleError(err);
46
- }
47
- }, "startServer");
48
-
49
- export {
50
- HTTP_SERVER,
51
- startServer
52
- };
53
- //# sourceMappingURL=chunk-ICFMWIIJ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/engine/server/server.ts"],"sourcesContent":["import app from \"./app.js\";\r\nimport {connectToMongo} from \"../mondoDb/mongoDB.js\";\r\nimport {ENV} from \"../../utility/libs/env.js\";\r\nimport {runPgSqlScript} from \"../sql/pgSql.js\";\r\nimport {handleError} from \"../../utility/utilis/general/error_handler.js\";\r\nimport {isMySQL, isPostgreSQL} from \"../../utility/utilis/general/sqlDb.js.js\";\r\nimport {runMySqlScript} from \"../sql/mySql.js\";\r\nimport * as http from \"node:http\";\r\n\r\n\r\n\r\n\r\n\r\nconst PORT = ENV.SERVER_PORT;\r\nconst SQL_URL = ENV.SQL_DB_URL;\r\nexport const HTTP_SERVER = http.createServer(app);\r\n\r\n\r\n\r\n\r\n\r\nexport const startServer = async () => {\r\n try {\r\n\r\n if (isPostgreSQL(SQL_URL)) {\r\n await runPgSqlScript()\r\n }\r\n if (isMySQL(SQL_URL)) {\r\n await runMySqlScript()\r\n }\r\n\r\n await connectToMongo();\r\n\r\n\r\n HTTP_SERVER.listen(PORT, () => {\r\n console.log(`Server running on port ${PORT}`);\r\n });\r\n }\r\n catch(err) {\r\n handleError(err)\r\n }\r\n\r\n};\r\n\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,YAAY,UAAU;AAMtB,IAAM,OAAO,IAAI;AACjB,IAAM,UAAU,IAAI;AACb,IAAM,cAAmB,kBAAa,WAAG;AAMzC,IAAM,cAAc,mCAAY;AACnC,MAAI;AAEA,QAAI,aAAa,OAAO,GAAG;AACvB,YAAM,eAAe;AAAA,IACzB;AACA,QAAI,QAAQ,OAAO,GAAG;AAClB,YAAM,eAAe;AAAA,IACzB;AAEA,UAAM,eAAe;AAGrB,gBAAY,OAAO,MAAM,MAAM;AAC3B,cAAQ,IAAI,0BAA0B,IAAI,EAAE;AAAA,IAChD,CAAC;AAAA,EACL,SACM,KAAK;AACP,gBAAY,GAAG;AAAA,EACnB;AAEJ,GArB2B;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/engine/script/run-bucket.ts"],"sourcesContent":["import {execSync} from \"node:child_process\";\r\n\r\nexport function runBucket() {\r\n\r\n execSync('docker-compose -f ./bucketConfigs/docker-compose.yml up', {\r\n cwd: process.cwd(),\r\n stdio: \"inherit\",\r\n })\r\n\r\n}\r\n\r\n\r\n"],"mappings":";;;;;AAAA,SAAQ,gBAAe;AAEhB,SAAS,YAAY;AAExB,WAAS,2DAA2D;AAAA,IAChE,KAAK,QAAQ,IAAI;AAAA,IACjB,OAAO;AAAA,EACX,CAAC;AAEL;AAPgB;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utility/utilis/general/sqlDb.js.ts"],"sourcesContent":["// constants.ts or at top of file\r\nimport type {DatabaseType} from \"../../libs/types.js\";\r\nimport { URL } from 'url';\r\nimport {ENV} from \"../../libs/env.js\";\r\n\r\n\r\n\r\n/**\r\n * Detects the SQL database type from a database connection URL.\r\n *\r\n * The function supports MySQL and PostgreSQL connection URL schemes,\r\n * including common driver-specific variants such as `mysql2`,\r\n * `mysql+pymysql`, `postgresql+psycopg2`, and `postgresql+asyncpg`.\r\n *\r\n * If the connection string does not contain a recognized protocol, the\r\n * function attempts to identify the database using keywords in the\r\n * connection string or the default database ports:\r\n *\r\n * - MySQL: `3306`\r\n * - PostgreSQL: `5432`\r\n *\r\n * Invalid URLs are also checked as raw connection strings before an error\r\n * is thrown. This allows common connection strings without a protocol to\r\n * still be detected.\r\n *\r\n * @param url - The SQL database connection URL or connection string.\r\n * @returns `ENV.MY_SQL` for MySQL connections or `ENV.POSTGRES_SQL` for\r\n * PostgreSQL connections.\r\n * @throws {Error} If the URL is invalid or the database type cannot be\r\n * identified as MySQL or PostgreSQL.\r\n *\r\n * @example\r\n * // Detect PostgreSQL from a standard connection URL.\r\n * const database = detectSQLDatabase(\r\n * 'postgresql://user:password@localhost:5432/my_database'\r\n * );\r\n *\r\n * // Returns: ENV.POSTGRES_SQL\r\n *\r\n * @example\r\n * // Detect MySQL from a standard connection URL.\r\n * const database = detectSQLDatabase(\r\n * 'mysql://user:password@localhost:3306/my_database'\r\n * );\r\n *\r\n * // Returns: ENV.MY_SQL\r\n *\r\n * @example\r\n * // Driver-specific PostgreSQL URLs are also supported.\r\n * const database = detectSQLDatabase(\r\n * 'postgresql+psycopg2://user:password@localhost:5432/my_database'\r\n * );\r\n *\r\n * // Returns: ENV.POSTGRES_SQL\r\n *\r\n * @example\r\n * // A connection string without a recognized protocol can be detected\r\n * // using the default PostgreSQL port.\r\n * const database = detectSQLDatabase(\r\n * 'localhost:5432/my_database'\r\n * );\r\n *\r\n * // Returns: ENV.POSTGRES_SQL\r\n *\r\n * @example\r\n * // Throws when the database type cannot be determined.\r\n * const database = detectSQLDatabase(\r\n * 'mongodb://localhost:27017/my_database'\r\n * );\r\n *\r\n * // Error: Unsupported or unrecognized database type.\r\n */\r\nexport function detectSQLDatabase(url: string): DatabaseType {\r\n try {\r\n // Parse the URL\r\n const parsedUrl = new URL(url);\r\n const scheme = parsedUrl.protocol.replace(':', '').toLowerCase();\r\n\r\n // MySQL schemes\r\n const mysqlSchemes = [\r\n 'mysql',\r\n 'mysql+pymysql',\r\n 'mysql+mysqldb',\r\n 'mysql+mysqlconnector',\r\n 'mysql2',\r\n 'mysql+mysql2'\r\n ];\r\n\r\n // PostgreSQL schemes\r\n const postgresSchemes = [\r\n 'postgresql',\r\n 'postgres',\r\n 'postgresql+psycopg2',\r\n 'postgres+psycopg2',\r\n 'postgresql+pg8000',\r\n 'postgres+pg8000',\r\n 'postgresql+asyncpg',\r\n 'postgresql+pg',\r\n 'postgres+pg'\r\n ];\r\n\r\n // Check for MySQL\r\n if (mysqlSchemes.includes(scheme)) {\r\n return ENV.MY_SQL;\r\n }\r\n\r\n // Check for PostgreSQL\r\n if (postgresSchemes.includes(scheme)) {\r\n return ENV.POSTGRES_SQL;\r\n }\r\n\r\n // If it's a generic URL without protocol, try to detect from connection string\r\n // This handles cases like \"localhost:5432/mydb\" or \"127.0.0.1:3306/mydb\"\r\n if (scheme === '' && !parsedUrl.protocol) {\r\n // Try parsing as a generic connection string\r\n const connectionString = url.toLowerCase();\r\n if (connectionString.includes('mysql') ||\r\n connectionString.includes('my-sql') ||\r\n parsedUrl.port === '3306') {\r\n return ENV.MY_SQL;\r\n }\r\n if (connectionString.includes('postgres') ||\r\n connectionString.includes('postgre') ||\r\n parsedUrl.port === '5432') {\r\n return ENV.POSTGRES_SQL;\r\n }\r\n }\r\n\r\n // If we reach here, we couldn't detect the database type\r\n throw new Error(\r\n `Unsupported or unrecognized database type. URL: ${url}. ` +\r\n `Detected scheme: ${scheme || 'none'}`\r\n );\r\n\r\n } catch (error) {\r\n if (error instanceof Error && error.message.includes('Invalid URL')) {\r\n // Try to detect from raw connection string without protocol\r\n const lowerUrl = url.toLowerCase();\r\n if (lowerUrl.includes('mysql') || lowerUrl.includes('my-sql')) {\r\n return ENV.MY_SQL;\r\n }\r\n if (lowerUrl.includes('postgres') || lowerUrl.includes('postgre')) {\r\n return ENV.POSTGRES_SQL;\r\n }\r\n // Check ports as fallback\r\n if (url.includes(':3306')) return ENV.MY_SQL;\r\n if (url.includes(':5432')) return ENV.POSTGRES_SQL;\r\n\r\n throw new Error(`Invalid URL format: ${url}`);\r\n }\r\n throw error;\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n/**\r\n * Determines whether a database connection URL represents a MySQL database.\r\n *\r\n * This function delegates database detection to `detectSQLDatabase()` and\r\n * compares the detected database type with the configured MySQL database\r\n * identifier.\r\n *\r\n * Any error encountered while parsing or detecting the database type is\r\n * handled internally, and the function returns `false` instead of throwing.\r\n * This makes the function safe to use when validating or conditionally\r\n * selecting a database implementation.\r\n *\r\n * @param url - The SQL database connection URL or connection string.\r\n * @returns `true` if the URL represents a MySQL database; otherwise `false`.\r\n *\r\n * @example\r\n * // Standard MySQL connection URL.\r\n * const result = isMySQL(\r\n * 'mysql://user:password@localhost:3306/my_database'\r\n * );\r\n *\r\n * // Returns: true\r\n *\r\n * @example\r\n * // PostgreSQL URL.\r\n * const result = isMySQL(\r\n * 'postgresql://user:password@localhost:5432/my_database'\r\n * );\r\n *\r\n * // Returns: false\r\n *\r\n * @example\r\n * // Invalid or unsupported connection URL.\r\n * const result = isMySQL('invalid-database-url');\r\n *\r\n * // Returns: false instead of throwing an error.\r\n */\r\nexport function isMySQL(url: string): boolean {\r\n try {\r\n return detectSQLDatabase(url) === ENV.MY_SQL;\r\n } catch {\r\n return false;\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n/**\r\n * Determines whether a database connection URL represents a PostgreSQL\r\n * database.\r\n *\r\n * This function delegates database detection to `detectSQLDatabase()` and\r\n * compares the detected database type with the configured PostgreSQL\r\n * identifier.\r\n *\r\n * Any error encountered while parsing or detecting the database type is\r\n * handled internally, causing the function to return `false` instead of\r\n * throwing. This makes the function safe to use when conditionally selecting\r\n * PostgreSQL-specific database logic.\r\n *\r\n * @param url - The SQL database connection URL or connection string.\r\n * @returns `true` if the URL represents a PostgreSQL database; otherwise\r\n * `false`.\r\n *\r\n * @example\r\n * // Standard PostgreSQL connection URL.\r\n * const result = isPostgreSQL(\r\n * 'postgresql://user:password@localhost:5432/my_database'\r\n * );\r\n *\r\n * // Returns: true\r\n *\r\n * @example\r\n * // MySQL connection URL.\r\n * const result = isPostgreSQL(\r\n * 'mysql://user:password@localhost:3306/my_database'\r\n * );\r\n *\r\n * // Returns: false\r\n *\r\n * @example\r\n * // Invalid or unsupported connection URL.\r\n * const result = isPostgreSQL('invalid-database-url');\r\n *\r\n * // Returns: false instead of throwing an error.\r\n */\r\nexport function isPostgreSQL(url: string): boolean {\r\n try {\r\n return detectSQLDatabase(url) === ENV.POSTGRES_SQL;\r\n } catch {\r\n return false;\r\n }\r\n}\r\n"],"mappings":";;;;;;;;AAEA,SAAS,WAAW;AAsEb,SAAS,kBAAkB,KAA2B;AACzD,MAAI;AAEA,UAAM,YAAY,IAAI,IAAI,GAAG;AAC7B,UAAM,SAAS,UAAU,SAAS,QAAQ,KAAK,EAAE,EAAE,YAAY;AAG/D,UAAM,eAAe;AAAA,MACjB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ;AAGA,UAAM,kBAAkB;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ;AAGA,QAAI,aAAa,SAAS,MAAM,GAAG;AAC/B,aAAO,IAAI;AAAA,IACf;AAGA,QAAI,gBAAgB,SAAS,MAAM,GAAG;AAClC,aAAO,IAAI;AAAA,IACf;AAIA,QAAI,WAAW,MAAM,CAAC,UAAU,UAAU;AAEtC,YAAM,mBAAmB,IAAI,YAAY;AACzC,UAAI,iBAAiB,SAAS,OAAO,KACjC,iBAAiB,SAAS,QAAQ,KAClC,UAAU,SAAS,QAAQ;AAC3B,eAAO,IAAI;AAAA,MACf;AACA,UAAI,iBAAiB,SAAS,UAAU,KACpC,iBAAiB,SAAS,SAAS,KACnC,UAAU,SAAS,QAAQ;AAC3B,eAAO,IAAI;AAAA,MACf;AAAA,IACJ;AAGA,UAAM,IAAI;AAAA,MACN,mDAAmD,GAAG,sBAClC,UAAU,MAAM;AAAA,IACxC;AAAA,EAEJ,SAAS,OAAO;AACZ,QAAI,iBAAiB,SAAS,MAAM,QAAQ,SAAS,aAAa,GAAG;AAEjE,YAAM,WAAW,IAAI,YAAY;AACjC,UAAI,SAAS,SAAS,OAAO,KAAK,SAAS,SAAS,QAAQ,GAAG;AAC3D,eAAO,IAAI;AAAA,MACf;AACA,UAAI,SAAS,SAAS,UAAU,KAAK,SAAS,SAAS,SAAS,GAAG;AAC/D,eAAO,IAAI;AAAA,MACf;AAEA,UAAI,IAAI,SAAS,OAAO,EAAG,QAAO,IAAI;AACtC,UAAI,IAAI,SAAS,OAAO,EAAG,QAAO,IAAI;AAEtC,YAAM,IAAI,MAAM,uBAAuB,GAAG,EAAE;AAAA,IAChD;AACA,UAAM;AAAA,EACV;AACJ;AAhFgB;AA4HT,SAAS,QAAQ,KAAsB;AAC1C,MAAI;AACA,WAAO,kBAAkB,GAAG,MAAM,IAAI;AAAA,EAC1C,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AANgB;AAkDT,SAAS,aAAa,KAAsB;AAC/C,MAAI;AACA,WAAO,kBAAkB,GAAG,MAAM,IAAI;AAAA,EAC1C,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AANgB;","names":[]}
@@ -1,44 +0,0 @@
1
- import {
2
- fileExistsAsync
3
- } from "./chunk-W3W3X2OE.js";
4
-
5
- // src/engine/server/app.ts
6
- import express from "express";
7
- import path from "path";
8
- import { pathToFileURL } from "url";
9
- var apiPathTs = path.join(process.cwd(), "src/apis/apis.ts");
10
- var apiPathJs = path.join(process.cwd(), "src/apis/apis.js");
11
- var { APIS } = await import(pathToFileURL(await fileExistsAsync(apiPathJs) ? apiPathJs : apiPathTs).href);
12
- var configPathTs = path.join(process.cwd(), "src/config/express.config.ts");
13
- var configPathJs = path.join(process.cwd(), "src/config/express.config.js");
14
- var { express_configurations } = await import(pathToFileURL(await fileExistsAsync(configPathJs) ? configPathJs : configPathTs).href);
15
- var app = express();
16
- express_configurations(app);
17
- var app_default = app;
18
- APIS.forEach((api) => {
19
- if ("get" in api) {
20
- const middleware = api.get.middleware ? Array.isArray(api.get.middleware) ? api.get.middleware : [api.get.middleware] : [];
21
- app.get(api.get.endpoint, ...middleware, api.get.callable);
22
- }
23
- if ("post" in api) {
24
- const middleware = api.post.middleware ? Array.isArray(api.post.middleware) ? api.post.middleware : [api.post.middleware] : [];
25
- app.post(api.post.endpoint, ...middleware, api.post.callable);
26
- }
27
- if ("put" in api) {
28
- const middleware = api.put.middleware ? Array.isArray(api.put.middleware) ? api.put.middleware : [api.put.middleware] : [];
29
- app.put(api.put.endpoint, ...middleware, api.put.callable);
30
- }
31
- if ("delete" in api) {
32
- const middleware = api.delete.middleware ? Array.isArray(api.delete.middleware) ? api.delete.middleware : [api.delete.middleware] : [];
33
- app.delete(api.delete.endpoint, ...middleware, api.delete.callable);
34
- }
35
- if ("patch" in api) {
36
- const middleware = api.patch.middleware ? Array.isArray(api.patch.middleware) ? api.patch.middleware : [api.patch.middleware] : [];
37
- app.patch(api.patch.endpoint, ...middleware, api.patch.callable);
38
- }
39
- });
40
-
41
- export {
42
- app_default
43
- };
44
- //# sourceMappingURL=chunk-NIOLLLJJ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/engine/server/app.ts"],"sourcesContent":["import express, {type Application } from 'express';\r\nimport type {ApisInterface} from \"../../utility/libs/types.js\";\r\nimport path from \"node:path\";\r\nimport { pathToFileURL } from \"node:url\";\r\nimport {fileExistsAsync} from \"../../utility/utilis/general/file-operations.js\";\r\n\r\nconst apiPathTs = path.join(process.cwd(), \"src/apis/apis.ts\");\r\nconst apiPathJs = path.join(process.cwd(), \"src/apis/apis.js\");\r\n\r\nconst { APIS } = await import(pathToFileURL(await fileExistsAsync(apiPathJs) ? apiPathJs : apiPathTs).href);\r\n\r\nconst configPathTs = path.join(process.cwd(), \"src/config/express.config.ts\");\r\nconst configPathJs = path.join(process.cwd(), \"src/config/express.config.js\");\r\nconst {express_configurations} = await import(pathToFileURL(await fileExistsAsync(configPathJs) ? configPathJs : configPathTs).href);\r\n\r\n\r\nconst app: Application = express();\r\nexpress_configurations(app)\r\n\r\n\r\nexport default app;\r\n\r\n\r\n\r\n\r\n\r\n// ======================== APIS ======================== //\r\n\r\n\r\n\r\n\r\n\r\n\r\nAPIS.forEach((api: ApisInterface) => {\r\n if ('get' in api) {\r\n const middleware = api.get.middleware\r\n ? (Array.isArray(api.get.middleware) ? api.get.middleware : [api.get.middleware])\r\n : [];\r\n app.get(api.get.endpoint, ...middleware, api.get.callable);\r\n }\r\n\r\n if ('post' in api) {\r\n const middleware = api.post.middleware\r\n ? (Array.isArray(api.post.middleware) ? api.post.middleware : [api.post.middleware])\r\n : [];\r\n app.post(api.post.endpoint, ...middleware, api.post.callable);\r\n }\r\n\r\n if ('put' in api) {\r\n const middleware = api.put.middleware\r\n ? (Array.isArray(api.put.middleware) ? api.put.middleware : [api.put.middleware])\r\n : [];\r\n app.put(api.put.endpoint, ...middleware, api.put.callable);\r\n }\r\n\r\n if ('delete' in api) {\r\n const middleware = api.delete.middleware\r\n ? (Array.isArray(api.delete.middleware) ? api.delete.middleware : [api.delete.middleware])\r\n : [];\r\n app.delete(api.delete.endpoint, ...middleware, api.delete.callable);\r\n }\r\n\r\n if ('patch' in api) {\r\n const middleware = api.patch.middleware\r\n ? (Array.isArray(api.patch.middleware) ? api.patch.middleware : [api.patch.middleware])\r\n : [];\r\n app.patch(api.patch.endpoint, ...middleware, api.patch.callable);\r\n }\r\n})\r\n\r\n\r\n\r\n\r\n"],"mappings":";;;;;AAAA,OAAO,aAAkC;AAEzC,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAG9B,IAAM,YAAY,KAAK,KAAK,QAAQ,IAAI,GAAG,kBAAkB;AAC7D,IAAM,YAAY,KAAK,KAAK,QAAQ,IAAI,GAAG,kBAAkB;AAE7D,IAAM,EAAE,KAAK,IAAI,MAAM,OAAO,cAAc,MAAM,gBAAgB,SAAS,IAAI,YAAY,SAAS,EAAE;AAEtG,IAAM,eAAe,KAAK,KAAK,QAAQ,IAAI,GAAG,8BAA8B;AAC5E,IAAM,eAAe,KAAK,KAAK,QAAQ,IAAI,GAAG,8BAA8B;AAC5E,IAAM,EAAC,uBAAsB,IAAI,MAAM,OAAO,cAAc,MAAM,gBAAgB,YAAY,IAAI,eAAe,YAAY,EAAE;AAG/H,IAAM,MAAmB,QAAQ;AACjC,uBAAuB,GAAG;AAG1B,IAAO,cAAQ;AAaf,KAAK,QAAQ,CAAC,QAAuB;AACjC,MAAI,SAAS,KAAK;AACd,UAAM,aAAa,IAAI,IAAI,aACpB,MAAM,QAAQ,IAAI,IAAI,UAAU,IAAI,IAAI,IAAI,aAAa,CAAC,IAAI,IAAI,UAAU,IAC7E,CAAC;AACP,QAAI,IAAI,IAAI,IAAI,UAAU,GAAG,YAAY,IAAI,IAAI,QAAQ;AAAA,EAC7D;AAEA,MAAI,UAAU,KAAK;AACf,UAAM,aAAa,IAAI,KAAK,aACrB,MAAM,QAAQ,IAAI,KAAK,UAAU,IAAI,IAAI,KAAK,aAAa,CAAC,IAAI,KAAK,UAAU,IAChF,CAAC;AACP,QAAI,KAAK,IAAI,KAAK,UAAU,GAAG,YAAY,IAAI,KAAK,QAAQ;AAAA,EAChE;AAEA,MAAI,SAAS,KAAK;AACd,UAAM,aAAa,IAAI,IAAI,aACpB,MAAM,QAAQ,IAAI,IAAI,UAAU,IAAI,IAAI,IAAI,aAAa,CAAC,IAAI,IAAI,UAAU,IAC7E,CAAC;AACP,QAAI,IAAI,IAAI,IAAI,UAAU,GAAG,YAAY,IAAI,IAAI,QAAQ;AAAA,EAC7D;AAEA,MAAI,YAAY,KAAK;AACjB,UAAM,aAAa,IAAI,OAAO,aACvB,MAAM,QAAQ,IAAI,OAAO,UAAU,IAAI,IAAI,OAAO,aAAa,CAAC,IAAI,OAAO,UAAU,IACtF,CAAC;AACP,QAAI,OAAO,IAAI,OAAO,UAAU,GAAG,YAAY,IAAI,OAAO,QAAQ;AAAA,EACtE;AAEA,MAAI,WAAW,KAAK;AAChB,UAAM,aAAa,IAAI,MAAM,aACtB,MAAM,QAAQ,IAAI,MAAM,UAAU,IAAI,IAAI,MAAM,aAAa,CAAC,IAAI,MAAM,UAAU,IACnF,CAAC;AACP,QAAI,MAAM,IAAI,MAAM,UAAU,GAAG,YAAY,IAAI,MAAM,QAAQ;AAAA,EACnE;AACJ,CAAC;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utility/utilis/general/web.ts"],"sourcesContent":["import type {URLOptions} from \"../../libs/interface.js\";\r\nimport {ENV} from \"../../libs/env.js\";\r\nimport type {ResponseInterface} from \"../../libs/types.js\";\r\n\r\n\r\n/**\r\n * Builds a normalized URL or path from an optional endpoint, path segments,\r\n * and file name.\r\n *\r\n * The function safely combines all provided segments while removing empty\r\n * values and normalizing slashes between segments. If the endpoint contains\r\n * an HTTP or HTTPS protocol, the protocol is preserved separately so that\r\n * slash normalization does not alter it.\r\n *\r\n * A `File` object can also be provided as `fileName`; in that case, its\r\n * original file name is extracted automatically.\r\n *\r\n * @param options - Options used to construct the URL.\r\n * @param options.end_point - Optional base URL or endpoint. Supports\r\n * `http://` and `https://` protocols.\r\n * @param options.path - Optional array of path segments to append to the\r\n * endpoint.\r\n * @param options.fileName - Optional file name or Web API `File` object.\r\n *\r\n * @returns A normalized URL/path containing the provided endpoint, path\r\n * segments, and file name. Returns an empty string when no valid segments\r\n * are provided.\r\n *\r\n * @example\r\n * // Build a URL from an endpoint, path, and file name.\r\n * const url = buildURL({\r\n * end_point: 'https://storage.example.com',\r\n * path: ['uploads', 'images'],\r\n * fileName: 'profile.jpg',\r\n * });\r\n *\r\n * // Returns:\r\n * // https://storage.example.com/uploads/images/profile.jpg\r\n *\r\n * @example\r\n * // Extra slashes are automatically normalized.\r\n * const url = buildURL({\r\n * end_point: 'https://storage.example.com/',\r\n * path: ['/uploads/', '/images//'],\r\n * fileName: '/profile.jpg',\r\n * });\r\n *\r\n * // Returns:\r\n * // https://storage.example.com/uploads/images/profile.jpg\r\n *\r\n * @example\r\n * // A File object can be used as the file name.\r\n * const url = buildURL({\r\n * end_point: 'https://storage.example.com',\r\n * path: ['uploads'],\r\n * fileName: file,\r\n * });\r\n *\r\n * // If file.name is \"document.pdf\":\r\n * // https://storage.example.com/uploads/document.pdf\r\n *\r\n * @example\r\n * // The function can also build a path without a URL endpoint.\r\n * const path = buildURL({\r\n * path: ['uploads', 'documents'],\r\n * fileName: 'report.pdf',\r\n * });\r\n *\r\n * // Returns:\r\n * // uploads/documents/report.pdf\r\n *\r\n * @example\r\n * // Empty or undefined segments are ignored.\r\n * const url = buildURL({\r\n * end_point: 'https://storage.example.com/',\r\n * path: ['', 'uploads', '', 'documents'],\r\n * fileName: 'report.pdf',\r\n * });\r\n *\r\n * // Returns:\r\n * // https://storage.example.com/uploads/documents/report.pdf\r\n *\r\n * @example\r\n * // Returns an empty string when no usable values are provided.\r\n * const url = buildURL({});\r\n *\r\n * // Returns:\r\n * // ''\r\n */\r\nexport function buildURL({\r\n end_point,\r\n path = [],\r\n fileName,\r\n }: URLOptions): string {\r\n const resolvedFileName =\r\n fileName instanceof File ? fileName.name : fileName ?? '';\r\n\r\n // Filter out undefined, null, or empty string values safely\r\n const rawSegments: string[] = [\r\n end_point ?? '',\r\n ...path,\r\n resolvedFileName,\r\n ].filter((segment): segment is string => Boolean(segment && segment.trim()));\r\n\r\n if (rawSegments.length === 0) return '';\r\n\r\n // Extract and preserve protocol (http:// or https://) if present\r\n const match = rawSegments[0]?.match(/^(https?:\\/\\/)(.*)/i);\r\n let protocol = '';\r\n\r\n if (match) {\r\n protocol = match[1] ?? '';\r\n rawSegments[0] = match[2] ?? '';\r\n }\r\n\r\n // Clean leading/trailing/duplicate slashes\r\n const cleanedPath = rawSegments\r\n .map((segment) => segment.replace(/^\\/+|\\/+$/g, ''))\r\n .map((segment) => segment.replace(/\\/+/g, '/'))\r\n .filter((segment) => segment.length > 0)\r\n .join('/');\r\n\r\n return `${protocol}${cleanedPath}`;\r\n}\r\n\r\n\r\n\r\n\r\n/**\r\n * Extracts the object key/path from a full public file URL.\r\n *\r\n * This function is intended for files stored in the configured bucket.\r\n * It parses the URL, extracts the pathname, removes the configured bucket\r\n * name when it appears as the first path segment, and decodes any\r\n * URL-encoded characters in the resulting object key.\r\n *\r\n * For example, a URL such as:\r\n *\r\n * `https://storage.example.com/my-bucket/uploads/images/profile%20photo.jpg`\r\n *\r\n * will produce:\r\n *\r\n * `uploads/images/profile photo.jpg`\r\n *\r\n * @param url - The full public URL of the stored file.\r\n * @returns The decoded object key/path without the bucket name.\r\n *\r\n * @throws {TypeError} If the provided value is not a valid URL.\r\n *\r\n * @example\r\n * // Extract the object key from a bucket URL.\r\n * const key = getKeyFromUrl(\r\n * 'https://storage.example.com/my-bucket/uploads/profile.jpg'\r\n * );\r\n *\r\n * // Returns:\r\n * // 'uploads/profile.jpg'\r\n *\r\n * @example\r\n * // URL-encoded characters are decoded automatically.\r\n * const key = getKeyFromUrl(\r\n * 'https://storage.example.com/my-bucket/uploads/profile%20photo.jpg'\r\n * );\r\n *\r\n * // Returns:\r\n * // 'uploads/profile photo.jpg'\r\n *\r\n * @example\r\n * // Nested directories are preserved.\r\n * const key = getKeyFromUrl(\r\n * 'https://storage.example.com/my-bucket/users/123/avatar/image.png'\r\n * );\r\n *\r\n * // Returns:\r\n * // 'users/123/avatar/image.png'\r\n */\r\nexport const getKeyFromUrl = (url: string): string => {\r\n\r\n\r\n const parsedUrl = new URL(url);\r\n const pathParts = parsedUrl.pathname.split(\"/\").filter(Boolean);\r\n\r\n if (pathParts[0] === ENV.BUCKET_NAME) {\r\n pathParts.shift();\r\n }\r\n\r\n return decodeURIComponent(pathParts.join(\"/\"));\r\n};\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n/**\r\n * Sends a standardized API response to the client.\r\n *\r\n * This function provides a consistent response structure for both successful\r\n * and failed requests. The `success` property acts as the discriminator\r\n * between the two response types.\r\n *\r\n * For successful responses, the function returns the supplied status,\r\n * message, data, and metadata. For failed responses, it returns the supplied\r\n * status, message, error information, and metadata.\r\n *\r\n * A response timestamp is automatically generated when one is not already\r\n * provided through `meta.timestamp`.\r\n *\r\n * @param response - Express `Response` object used to send the HTTP response.\r\n * @param success - Indicates whether the request was successful.\r\n * @param status - HTTP status code returned to the client.\r\n * @param message - Optional human-readable response message.\r\n * @param data - Optional data returned by a successful operation.\r\n * @param error - Error information returned when the operation fails.\r\n * @param meta - Optional response metadata such as request ID, timestamp,\r\n * pagination information, or other request-related information.\r\n *\r\n * @returns The Express response containing the standardized API payload.\r\n *\r\n * @example\r\n * // Successful response.\r\n * return response_to_client({\r\n * response: res,\r\n * success: true,\r\n * status: 200,\r\n * message: 'User fetched successfully.',\r\n * data: user,\r\n * });\r\n *\r\n * @example\r\n * // Successful response with pagination metadata.\r\n * return response_to_client({\r\n * response: res,\r\n * success: true,\r\n * status: 200,\r\n * message: 'Users fetched successfully.',\r\n * data: users,\r\n * meta: {\r\n * timestamp: new Date().toISOString(),\r\n * requestId: 'req_123456',\r\n * page: 1,\r\n * limit: 20,\r\n * totalItems: 100,\r\n * totalPages: 5,\r\n * },\r\n * });\r\n *\r\n * @example\r\n * // Error response.\r\n * return response_to_client({\r\n * response: res,\r\n * success: false,\r\n * status: 404,\r\n * message: 'File not found.',\r\n * error: {\r\n * code: 'FILE_NOT_FOUND',\r\n * path: '/files/profile.jpg',\r\n * },\r\n * });\r\n *\r\n * @example\r\n * // Validation error with structured details.\r\n * return response_to_client({\r\n * response: res,\r\n * success: false,\r\n * status: 400,\r\n * message: 'Validation failed.',\r\n * error: {\r\n * code: 'VALIDATION_ERROR',\r\n * details: [\r\n * {\r\n * field: 'email',\r\n * message: 'Invalid email address.',\r\n * },\r\n * {\r\n * field: 'password',\r\n * message: 'Password is required.',\r\n * },\r\n * ],\r\n * },\r\n * });\r\n *\r\n * @example\r\n * // Error response with a request ID for tracing.\r\n * return response_to_client({\r\n * response: res,\r\n * success: false,\r\n * status: 500,\r\n * message: 'Internal server error.',\r\n * error: {\r\n * code: 'INTERNAL_SERVER_ERROR',\r\n * },\r\n * meta: {\r\n * timestamp: new Date().toISOString(),\r\n * requestId: 'req_abc123',\r\n * },\r\n * });\r\n */\r\nexport const response_to_client = ({\r\n response,\r\n ...payload\r\n }: ResponseInterface) => {\r\n const timestamp = payload.meta?.timestamp || new Date().toISOString();\r\n\r\n if (payload.success) {\r\n return response.status(payload.status).json({\r\n success: true,\r\n status: payload.status,\r\n message: payload.message ?? 'Success',\r\n data: payload.data,\r\n meta: {\r\n ...payload.meta,\r\n timestamp,\r\n },\r\n });\r\n }\r\n\r\n return response.status(payload.status).json({\r\n success: false,\r\n status: payload.status,\r\n message: payload.message ?? 'An error occurred',\r\n error: payload.error,\r\n meta: {\r\n ...payload.meta,\r\n timestamp,\r\n },\r\n });\r\n};\r\n\r\n\r\n\r\n"],"mappings":";;;;;;;;AAyFO,SAAS,SAAS;AAAA,EACI;AAAA,EACA,OAAO,CAAC;AAAA,EACR;AACJ,GAAuB;AAC5C,QAAM,mBACF,oBAAoB,OAAO,SAAS,OAAO,YAAY;AAG3D,QAAM,cAAwB;AAAA,IAC1B,aAAa;AAAA,IACb,GAAG;AAAA,IACH;AAAA,EACJ,EAAE,OAAO,CAAC,YAA+B,QAAQ,WAAW,QAAQ,KAAK,CAAC,CAAC;AAE3E,MAAI,YAAY,WAAW,EAAG,QAAO;AAGrC,QAAM,QAAQ,YAAY,CAAC,GAAG,MAAM,qBAAqB;AACzD,MAAI,WAAW;AAEf,MAAI,OAAO;AACP,eAAW,MAAM,CAAC,KAAK;AACvB,gBAAY,CAAC,IAAI,MAAM,CAAC,KAAK;AAAA,EACjC;AAGA,QAAM,cAAc,YACf,IAAI,CAAC,YAAY,QAAQ,QAAQ,cAAc,EAAE,CAAC,EAClD,IAAI,CAAC,YAAY,QAAQ,QAAQ,QAAQ,GAAG,CAAC,EAC7C,OAAO,CAAC,YAAY,QAAQ,SAAS,CAAC,EACtC,KAAK,GAAG;AAEb,SAAO,GAAG,QAAQ,GAAG,WAAW;AACpC;AAlCgB;AAuFT,IAAM,gBAAgB,wBAAC,QAAwB;AAGlD,QAAM,YAAY,IAAI,IAAI,GAAG;AAC7B,QAAM,YAAY,UAAU,SAAS,MAAM,GAAG,EAAE,OAAO,OAAO;AAE9D,MAAI,UAAU,CAAC,MAAM,IAAI,aAAa;AAClC,cAAU,MAAM;AAAA,EACpB;AAEA,SAAO,mBAAmB,UAAU,KAAK,GAAG,CAAC;AACjD,GAX6B;AA4HtB,IAAM,qBAAqB,wBAAC;AAAA,EACO;AAAA,EACA,GAAG;AACP,MAAyB;AAC3D,QAAM,YAAY,QAAQ,MAAM,cAAa,oBAAI,KAAK,GAAE,YAAY;AAEpE,MAAI,QAAQ,SAAS;AACjB,WAAO,SAAS,OAAO,QAAQ,MAAM,EAAE,KAAK;AAAA,MACxC,SAAS;AAAA,MACT,QAAQ,QAAQ;AAAA,MAChB,SAAS,QAAQ,WAAW;AAAA,MAC5B,MAAM,QAAQ;AAAA,MACd,MAAM;AAAA,QACF,GAAG,QAAQ;AAAA,QACX;AAAA,MACJ;AAAA,IACJ,CAAC;AAAA,EACL;AAEA,SAAO,SAAS,OAAO,QAAQ,MAAM,EAAE,KAAK;AAAA,IACxC,SAAS;AAAA,IACT,QAAQ,QAAQ;AAAA,IAChB,SAAS,QAAQ,WAAW;AAAA,IAC5B,OAAO,QAAQ;AAAA,IACf,MAAM;AAAA,MACF,GAAG,QAAQ;AAAA,MACX;AAAA,IACJ;AAAA,EACJ,CAAC;AACL,GA7BkC;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utility/utilis/general/file-operations.ts"],"sourcesContent":["import type {PathOptions} from \"../../libs/interface.js\";\r\nimport mime from \"mime-types\";\r\nimport {ENV} from \"../../libs/env.js\";\r\nimport {readFile} from \"node:fs/promises\";\r\nimport fs from \"fs/promises\";\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nexport async function fileExistsAsync(filePath: string) {\r\n try {\r\n await fs.access(filePath);\r\n return true; // File exists and is accessible\r\n } catch {\r\n return false; // File does not exist\r\n }\r\n}\r\n\r\n\r\nasync function fileExistsSync(filePath: string) {\r\n try {\r\n fs.access(filePath);\r\n return true; // File exists and is accessible\r\n } catch {\r\n return false; // File does not exist\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n\r\n/**\r\n * Extracts the file extension from a supported file input.\r\n *\r\n * Supports Express Multer files, Web API `File` objects, raw `Buffer` values,\r\n * and file paths or URLs. For URLs and paths, query parameters and hash\r\n * fragments are ignored when determining the extension.\r\n *\r\n * @param input - The file, buffer, path, or URL from which to extract the extension.\r\n * @returns The file extension without the leading dot, converted to lowercase.\r\n * Returns an empty string if no extension can be determined.\r\n *\r\n * @example\r\n * const extension = getFileExtension('https://example.com/files/image.PNG');\r\n * // Returns: \"png\"\r\n *\r\n * @example\r\n * const extension = getFileExtension(req.file);\r\n * // Returns: \"pdf\"\r\n *\r\n * @example\r\n * const extension = getFileExtension('documents/report.pdf?download=true');\r\n * // Returns: \"pdf\"\r\n *\r\n * @example\r\n * const extension = getFileExtension(buffer);\r\n * // Returns: \"\"\r\n */\r\nexport function getFileExtension(input: Express.Multer.File | File | Buffer | string): string {\r\n // 1. If it's a raw Buffer, it has no file name/extension metadata\r\n if (Buffer.isBuffer(input)) {\r\n return '';\r\n }\r\n\r\n // 2. Extract the filename string based on the input type\r\n let filename = '';\r\n\r\n if (typeof input === 'string') {\r\n filename = input;\r\n }\r\n else if ('originalname' in input && input.originalname) {\r\n // Express.Multer.File\r\n filename = input.originalname;\r\n }\r\n else if ('name' in input && input.name) {\r\n // Web API File\r\n filename = input.name;\r\n }\r\n\r\n if (!filename) {\r\n return '';\r\n }\r\n\r\n // 3. Remove URL query parameters or hashes (if a URL/path string is passed)\r\n const cleanFilename = filename.split(/[?#]/)[0] as string;\r\n\r\n // 4. Extract the last segment after the final dot\r\n const match = cleanFilename.match(/\\.([^./\\\\]+)$/);\r\n\r\n return match?.[1]?.toLowerCase() ?? '';\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n/**\r\n * Builds a normalized file path from the provided path components.\r\n *\r\n * Combines the path prefix, path segments, path postfix, and file name,\r\n * while removing empty values and normalizing redundant slashes.\r\n *\r\n * If `fileName` is a Web API `File` object, its `name` property is used.\r\n *\r\n * @param options - The path components used to construct the final path.\r\n * @param options.path_prefix - An optional prefix to prepend to the path.\r\n * @param options.path - An array of path segments.\r\n * @param options.path_postfix - An optional postfix to append before the file name.\r\n * @param options.fileName - The file name or a Web API `File` object.\r\n * @returns A normalized path with components separated by a single slash.\r\n *\r\n * @example\r\n * const filePath = buildPath({\r\n * path_prefix: 'uploads',\r\n * path: ['documents', 'reports'],\r\n * fileName: 'report.pdf',\r\n * });\r\n * // Returns: \"uploads/documents/reports/report.pdf\"\r\n *\r\n * @example\r\n * const filePath = buildPath({\r\n * path: ['documents//', '/reports/'],\r\n * fileName: 'report.pdf',\r\n * });\r\n * // Returns: \"documents/reports/report.pdf\"\r\n */\r\nexport function buildPath({\r\n path_prefix = '',\r\n path = [],\r\n path_postfix = '',\r\n fileName,\r\n }: PathOptions): string {\r\n // Extract string name if fileName is a File object\r\n const resolvedFileName =\r\n fileName instanceof File ? fileName.name : fileName ?? '';\r\n\r\n // Combine all segments into a single array\r\n const allSegments = [\r\n path_prefix,\r\n ...path,\r\n path_postfix,\r\n resolvedFileName,\r\n ];\r\n\r\n return allSegments\r\n // Filter out null/undefined/empty string items\r\n .filter((segment): segment is string => Boolean(segment && segment.trim()))\r\n // Clean leading/trailing slashes from individual segments\r\n .map((segment) => segment.replace(/^\\/+|\\/+$/g, ''))\r\n // Remove any extra slashes inside a segment (e.g. \"folder//subfolder\")\r\n .map((segment) => segment.replace(/\\/+/g, '/'))\r\n // Filter again in case cleaning left an empty string\r\n .filter((segment) => segment.length > 0)\r\n // Join with a single slash\r\n .join('/');\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n/**\r\n * Builds the local file path for a downloaded file.\r\n *\r\n * Removes any occurrence of the configured in-app bucket from the provided\r\n * path to prevent duplicating the bucket name, then constructs the final\r\n * path using the configured in-app bucket as the path prefix.\r\n *\r\n * @param options - The path and file name options used to build the downloaded file path.\r\n * @param options.path - The path segments leading to the file.\r\n * @param options.fileName - The name of the file or a Web API `File` object.\r\n * @returns The complete local path for the downloaded file.\r\n *\r\n * @example\r\n * const filePath = downloadedFilePath({\r\n * path: ['documents', 'reports'],\r\n * fileName: 'report.pdf',\r\n * });\r\n * // Returns a path prefixed with ENV.IN_APP_BUCKET.\r\n *\r\n * @example\r\n * const filePath = downloadedFilePath({\r\n * path: [ENV.IN_APP_BUCKET, 'documents'],\r\n * fileName: file,\r\n * });\r\n * // The duplicate bucket segment is removed before building the path.\r\n */\r\nexport function downloadedFilePath({path = [], fileName}: PathOptions): string {\r\n // Filter out any occurrence of ENV.IN_APP_BUCKET (case-sensitive or trimmed)\r\n const cleanedPath = path.filter((segment) => segment !== ENV.IN_APP_BUCKET);\r\n\r\n return buildPath({\r\n path_prefix: ENV.IN_APP_BUCKET,\r\n fileName: fileName instanceof File ? fileName.name : fileName ?? '',\r\n path: cleanedPath,\r\n });\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n/**\r\n * Determines the MIME content type of a file from its available metadata\r\n * or, when given a file path or URL, from its file extension.\r\n *\r\n * Supports Express Multer files, Web API `File` objects, raw `Buffer` values,\r\n * and file paths or URLs.\r\n *\r\n * @param file - The file, buffer, path, or URL whose content type should be determined.\r\n * @returns A promise resolving to the detected MIME content type.\r\n *\r\n * @example\r\n * const contentType = await getFileContentType(req.file);\r\n * // Returns something like: \"image/jpeg\"\r\n *\r\n * @example\r\n * const contentType = await getFileContentType('/uploads/document.pdf');\r\n * // Returns: \"application/pdf\"\r\n *\r\n * @example\r\n * const contentType = await getFileContentType(buffer);\r\n * // Returns: \"application/octet-stream\"\r\n */\r\nexport const getFileContentType = async (\r\n file: Express.Multer.File | File | Buffer | string\r\n): Promise<string> => {\r\n // 1. Raw Buffer: Buffers don't carry MIME metadata, so default to octet-stream\r\n if (Buffer.isBuffer(file)) {\r\n return 'application/octet-stream';\r\n }\r\n\r\n // 2. String path or URL: Look up MIME type based on extension/filename\r\n if (typeof file === 'string') {\r\n const detectedType = mime.lookup(file);\r\n return detectedType || 'application/octet-stream';\r\n }\r\n\r\n // 3. Express.Multer.File: Has 'mimetype' property\r\n if ('mimetype' in file && file.mimetype) {\r\n return file.mimetype;\r\n }\r\n\r\n // 4. Web API File: Has 'type' property\r\n if ('type' in file && file.type) {\r\n return file.type;\r\n }\r\n\r\n // 5. Fallback if object has no recognizable MIME type\r\n return 'application/octet-stream';\r\n};\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n/**\r\n * Determines whether the provided value is a URL or a local/server based file path.\r\n *\r\n * If the value is a valid HTTP/HTTPS URL, the configured URL environment\r\n * value is returned. Otherwise, the configured local path environment value\r\n * is returned.\r\n *\r\n * @param val - The URL or local file path to evaluate.\r\n * @returns The configured URL or local path based on the input type.\r\n *\r\n * @example\r\n * const basePath = url_or_path('https://example.com/file.png');\r\n * // Returns ENV.URL\r\n *\r\n * @example\r\n * const basePath = url_or_path('/uploads/file.png');\r\n * // Returns ENV.PATH\r\n */\r\nexport const url_or_path = (val: string): string => {\r\n try {\r\n const parsed = new URL(val);\r\n if (parsed.protocol === \"http:\" || parsed.protocol === \"https:\") {\r\n return ENV.URL;\r\n }\r\n } catch {\r\n // If new URL() throws, it is a local path\r\n }\r\n return ENV.PATH;\r\n};\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n/**\r\n * Safely normalizes Buffer, Express.Multer.File, Web File, or File Path into Uint8Array\r\n */\r\nexport async function toUint8Array(file: Express.Multer.File | File | Buffer | string): Promise<Uint8Array> {\r\n if (typeof file === \"string\") {\r\n // File path on disk\r\n return await readFile(file);\r\n }\r\n\r\n if (Buffer.isBuffer(file)) {\r\n // Raw Node.js Buffer\r\n return new Uint8Array(file);\r\n }\r\n\r\n if (\"buffer\" in file && Buffer.isBuffer(file.buffer)) {\r\n // Express.Multer.File (Memory storage)\r\n return new Uint8Array(file.buffer);\r\n }\r\n\r\n if (\"path\" in file && typeof file.path === \"string\") {\r\n // Express.Multer.File (Disk storage)\r\n return await readFile(file.path);\r\n }\r\n\r\n if (\"arrayBuffer\" in file && typeof file.arrayBuffer === \"function\") {\r\n // Web API File / Blob\r\n return new Uint8Array(await file.arrayBuffer());\r\n }\r\n\r\n throw new Error(\"Unable to parse file input into a valid binary buffer.\");\r\n}\r\n\r\n\r\n\r\n\r\n\r\n"],"mappings":";;;;;;;;AACA,OAAO,UAAU;AAEjB,SAAQ,gBAAe;AACvB,OAAO,QAAQ;AAUf,eAAsB,gBAAgB,UAAkB;AACpD,MAAI;AACA,UAAM,GAAG,OAAO,QAAQ;AACxB,WAAO;AAAA,EACX,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAPsB;AAkDf,SAAS,iBAAiB,OAA6D;AAE1F,MAAI,OAAO,SAAS,KAAK,GAAG;AACxB,WAAO;AAAA,EACX;AAGA,MAAI,WAAW;AAEf,MAAI,OAAO,UAAU,UAAU;AAC3B,eAAW;AAAA,EACf,WACS,kBAAkB,SAAS,MAAM,cAAc;AAEpD,eAAW,MAAM;AAAA,EACrB,WACS,UAAU,SAAS,MAAM,MAAM;AAEpC,eAAW,MAAM;AAAA,EACrB;AAEA,MAAI,CAAC,UAAU;AACX,WAAO;AAAA,EACX;AAGA,QAAM,gBAAgB,SAAS,MAAM,MAAM,EAAE,CAAC;AAG9C,QAAM,QAAQ,cAAc,MAAM,eAAe;AAEjD,SAAO,QAAQ,CAAC,GAAG,YAAY,KAAK;AACxC;AAhCgB;AA6ET,SAAS,UAAU;AAAA,EACI,cAAc;AAAA,EACd,OAAO,CAAC;AAAA,EACR,eAAe;AAAA,EACf;AACJ,GAAwB;AAE9C,QAAM,mBACF,oBAAoB,OAAO,SAAS,OAAO,YAAY;AAG3D,QAAM,cAAc;AAAA,IAChB;AAAA,IACA,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACJ;AAEA,SAAO,YAEF,OAAO,CAAC,YAA+B,QAAQ,WAAW,QAAQ,KAAK,CAAC,CAAC,EAEzE,IAAI,CAAC,YAAY,QAAQ,QAAQ,cAAc,EAAE,CAAC,EAElD,IAAI,CAAC,YAAY,QAAQ,QAAQ,QAAQ,GAAG,CAAC,EAE7C,OAAO,CAAC,YAAY,QAAQ,SAAS,CAAC,EAEtC,KAAK,GAAG;AACjB;AA7BgB;AAsET,SAAS,mBAAmB,EAAC,OAAO,CAAC,GAAG,SAAQ,GAAwB;AAE3E,QAAM,cAAc,KAAK,OAAO,CAAC,YAAY,YAAY,IAAI,aAAa;AAE1E,SAAO,UAAU;AAAA,IACb,aAAa,IAAI;AAAA,IACjB,UAAU,oBAAoB,OAAO,SAAS,OAAO,YAAY;AAAA,IACjE,MAAM;AAAA,EACV,CAAC;AACL;AATgB;AA4CT,IAAM,qBAAqB,8BAC9B,SACkB;AAElB,MAAI,OAAO,SAAS,IAAI,GAAG;AACvB,WAAO;AAAA,EACX;AAGA,MAAI,OAAO,SAAS,UAAU;AAC1B,UAAM,eAAe,KAAK,OAAO,IAAI;AACrC,WAAO,gBAAgB;AAAA,EAC3B;AAGA,MAAI,cAAc,QAAQ,KAAK,UAAU;AACrC,WAAO,KAAK;AAAA,EAChB;AAGA,MAAI,UAAU,QAAQ,KAAK,MAAM;AAC7B,WAAO,KAAK;AAAA,EAChB;AAGA,SAAO;AACX,GA1BkC;AAyD3B,IAAM,cAAc,wBAAC,QAAwB;AAChD,MAAI;AACA,UAAM,SAAS,IAAI,IAAI,GAAG;AAC1B,QAAI,OAAO,aAAa,WAAW,OAAO,aAAa,UAAU;AAC7D,aAAO,IAAI;AAAA,IACf;AAAA,EACJ,QAAQ;AAAA,EAER;AACA,SAAO,IAAI;AACf,GAV2B;AA2B3B,eAAsB,aAAa,MAAyE;AACxG,MAAI,OAAO,SAAS,UAAU;AAE1B,WAAO,MAAM,SAAS,IAAI;AAAA,EAC9B;AAEA,MAAI,OAAO,SAAS,IAAI,GAAG;AAEvB,WAAO,IAAI,WAAW,IAAI;AAAA,EAC9B;AAEA,MAAI,YAAY,QAAQ,OAAO,SAAS,KAAK,MAAM,GAAG;AAElD,WAAO,IAAI,WAAW,KAAK,MAAM;AAAA,EACrC;AAEA,MAAI,UAAU,QAAQ,OAAO,KAAK,SAAS,UAAU;AAEjD,WAAO,MAAM,SAAS,KAAK,IAAI;AAAA,EACnC;AAEA,MAAI,iBAAiB,QAAQ,OAAO,KAAK,gBAAgB,YAAY;AAEjE,WAAO,IAAI,WAAW,MAAM,KAAK,YAAY,CAAC;AAAA,EAClD;AAEA,QAAM,IAAI,MAAM,wDAAwD;AAC5E;AA3BsB;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utility/utilis/general/uuids.ts"],"sourcesContent":["import crypto from 'crypto';\r\nimport { getRandomValues } from 'node:crypto';\r\nimport type {GenerateIdOptions} from \"../../libs/interface.js\";\r\n\r\n\r\n\r\n/**\r\n * Generates one or more cryptographically secure unique values.\r\n *\r\n * Values can be generated using hexadecimal characters or a custom\r\n * alphanumeric character set. Optional timestamps and prefixes can be\r\n * included in the generated values.\r\n *\r\n * When `count` is provided, multiple unique values are returned as an array.\r\n * Otherwise, a single string is returned.\r\n *\r\n * @param length - The length of the randomly generated portion of each value.\r\n * @param options - Optional configuration for generating the value(s).\r\n * @param options.useHex - Whether to generate the random portion using hexadecimal characters.\r\n * @param options.includeTimestamp - Whether to prepend a hexadecimal timestamp.\r\n * @param options.prefix - An optional prefix to prepend to the generated value.\r\n * @param options.count - The number of values to generate. If omitted, one value is returned.\r\n * @returns A single unique string when `count` is not provided, or an array of unique strings when `count` is specified.\r\n * @throws {Error} If `length` or `count` is less than or equal to zero.\r\n *\r\n * @example\r\n * const id = generateUniqueValue(16);\r\n * // Returns: \"aZ7_kP2mQ9xL3nBc\"\r\n *\r\n * @example\r\n * const id = generateUniqueValue(16, {\r\n * useHex: true,\r\n * prefix: 'file',\r\n * });\r\n * // Returns: \"file-7f3a9c12d84e...\"\r\n *\r\n * @example\r\n * const id = generateUniqueValue(12, {\r\n * includeTimestamp: true,\r\n * });\r\n * // Returns: \"198a7f3c12a-7Kx9mP...\"\r\n *\r\n * @example\r\n * const ids = generateUniqueValue(10, {\r\n * count: 5,\r\n * prefix: 'file',\r\n * });\r\n * // Returns: [\"file-...\", \"file-...\", \"file-...\", \"file-...\", \"file-...\"]\r\n */\r\nexport function generateUniqueValue(length: number, options?: GenerateIdOptions): string;\r\nexport function generateUniqueValue(length: number, options: GenerateIdOptions & { count: number }): string[];\r\nexport function generateUniqueValue(\r\n length: number,\r\n options?: GenerateIdOptions & { count?: number }\r\n): string | string[] {\r\n if (length <= 0) {\r\n throw new Error('Length must be greater than 0');\r\n }\r\n\r\n const count = options?.count ?? 1;\r\n if (count <= 0) {\r\n throw new Error('Count must be greater than 0');\r\n }\r\n\r\n const generateSingleId = (): string => {\r\n let id = '';\r\n\r\n if (options?.useHex) {\r\n // 1 byte = 2 hex chars. We use Math.ceil and slice to ensure exact requested length.\r\n id = crypto.randomBytes(Math.ceil(length / 2)).toString('hex').slice(0, length);\r\n } else {\r\n // Allowed characters: A-Z, a-z, 0-9, and _ (63 total characters)\r\n const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_';\r\n const alphabetLength = alphabet.length; // 63\r\n\r\n // 63 is less than 64 (2^6), so 6 bits can represent 0-62.\r\n // Using a bitmask (63) avoids modulo bias for uniform randomness.\r\n const mask = (2 << (31 - Math.clz32((alphabetLength - 1) | 1))) - 1;\r\n const step = Math.ceil((1.6 * mask * length) / alphabetLength);\r\n\r\n const getBaseId = (): string => {\r\n let baseId = '';\r\n while (true) {\r\n const bytes = new Uint8Array(step);\r\n getRandomValues(bytes);\r\n\r\n for (const byteValue of bytes) {\r\n const byte = byteValue & mask;\r\n if (byte < alphabetLength) {\r\n baseId += alphabet[byte];\r\n if (baseId.length === length) {\r\n return baseId;\r\n }\r\n }\r\n }\r\n }\r\n };\r\n id = getBaseId();\r\n }\r\n\r\n // Apply formatting (Timestamp first, then Prefix)\r\n if (options?.includeTimestamp) {\r\n const timestamp = Date.now().toString(16);\r\n id = `${timestamp}-${id}`;\r\n }\r\n\r\n if (options?.prefix) {\r\n id = `${options.prefix}-${id}`;\r\n }\r\n\r\n return id;\r\n };\r\n\r\n // Return an array if count is explicitly requested, otherwise return a single string\r\n if (options?.count !== undefined) {\r\n return Array.from({ length: count }, () => generateSingleId());\r\n }\r\n\r\n return generateSingleId();\r\n}\r\n"],"mappings":";;;;;AAAA,OAAO,YAAY;AACnB,SAAS,uBAAuB;AAkDzB,SAAS,oBACZ,QACA,SACiB;AACnB,MAAI,UAAU,GAAG;AACf,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AAEA,QAAM,QAAQ,SAAS,SAAS;AAChC,MAAI,SAAS,GAAG;AACd,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AAEA,QAAM,mBAAmB,6BAAc;AACrC,QAAI,KAAK;AAET,QAAI,SAAS,QAAQ;AAEnB,WAAK,OAAO,YAAY,KAAK,KAAK,SAAS,CAAC,CAAC,EAAE,SAAS,KAAK,EAAE,MAAM,GAAG,MAAM;AAAA,IAChF,OAAO;AAEL,YAAM,WAAW;AACjB,YAAM,iBAAiB,SAAS;AAIhC,YAAM,QAAQ,KAAM,KAAK,KAAK,MAAO,iBAAiB,IAAK,CAAC,KAAM;AAClE,YAAM,OAAO,KAAK,KAAM,MAAM,OAAO,SAAU,cAAc;AAE7D,YAAM,YAAY,6BAAc;AAC9B,YAAI,SAAS;AACb,eAAO,MAAM;AACX,gBAAM,QAAQ,IAAI,WAAW,IAAI;AACjC,0BAAgB,KAAK;AAErB,qBAAW,aAAa,OAAO;AAC7B,kBAAM,OAAO,YAAY;AACzB,gBAAI,OAAO,gBAAgB;AACzB,wBAAU,SAAS,IAAI;AACvB,kBAAI,OAAO,WAAW,QAAQ;AAC5B,uBAAO;AAAA,cACT;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF,GAhBkB;AAiBlB,WAAK,UAAU;AAAA,IACjB;AAGA,QAAI,SAAS,kBAAkB;AAC7B,YAAM,YAAY,KAAK,IAAI,EAAE,SAAS,EAAE;AACxC,WAAK,GAAG,SAAS,IAAI,EAAE;AAAA,IACzB;AAEA,QAAI,SAAS,QAAQ;AACnB,WAAK,GAAG,QAAQ,MAAM,IAAI,EAAE;AAAA,IAC9B;AAEA,WAAO;AAAA,EACT,GA/CyB;AAkDzB,MAAI,SAAS,UAAU,QAAW;AAChC,WAAO,MAAM,KAAK,EAAE,QAAQ,MAAM,GAAG,MAAM,iBAAiB,CAAC;AAAA,EAC/D;AAEA,SAAO,iBAAiB;AAC1B;AApEgB;","names":[]}
@@ -1,23 +0,0 @@
1
- import {
2
- __name
3
- } from "./chunk-7QVYU63E.js";
4
-
5
- // src/engine/script/run-all.ts
6
- import { execSync } from "child_process";
7
- import path from "path";
8
- function runAll() {
9
- execSync("docker-compose -f ./bucketConfigs/docker-compose.yml up -d", {
10
- cwd: process.cwd(),
11
- stdio: "inherit"
12
- });
13
- execSync("tsx " + path.join(process.cwd(), "node_modules/backfarm/dist/utility/utilis/server/server.js"), {
14
- cwd: process.cwd(),
15
- stdio: "inherit"
16
- });
17
- }
18
- __name(runAll, "runAll");
19
-
20
- export {
21
- runAll
22
- };
23
- //# sourceMappingURL=chunk-YWFCWT6R.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/engine/script/run-all.ts"],"sourcesContent":["import {execSync} from \"node:child_process\";\r\nimport path from \"node:path\";\r\n\r\n\r\n\r\nexport function runAll() {\r\n execSync('docker-compose -f ./bucketConfigs/docker-compose.yml up -d', {\r\n cwd: process.cwd(),\r\n stdio: \"inherit\",\r\n })\r\n\r\n execSync(\"tsx \" + path.join(process.cwd() , \"node_modules/backfarm/dist/utility/utilis/server/server.js\"), {\r\n cwd: process.cwd(),\r\n stdio: \"inherit\",\r\n })\r\n\r\n}\r\n\r\n"],"mappings":";;;;;AAAA,SAAQ,gBAAe;AACvB,OAAO,UAAU;AAIV,SAAS,SAAS;AACrB,WAAS,8DAA8D;AAAA,IACnE,KAAK,QAAQ,IAAI;AAAA,IACjB,OAAO;AAAA,EACX,CAAC;AAED,WAAS,SAAS,KAAK,KAAK,QAAQ,IAAI,GAAI,4DAA4D,GAAG;AAAA,IACvG,KAAK,QAAQ,IAAI;AAAA,IACjB,OAAO;AAAA,EACX,CAAC;AAEL;AAXgB;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utility/utilis/cloud_storage/uploadFile.ts"],"sourcesContent":["import {ENV} from \"../../libs/env.js\";\r\nimport type {PathOptions, UploadFileInput} from \"../../libs/interface.js\";\r\nimport {PutObjectCommand} from \"@aws-sdk/client-s3\";\r\nimport {buildPath, getFileContentType, getFileExtension, toUint8Array} from \"../general/file-operations.js\";\r\nimport {buildURL} from \"../general/web.js\";\r\nimport {generateUniqueValue} from \"../general/uuids.js\";\r\nimport {s3Client} from \"../../../engine/cloudBucket/r2Storage.js\";\r\nimport type {FileUploadedResponseData} from \"../../libs/types.js\";\r\n\r\n\r\n\r\n\r\n\r\n\r\n/**\r\n * Uploads a single file to the configured S3-compatible storage bucket.\r\n *\r\n * The function accepts a Multer file, Web API `File`, raw `Buffer`, or file\r\n * path/URL. A unique file name is generated while preserving the original\r\n * file extension. The file is then converted to a byte array, its content\r\n * type is detected, and it is uploaded to the configured bucket.\r\n *\r\n * On successful upload, the function returns the generated storage path and\r\n * public URL along with the original file data when applicable. If the upload\r\n * fails, it returns the encountered error and the original file data when\r\n * available.\r\n *\r\n * @param params - The file and optional storage path used for the upload.\r\n * @param params.file - The file, buffer, or file path/URL to upload.\r\n * @param params.path - Optional array of path segments under which the file\r\n * should be stored.\r\n * @returns A promise resolving to a `FileUploadedResponseData` containing\r\n * either the uploaded file information or the encountered error.\r\n *\r\n * @example\r\n * const result = await upload_file({\r\n * file: req.file,\r\n * path: ['temporary_files'],\r\n * });\r\n *\r\n * if ('error' in result) {\r\n * console.error('Upload failed:', result.error);\r\n * } else {\r\n * console.log('File uploaded:', result.url);\r\n * }\r\n *\r\n * @example\r\n * const result = await upload_file({\r\n * file: buffer,\r\n * path: ['documents', 'reports'],\r\n * });\r\n *\r\n * if (!result.error) {\r\n * console.log('Uploaded to:', result.path);\r\n * }\r\n */\r\nexport const upload_file = async ({ file, path }: UploadFileInput): Promise<FileUploadedResponseData> => {\r\n // 1. Inspect input type\r\n const isMulterFile = file && typeof file === 'object' && 'buffer' in file && 'originalname' in file;\r\n const multerFile = isMulterFile ? (file as Express.Multer.File) : undefined;\r\n const rawBuffer = Buffer.isBuffer(file) ? file : undefined;\r\n const rawFile = (typeof File !== 'undefined' && file instanceof File) ? file : undefined;\r\n const filePath = typeof file === 'string' ? file : undefined;\r\n\r\n try {\r\n const baseFileName = generateUniqueValue(16);\r\n const fileExtension = getFileExtension(file);\r\n\r\n const fileName: string = fileExtension ? `${baseFileName}.${fileExtension}` : baseFileName;\r\n\r\n const body: PathOptions = { fileName };\r\n if (path && path.length) {\r\n body.path = path;\r\n }\r\n\r\n const finalFileName = buildPath(body);\r\n const fileBuffer = await toUint8Array(file);\r\n const contentType = await getFileContentType(file);\r\n\r\n await s3Client.send(new PutObjectCommand({\r\n Bucket: ENV.BUCKET_NAME,\r\n Key: finalFileName,\r\n Body: fileBuffer,\r\n ContentType: contentType\r\n }));\r\n\r\n const generatedUrl = buildURL({\r\n path: [ENV.BUCKET_END_POINT as string, ENV.BUCKET_NAME as string, finalFileName]\r\n });\r\n\r\n // 2. Build success object omitting undefined keys\r\n return {\r\n path: filePath || finalFileName,\r\n url: generatedUrl,\r\n ...(rawFile && {file: rawFile}),\r\n ...(rawBuffer && {buffer: rawBuffer}),\r\n ...(multerFile && {multerFile: multerFile}),\r\n };\r\n\r\n } catch (error: any | unknown | Error) {\r\n // 3. Build error object omitting undefined keys\r\n return {\r\n error: error,\r\n ...(filePath && {path: filePath}),\r\n ...(rawFile && {file: rawFile}),\r\n ...(rawBuffer && {buffer: rawBuffer}),\r\n ...(multerFile && {multerFile: multerFile}),\r\n };\r\n }\r\n};\r\n\r\n\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAQ,wBAAuB;AAsDxB,IAAM,cAAc,8BAAO,EAAE,MAAM,KAAK,MAA0D;AAErG,QAAM,eAAe,QAAQ,OAAO,SAAS,YAAY,YAAY,QAAQ,kBAAkB;AAC/F,QAAM,aAAa,eAAgB,OAA+B;AAClE,QAAM,YAAY,OAAO,SAAS,IAAI,IAAI,OAAO;AACjD,QAAM,UAAW,OAAO,SAAS,eAAe,gBAAgB,OAAQ,OAAO;AAC/E,QAAM,WAAW,OAAO,SAAS,WAAW,OAAO;AAEnD,MAAI;AACA,UAAM,eAAe,oBAAoB,EAAE;AAC3C,UAAM,gBAAgB,iBAAiB,IAAI;AAE3C,UAAM,WAAmB,gBAAgB,GAAG,YAAY,IAAI,aAAa,KAAK;AAE9E,UAAM,OAAoB,EAAE,SAAS;AACrC,QAAI,QAAQ,KAAK,QAAQ;AACrB,WAAK,OAAO;AAAA,IAChB;AAEA,UAAM,gBAAgB,UAAU,IAAI;AACpC,UAAM,aAAa,MAAM,aAAa,IAAI;AAC1C,UAAM,cAAc,MAAM,mBAAmB,IAAI;AAEjD,UAAM,SAAS,KAAK,IAAI,iBAAiB;AAAA,MACrC,QAAQ,IAAI;AAAA,MACZ,KAAK;AAAA,MACL,MAAM;AAAA,MACN,aAAa;AAAA,IACjB,CAAC,CAAC;AAEF,UAAM,eAAe,SAAS;AAAA,MAC1B,MAAM,CAAC,IAAI,kBAA4B,IAAI,aAAuB,aAAa;AAAA,IACnF,CAAC;AAGD,WAAO;AAAA,MACH,MAAM,YAAY;AAAA,MAClB,KAAK;AAAA,MACL,GAAI,WAAW,EAAC,MAAM,QAAO;AAAA,MAC7B,GAAI,aAAa,EAAC,QAAQ,UAAS;AAAA,MACnC,GAAI,cAAc,EAAC,WAAsB;AAAA,IAC7C;AAAA,EAEJ,SAAS,OAA8B;AAEnC,WAAO;AAAA,MACH;AAAA,MACA,GAAI,YAAY,EAAC,MAAM,SAAQ;AAAA,MAC/B,GAAI,WAAW,EAAC,MAAM,QAAO;AAAA,MAC7B,GAAI,aAAa,EAAC,QAAQ,UAAS;AAAA,MACnC,GAAI,cAAc,EAAC,WAAsB;AAAA,IAC7C;AAAA,EACJ;AACJ,GArD2B;","names":[]}
@@ -1,3 +0,0 @@
1
- declare function runAll(): void;
2
-
3
- export { runAll };
@@ -1,8 +0,0 @@
1
- import {
2
- runAll
3
- } from "../../chunk-YWFCWT6R.js";
4
- import "../../chunk-7QVYU63E.js";
5
- export {
6
- runAll
7
- };
8
- //# sourceMappingURL=run-all.js.map
@@ -1,3 +0,0 @@
1
- declare function runBucket(): void;
2
-
3
- export { runBucket };
@@ -1,8 +0,0 @@
1
- import {
2
- runBucket
3
- } from "../../chunk-LFRKRR7G.js";
4
- import "../../chunk-7QVYU63E.js";
5
- export {
6
- runBucket
7
- };
8
- //# sourceMappingURL=run-bucket.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,3 +0,0 @@
1
- declare function runNodeServer(): void;
2
-
3
- export { runNodeServer };
@@ -1,8 +0,0 @@
1
- import {
2
- runNodeServer
3
- } from "../../chunk-5A3RVJNT.js";
4
- import "../../chunk-7QVYU63E.js";
5
- export {
6
- runNodeServer
7
- };
8
- //# sourceMappingURL=run-node-server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,5 +0,0 @@
1
- import { Application } from 'express';
2
-
3
- declare const app: Application;
4
-
5
- export { app as default };
@@ -1,10 +0,0 @@
1
- import {
2
- app_default
3
- } from "../../chunk-NIOLLLJJ.js";
4
- import "../../chunk-W3W3X2OE.js";
5
- import "../../chunk-EWQYVPOL.js";
6
- import "../../chunk-7QVYU63E.js";
7
- export {
8
- app_default as default
9
- };
10
- //# sourceMappingURL=app.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,8 +0,0 @@
1
- import {
2
- runAll
3
- } from "../../chunk-YWFCWT6R.js";
4
- import "../../chunk-7QVYU63E.js";
5
-
6
- // src/utility/script/run-all.ts
7
- runAll();
8
- //# sourceMappingURL=run-all.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/utility/script/run-all.ts"],"sourcesContent":["import {runAll} from \"../../engine/script/run-all.js\";\r\n\r\n\r\nrunAll()\r\n"],"mappings":";;;;;;AAGA,OAAO;","names":[]}
@@ -1,8 +0,0 @@
1
- import {
2
- runBucket
3
- } from "../../chunk-LFRKRR7G.js";
4
- import "../../chunk-7QVYU63E.js";
5
-
6
- // src/utility/script/run-bucket.ts
7
- runBucket();
8
- //# sourceMappingURL=run-bucket.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/utility/script/run-bucket.ts"],"sourcesContent":["import {runBucket} from \"../../engine/script/run-bucket.js\";\r\n\r\nrunBucket()\r\n\r\n"],"mappings":";;;;;;AAEA,UAAU;","names":[]}
@@ -1,8 +0,0 @@
1
- import {
2
- runNodeServer
3
- } from "../../chunk-5A3RVJNT.js";
4
- import "../../chunk-7QVYU63E.js";
5
-
6
- // src/utility/script/run-node-server.ts
7
- runNodeServer();
8
- //# sourceMappingURL=run-node-server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/utility/script/run-node-server.ts"],"sourcesContent":["import {runNodeServer} from \"../../engine/script/run-node-server.js\";\r\n\r\nrunNodeServer()\r\n"],"mappings":";;;;;;AAEA,cAAc;","names":[]}
@@ -1,5 +0,0 @@
1
- import { S3Client } from '@aws-sdk/client-s3';
2
-
3
- declare const getS3Client: () => Promise<S3Client>;
4
-
5
- export { getS3Client };
@@ -1,17 +0,0 @@
1
- import {
2
- s3Client
3
- } from "../../../chunk-YTBSGKGF.js";
4
- import "../../../chunk-W3W3X2OE.js";
5
- import "../../../chunk-EWQYVPOL.js";
6
- import {
7
- __name
8
- } from "../../../chunk-7QVYU63E.js";
9
-
10
- // src/utility/utilis/cloud_storage/s3Client.ts
11
- var getS3Client = /* @__PURE__ */ __name(async () => {
12
- return s3Client;
13
- }, "getS3Client");
14
- export {
15
- getS3Client
16
- };
17
- //# sourceMappingURL=s3Client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/utility/utilis/cloud_storage/s3Client.ts"],"sourcesContent":["import {s3Client as sss} from \"../../../engine/cloudBucket/r2Storage.js\";\r\nimport type {S3Client} from \"@aws-sdk/client-s3\";\r\n\r\nexport const getS3Client = async (): Promise<S3Client> => {\r\n return sss;\r\n}\r\n"],"mappings":";;;;;;;;;;AAGO,IAAM,cAAc,mCAA+B;AACtD,SAAO;AACX,GAF2B;","names":[]}
File without changes
File without changes