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.
- package/dist/chunk-7QVYU63E.js +7 -0
- package/dist/chunk-7QVYU63E.js.map +1 -0
- package/dist/chunk-BMPUYKJJ.js +148 -0
- package/dist/chunk-BMPUYKJJ.js.map +1 -0
- package/dist/chunk-EB35KLDE.js +49 -0
- package/dist/chunk-EB35KLDE.js.map +1 -0
- package/dist/chunk-EWQYVPOL.js +30 -0
- package/dist/chunk-EWQYVPOL.js.map +1 -0
- package/dist/chunk-FMCW72HO.js +110 -0
- package/dist/chunk-FMCW72HO.js.map +1 -0
- package/dist/chunk-GBXVVI2R.js +528 -0
- package/dist/chunk-GBXVVI2R.js.map +1 -0
- package/dist/chunk-HZ4GLSOO.js +91 -0
- package/dist/chunk-HZ4GLSOO.js.map +1 -0
- package/dist/chunk-I6VD2JKM.js +72 -0
- package/dist/chunk-I6VD2JKM.js.map +1 -0
- package/dist/chunk-IN3YY526.js +165 -0
- package/dist/chunk-IN3YY526.js.map +1 -0
- package/dist/chunk-MEQAHLW6.js +135 -0
- package/dist/chunk-MEQAHLW6.js.map +1 -0
- package/dist/chunk-MNSQSU7T.js +90 -0
- package/dist/chunk-MNSQSU7T.js.map +1 -0
- package/dist/chunk-NDJVYPUT.js +61 -0
- package/dist/chunk-NDJVYPUT.js.map +1 -0
- package/dist/chunk-NMNAPTVV.js +91 -0
- package/dist/chunk-NMNAPTVV.js.map +1 -0
- package/dist/chunk-P5XJG7OG.js +71 -0
- package/dist/chunk-P5XJG7OG.js.map +1 -0
- package/dist/chunk-SSFPGDA3.js +73 -0
- package/dist/chunk-SSFPGDA3.js.map +1 -0
- package/dist/chunk-UWIMSKL5.js +35 -0
- package/dist/chunk-UWIMSKL5.js.map +1 -0
- package/dist/chunk-W2745SOE.js +38 -0
- package/dist/chunk-W2745SOE.js.map +1 -0
- package/dist/chunk-X3R3RLXY.js +62 -0
- package/dist/chunk-X3R3RLXY.js.map +1 -0
- package/dist/engine/cloudBucket/r2Storage.d.ts +5 -0
- package/dist/engine/cloudBucket/r2Storage.js +10 -0
- package/dist/engine/cloudBucket/r2Storage.js.map +1 -0
- package/dist/engine/mondoDb/mongoDB.d.ts +6 -0
- package/dist/engine/mondoDb/mongoDB.js +11 -0
- package/dist/engine/mondoDb/mongoDB.js.map +1 -0
- package/dist/engine/multer/multer_configs.d.ts +6 -0
- package/dist/engine/multer/multer_configs.js +11 -0
- package/dist/engine/multer/multer_configs.js.map +1 -0
- package/dist/engine/server/app.d.ts +5 -0
- package/dist/engine/server/app.js +8 -0
- package/dist/engine/server/app.js.map +1 -0
- package/dist/engine/server/server.d.ts +6 -0
- package/dist/engine/server/server.js +17 -0
- package/dist/engine/server/server.js.map +1 -0
- package/dist/engine/sql/mySql.d.ts +7 -0
- package/dist/engine/sql/mySql.js +13 -0
- package/dist/engine/sql/mySql.js.map +1 -0
- package/dist/engine/sql/pgSql.d.ts +7 -0
- package/dist/engine/sql/pgSql.js +13 -0
- package/dist/engine/sql/pgSql.js.map +1 -0
- package/dist/event-streams-PM4LQKAH.js +993 -0
- package/dist/event-streams-PM4LQKAH.js.map +1 -0
- package/dist/utility/libs/env.d.ts +24 -0
- package/dist/utility/libs/env.js +8 -0
- package/dist/utility/libs/env.js.map +1 -0
- package/dist/utility/libs/interface.d.ts +114 -0
- package/dist/utility/libs/interface.js +1 -0
- package/dist/utility/libs/interface.js.map +1 -0
- package/dist/utility/libs/types.d.ts +207 -0
- package/dist/utility/libs/types.js +6 -0
- package/dist/utility/libs/types.js.map +1 -0
- package/dist/utility/utilis/cloud_storage/deleteFile.d.ts +9 -0
- package/dist/utility/utilis/cloud_storage/deleteFile.js +60 -0
- package/dist/utility/utilis/cloud_storage/deleteFile.js.map +1 -0
- package/dist/utility/utilis/cloud_storage/deleteFiles.d.ts +9 -0
- package/dist/utility/utilis/cloud_storage/deleteFiles.js +89 -0
- package/dist/utility/utilis/cloud_storage/deleteFiles.js.map +1 -0
- package/dist/utility/utilis/cloud_storage/downloadFile.d.ts +9 -0
- package/dist/utility/utilis/cloud_storage/downloadFile.js +74 -0
- package/dist/utility/utilis/cloud_storage/downloadFile.js.map +1 -0
- package/dist/utility/utilis/cloud_storage/downloadFiles.d.ts +9 -0
- package/dist/utility/utilis/cloud_storage/downloadFiles.js +88 -0
- package/dist/utility/utilis/cloud_storage/downloadFiles.js.map +1 -0
- package/dist/utility/utilis/cloud_storage/s3Client.d.ts +5 -0
- package/dist/utility/utilis/cloud_storage/s3Client.js +17 -0
- package/dist/utility/utilis/cloud_storage/s3Client.js.map +1 -0
- package/dist/utility/utilis/cloud_storage/uploadFile.d.ts +51 -0
- package/dist/utility/utilis/cloud_storage/uploadFile.js +14 -0
- package/dist/utility/utilis/cloud_storage/uploadFile.js.map +1 -0
- package/dist/utility/utilis/cloud_storage/uploadFiles.d.ts +73 -0
- package/dist/utility/utilis/cloud_storage/uploadFiles.js +49 -0
- package/dist/utility/utilis/cloud_storage/uploadFiles.js.map +1 -0
- package/dist/utility/utilis/general/error_handler.d.ts +31 -0
- package/dist/utility/utilis/general/error_handler.js +8 -0
- package/dist/utility/utilis/general/error_handler.js.map +1 -0
- package/dist/utility/utilis/general/file-operations.d.ts +140 -0
- package/dist/utility/utilis/general/file-operations.js +19 -0
- package/dist/utility/utilis/general/file-operations.js.map +1 -0
- package/dist/utility/utilis/general/sqlDb.js.d.ts +151 -0
- package/dist/utility/utilis/general/sqlDb.js.js +13 -0
- package/dist/utility/utilis/general/sqlDb.js.js.map +1 -0
- package/dist/utility/utilis/general/uuids.d.ts +55 -0
- package/dist/utility/utilis/general/uuids.js +8 -0
- package/dist/utility/utilis/general/uuids.js.map +1 -0
- package/dist/utility/utilis/general/web.d.ts +247 -0
- package/dist/utility/utilis/general/web.js +13 -0
- package/dist/utility/utilis/general/web.js.map +1 -0
- package/dist/utility/utilis/mongoDb/buldWrite.d.ts +53 -0
- package/dist/utility/utilis/mongoDb/buldWrite.js +32 -0
- package/dist/utility/utilis/mongoDb/buldWrite.js.map +1 -0
- package/dist/utility/utilis/mongoDb/deleteDocument.d.ts +54 -0
- package/dist/utility/utilis/mongoDb/deleteDocument.js +34 -0
- package/dist/utility/utilis/mongoDb/deleteDocument.js.map +1 -0
- package/dist/utility/utilis/mongoDb/insertField.d.ts +40 -0
- package/dist/utility/utilis/mongoDb/insertField.js +33 -0
- package/dist/utility/utilis/mongoDb/insertField.js.map +1 -0
- package/dist/utility/utilis/mongoDb/insertFields.d.ts +48 -0
- package/dist/utility/utilis/mongoDb/insertFields.js +35 -0
- package/dist/utility/utilis/mongoDb/insertFields.js.map +1 -0
- package/dist/utility/utilis/mongoDb/updateFiled.d.ts +65 -0
- package/dist/utility/utilis/mongoDb/updateFiled.js +40 -0
- package/dist/utility/utilis/mongoDb/updateFiled.js.map +1 -0
- package/dist/utility/utilis/multer/upload_batch.d.ts +7 -0
- package/dist/utility/utilis/multer/upload_batch.js +17 -0
- package/dist/utility/utilis/multer/upload_batch.js.map +1 -0
- package/dist/utility/utilis/multer/upload_single.d.ts +7 -0
- package/dist/utility/utilis/multer/upload_single.js +16 -0
- package/dist/utility/utilis/multer/upload_single.js.map +1 -0
- package/dist/utility/utilis/postgres/executeQuery.d.ts +215 -0
- package/dist/utility/utilis/postgres/executeQuery.js +46 -0
- package/dist/utility/utilis/postgres/executeQuery.js.map +1 -0
- package/dist/utility/utilis/postgres/subSqlfiles/executeMySqlQuery.d.ts +9 -0
- package/dist/utility/utilis/postgres/subSqlfiles/executeMySqlQuery.js +10 -0
- package/dist/utility/utilis/postgres/subSqlfiles/executeMySqlQuery.js.map +1 -0
- package/dist/utility/utilis/postgres/subSqlfiles/executePgQuery.d.ts +11 -0
- package/dist/utility/utilis/postgres/subSqlfiles/executePgQuery.js +12 -0
- package/dist/utility/utilis/postgres/subSqlfiles/executePgQuery.js.map +1 -0
- package/dist/utility/utilis/server/app.d.ts +5 -0
- package/dist/utility/utilis/server/app.js +15 -0
- package/dist/utility/utilis/server/app.js.map +1 -0
- package/dist/utility/utilis/server/server.d.ts +5 -0
- package/dist/utility/utilis/server/server.js +24 -0
- package/dist/utility/utilis/server/server.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
app_default
|
|
3
|
+
} from "./chunk-W2745SOE.js";
|
|
4
|
+
import {
|
|
5
|
+
handleError
|
|
6
|
+
} from "./chunk-P5XJG7OG.js";
|
|
7
|
+
import {
|
|
8
|
+
isMySQL,
|
|
9
|
+
isPostgreSQL
|
|
10
|
+
} from "./chunk-MNSQSU7T.js";
|
|
11
|
+
import {
|
|
12
|
+
runMySqlScript
|
|
13
|
+
} from "./chunk-HZ4GLSOO.js";
|
|
14
|
+
import {
|
|
15
|
+
runPgSqlScript
|
|
16
|
+
} from "./chunk-NMNAPTVV.js";
|
|
17
|
+
import {
|
|
18
|
+
connectToMongo
|
|
19
|
+
} from "./chunk-EB35KLDE.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
|
+
import path from "path";
|
|
30
|
+
import { pathToFileURL } from "url";
|
|
31
|
+
var PORT = ENV.SERVER_PORT;
|
|
32
|
+
var SQL_URL = ENV.SQL_DB_URL;
|
|
33
|
+
var HTTP_SERVER = http.createServer(app_default);
|
|
34
|
+
var startServer = /* @__PURE__ */ __name(async () => {
|
|
35
|
+
try {
|
|
36
|
+
if (isPostgreSQL(SQL_URL)) {
|
|
37
|
+
await runPgSqlScript();
|
|
38
|
+
}
|
|
39
|
+
if (isMySQL(SQL_URL)) {
|
|
40
|
+
await runMySqlScript();
|
|
41
|
+
}
|
|
42
|
+
await connectToMongo();
|
|
43
|
+
try {
|
|
44
|
+
const functionPath = path.join(process.cwd(), "src/app/services/test.services.js");
|
|
45
|
+
const { testFunctions } = await import(pathToFileURL(functionPath).href);
|
|
46
|
+
testFunctions();
|
|
47
|
+
} catch {
|
|
48
|
+
}
|
|
49
|
+
HTTP_SERVER.listen(PORT, () => {
|
|
50
|
+
console.log(`Server running on port ${PORT}`);
|
|
51
|
+
});
|
|
52
|
+
} catch (err) {
|
|
53
|
+
handleError(err);
|
|
54
|
+
}
|
|
55
|
+
}, "startServer");
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
HTTP_SERVER,
|
|
59
|
+
startServer
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=chunk-NDJVYPUT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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\nimport path from \"node:path\"\r\nimport {pathToFileURL} from \"node:url\";\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 try {\r\n const functionPath = path.join(process.cwd(), \"src/app/services/test.services.js\");\r\n const {testFunctions} = await import(pathToFileURL(functionPath).href);\r\n testFunctions()\r\n }\r\n catch {}\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;AAEtB,OAAO,UAAU;AACjB,SAAQ,qBAAoB;AAM5B,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;AAErB,QAAI;AACA,YAAM,eAAe,KAAK,KAAK,QAAQ,IAAI,GAAG,mCAAmC;AACjF,YAAM,EAAC,cAAa,IAAI,MAAM,OAAO,cAAc,YAAY,EAAE;AACjE,oBAAc;AAAA,IAClB,QACM;AAAA,IAAC;AAEP,gBAAY,OAAO,MAAM,MAAM;AAC3B,cAAQ,IAAI,0BAA0B,IAAI,EAAE;AAAA,IAChD,CAAC;AAAA,EACL,SACM,KAAK;AACP,gBAAY,GAAG;AAAA,EACnB;AAEJ,GA3B2B;","names":[]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ENV
|
|
3
|
+
} from "./chunk-EWQYVPOL.js";
|
|
4
|
+
import {
|
|
5
|
+
__name
|
|
6
|
+
} from "./chunk-7QVYU63E.js";
|
|
7
|
+
|
|
8
|
+
// src/engine/sql/pgSql.ts
|
|
9
|
+
import pg from "pg";
|
|
10
|
+
import dotenv from "dotenv";
|
|
11
|
+
import fs from "fs/promises";
|
|
12
|
+
import path from "path";
|
|
13
|
+
import { pathToFileURL } from "url";
|
|
14
|
+
dotenv.config();
|
|
15
|
+
var { Pool } = pg;
|
|
16
|
+
var pool = null;
|
|
17
|
+
async function getPgSqlPool() {
|
|
18
|
+
if (!pool) {
|
|
19
|
+
let options;
|
|
20
|
+
try {
|
|
21
|
+
const mySqlConfigFile = path.join(process.cwd(), "src/config/pgSql.config.ts");
|
|
22
|
+
const { PGSQL_POOL_OPTIONS } = await import(pathToFileURL(mySqlConfigFile).href);
|
|
23
|
+
options = PGSQL_POOL_OPTIONS || {};
|
|
24
|
+
options.connectionString = ENV.SQL_DB_URL;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
options = {};
|
|
27
|
+
}
|
|
28
|
+
pool = new Pool(options);
|
|
29
|
+
pool.connect().then((client) => {
|
|
30
|
+
console.log("\u2705 PostgreSQL Database connected successfully");
|
|
31
|
+
client.release();
|
|
32
|
+
}).catch((err) => {
|
|
33
|
+
console.error("\u274C Failed to connect to PostgreSQL:", err.message);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
});
|
|
36
|
+
pool.on("connect", () => {
|
|
37
|
+
console.log("\u{1F50C} New PostgreSQL connection established");
|
|
38
|
+
});
|
|
39
|
+
pool.on("error", (err) => {
|
|
40
|
+
console.error("\u274C Unexpected PostgreSQL error:", err.message);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return pool;
|
|
44
|
+
}
|
|
45
|
+
__name(getPgSqlPool, "getPgSqlPool");
|
|
46
|
+
var runPgSqlScript = /* @__PURE__ */ __name(async () => {
|
|
47
|
+
try {
|
|
48
|
+
const fileQuery = await fs.readFile("db.sql", "utf8");
|
|
49
|
+
const queries = fileQuery.split(";").map((q) => q.trim()).filter((q) => q.length > 0);
|
|
50
|
+
const client = await (await getPgSqlPool()).connect();
|
|
51
|
+
try {
|
|
52
|
+
await client.query("BEGIN");
|
|
53
|
+
for (const query of queries) {
|
|
54
|
+
await client.query(query);
|
|
55
|
+
}
|
|
56
|
+
await client.query("COMMIT");
|
|
57
|
+
console.log("\u2705 Database schema created successfully");
|
|
58
|
+
} catch (err) {
|
|
59
|
+
await client.query("ROLLBACK");
|
|
60
|
+
throw err;
|
|
61
|
+
} finally {
|
|
62
|
+
client.release();
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.error("\u274C Failed to execute SQL script:", err);
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
}, "runPgSqlScript");
|
|
69
|
+
var closePgPool = /* @__PURE__ */ __name(async () => {
|
|
70
|
+
if (pool) {
|
|
71
|
+
console.log("\u{1F504} Closing PostgreSQL pool...");
|
|
72
|
+
await pool.end();
|
|
73
|
+
pool = null;
|
|
74
|
+
console.log("\u2705 PostgreSQL pool closed");
|
|
75
|
+
}
|
|
76
|
+
}, "closePgPool");
|
|
77
|
+
process.on("SIGINT", async () => {
|
|
78
|
+
await closePgPool();
|
|
79
|
+
process.exit(0);
|
|
80
|
+
});
|
|
81
|
+
process.on("SIGTERM", async () => {
|
|
82
|
+
await closePgPool();
|
|
83
|
+
process.exit(0);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export {
|
|
87
|
+
getPgSqlPool,
|
|
88
|
+
runPgSqlScript,
|
|
89
|
+
closePgPool
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=chunk-NMNAPTVV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/engine/sql/pgSql.ts"],"sourcesContent":["// pgSql.ts\r\nimport pg from 'pg';\r\nimport dotenv from 'dotenv';\r\nimport {ENV} from \"../../utility/libs/env.js\";\r\nimport fs from 'fs/promises';\r\nimport path from \"node:path\";\r\nimport {pathToFileURL} from \"node:url\";\r\n\r\ndotenv.config();\r\n\r\nconst { Pool } = pg;\r\n\r\nlet pool: pg.Pool | null = null;\r\n\r\nexport async function getPgSqlPool(): Promise<pg.Pool> {\r\n if (!pool) {\r\n\r\n let options: pg.PoolConfig;\r\n\r\n try {\r\n const mySqlConfigFile = path.join(process.cwd(), \"src/config/pgSql.config.ts\");\r\n const {PGSQL_POOL_OPTIONS} = await import(pathToFileURL(mySqlConfigFile).href);\r\n options = PGSQL_POOL_OPTIONS || {};\r\n options.connectionString = ENV.SQL_DB_URL\r\n }\r\n catch (error) {\r\n options = {};\r\n }\r\n\r\n pool = new Pool(options);\r\n\r\n // Test connection on startup\r\n pool.connect()\r\n .then(client => {\r\n console.log('✅ PostgreSQL Database connected successfully');\r\n client.release();\r\n })\r\n .catch(err => {\r\n console.error('❌ Failed to connect to PostgreSQL:', err.message);\r\n process.exit(1);\r\n });\r\n\r\n pool.on('connect', () => {\r\n console.log('🔌 New PostgreSQL connection established');\r\n });\r\n\r\n pool.on('error', (err: Error) => {\r\n console.error('❌ Unexpected PostgreSQL error:', err.message);\r\n });\r\n }\r\n\r\n return pool;\r\n}\r\n\r\nexport const runPgSqlScript = async () => {\r\n try {\r\n const fileQuery = await fs.readFile('db.sql', 'utf8');\r\n\r\n // Split queries for multiple statements\r\n const queries = fileQuery\r\n .split(';')\r\n .map(q => q.trim())\r\n .filter(q => q.length > 0);\r\n\r\n const client = await (await getPgSqlPool()).connect();\r\n\r\n try {\r\n // Run all queries in a transaction\r\n await client.query('BEGIN');\r\n\r\n for (const query of queries) {\r\n await client.query(query);\r\n }\r\n\r\n await client.query('COMMIT');\r\n console.log(\"✅ Database schema created successfully\");\r\n } catch (err) {\r\n await client.query('ROLLBACK');\r\n throw err;\r\n } finally {\r\n client.release();\r\n }\r\n } catch (err) {\r\n console.error('❌ Failed to execute SQL script:', err);\r\n throw err;\r\n }\r\n};\r\n\r\n// Graceful shutdown\r\nexport const closePgPool = async () => {\r\n if (pool) {\r\n console.log('🔄 Closing PostgreSQL pool...');\r\n await pool.end();\r\n pool = null;\r\n console.log('✅ PostgreSQL pool closed');\r\n }\r\n};\r\n\r\n// Handle process termination\r\nprocess.on('SIGINT', async () => {\r\n await closePgPool();\r\n process.exit(0);\r\n});\r\n\r\nprocess.on('SIGTERM', async () => {\r\n await closePgPool();\r\n process.exit(0);\r\n});\r\n"],"mappings":";;;;;;;;AACA,OAAO,QAAQ;AACf,OAAO,YAAY;AAEnB,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAQ,qBAAoB;AAE5B,OAAO,OAAO;AAEd,IAAM,EAAE,KAAK,IAAI;AAEjB,IAAI,OAAuB;AAE3B,eAAsB,eAAiC;AACnD,MAAI,CAAC,MAAM;AAEP,QAAI;AAEJ,QAAI;AACA,YAAM,kBAAkB,KAAK,KAAK,QAAQ,IAAI,GAAG,4BAA4B;AAC7E,YAAM,EAAC,mBAAkB,IAAI,MAAM,OAAO,cAAc,eAAe,EAAE;AACzE,gBAAU,sBAAsB,CAAC;AACjC,cAAQ,mBAAmB,IAAI;AAAA,IACnC,SACO,OAAO;AACV,gBAAU,CAAC;AAAA,IACf;AAEA,WAAO,IAAI,KAAK,OAAO;AAGvB,SAAK,QAAQ,EACR,KAAK,YAAU;AACZ,cAAQ,IAAI,mDAA8C;AAC1D,aAAO,QAAQ;AAAA,IACnB,CAAC,EACA,MAAM,SAAO;AACV,cAAQ,MAAM,2CAAsC,IAAI,OAAO;AAC/D,cAAQ,KAAK,CAAC;AAAA,IAClB,CAAC;AAEL,SAAK,GAAG,WAAW,MAAM;AACrB,cAAQ,IAAI,iDAA0C;AAAA,IAC1D,CAAC;AAED,SAAK,GAAG,SAAS,CAAC,QAAe;AAC7B,cAAQ,MAAM,uCAAkC,IAAI,OAAO;AAAA,IAC/D,CAAC;AAAA,EACL;AAEA,SAAO;AACX;AAtCsB;AAwCf,IAAM,iBAAiB,mCAAY;AACtC,MAAI;AACA,UAAM,YAAY,MAAM,GAAG,SAAS,UAAU,MAAM;AAGpD,UAAM,UAAU,UACX,MAAM,GAAG,EACT,IAAI,OAAK,EAAE,KAAK,CAAC,EACjB,OAAO,OAAK,EAAE,SAAS,CAAC;AAE7B,UAAM,SAAS,OAAO,MAAM,aAAa,GAAG,QAAQ;AAEpD,QAAI;AAEA,YAAM,OAAO,MAAM,OAAO;AAE1B,iBAAW,SAAS,SAAS;AACzB,cAAM,OAAO,MAAM,KAAK;AAAA,MAC5B;AAEA,YAAM,OAAO,MAAM,QAAQ;AAC3B,cAAQ,IAAI,6CAAwC;AAAA,IACxD,SAAS,KAAK;AACV,YAAM,OAAO,MAAM,UAAU;AAC7B,YAAM;AAAA,IACV,UAAE;AACE,aAAO,QAAQ;AAAA,IACnB;AAAA,EACJ,SAAS,KAAK;AACV,YAAQ,MAAM,wCAAmC,GAAG;AACpD,UAAM;AAAA,EACV;AACJ,GAhC8B;AAmCvB,IAAM,cAAc,mCAAY;AACnC,MAAI,MAAM;AACN,YAAQ,IAAI,sCAA+B;AAC3C,UAAM,KAAK,IAAI;AACf,WAAO;AACP,YAAQ,IAAI,+BAA0B;AAAA,EAC1C;AACJ,GAP2B;AAU3B,QAAQ,GAAG,UAAU,YAAY;AAC7B,QAAM,YAAY;AAClB,UAAQ,KAAK,CAAC;AAClB,CAAC;AAED,QAAQ,GAAG,WAAW,YAAY;AAC9B,QAAM,YAAY;AAClB,UAAQ,KAAK,CAAC;AAClB,CAAC;","names":[]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-7QVYU63E.js";
|
|
4
|
+
|
|
5
|
+
// src/utility/utilis/general/error_handler.ts
|
|
6
|
+
function normalizeError(err) {
|
|
7
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
8
|
+
if (err instanceof Error) {
|
|
9
|
+
return {
|
|
10
|
+
timestamp,
|
|
11
|
+
type: err.name || "Error",
|
|
12
|
+
message: err.message || "An unknown error occurred.",
|
|
13
|
+
...err.stack !== void 0 && { stack: err.stack },
|
|
14
|
+
rawError: err
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
if (typeof err === "string") {
|
|
18
|
+
return {
|
|
19
|
+
timestamp,
|
|
20
|
+
type: "StringError",
|
|
21
|
+
message: err,
|
|
22
|
+
rawError: err
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (typeof err === "object" && err !== null) {
|
|
26
|
+
return {
|
|
27
|
+
timestamp,
|
|
28
|
+
type: "ObjectError",
|
|
29
|
+
message: JSON.stringify(err),
|
|
30
|
+
rawError: err
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
timestamp,
|
|
35
|
+
type: "UnknownError",
|
|
36
|
+
message: String(err),
|
|
37
|
+
rawError: err
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
__name(normalizeError, "normalizeError");
|
|
41
|
+
function handleError(err, context) {
|
|
42
|
+
const normalized = normalizeError(err);
|
|
43
|
+
const contextLabel = context ? ` [${context.toUpperCase()}]` : "";
|
|
44
|
+
const titleStyle = "color: #ff4d4f; font-weight: bold; font-size: 12px;";
|
|
45
|
+
const labelStyle = "color: #999; font-weight: normal;";
|
|
46
|
+
console.groupCollapsed(
|
|
47
|
+
`%c\u{1F6A8} ERROR${contextLabel}: ${normalized.type} \u2014 ${normalized.message}`,
|
|
48
|
+
titleStyle
|
|
49
|
+
);
|
|
50
|
+
console.log(`%cTimestamp:%c ${normalized.timestamp}`, labelStyle, "color: inherit;");
|
|
51
|
+
if (context) {
|
|
52
|
+
console.log(`%cContext:%c ${context}`, labelStyle, "color: inherit;");
|
|
53
|
+
}
|
|
54
|
+
console.log(`%cMessage:%c ${normalized.message}`, labelStyle, "color: #ff7875;");
|
|
55
|
+
if (normalized.stack) {
|
|
56
|
+
console.group("Stack Trace");
|
|
57
|
+
console.log(normalized.stack);
|
|
58
|
+
console.groupEnd();
|
|
59
|
+
}
|
|
60
|
+
console.group("Raw Error Object");
|
|
61
|
+
console.dir(normalized.rawError);
|
|
62
|
+
console.groupEnd();
|
|
63
|
+
console.groupEnd();
|
|
64
|
+
return normalized;
|
|
65
|
+
}
|
|
66
|
+
__name(handleError, "handleError");
|
|
67
|
+
|
|
68
|
+
export {
|
|
69
|
+
handleError
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=chunk-P5XJG7OG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utility/utilis/general/error_handler.ts"],"sourcesContent":["import type {CustomErrorTemplate} from \"../../libs/interface.js\";\r\n\r\nfunction normalizeError(err: unknown): CustomErrorTemplate {\r\n const timestamp = new Date().toISOString();\r\n\r\n if (err instanceof Error) {\r\n return {\r\n timestamp,\r\n type: err.name || 'Error',\r\n message: err.message || 'An unknown error occurred.',\r\n ...(err.stack !== undefined && { stack: err.stack }),\r\n rawError: err,\r\n };\r\n }\r\n\r\n if (typeof err === 'string') {\r\n return {\r\n timestamp,\r\n type: 'StringError',\r\n message: err,\r\n rawError: err,\r\n };\r\n }\r\n\r\n if (typeof err === 'object' && err !== null) {\r\n return {\r\n timestamp,\r\n type: 'ObjectError',\r\n message: JSON.stringify(err),\r\n rawError: err,\r\n };\r\n }\r\n\r\n return {\r\n timestamp,\r\n type: 'UnknownError',\r\n message: String(err),\r\n rawError: err,\r\n };\r\n}\r\n\r\n/**\r\n * Normalizes and logs an error with optional contextual information.\r\n *\r\n * Formats the error for both terminal and browser environments, displaying\r\n * its type, message, timestamp, context, stack trace, and raw error object.\r\n * The normalized error is returned after being logged.\r\n *\r\n * @param err - The unknown error value to normalize and handle.\r\n * @param context - Optional context describing where the error occurred.\r\n * @returns The normalized error as a `CustomErrorTemplate`.\r\n *\r\n * @example\r\n * const error = handleError(error, 'File Upload');\r\n * // Logs the normalized error and returns a CustomErrorTemplate.\r\n *\r\n * @example\r\n * try {\r\n * await upload_file(file);\r\n * } catch (error) {\r\n * handleError(error, 'MinIO Upload');\r\n * }\r\n */\r\nexport function handleError(\r\n err: unknown,\r\n context?: string\r\n): CustomErrorTemplate {\r\n const normalized = normalizeError(err);\r\n const contextLabel = context ? ` [${context.toUpperCase()}]` : '';\r\n\r\n // Terminal/Browser styling rules\r\n const titleStyle = 'color: #ff4d4f; font-weight: bold; font-size: 12px;';\r\n const labelStyle = 'color: #999; font-weight: normal;';\r\n\r\n console.groupCollapsed(\r\n `%c🚨 ERROR${contextLabel}: ${normalized.type} — ${normalized.message}`,\r\n titleStyle\r\n );\r\n\r\n console.log(`%cTimestamp:%c ${normalized.timestamp}`, labelStyle, 'color: inherit;');\r\n\r\n if (context) {\r\n console.log(`%cContext:%c ${context}`, labelStyle, 'color: inherit;');\r\n }\r\n\r\n console.log(`%cMessage:%c ${normalized.message}`, labelStyle, 'color: #ff7875;');\r\n\r\n if (normalized.stack) {\r\n console.group('Stack Trace');\r\n console.log(normalized.stack);\r\n console.groupEnd();\r\n }\r\n\r\n console.group('Raw Error Object');\r\n console.dir(normalized.rawError);\r\n console.groupEnd();\r\n\r\n console.groupEnd();\r\n\r\n return normalized;\r\n}\r\n"],"mappings":";;;;;AAEA,SAAS,eAAe,KAAmC;AACvD,QAAM,aAAY,oBAAI,KAAK,GAAE,YAAY;AAEzC,MAAI,eAAe,OAAO;AACtB,WAAO;AAAA,MACH;AAAA,MACA,MAAM,IAAI,QAAQ;AAAA,MAClB,SAAS,IAAI,WAAW;AAAA,MACxB,GAAI,IAAI,UAAU,UAAa,EAAE,OAAO,IAAI,MAAM;AAAA,MAClD,UAAU;AAAA,IACd;AAAA,EACJ;AAEA,MAAI,OAAO,QAAQ,UAAU;AACzB,WAAO;AAAA,MACH;AAAA,MACA,MAAM;AAAA,MACN,SAAS;AAAA,MACT,UAAU;AAAA,IACd;AAAA,EACJ;AAEA,MAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM;AACzC,WAAO;AAAA,MACH;AAAA,MACA,MAAM;AAAA,MACN,SAAS,KAAK,UAAU,GAAG;AAAA,MAC3B,UAAU;AAAA,IACd;AAAA,EACJ;AAEA,SAAO;AAAA,IACH;AAAA,IACA,MAAM;AAAA,IACN,SAAS,OAAO,GAAG;AAAA,IACnB,UAAU;AAAA,EACd;AACJ;AArCS;AA6DF,SAAS,YACZ,KACA,SACmB;AACnB,QAAM,aAAa,eAAe,GAAG;AACrC,QAAM,eAAe,UAAU,KAAK,QAAQ,YAAY,CAAC,MAAM;AAG/D,QAAM,aAAa;AACnB,QAAM,aAAa;AAEnB,UAAQ;AAAA,IACJ,oBAAa,YAAY,KAAK,WAAW,IAAI,WAAM,WAAW,OAAO;AAAA,IACrE;AAAA,EACJ;AAEA,UAAQ,IAAI,kBAAkB,WAAW,SAAS,IAAI,YAAY,iBAAiB;AAEnF,MAAI,SAAS;AACT,YAAQ,IAAI,gBAAgB,OAAO,IAAI,YAAY,iBAAiB;AAAA,EACxE;AAEA,UAAQ,IAAI,gBAAgB,WAAW,OAAO,IAAI,YAAY,iBAAiB;AAE/E,MAAI,WAAW,OAAO;AAClB,YAAQ,MAAM,aAAa;AAC3B,YAAQ,IAAI,WAAW,KAAK;AAC5B,YAAQ,SAAS;AAAA,EACrB;AAEA,UAAQ,MAAM,kBAAkB;AAChC,UAAQ,IAAI,WAAW,QAAQ;AAC/B,UAAQ,SAAS;AAEjB,UAAQ,SAAS;AAEjB,SAAO;AACX;AArCgB;","names":[]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ENV
|
|
3
|
+
} from "./chunk-EWQYVPOL.js";
|
|
4
|
+
import {
|
|
5
|
+
__name
|
|
6
|
+
} from "./chunk-7QVYU63E.js";
|
|
7
|
+
|
|
8
|
+
// src/utility/utilis/general/web.ts
|
|
9
|
+
function buildURL({
|
|
10
|
+
end_point,
|
|
11
|
+
path = [],
|
|
12
|
+
fileName
|
|
13
|
+
}) {
|
|
14
|
+
const resolvedFileName = fileName instanceof File ? fileName.name : fileName ?? "";
|
|
15
|
+
const rawSegments = [
|
|
16
|
+
end_point ?? "",
|
|
17
|
+
...path,
|
|
18
|
+
resolvedFileName
|
|
19
|
+
].filter((segment) => Boolean(segment && segment.trim()));
|
|
20
|
+
if (rawSegments.length === 0) return "";
|
|
21
|
+
const match = rawSegments[0]?.match(/^(https?:\/\/)(.*)/i);
|
|
22
|
+
let protocol = "";
|
|
23
|
+
if (match) {
|
|
24
|
+
protocol = match[1] ?? "";
|
|
25
|
+
rawSegments[0] = match[2] ?? "";
|
|
26
|
+
}
|
|
27
|
+
const cleanedPath = rawSegments.map((segment) => segment.replace(/^\/+|\/+$/g, "")).map((segment) => segment.replace(/\/+/g, "/")).filter((segment) => segment.length > 0).join("/");
|
|
28
|
+
return `${protocol}${cleanedPath}`;
|
|
29
|
+
}
|
|
30
|
+
__name(buildURL, "buildURL");
|
|
31
|
+
var getKeyFromUrl = /* @__PURE__ */ __name((url) => {
|
|
32
|
+
const parsedUrl = new URL(url);
|
|
33
|
+
const pathParts = parsedUrl.pathname.split("/").filter(Boolean);
|
|
34
|
+
if (pathParts[0] === ENV.BUCKET_NAME) {
|
|
35
|
+
pathParts.shift();
|
|
36
|
+
}
|
|
37
|
+
return decodeURIComponent(pathParts.join("/"));
|
|
38
|
+
}, "getKeyFromUrl");
|
|
39
|
+
var response_to_client = /* @__PURE__ */ __name(({
|
|
40
|
+
response,
|
|
41
|
+
...payload
|
|
42
|
+
}) => {
|
|
43
|
+
const timestamp = payload.meta?.timestamp || (/* @__PURE__ */ new Date()).toISOString();
|
|
44
|
+
if (payload.success) {
|
|
45
|
+
return response.status(payload.status).json({
|
|
46
|
+
success: true,
|
|
47
|
+
status: payload.status,
|
|
48
|
+
message: payload.message ?? "Success",
|
|
49
|
+
data: payload.data,
|
|
50
|
+
meta: {
|
|
51
|
+
...payload.meta,
|
|
52
|
+
timestamp
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return response.status(payload.status).json({
|
|
57
|
+
success: false,
|
|
58
|
+
status: payload.status,
|
|
59
|
+
message: payload.message ?? "An error occurred",
|
|
60
|
+
error: payload.error,
|
|
61
|
+
meta: {
|
|
62
|
+
...payload.meta,
|
|
63
|
+
timestamp
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}, "response_to_client");
|
|
67
|
+
|
|
68
|
+
export {
|
|
69
|
+
buildURL,
|
|
70
|
+
getKeyFromUrl,
|
|
71
|
+
response_to_client
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=chunk-SSFPGDA3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ENV
|
|
3
|
+
} from "./chunk-EWQYVPOL.js";
|
|
4
|
+
import {
|
|
5
|
+
__name
|
|
6
|
+
} from "./chunk-7QVYU63E.js";
|
|
7
|
+
|
|
8
|
+
// src/engine/multer/multer_configs.ts
|
|
9
|
+
import "multer";
|
|
10
|
+
import multer from "multer";
|
|
11
|
+
var MAX_FILE_SIZE = ENV.MAX_FILE_SIZE_IN_MB ? parseInt(ENV.MAX_FILE_SIZE_IN_MB, 10) * 1024 * 1024 : 50 * 1024 * 1024;
|
|
12
|
+
var MAX_BATCH_FILES = ENV.MAX_BATCH_FILES ? parseInt(ENV.MAX_BATCH_FILES, 10) : 10;
|
|
13
|
+
var fileFilter = /* @__PURE__ */ __name((req, file, cb) => {
|
|
14
|
+
const forbiddenExtensions = /\.(exe|sh|bat|cmd|dll|dmg|so|jar|php|py|js)$/i;
|
|
15
|
+
if (file.originalname.match(forbiddenExtensions)) {
|
|
16
|
+
return cb(new Error(`File type not allowed: ${file.originalname}`));
|
|
17
|
+
}
|
|
18
|
+
cb(null, true);
|
|
19
|
+
}, "fileFilter");
|
|
20
|
+
var multerInstance = multer({
|
|
21
|
+
storage: multer.memoryStorage(),
|
|
22
|
+
limits: {
|
|
23
|
+
fileSize: MAX_FILE_SIZE,
|
|
24
|
+
files: MAX_BATCH_FILES,
|
|
25
|
+
fieldSize: parseInt(ENV.MAX_BATCH_FILES, 2) * 1024 * 1024
|
|
26
|
+
// 2MB max for standard form fields
|
|
27
|
+
},
|
|
28
|
+
fileFilter
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
MAX_BATCH_FILES,
|
|
33
|
+
multerInstance
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=chunk-UWIMSKL5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/engine/multer/multer_configs.ts"],"sourcesContent":["import {type FileFilterCallback } from 'multer';\r\nimport type {Request} from 'express';\r\nimport {ENV} from \"../../utility/libs/env.js\";\r\nimport multer from \"multer\";\r\n// 1. Production Limits (Fallback to defaults if env variables aren't set)\r\n\r\nconst MAX_FILE_SIZE = ENV.MAX_FILE_SIZE_IN_MB\r\n ? parseInt(ENV.MAX_FILE_SIZE_IN_MB, 10) * 1024 * 1024 // ✅ 10 MB = 10,485,760 Bytes\r\n : 50 * 1024 * 1024; // 50 MB\r\n\r\n\r\n\r\n\r\nexport const MAX_BATCH_FILES = ENV.MAX_BATCH_FILES\r\n ? parseInt(ENV.MAX_BATCH_FILES, 10)\r\n : 10; // Max 10 files per request\r\n\r\n\r\n\r\n// 2. Optional: Production File Type Filter (Prevent malicious executable uploads)\r\nconst fileFilter = (\r\n req: Request,\r\n file: Express.Multer.File,\r\n cb: FileFilterCallback\r\n) => {\r\n // Exclude executable and script extensions\r\n const forbiddenExtensions = /\\.(exe|sh|bat|cmd|dll|dmg|so|jar|php|py|js)$/i;\r\n\r\n if (file.originalname.match(forbiddenExtensions)) {\r\n return cb(new Error(`File type not allowed: ${file.originalname}`));\r\n }\r\n\r\n cb(null, true);\r\n};\r\n\r\n\r\n\r\n\r\n// 3. Main Multer Instance\r\nexport const multerInstance = multer({\r\n storage: multer.memoryStorage(),\r\n limits: {\r\n fileSize: MAX_FILE_SIZE,\r\n files: MAX_BATCH_FILES,\r\n fieldSize: parseInt(ENV.MAX_BATCH_FILES, 2) * 1024 * 1024, // 2MB max for standard form fields\r\n },\r\n fileFilter: fileFilter,\r\n});\r\n\r\n\r\n\r\n\r\n// 4. Pre-configured Helper Middlewares for Export\r\n\r\n\r\n\r\n\r\n\r\n\r\n"],"mappings":";;;;;;;;AAAA,OAAuC;AAGvC,OAAO,YAAY;AAGnB,IAAM,gBAAgB,IAAI,sBACpB,SAAS,IAAI,qBAAqB,EAAE,IAAI,OAAO,OAC/C,KAAK,OAAO;AAKX,IAAM,kBAAkB,IAAI,kBAC7B,SAAS,IAAI,iBAAiB,EAAE,IAChC;AAKN,IAAM,aAAa,wBACf,KACA,MACA,OACC;AAED,QAAM,sBAAsB;AAE5B,MAAI,KAAK,aAAa,MAAM,mBAAmB,GAAG;AAC9C,WAAO,GAAG,IAAI,MAAM,0BAA0B,KAAK,YAAY,EAAE,CAAC;AAAA,EACtE;AAEA,KAAG,MAAM,IAAI;AACjB,GAbmB;AAmBZ,IAAM,iBAAiB,OAAO;AAAA,EACjC,SAAS,OAAO,cAAc;AAAA,EAC9B,QAAQ;AAAA,IACJ,UAAU;AAAA,IACV,OAAO;AAAA,IACP,WAAW,SAAS,IAAI,iBAAiB,CAAC,IAAI,OAAO;AAAA;AAAA,EACzD;AAAA,EACA;AACJ,CAAC;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/engine/server/app.ts
|
|
2
|
+
import express from "express";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { pathToFileURL } from "url";
|
|
5
|
+
var apiPath = path.join(process.cwd(), "src/apis/apis.ts");
|
|
6
|
+
var configPath = path.join(process.cwd(), "src/config/express.config.ts");
|
|
7
|
+
var { APIS } = await import(pathToFileURL(apiPath).href);
|
|
8
|
+
var { express_configurations } = await import(pathToFileURL(configPath).href);
|
|
9
|
+
var app = express();
|
|
10
|
+
express_configurations(app);
|
|
11
|
+
var app_default = app;
|
|
12
|
+
APIS.forEach((api) => {
|
|
13
|
+
if ("get" in api) {
|
|
14
|
+
const middleware = api.get.middleware ? Array.isArray(api.get.middleware) ? api.get.middleware : [api.get.middleware] : [];
|
|
15
|
+
app.get(api.get.endpoint, ...middleware, api.get.callable);
|
|
16
|
+
}
|
|
17
|
+
if ("post" in api) {
|
|
18
|
+
const middleware = api.post.middleware ? Array.isArray(api.post.middleware) ? api.post.middleware : [api.post.middleware] : [];
|
|
19
|
+
app.post(api.post.endpoint, ...middleware, api.post.callable);
|
|
20
|
+
}
|
|
21
|
+
if ("put" in api) {
|
|
22
|
+
const middleware = api.put.middleware ? Array.isArray(api.put.middleware) ? api.put.middleware : [api.put.middleware] : [];
|
|
23
|
+
app.put(api.put.endpoint, ...middleware, api.put.callable);
|
|
24
|
+
}
|
|
25
|
+
if ("delete" in api) {
|
|
26
|
+
const middleware = api.delete.middleware ? Array.isArray(api.delete.middleware) ? api.delete.middleware : [api.delete.middleware] : [];
|
|
27
|
+
app.delete(api.delete.endpoint, ...middleware, api.delete.callable);
|
|
28
|
+
}
|
|
29
|
+
if ("patch" in api) {
|
|
30
|
+
const middleware = api.patch.middleware ? Array.isArray(api.patch.middleware) ? api.patch.middleware : [api.patch.middleware] : [];
|
|
31
|
+
app.patch(api.patch.endpoint, ...middleware, api.patch.callable);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
app_default
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=chunk-W2745SOE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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\n\r\nconst apiPath = path.join(process.cwd(), \"src/apis/apis.ts\");\r\nconst configPath = path.join(process.cwd(), \"src/config/express.config.ts\");\r\nconst { APIS } = await import(pathToFileURL(apiPath).href);\r\nconst {express_configurations} = await import(pathToFileURL(configPath).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;AAE9B,IAAM,UAAU,KAAK,KAAK,QAAQ,IAAI,GAAG,kBAAkB;AAC3D,IAAM,aAAa,KAAK,KAAK,QAAQ,IAAI,GAAG,8BAA8B;AAC1E,IAAM,EAAE,KAAK,IAAI,MAAM,OAAO,cAAc,OAAO,EAAE;AACrD,IAAM,EAAC,uBAAsB,IAAI,MAAM,OAAO,cAAc,UAAU,EAAE;AAGxE,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":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-7QVYU63E.js";
|
|
4
|
+
|
|
5
|
+
// src/utility/utilis/general/uuids.ts
|
|
6
|
+
import crypto from "crypto";
|
|
7
|
+
import { getRandomValues } from "crypto";
|
|
8
|
+
function generateUniqueValue(length, options) {
|
|
9
|
+
if (length <= 0) {
|
|
10
|
+
throw new Error("Length must be greater than 0");
|
|
11
|
+
}
|
|
12
|
+
const count = options?.count ?? 1;
|
|
13
|
+
if (count <= 0) {
|
|
14
|
+
throw new Error("Count must be greater than 0");
|
|
15
|
+
}
|
|
16
|
+
const generateSingleId = /* @__PURE__ */ __name(() => {
|
|
17
|
+
let id = "";
|
|
18
|
+
if (options?.useHex) {
|
|
19
|
+
id = crypto.randomBytes(Math.ceil(length / 2)).toString("hex").slice(0, length);
|
|
20
|
+
} else {
|
|
21
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
|
|
22
|
+
const alphabetLength = alphabet.length;
|
|
23
|
+
const mask = (2 << 31 - Math.clz32(alphabetLength - 1 | 1)) - 1;
|
|
24
|
+
const step = Math.ceil(1.6 * mask * length / alphabetLength);
|
|
25
|
+
const getBaseId = /* @__PURE__ */ __name(() => {
|
|
26
|
+
let baseId = "";
|
|
27
|
+
while (true) {
|
|
28
|
+
const bytes = new Uint8Array(step);
|
|
29
|
+
getRandomValues(bytes);
|
|
30
|
+
for (const byteValue of bytes) {
|
|
31
|
+
const byte = byteValue & mask;
|
|
32
|
+
if (byte < alphabetLength) {
|
|
33
|
+
baseId += alphabet[byte];
|
|
34
|
+
if (baseId.length === length) {
|
|
35
|
+
return baseId;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}, "getBaseId");
|
|
41
|
+
id = getBaseId();
|
|
42
|
+
}
|
|
43
|
+
if (options?.includeTimestamp) {
|
|
44
|
+
const timestamp = Date.now().toString(16);
|
|
45
|
+
id = `${timestamp}-${id}`;
|
|
46
|
+
}
|
|
47
|
+
if (options?.prefix) {
|
|
48
|
+
id = `${options.prefix}-${id}`;
|
|
49
|
+
}
|
|
50
|
+
return id;
|
|
51
|
+
}, "generateSingleId");
|
|
52
|
+
if (options?.count !== void 0) {
|
|
53
|
+
return Array.from({ length: count }, () => generateSingleId());
|
|
54
|
+
}
|
|
55
|
+
return generateSingleId();
|
|
56
|
+
}
|
|
57
|
+
__name(generateUniqueValue, "generateUniqueValue");
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
generateUniqueValue
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=chunk-X3R3RLXY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|