arkos 1.0.20-beta → 1.0.21-beta
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/cjs/server.js +1 -1
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/utils/helpers/fs.helpers.js +45 -12
- package/dist/cjs/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/prisma.helpers.js +6 -2
- package/dist/cjs/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/es2020/server.js +1 -1
- package/dist/es2020/server.js.map +1 -1
- package/dist/es2020/utils/helpers/fs.helpers.js +45 -12
- package/dist/es2020/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/prisma.helpers.js +6 -2
- package/dist/es2020/utils/helpers/prisma.helpers.js.map +1 -1
- package/package.json +1 -5
package/dist/cjs/server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,n,s){function
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,t,n,s){function l(r){return r instanceof n?r:new n(function(i){i(r)})}return new(n||(n=Promise))(function(r,i){function u(o){try{p(s.next(o))}catch(c){i(c)}}function a(o){try{p(s.throw(o))}catch(c){i(c)}}function p(o){o.done?r(o.value):l(o.value).then(u,a)}p((s=s.apply(e,t||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.server=void 0,exports.getArkosConfig=getArkosConfig,exports.getExpressApp=getExpressApp,exports.initApp=initApp;const app_1=require("./app"),deepmerge_helper_1=__importDefault(require("./utils/helpers/deepmerge.helper"));process.on("uncaughtException",e=>{console.error("UNCAUGHT EXCEPTION! SHUTTING DOWN..."),console.error(e.name,e.message),console.error(e),process.exit(1)});let server,_app,_arkosConfig={welcomeMessage:"Welcome to our RESTful API generated by Arkos, find out more about Arkos at www.arkosjs.com",port:8e3,fileUpload:{baseUploadDir:"uploads",baseRoute:"/api/uploads"}};function initApp(){return __awaiter(this,arguments,void 0,function*(e={}){_arkosConfig=(0,deepmerge_helper_1.default)(_arkosConfig,e);const t=_arkosConfig.port;return _app=yield(0,app_1.bootstrap)(_arkosConfig),t&&(exports.server=server=_app.listen(e?.host?[t,e?.host]:t,()=>{const n=new Date().toTimeString().split(" ")[0];console.info(`[\x1B[32mREADY\x1B[0m] \x1B[90m${n}\x1B[0m App running on port \x1B[33m${t}\x1B[0m, server waiting on http://localhost:${t}`),process.env.NODE_ENV&&console.info(`${`Environment: ${process.env.NODE_ENV}`}`)})),_app})}process.on("unhandledRejection",e=>{console.error("UNHANDLED REJECTION! SHUTTING DOWN..."),console.error(e.name,e.message),console.error(e),server?.close(()=>{process.exit(1)})});function getArkosConfig(){return _arkosConfig}function getExpressApp(){return _app}
|
package/dist/cjs/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAwEA,wCAEC;AAED,sCAEC;AAEgB,0BAAO;AA7ExB,+BAAkC;AAElC,wFAAyD;AAEzD,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;IACtC,OAAO,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACtD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,IAAI,MAA6D,CAAC;AAClE,IAAI,IAAa,CAAC;AAElB,IAAI,YAAY,GAAgB;IAC9B,cAAc,EACZ,6FAA6F;IAC/F,IAAI,EAAE,IAAI;IACV,UAAU,EAAE;QACV,aAAa,EAAE,SAAS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BACrD,OAAO,CAAC,IAAI,CACV,kCAAkC,IAAI,uCAAuC,IAAI,+CAA+C,IAAI,EAAE,CACvI,CAAC;gBAEF,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ;oBACxB,OAAO,CAAC,IAAI,CAAC,GAAG,gBAAgB,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YAC9D,CAAC,CACF,CAAC;QAEJ,OAAO,IAAI,CAAC;IACd,CAAC;CAAA;AAED,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,GAAa,EAAE,EAAE;IACjD,OAAO,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;IACvD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CAAC,GAAG,EAAE;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,SAAgB,cAAc;IAC5B,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAgB,aAAa;IAC3B,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { IncomingMessage, Server, ServerResponse } from \"http\";\nimport AppError from \"./modules/error-handler/utils/app-error\";\nimport { Express } from \"express\";\nimport { bootstrap } from \"./app\";\nimport { ArkosConfig } from \"./types/arkos-config\";\nimport deepmerge from \"./utils/helpers/deepmerge.helper\";\n\nprocess.on(\"uncaughtException\", (err) => {\n console.error(\"UNCAUGHT EXCEPTION! SHUTTING DOWN...\");\n console.error(err.name, err.message);\n console.error(err);\n process.exit(1);\n});\n\nlet server: Server<typeof IncomingMessage, typeof ServerResponse>;\nlet _app: Express;\n\nlet _arkosConfig: ArkosConfig = {\n welcomeMessage:\n \"Welcome to our RESTful API generated by Arkos, find out more about Arkos at www.arkosjs.com\",\n port: 8000,\n fileUpload: {\n baseUploadDir: \"uploads\",\n baseRoute: \"/api/uploads\",\n },\n};\n\n/**\n * Initializes the application server.\n *\n * This function starts the server by listening on a specified port.\n * The port is determined by the following order of precedence:\n * 1. The `port` argument passed to the function.\n * 2. Defaults to `8000` if neither is provided.\n *\n * @param {ArkosConfig} arkosConfig - initial configs for the api ( authentication, port).\n * @returns {Promise<Express>} This function returns the Express App after all middlewares configurations.\n * You can prevent it from listen py passing port as undefined\n *\n */\nasync function initApp(arkosConfig: ArkosConfig = {}): Promise<Express> {\n _arkosConfig = deepmerge(_arkosConfig, arkosConfig);\n\n const port = _arkosConfig.port;\n _app = await bootstrap(_arkosConfig);\n\n if (port)\n server = _app.listen(\n arkosConfig?.host ? [port, arkosConfig?.host!] : port,\n () => {\n const time = new Date().toTimeString().split(\" \")[0];\n console.info(\n `[\\x1b[32mREADY\\x1b[0m] \\x1b[90m${time}\\x1b[0m App running on port \\x1b[33m${port}\\x1b[0m, server waiting on http://localhost:${port}`\n );\n\n if (!!process.env.NODE_ENV)\n console.info(`${`Environment: ${process.env.NODE_ENV}`}`);\n }\n );\n\n return _app;\n}\n\nprocess.on(\"unhandledRejection\", (err: AppError) => {\n console.error(\"UNHANDLED REJECTION! SHUTTING DOWN...\");\n console.error(err.name, err.message);\n console.error(err);\n server?.close(() => {\n process.exit(1);\n });\n});\n\nexport function getArkosConfig() {\n return _arkosConfig;\n}\n\nexport function getExpressApp() {\n return _app;\n}\n\nexport { server, initApp };\n"]}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getUserFileExtension = exports.userFileExtension = exports.mkdirAsync = exports.accessAsync = exports.statAsync = void 0;
|
|
7
7
|
const util_1 = require("util");
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
9
10
|
exports.statAsync = (0, util_1.promisify)(fs_1.default.stat);
|
|
10
11
|
exports.accessAsync = (0, util_1.promisify)(fs_1.default.access);
|
|
11
12
|
exports.mkdirAsync = (0, util_1.promisify)(fs_1.default.mkdir);
|
|
@@ -13,24 +14,56 @@ const getUserFileExtension = () => {
|
|
|
13
14
|
if (exports.userFileExtension)
|
|
14
15
|
return exports.userFileExtension;
|
|
15
16
|
try {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
exports.userFileExtension = "ts";
|
|
17
|
+
const currentDir = process.cwd();
|
|
18
|
+
const dirName = path_1.default.basename(currentDir);
|
|
19
|
+
if ([".build", "build", "dist", "lib", "out"].includes(dirName)) {
|
|
20
|
+
exports.userFileExtension = "js";
|
|
21
21
|
return exports.userFileExtension;
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
const executionPath = process.argv[1] || "";
|
|
24
|
+
if (executionPath.includes("/.build/") ||
|
|
25
|
+
executionPath.includes("/build/") ||
|
|
26
|
+
executionPath.includes("/dist/")) {
|
|
27
|
+
exports.userFileExtension = "js";
|
|
28
|
+
return exports.userFileExtension;
|
|
29
|
+
}
|
|
30
|
+
let callerIsJS = false;
|
|
31
|
+
try {
|
|
32
|
+
const stack = new Error().stack;
|
|
33
|
+
if (stack) {
|
|
34
|
+
const callerLine = stack.split("\n")[2] || "";
|
|
35
|
+
callerIsJS = callerLine.includes(".js:");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
}
|
|
40
|
+
if (callerIsJS) {
|
|
41
|
+
exports.userFileExtension = "js";
|
|
42
|
+
return exports.userFileExtension;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const files = fs_1.default.readdirSync(currentDir);
|
|
46
|
+
const hasJSFiles = files.some((file) => file.endsWith(".js") && !file.endsWith(".config.js"));
|
|
47
|
+
const hasTSFiles = files.some((file) => file.endsWith(".ts") && !file.endsWith(".config.ts"));
|
|
48
|
+
if (hasJSFiles && !hasTSFiles) {
|
|
49
|
+
exports.userFileExtension = "js";
|
|
50
|
+
return exports.userFileExtension;
|
|
51
|
+
}
|
|
52
|
+
if (hasTSFiles) {
|
|
30
53
|
exports.userFileExtension = "ts";
|
|
31
54
|
return exports.userFileExtension;
|
|
32
55
|
}
|
|
33
56
|
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
if (fs_1.default.existsSync(path_1.default.join(currentDir, "tsconfig.json"))) {
|
|
61
|
+
exports.userFileExtension = "ts";
|
|
62
|
+
return exports.userFileExtension;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
}
|
|
34
67
|
exports.userFileExtension = "js";
|
|
35
68
|
return exports.userFileExtension;
|
|
36
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/fs.helpers.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAiC;AACjC,4CAAoB;
|
|
1
|
+
{"version":3,"file":"fs.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/fs.helpers.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAiC;AACjC,4CAAoB;AACpB,gDAAwB;AAEX,QAAA,SAAS,GAAG,IAAA,gBAAS,EAAC,YAAE,CAAC,IAAI,CAAC,CAAC;AAC/B,QAAA,WAAW,GAAG,IAAA,gBAAS,EAAC,YAAE,CAAC,MAAM,CAAC,CAAC;AACnC,QAAA,UAAU,GAAG,IAAA,gBAAS,EAAC,YAAE,CAAC,KAAK,CAAC,CAAC;AASvC,MAAM,oBAAoB,GAAG,GAAgB,EAAE;IACpD,IAAI,yBAAiB;QAAE,OAAO,yBAAiB,CAAC;IAEhD,IAAI,CAAC;QAEH,MAAM,UAAU,GAAG,OAAO,CA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Q,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAC/D,CAAC;YACF,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAC3B,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAC/D,CAAC;YAGF,IAAI,UAAU,IAAI,CAAC,UAAU,EAAE,CAAC;gBAC9B,yBAAiB,GAAG,IAAI,CAAC;gBACzB,OAAO,yBAAiB,CAAC;YAC3B,CAAC;YAGD,IAAI,UAAU,EAAE,CAAC;gBACf,yBAAiB,GAAG,IAAI,CAAC;gBACzB,OAAO,yBAAiB,CAAC;YAC3B,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;QAEb,CAAC;QAGD,IAAI,CAAC;YACH,IAAI,YAAE,CAAC,UAAU,CAAC,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC;gBAC1D,yBAAiB,GAAG,IAAI,CAAC;gBACzB,OAAO,yBAAiB,CAAC;YAC3B,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;QAEb,CAAC;QAGD,yBAAiB,GAAG,IAAI,CAAC;QACzB,OAAO,yBAAiB,CAAC;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QAEX,yBAAiB,GAAG,IAAI,CAAC;QACzB,OAAO,yBAAiB,CAAC;IAC3B,CAAC;AACH,CAAC,CAAC;AAtFW,QAAA,oBAAoB,wBAsF/B","sourcesContent":["import { promisify } from \"util\";\nimport fs from \"fs\";\nimport path from \"path\";\n\nexport const statAsync = promisify(fs.stat);\nexport const accessAsync = promisify(fs.access);\nexport const mkdirAsync = promisify(fs.mkdir);\n\nexport let userFileExtension: \"ts\" | \"js\" | undefined;\n\n/**\n * Detects the file extension that should be used in the current execution context\n * Returns 'js' when running from compiled code and 'ts' in development\n * @returns 'ts' | 'js'\n */\nexport const getUserFileExtension = (): \"ts\" | \"js\" => {\n if (userFileExtension) return userFileExtension;\n\n try {\n // Check if we're currently in a build/compiled directory\n const currentDir = process.cwd();\n const dirName = path.basename(currentDir);\n\n // If we're in a build directory, we should use .js because we're in compiled code\n if ([\".build\", \"build\", \"dist\", \"lib\", \"out\"].includes(dirName)) {\n userFileExtension = \"js\";\n return userFileExtension;\n }\n\n // Check if current execution path contains indicators of compiled code\n const executionPath = process.argv[1] || \"\";\n if (\n executionPath.includes(\"/.build/\") ||\n executionPath.includes(\"/build/\") ||\n executionPath.includes(\"/dist/\")\n ) {\n userFileExtension = \"js\";\n return userFileExtension;\n }\n\n // Check the caller file - if it ends with .js, we're likely in compiled code\n let callerIsJS = false;\n try {\n // This is a hacky way to get the caller file, but can help in many cases\n const stack = new Error().stack;\n if (stack) {\n const callerLine = stack.split(\"\\n\")[2] || \"\";\n callerIsJS = callerLine.includes(\".js:\");\n }\n } catch (e) {\n // Ignore error if we can't get stack trace\n }\n\n if (callerIsJS) {\n userFileExtension = \"js\";\n return userFileExtension;\n }\n\n // Check which file extensions are available in the current directory\n try {\n const files = fs.readdirSync(currentDir);\n const hasJSFiles = files.some(\n (file) => file.endsWith(\".js\") && !file.endsWith(\".config.js\")\n );\n const hasTSFiles = files.some(\n (file) => file.endsWith(\".ts\") && !file.endsWith(\".config.ts\")\n );\n\n // If we only have JS files and no TS files, use JS\n if (hasJSFiles && !hasTSFiles) {\n userFileExtension = \"js\";\n return userFileExtension;\n }\n\n // If we have TS files, prefer TS\n if (hasTSFiles) {\n userFileExtension = \"ts\";\n return userFileExtension;\n }\n } catch (e) {\n // Continue if directory read fails\n }\n\n // As a last resort, check for tsconfig.json\n try {\n if (fs.existsSync(path.join(currentDir, \"tsconfig.json\"))) {\n userFileExtension = \"ts\";\n return userFileExtension;\n }\n } catch (e) {\n // Continue if check fails\n }\n\n // Default to js for safety\n userFileExtension = \"js\";\n return userFileExtension;\n } catch (e) {\n // Always default to js if anything goes wrong\n userFileExtension = \"js\";\n return userFileExtension;\n }\n};\n"]}
|
|
@@ -25,9 +25,13 @@ function loadPrismaModule(a) {
|
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
26
|
if (!exports.prismaInstance) {
|
|
27
27
|
try {
|
|
28
|
-
let prismaPath = `${process.
|
|
28
|
+
let prismaPath = `${process.env.NODE_ENV === "production"
|
|
29
|
+
? process.cwd() + "/.build/"
|
|
30
|
+
: process.cwd()}/src/utils/prisma.${(0, fs_helpers_1.getUserFileExtension)()}`;
|
|
29
31
|
if (!fs_1.default.existsSync(prismaPath)) {
|
|
30
|
-
prismaPath = `${process.
|
|
32
|
+
prismaPath = `${process.env.NODE_ENV === "production"
|
|
33
|
+
? process.cwd() + "/.build/"
|
|
34
|
+
: process.cwd()}/src/utils/prisma/index.${(0, fs_helpers_1.getUserFileExtension)()}`;
|
|
31
35
|
}
|
|
32
36
|
const prismaModule = yield (0, global_helpers_1.importModule)(prismaPath);
|
|
33
37
|
exports.prismaInstance = prismaModule.default || prismaModule.prisma;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/prisma.helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AASA,
|
|
1
|
+
{"version":3,"file":"prisma.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/prisma.helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AASA,4CA4BC;AAED,8CAEC;AAzCD,4CAAoB;AAEpB,gGAAuE;AACvE,4FAAmE;AACnE,6CAAoD;AACpD,qDAAgD;AAErC,QAAA,cAAc,GAAQ,IAAI,CAAC;AAEtC,SAAsB,gBAAgB,CAAC,CAAU;;QAC/C,IAAI,CAAC,sBAAc,EAAE,CAAC;YACpB,IAAI,CAAC;gBACH,IAAI,UAAU,GAAG,GACf,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,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AO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,mBAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC;AACH,CAAC,CAAA,CACF,CAAC","sourcesContent":["import fs from \"fs\";\nimport { Request, Response, NextFunction } from \"express\";\nimport catchAsync from \"../../modules/error-handler/utils/catch-async\";\nimport AppError from \"../../modules/error-handler/utils/app-error\";\nimport { getUserFileExtension } from \"./fs.helpers\";\nimport { importModule } from \"./global.helpers\";\n\nexport let prismaInstance: any = null;\n\nexport async function loadPrismaModule(a?: string) {\n if (!prismaInstance) {\n try {\n let prismaPath = `${\n process.env.NODE_ENV === \"production\"\n ? process.cwd() + \"/.build/\"\n : process.cwd()\n }/src/utils/prisma.${getUserFileExtension()}`;\n\n if (!fs.existsSync(prismaPath)) {\n prismaPath = `${\n process.env.NODE_ENV === \"production\"\n ? process.cwd() + \"/.build/\"\n : process.cwd()\n }/src/utils/prisma/index.${getUserFileExtension()}`;\n }\n\n const prismaModule = await importModule(prismaPath);\n prismaInstance = prismaModule.default || prismaModule.prisma;\n\n if (!prismaInstance) throw new Error(\"not found\");\n } catch (error) {\n throw new AppError(\"Could not initialize Prisma module.\", 500, {\n tip: `Make sure your prisma instance is exported under src/utils/prisma.${getUserFileExtension()}, read more about Arkos' Project Structure under https://www.arkosjs.com/docs/project-structure#root-structure`,\n });\n }\n }\n return prismaInstance;\n}\n\nexport function getPrismaInstance() {\n return prismaInstance;\n}\n\nexport const checkDatabaseConnection = catchAsync(\n async (req: Request, res: Response, next: NextFunction) => {\n const prisma = await loadPrismaModule();\n try {\n await prisma.$connect();\n next();\n } catch (error: any) {\n console.error(\"Database connection error\", error.message);\n next(new AppError(error.message, 503));\n }\n }\n);\n"]}
|
package/dist/es2020/server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var x=function(o,e,n,
|
|
1
|
+
"use strict";var x=function(o,e,n,c){function m(r){return r instanceof n?r:new n(function(p){p(r)})}return new(n||(n=Promise))(function(r,p){function d(t){try{u(c.next(t))}catch(a){p(a)}}function f(t){try{u(c.throw(t))}catch(a){p(a)}}function u(t){t.done?r(t.value):m(t.value).then(d,f)}u((c=c.apply(o,e||[])).next())})};import{bootstrap as E}from"./app";import h from"./utils/helpers/deepmerge.helper";process.on("uncaughtException",o=>{console.error("UNCAUGHT EXCEPTION! SHUTTING DOWN..."),console.error(o.name,o.message),console.error(o),process.exit(1)});let i,l,s={welcomeMessage:"Welcome to our RESTful API generated by Arkos, find out more about Arkos at www.arkosjs.com",port:8e3,fileUpload:{baseUploadDir:"uploads",baseRoute:"/api/uploads"}};function v(){return x(this,arguments,void 0,function*(o={}){s=h(s,o);const e=s.port;return l=yield E(s),e&&(i=l.listen(o?.host?[e,o?.host]:e,()=>{const n=new Date().toTimeString().split(" ")[0];console.info(`[\x1B[32mREADY\x1B[0m] \x1B[90m${n}\x1B[0m App running on port \x1B[33m${e}\x1B[0m, server waiting on http://localhost:${e}`),process.env.NODE_ENV&&console.info(`${`Environment: ${process.env.NODE_ENV}`}`)})),l})}process.on("unhandledRejection",o=>{console.error("UNHANDLED REJECTION! SHUTTING DOWN..."),console.error(o.name,o.message),console.error(o),i?.close(()=>{process.exit(1)})});export function getArkosConfig(){return s}export function getExpressApp(){return l}export{i as server,v as initApp};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":";;;;;;;;;AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,SAAS,MAAM,kCAAkC,CAAC;AAEzD,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;IACtC,OAAO,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACtD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,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ules/error-handler/utils/app-error\";\nimport { Express } from \"express\";\nimport { bootstrap } from \"./app\";\nimport { ArkosConfig } from \"./types/arkos-config\";\nimport deepmerge from \"./utils/helpers/deepmerge.helper\";\n\nprocess.on(\"uncaughtException\", (err) => {\n console.error(\"UNCAUGHT EXCEPTION! SHUTTING DOWN...\");\n console.error(err.name, err.message);\n console.error(err);\n process.exit(1);\n});\n\nlet server: Server<typeof IncomingMessage, typeof ServerResponse>;\nlet _app: Express;\n\nlet _arkosConfig: ArkosConfig = {\n welcomeMessage:\n \"Welcome to our RESTful API generated by Arkos, find out more about Arkos at www.arkosjs.com\",\n port: 8000,\n fileUpload: {\n baseUploadDir: \"uploads\",\n baseRoute: \"/api/uploads\",\n },\n};\n\n/**\n * Initializes the application server.\n *\n * This function starts the server by listening on a specified port.\n * The port is determined by the following order of precedence:\n * 1. The `port` argument passed to the function.\n * 2. Defaults to `8000` if neither is provided.\n *\n * @param {ArkosConfig} arkosConfig - initial configs for the api ( authentication, port).\n * @returns {Promise<Express>} This function returns the Express App after all middlewares configurations.\n * You can prevent it from listen py passing port as undefined\n *\n */\nasync function initApp(arkosConfig: ArkosConfig = {}): Promise<Express> {\n _arkosConfig = deepmerge(_arkosConfig, arkosConfig);\n\n const port = _arkosConfig.port;\n _app = await bootstrap(_arkosConfig);\n\n if (port)\n server = _app.listen(\n arkosConfig?.host ? [port, arkosConfig?.host!] : port,\n () => {\n const time = new Date().toTimeString().split(\" \")[0];\n console.info(\n `[\\x1b[32mREADY\\x1b[0m] \\x1b[90m${time}\\x1b[0m App running on port \\x1b[33m${port}\\x1b[0m, server waiting on http://localhost:${port}`\n );\n\n if (!!process.env.NODE_ENV)\n console.info(`${`Environment: ${process.env.NODE_ENV}`}`);\n }\n );\n\n return _app;\n}\n\nprocess.on(\"unhandledRejection\", (err: AppError) => {\n console.error(\"UNHANDLED REJECTION! SHUTTING DOWN...\");\n console.error(err.name, err.message);\n console.error(err);\n server?.close(() => {\n process.exit(1);\n });\n});\n\nexport function getArkosConfig() {\n return _arkosConfig;\n}\n\nexport function getExpressApp() {\n return _app;\n}\n\nexport { server, initApp };\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { promisify } from "util";
|
|
2
2
|
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
3
4
|
export const statAsync = promisify(fs.stat);
|
|
4
5
|
export const accessAsync = promisify(fs.access);
|
|
5
6
|
export const mkdirAsync = promisify(fs.mkdir);
|
|
@@ -8,24 +9,56 @@ export const getUserFileExtension = () => {
|
|
|
8
9
|
if (userFileExtension)
|
|
9
10
|
return userFileExtension;
|
|
10
11
|
try {
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
userFileExtension = "ts";
|
|
12
|
+
const currentDir = process.cwd();
|
|
13
|
+
const dirName = path.basename(currentDir);
|
|
14
|
+
if ([".build", "build", "dist", "lib", "out"].includes(dirName)) {
|
|
15
|
+
userFileExtension = "js";
|
|
16
16
|
return userFileExtension;
|
|
17
17
|
}
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
const executionPath = process.argv[1] || "";
|
|
19
|
+
if (executionPath.includes("/.build/") ||
|
|
20
|
+
executionPath.includes("/build/") ||
|
|
21
|
+
executionPath.includes("/dist/")) {
|
|
22
|
+
userFileExtension = "js";
|
|
23
|
+
return userFileExtension;
|
|
24
|
+
}
|
|
25
|
+
let callerIsJS = false;
|
|
26
|
+
try {
|
|
27
|
+
const stack = new Error().stack;
|
|
28
|
+
if (stack) {
|
|
29
|
+
const callerLine = stack.split("\n")[2] || "";
|
|
30
|
+
callerIsJS = callerLine.includes(".js:");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
}
|
|
35
|
+
if (callerIsJS) {
|
|
36
|
+
userFileExtension = "js";
|
|
37
|
+
return userFileExtension;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const files = fs.readdirSync(currentDir);
|
|
41
|
+
const hasJSFiles = files.some((file) => file.endsWith(".js") && !file.endsWith(".config.js"));
|
|
42
|
+
const hasTSFiles = files.some((file) => file.endsWith(".ts") && !file.endsWith(".config.ts"));
|
|
43
|
+
if (hasJSFiles && !hasTSFiles) {
|
|
44
|
+
userFileExtension = "js";
|
|
45
|
+
return userFileExtension;
|
|
46
|
+
}
|
|
47
|
+
if (hasTSFiles) {
|
|
25
48
|
userFileExtension = "ts";
|
|
26
49
|
return userFileExtension;
|
|
27
50
|
}
|
|
28
51
|
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
if (fs.existsSync(path.join(currentDir, "tsconfig.json"))) {
|
|
56
|
+
userFileExtension = "ts";
|
|
57
|
+
return userFileExtension;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
}
|
|
29
62
|
userFileExtension = "js";
|
|
30
63
|
return userFileExtension;
|
|
31
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/fs.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"fs.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/fs.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAC5C,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;AA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AACH,CAAC,CAAC","sourcesContent":["import { promisify } from \"util\";\nimport fs from \"fs\";\nimport path from \"path\";\n\nexport const statAsync = promisify(fs.stat);\nexport const accessAsync = promisify(fs.access);\nexport const mkdirAsync = promisify(fs.mkdir);\n\nexport let userFileExtension: \"ts\" | \"js\" | undefined;\n\n/**\n * Detects the file extension that should be used in the current execution context\n * Returns 'js' when running from compiled code and 'ts' in development\n * @returns 'ts' | 'js'\n */\nexport const getUserFileExtension = (): \"ts\" | \"js\" => {\n if (userFileExtension) return userFileExtension;\n\n try {\n // Check if we're currently in a build/compiled directory\n const currentDir = process.cwd();\n const dirName = path.basename(currentDir);\n\n // If we're in a build directory, we should use .js because we're in compiled code\n if ([\".build\", \"build\", \"dist\", \"lib\", \"out\"].includes(dirName)) {\n userFileExtension = \"js\";\n return userFileExtension;\n }\n\n // Check if current execution path contains indicators of compiled code\n const executionPath = process.argv[1] || \"\";\n if (\n executionPath.includes(\"/.build/\") ||\n executionPath.includes(\"/build/\") ||\n executionPath.includes(\"/dist/\")\n ) {\n userFileExtension = \"js\";\n return userFileExtension;\n }\n\n // Check the caller file - if it ends with .js, we're likely in compiled code\n let callerIsJS = false;\n try {\n // This is a hacky way to get the caller file, but can help in many cases\n const stack = new Error().stack;\n if (stack) {\n const callerLine = stack.split(\"\\n\")[2] || \"\";\n callerIsJS = callerLine.includes(\".js:\");\n }\n } catch (e) {\n // Ignore error if we can't get stack trace\n }\n\n if (callerIsJS) {\n userFileExtension = \"js\";\n return userFileExtension;\n }\n\n // Check which file extensions are available in the current directory\n try {\n const files = fs.readdirSync(currentDir);\n const hasJSFiles = files.some(\n (file) => file.endsWith(\".js\") && !file.endsWith(\".config.js\")\n );\n const hasTSFiles = files.some(\n (file) => file.endsWith(\".ts\") && !file.endsWith(\".config.ts\")\n );\n\n // If we only have JS files and no TS files, use JS\n if (hasJSFiles && !hasTSFiles) {\n userFileExtension = \"js\";\n return userFileExtension;\n }\n\n // If we have TS files, prefer TS\n if (hasTSFiles) {\n userFileExtension = \"ts\";\n return userFileExtension;\n }\n } catch (e) {\n // Continue if directory read fails\n }\n\n // As a last resort, check for tsconfig.json\n try {\n if (fs.existsSync(path.join(currentDir, \"tsconfig.json\"))) {\n userFileExtension = \"ts\";\n return userFileExtension;\n }\n } catch (e) {\n // Continue if check fails\n }\n\n // Default to js for safety\n userFileExtension = \"js\";\n return userFileExtension;\n } catch (e) {\n // Always default to js if anything goes wrong\n userFileExtension = \"js\";\n return userFileExtension;\n }\n};\n"]}
|
|
@@ -17,9 +17,13 @@ export function loadPrismaModule(a) {
|
|
|
17
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
18
|
if (!prismaInstance) {
|
|
19
19
|
try {
|
|
20
|
-
let prismaPath = `${process.
|
|
20
|
+
let prismaPath = `${process.env.NODE_ENV === "production"
|
|
21
|
+
? process.cwd() + "/.build/"
|
|
22
|
+
: process.cwd()}/src/utils/prisma.${getUserFileExtension()}`;
|
|
21
23
|
if (!fs.existsSync(prismaPath)) {
|
|
22
|
-
prismaPath = `${process.
|
|
24
|
+
prismaPath = `${process.env.NODE_ENV === "production"
|
|
25
|
+
? process.cwd() + "/.build/"
|
|
26
|
+
: process.cwd()}/src/utils/prisma/index.${getUserFileExtension()}`;
|
|
23
27
|
}
|
|
24
28
|
const prismaModule = yield importModule(prismaPath);
|
|
25
29
|
prismaInstance = prismaModule.default || prismaModule.prisma;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/prisma.helpers.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,UAAU,MAAM,+CAA+C,CAAC;AACvE,OAAO,QAAQ,MAAM,6CAA6C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,MAAM,CAAC,IAAI,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C;gBACpD,cAAc,GAAG,YAAY,CAAC,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC;gBAE7D,IAAI,CAAC,cAAc;oBAAE,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC;YACpD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,QAAQ,CAAC,qCAAqC,EAAE,GAAG,EAAE;oBAC7D,GAAG,EAAE,qEAAqE,oBAAoB,EAAE,gHAAgH;iBACjN,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,OAAO,cAAc,CAAC;IACxB,CAAC;CAAA;AAED,MAAM,UAAU,iBAAiB;IAC/B,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAC/C,CAAO,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACxD,MAAM,MAAM,GAAG,MAAM,gBAAgB,EAAE,CAAC;IACxC,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC;QACxB,IAAI,EAAE,CAAC;IACT,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC;AACH,CAAC,CAAA,CACF,CAAC","sourcesContent":["import fs from \"fs\";\nimport { Request, Response, NextFunction } from \"express\";\nimport catchAsync from \"../../modules/error-handler/utils/catch-async\";\nimport AppError from \"../../modules/error-handler/utils/app-error\";\nimport { getUserFileExtension } from \"./fs.helpers\";\nimport { importModule } from \"./global.helpers\";\n\nexport let prismaInstance: any = null;\n\nexport async function loadPrismaModule(a?: string) {\n if (!prismaInstance) {\n try {\n let prismaPath = `${\n process.env.NODE_ENV === \"production\"\n ? process.cwd() + \"/.build/\"\n : process.cwd()\n }/src/utils/prisma.${getUserFileExtension()}`;\n\n if (!fs.existsSync(prismaPath)) {\n prismaPath = `${\n process.env.NODE_ENV === \"production\"\n ? process.cwd() + \"/.build/\"\n : process.cwd()\n }/src/utils/prisma/index.${getUserFileExtension()}`;\n }\n\n const prismaModule = await importModule(prismaPath);\n prismaInstance = prismaModule.default || prismaModule.prisma;\n\n if (!prismaInstance) throw new Error(\"not found\");\n } catch (error) {\n throw new AppError(\"Could not initialize Prisma module.\", 500, {\n tip: `Make sure your prisma instance is exported under src/utils/prisma.${getUserFileExtension()}, read more about Arkos' Project Structure under https://www.arkosjs.com/docs/project-structure#root-structure`,\n });\n }\n }\n return prismaInstance;\n}\n\nexport function getPrismaInstance() {\n return prismaInstance;\n}\n\nexport const checkDatabaseConnection = catchAsync(\n async (req: Request, res: Response, next: NextFunction) => {\n const prisma = await loadPrismaModule();\n try {\n await prisma.$connect();\n next();\n } catch (error: any) {\n console.error(\"Database connection error\", error.message);\n next(new AppError(error.message, 503));\n }\n }\n);\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arkos",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21-beta",
|
|
4
4
|
"description": "The Express & Prisma Framework For RESTful API",
|
|
5
5
|
"main": "dist/cjs/exports/index.js",
|
|
6
6
|
"module": "dist/es2020/exports/index.js",
|
|
@@ -71,10 +71,6 @@
|
|
|
71
71
|
]
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
|
-
"bin": {
|
|
75
|
-
"arkos": "./dist/src/utils/scripts/index.js",
|
|
76
|
-
"arkos-dev": "./src/utils/scripts/index.ts"
|
|
77
|
-
},
|
|
78
74
|
"scripts": {
|
|
79
75
|
"build:es2020": "tsc -p tsconfig.es2020.json",
|
|
80
76
|
"build:types": "tsc -p tsconfig.types.json",
|