arkos 1.1.26-test → 1.1.27-test

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.
@@ -33,6 +33,8 @@ function addRouteMiddlwaresAndConfigs() { }
33
33
  function addPrismaQueryOptionsToRequest(prismaQueryOptions, action) {
34
34
  return (req, res, next) => {
35
35
  const configs = (0, server_1.getArkosConfig)();
36
+ console.log(prismaQueryOptions?.queryOptions, prismaQueryOptions?.[action]);
37
+ console.log(req.prismaQueryOptions);
36
38
  next();
37
39
  };
38
40
  }
@@ -1 +1 @@
1
- {"version":3,"file":"base.middlewares.js","sourceRoot":"","sources":["../../../../src/modules/base/base.middlewares.ts"],"names":[],"mappings":";;;;;AAiBA,4BAEC;AAED,oCAeC;AAED,oEAAiD;AAUjD,wEA2BC;AAMD,8CAwDC;AAcD,oGA2BC;AA1KD,yCAA8C;AAC9C,4FAA6D;AAC7D,+DAAyD;AACzD,4EAAmD;AACnD,kFAAyD;AAKzD,SAAgB,QAAQ,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;IACtE,IAAI,EAAE,CAAC;AACT,CAAC;AAED,SAAgB,YAAY,CAC1B,GAAiB,EACjB,GAAkB,EAClB,IAAkB;IAElB,IAAI,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,KAAK,GAAG;QACrC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SAC5C,IAAI,GAAG,CAAC,YAAY,IAAI,GAAG,EAAE,cAAc;QAC9C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;SAC5D,IAAI,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY;QACvD,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,c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,EAAE,IAAI;gBACf,GAAG,+BAA+B;aACnC,EACD,iBAAiB,EAAE,iBAAiB,IAAI,EAAE,CAC3C,CACF,CAAC;aACC,IAAI,iBAAiB,EAAE,QAAQ,KAAK,KAAK,IAAI,gBAAgB;YAChE,GAAG,CAAC,IAAI,GAAG,MAAM,IAAA,yBAAc,EAAC,gBAAgC,EAAE,IAAI,CAAC,CAAC;QAE1E,IAAI,EAAE,CAAC;IACT,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport {\n PrismaQueryOptions,\n ArkosNextFunction,\n ArkosRequest,\n ArkosRequestHandler,\n ArkosResponse,\n} from \"../../types\";\nimport { getArkosConfig } from \"../../server\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { catchAsync } from \"../../exports/error-handler\";\nimport validateDto from \"../../utils/validate-dto\";\nimport validateSchema from \"../../utils/validate-schema\";\nimport { ZodSchema } from \"zod\";\nimport { ClassConstructor } from \"class-transformer\";\nimport { ValidatorOptions } from \"class-validator\";\n\nexport function callNext(req: Request, res: Response, next: NextFunction) {\n next();\n}\n\nexport function sendResponse(\n req: ArkosRequest,\n res: ArkosResponse,\n next: NextFunction\n) {\n if (Number(req?.responseStatus) === 204)\n res.status(Number(req?.responseStatus)).send();\n else if (req.responseData && req?.responseStatus)\n res.status(Number(req?.responseStatus)).json(req.responseData);\n else if (Number(req?.responseStatus) && !req.responseData)\n res.status(Number(req?.responseStatus)).send();\n else\n res\n .status(500)\n .json({ message: \"No status or data attached to the response\" });\n}\n\nexport function addRouteMiddlwaresAndConfigs() {}\n\n/**\n * Middleware to add Prisma query options to the request's query parameters.\n *\n * @template T - The type of the Prisma model.\n * @param {PrismaQueryOptions<T>} prismaQueryOptions - The Prisma query options to attach.\n * @param {ControllerActions} action - The controller action to apply.\n * @returns A middleware function that attaches the query options to the request.\n */\nexport function addPrismaQueryOptionsToRequest<T extends Record<string, any>>(\n prismaQueryOptions: PrismaQueryOptions<T>,\n action: keyof PrismaQueryOptions<T>\n) {\n return (req: ArkosRequest, res: ArkosResponse, next: NextFunction) => {\n const configs = getArkosConfig();\n\n // const firstMerge = deepmerge(\n // prismaQueryOptions?.queryOptions || {},\n // prismaQueryOptions?.[action] || {}\n // ) as Record<string, any>;\n\n // console.log(\"firstMerge\", JSON.stringify(firstMerge));\n\n // req.prismaQueryOptions = deepmerge(\n // firstMerge,\n // JSON.parse(\n // configs?.request?.parameters?.allowDangerousPrismaQueryOptions\n // ? (req.query?.prismaQueryOptions as string)\n // : \"{}\"\n // )\n // );\n\n // console.log(\"secondMerge\", JSON.stringify(req.prismaQueryOptions));\n\n next();\n };\n}\n\n/**\n * Logs request events with colored text such as errors, requests responses.\n *\n */\nexport function handleRequestLogs(\n req: Request,\n res: Response,\n next: NextFunction\n) {\n // if (process.env.NODE_ENV === \"production\") return next()\n const startTime = Date.now(); // Capture the start time\n\n // Define colors for each HTTP method\n const methodColors = {\n GET: \"\\x1b[36m\", // Cyan\n POST: \"\\x1b[32m\", // Green\n PUT: \"\\x1b[33m\", // Orange/Yellow\n PATCH: \"\\x1b[33m\", // Orange/Yellow\n DELETE: \"\\x1b[31m\", // Red\n HEAD: \"\\x1b[34m\", // Blue\n OPTIONS: \"\\x1b[34m\", // Blue\n };\n\n // Function to determine status code color\n const getStatusColor = (statusCode: number) => {\n if (statusCode >= 200 && statusCode < 300) return \"\\x1b[32m\"; // Green\n if (statusCode >= 300 && statusCode < 400) return \"\\x1b[33m\"; // Orange/Yellow\n if (statusCode >= 400 && statusCode < 500) return \"\\x1b[33m\"; // Red\n if (statusCode >= 500) return \"\\x1b[31m\"; // White on Red background\n return \"\\x1b[0m\"; // Default (no color)\n };\n\n res.on(\"finish\", () => {\n const duration = Date.now() - startTime; // Calculate the time taken to process the request\n\n // Get the current date and time\n const now = new Date();\n const dayNames = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"];\n const dayName = dayNames[now.getDay()];\n const dayOfMonth = now.getDate();\n const time = now.toTimeString().split(\" \")[0]; // Format as HH:MM:SS\n\n const methodColor =\n methodColors[req.method as keyof typeof methodColors] || \"\\x1b[0m\"; // Default to no color\n const statusColor = getStatusColor(res.statusCode); // Get the color for the status code\n\n console.info(\n `[\\x1b[36mINFO\\x1b[0m] \\x1b[90m${time}\\x1b[0m ${methodColor}${\n req.method\n }\\x1b[0m ${decodeURIComponent(req.originalUrl)} ${statusColor}${\n res.statusCode\n }\\x1b[0m \\x1b[35m${duration}ms\\x1b[0m`\n );\n // Keep the commented-out example as it is\n // console.info(\n // `[\\x1b[36mINFO\\x1b[0m] ${dayName} ${dayOfMonth} ${time} ${methodColor}${req.method}\\x1b[0m ${req.originalUrl} \\x1b[32m${res.statusCode}\\x1b[0m \\x1b[35m${duration}ms\\x1b[0m`\n // );\n });\n\n next(); // Pass control to the next middleware or route handler\n}\n\n// Overload for 'auth'\nexport function handleRequestBodyValidationAndTransformation<T extends object>(\n schemaOrDtoClass?: ClassConstructor<T>,\n classValidatorValidationOptions?: ValidatorOptions\n): ArkosRequestHandler;\n\n// Overload for other models\nexport function handleRequestBodyValidationAndTransformation<T extends object>(\n schemaOrDtoClass?: ZodSchema<T>\n): ArkosRequestHandler;\n\n// Implementation\nexport function handleRequestBodyValidationAndTransformation<T extends object>(\n schemaOrDtoClass?: ZodSchema<T> | ClassConstructor<T>,\n classValidatorValidationOptions?: ValidatorOptions\n) {\n return catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n const validationConfigs = getArkosConfig()?.validation;\n let body = req.body;\n\n if (validationConfigs?.resolver === \"class-validator\" && schemaOrDtoClass)\n req.body = await validateDto(\n schemaOrDtoClass as ClassConstructor<T>,\n body,\n deepmerge(\n {\n whitelist: true,\n ...classValidatorValidationOptions,\n },\n validationConfigs?.validationOptions || {}\n )\n );\n else if (validationConfigs?.resolver === \"zod\" && schemaOrDtoClass)\n req.body = await validateSchema(schemaOrDtoClass as ZodSchema<T>, body);\n\n next();\n }\n );\n}\n"]}
1
+ {"version":3,"file":"base.middlewares.js","sourceRoot":"","sources":["../../../../src/modules/base/base.middlewares.ts"],"names":[],"mappings":";;;;;AAiBA,4BAEC;AAED,oCAeC;AAED,oEAAiD;AAUjD,wEA8BC;AAMD,8CAwDC;AAcD,oGA2BC;AA7KD,yCAA8C;AAC9C,4FAA6D;AAC7D,+DAAyD;AACzD,4EAAmD;AACnD,kFAAyD;AAKzD,SAAgB,QAAQ,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;IACtE,IAAI,EAAE,CAAC;AACT,CAAC;AAED,SAAgB,YAAY,CAC1B,GAAiB,EACjB,GAAkB,EAClB,IAAkB;IAElB,IAAI,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,KAAK,GAAG;QACrC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SAC5C,IAAI,GAAG,CAAC,YAAY,IAAI,GAAG,EAAE,cAAc;QAC9C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;SAC5D,IAAI,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY;QACvD,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;;QAE/C,GAAG;aACA,MAAM,CAAC,GAAG,CAAC;aACX,IAAI,CAAC,EAAE,OAAO,EAAE,4CAA4C,EAAE,CAAC,CAAC;AACvE,CAAC;AAED,SAAgB,4BAA4B,KAAI,CAAC;AAUjD,SAAgB,8BAA8B,CAC5C,kBAAyC,EACzC,MAAmC;IAEnC,OAAO,CAAC,GAAiB,EAAE,GAAkB,EAAE,IAAkB,EAAE,EAAE;QACnE,MAAM,OAAO,GAAG,I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,CAAC,IAAI,GAAG,MAAM,IAAA,yBAAc,EAAC,gBAAgC,EAAE,IAAI,CAAC,CAAC;QAE1E,IAAI,EAAE,CAAC;IACT,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport {\n PrismaQueryOptions,\n ArkosNextFunction,\n ArkosRequest,\n ArkosRequestHandler,\n ArkosResponse,\n} from \"../../types\";\nimport { getArkosConfig } from \"../../server\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { catchAsync } from \"../../exports/error-handler\";\nimport validateDto from \"../../utils/validate-dto\";\nimport validateSchema from \"../../utils/validate-schema\";\nimport { ZodSchema } from \"zod\";\nimport { ClassConstructor } from \"class-transformer\";\nimport { ValidatorOptions } from \"class-validator\";\n\nexport function callNext(req: Request, res: Response, next: NextFunction) {\n next();\n}\n\nexport function sendResponse(\n req: ArkosRequest,\n res: ArkosResponse,\n next: NextFunction\n) {\n if (Number(req?.responseStatus) === 204)\n res.status(Number(req?.responseStatus)).send();\n else if (req.responseData && req?.responseStatus)\n res.status(Number(req?.responseStatus)).json(req.responseData);\n else if (Number(req?.responseStatus) && !req.responseData)\n res.status(Number(req?.responseStatus)).send();\n else\n res\n .status(500)\n .json({ message: \"No status or data attached to the response\" });\n}\n\nexport function addRouteMiddlwaresAndConfigs() {}\n\n/**\n * Middleware to add Prisma query options to the request's query parameters.\n *\n * @template T - The type of the Prisma model.\n * @param {PrismaQueryOptions<T>} prismaQueryOptions - The Prisma query options to attach.\n * @param {ControllerActions} action - The controller action to apply.\n * @returns A middleware function that attaches the query options to the request.\n */\nexport function addPrismaQueryOptionsToRequest<T extends Record<string, any>>(\n prismaQueryOptions: PrismaQueryOptions<T>,\n action: keyof PrismaQueryOptions<T>\n) {\n return (req: ArkosRequest, res: ArkosResponse, next: NextFunction) => {\n const configs = getArkosConfig();\n\n // const firstMerge = deepmerge(\n // prismaQueryOptions?.queryOptions || {},\n // prismaQueryOptions?.[action] || {}\n // ) as Record<string, any>;\n\n console.log(prismaQueryOptions?.queryOptions, prismaQueryOptions?.[action]);\n\n // console.log(\"firstMerge\", JSON.stringify(firstMerge));\n\n // req.prismaQueryOptions = deepmerge(\n // firstMerge,\n // JSON.parse(\n // configs?.request?.parameters?.allowDangerousPrismaQueryOptions\n // ? (req.query?.prismaQueryOptions as string)\n // : \"{}\"\n // )\n // );\n\n // console.log(\"secondMerge\", JSON.stringify(req.prismaQueryOptions));\n console.log(req.prismaQueryOptions);\n\n next();\n };\n}\n\n/**\n * Logs request events with colored text such as errors, requests responses.\n *\n */\nexport function handleRequestLogs(\n req: Request,\n res: Response,\n next: NextFunction\n) {\n // if (process.env.NODE_ENV === \"production\") return next()\n const startTime = Date.now(); // Capture the start time\n\n // Define colors for each HTTP method\n const methodColors = {\n GET: \"\\x1b[36m\", // Cyan\n POST: \"\\x1b[32m\", // Green\n PUT: \"\\x1b[33m\", // Orange/Yellow\n PATCH: \"\\x1b[33m\", // Orange/Yellow\n DELETE: \"\\x1b[31m\", // Red\n HEAD: \"\\x1b[34m\", // Blue\n OPTIONS: \"\\x1b[34m\", // Blue\n };\n\n // Function to determine status code color\n const getStatusColor = (statusCode: number) => {\n if (statusCode >= 200 && statusCode < 300) return \"\\x1b[32m\"; // Green\n if (statusCode >= 300 && statusCode < 400) return \"\\x1b[33m\"; // Orange/Yellow\n if (statusCode >= 400 && statusCode < 500) return \"\\x1b[33m\"; // Red\n if (statusCode >= 500) return \"\\x1b[31m\"; // White on Red background\n return \"\\x1b[0m\"; // Default (no color)\n };\n\n res.on(\"finish\", () => {\n const duration = Date.now() - startTime; // Calculate the time taken to process the request\n\n // Get the current date and time\n const now = new Date();\n const dayNames = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"];\n const dayName = dayNames[now.getDay()];\n const dayOfMonth = now.getDate();\n const time = now.toTimeString().split(\" \")[0]; // Format as HH:MM:SS\n\n const methodColor =\n methodColors[req.method as keyof typeof methodColors] || \"\\x1b[0m\"; // Default to no color\n const statusColor = getStatusColor(res.statusCode); // Get the color for the status code\n\n console.info(\n `[\\x1b[36mINFO\\x1b[0m] \\x1b[90m${time}\\x1b[0m ${methodColor}${\n req.method\n }\\x1b[0m ${decodeURIComponent(req.originalUrl)} ${statusColor}${\n res.statusCode\n }\\x1b[0m \\x1b[35m${duration}ms\\x1b[0m`\n );\n // Keep the commented-out example as it is\n // console.info(\n // `[\\x1b[36mINFO\\x1b[0m] ${dayName} ${dayOfMonth} ${time} ${methodColor}${req.method}\\x1b[0m ${req.originalUrl} \\x1b[32m${res.statusCode}\\x1b[0m \\x1b[35m${duration}ms\\x1b[0m`\n // );\n });\n\n next(); // Pass control to the next middleware or route handler\n}\n\n// Overload for 'auth'\nexport function handleRequestBodyValidationAndTransformation<T extends object>(\n schemaOrDtoClass?: ClassConstructor<T>,\n classValidatorValidationOptions?: ValidatorOptions\n): ArkosRequestHandler;\n\n// Overload for other models\nexport function handleRequestBodyValidationAndTransformation<T extends object>(\n schemaOrDtoClass?: ZodSchema<T>\n): ArkosRequestHandler;\n\n// Implementation\nexport function handleRequestBodyValidationAndTransformation<T extends object>(\n schemaOrDtoClass?: ZodSchema<T> | ClassConstructor<T>,\n classValidatorValidationOptions?: ValidatorOptions\n) {\n return catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n const validationConfigs = getArkosConfig()?.validation;\n let body = req.body;\n\n if (validationConfigs?.resolver === \"class-validator\" && schemaOrDtoClass)\n req.body = await validateDto(\n schemaOrDtoClass as ClassConstructor<T>,\n body,\n deepmerge(\n {\n whitelist: true,\n ...classValidatorValidationOptions,\n },\n validationConfigs?.validationOptions || {}\n )\n );\n else if (validationConfigs?.resolver === \"zod\" && schemaOrDtoClass)\n req.body = await validateSchema(schemaOrDtoClass as ZodSchema<T>, body);\n\n next();\n }\n );\n}\n"]}
package/dist/cjs/proxy.js CHANGED
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(r,e,i,t){t===void 0&&(t=i);var n=Object.getOwnPropertyDescriptor(e,i);(!n||("get"in n?!e.__esModule:n.writable||n.configurable))&&(n={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(r,t,n)}:function(r,e,i,t){t===void 0&&(t=i),r[t]=e[i]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),__importStar=this&&this.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(i){var t=[];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[t.length]=n);return t},r(e)};return function(e){if(e&&e.__esModule)return e;var i={};if(e!=null)for(var t=r(e),n=0;n<t.length;n++)t[n]!=="default"&&__createBinding(i,e,t[n]);return __setModuleDefault(i,e),i}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.arkosProxy=void 0,exports.getCapturedConfig=getCapturedConfig;let capturedConfig=null;exports.arkosProxy={init:r=>(capturedConfig=r,Promise.resolve().then(()=>__importStar(require("../path/to/real/arkos"))).then(e=>e.initApp(r)))};function getCapturedConfig(){return capturedConfig}
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(r,e,o,t){t===void 0&&(t=o);var n=Object.getOwnPropertyDescriptor(e,o);(!n||("get"in n?!e.__esModule:n.writable||n.configurable))&&(n={enumerable:!0,get:function(){return e[o]}}),Object.defineProperty(r,t,n)}:function(r,e,o,t){t===void 0&&(t=o),r[t]=e[o]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),__importStar=this&&this.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(o){var t=[];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(t[t.length]=n);return t},r(e)};return function(e){if(e&&e.__esModule)return e;var o={};if(e!=null)for(var t=r(e),n=0;n<t.length;n++)t[n]!=="default"&&__createBinding(o,e,t[n]);return __setModuleDefault(o,e),o}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.arkosProxy=void 0,exports.getCapturedConfig=getCapturedConfig;let capturedConfig=null;exports.arkosProxy={init:r=>(capturedConfig=r,Promise.resolve().then(()=>__importStar(require("../path/to/real/arkos"))).then(e=>e.initApp(r)))};function getCapturedConfig(){return capturedConfig}
@@ -22,6 +22,8 @@ export function addRouteMiddlwaresAndConfigs() { }
22
22
  export function addPrismaQueryOptionsToRequest(prismaQueryOptions, action) {
23
23
  return (req, res, next) => {
24
24
  const configs = getArkosConfig();
25
+ console.log(prismaQueryOptions?.queryOptions, prismaQueryOptions?.[action]);
26
+ console.log(req.prismaQueryOptions);
25
27
  next();
26
28
  };
27
29
  }
@@ -1 +1 @@
1
- {"version":3,"file":"base.middlewares.js","sourceRoot":"","sources":["../../../../src/modules/base/base.middlewares.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,SAAS,MAAM,sCAAsC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,cAAc,MAAM,6BAA6B,CAAC;AAKzD,MAAM,UAAU,QAAQ,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;IACtE,IAAI,EAAE,CAAC;AACT,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,GAAiB,EACjB,GAAkB,EAClB,IAAkB;IAElB,IAAI,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,KAAK,GAAG;QACrC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SAC5C,IAAI,GAAG,CAAC,YAAY,IAAI,GAAG,EAAE,cAAc;QAC9C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAA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;QAEpB,IAAI,iBAAiB,EAAE,QAAQ,KAAK,iBAAiB,IAAI,gBAAgB;YACvE,GAAG,CAAC,IAAI,GAAG,MAAM,WAAW,CAC1B,gBAAuC,EACvC,IAAI,EACJ,SAAS,CACP;gBACE,SAAS,EAAE,IAAI;gBACf,GAAG,+BAA+B;aACnC,EACD,iBAAiB,EAAE,iBAAiB,IAAI,EAAE,CAC3C,CACF,CAAC;aACC,IAAI,iBAAiB,EAAE,QAAQ,KAAK,KAAK,IAAI,gBAAgB;YAChE,GAAG,CAAC,IAAI,GAAG,MAAM,cAAc,CAAC,gBAAgC,EAAE,IAAI,CAAC,CAAC;QAE1E,IAAI,EAAE,CAAC;IACT,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport {\n PrismaQueryOptions,\n ArkosNextFunction,\n ArkosRequest,\n ArkosRequestHandler,\n ArkosResponse,\n} from \"../../types\";\nimport { getArkosConfig } from \"../../server\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { catchAsync } from \"../../exports/error-handler\";\nimport validateDto from \"../../utils/validate-dto\";\nimport validateSchema from \"../../utils/validate-schema\";\nimport { ZodSchema } from \"zod\";\nimport { ClassConstructor } from \"class-transformer\";\nimport { ValidatorOptions } from \"class-validator\";\n\nexport function callNext(req: Request, res: Response, next: NextFunction) {\n next();\n}\n\nexport function sendResponse(\n req: ArkosRequest,\n res: ArkosResponse,\n next: NextFunction\n) {\n if (Number(req?.responseStatus) === 204)\n res.status(Number(req?.responseStatus)).send();\n else if (req.responseData && req?.responseStatus)\n res.status(Number(req?.responseStatus)).json(req.responseData);\n else if (Number(req?.responseStatus) && !req.responseData)\n res.status(Number(req?.responseStatus)).send();\n else\n res\n .status(500)\n .json({ message: \"No status or data attached to the response\" });\n}\n\nexport function addRouteMiddlwaresAndConfigs() {}\n\n/**\n * Middleware to add Prisma query options to the request's query parameters.\n *\n * @template T - The type of the Prisma model.\n * @param {PrismaQueryOptions<T>} prismaQueryOptions - The Prisma query options to attach.\n * @param {ControllerActions} action - The controller action to apply.\n * @returns A middleware function that attaches the query options to the request.\n */\nexport function addPrismaQueryOptionsToRequest<T extends Record<string, any>>(\n prismaQueryOptions: PrismaQueryOptions<T>,\n action: keyof PrismaQueryOptions<T>\n) {\n return (req: ArkosRequest, res: ArkosResponse, next: NextFunction) => {\n const configs = getArkosConfig();\n\n // const firstMerge = deepmerge(\n // prismaQueryOptions?.queryOptions || {},\n // prismaQueryOptions?.[action] || {}\n // ) as Record<string, any>;\n\n // console.log(\"firstMerge\", JSON.stringify(firstMerge));\n\n // req.prismaQueryOptions = deepmerge(\n // firstMerge,\n // JSON.parse(\n // configs?.request?.parameters?.allowDangerousPrismaQueryOptions\n // ? (req.query?.prismaQueryOptions as string)\n // : \"{}\"\n // )\n // );\n\n // console.log(\"secondMerge\", JSON.stringify(req.prismaQueryOptions));\n\n next();\n };\n}\n\n/**\n * Logs request events with colored text such as errors, requests responses.\n *\n */\nexport function handleRequestLogs(\n req: Request,\n res: Response,\n next: NextFunction\n) {\n // if (process.env.NODE_ENV === \"production\") return next()\n const startTime = Date.now(); // Capture the start time\n\n // Define colors for each HTTP method\n const methodColors = {\n GET: \"\\x1b[36m\", // Cyan\n POST: \"\\x1b[32m\", // Green\n PUT: \"\\x1b[33m\", // Orange/Yellow\n PATCH: \"\\x1b[33m\", // Orange/Yellow\n DELETE: \"\\x1b[31m\", // Red\n HEAD: \"\\x1b[34m\", // Blue\n OPTIONS: \"\\x1b[34m\", // Blue\n };\n\n // Function to determine status code color\n const getStatusColor = (statusCode: number) => {\n if (statusCode >= 200 && statusCode < 300) return \"\\x1b[32m\"; // Green\n if (statusCode >= 300 && statusCode < 400) return \"\\x1b[33m\"; // Orange/Yellow\n if (statusCode >= 400 && statusCode < 500) return \"\\x1b[33m\"; // Red\n if (statusCode >= 500) return \"\\x1b[31m\"; // White on Red background\n return \"\\x1b[0m\"; // Default (no color)\n };\n\n res.on(\"finish\", () => {\n const duration = Date.now() - startTime; // Calculate the time taken to process the request\n\n // Get the current date and time\n const now = new Date();\n const dayNames = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"];\n const dayName = dayNames[now.getDay()];\n const dayOfMonth = now.getDate();\n const time = now.toTimeString().split(\" \")[0]; // Format as HH:MM:SS\n\n const methodColor =\n methodColors[req.method as keyof typeof methodColors] || \"\\x1b[0m\"; // Default to no color\n const statusColor = getStatusColor(res.statusCode); // Get the color for the status code\n\n console.info(\n `[\\x1b[36mINFO\\x1b[0m] \\x1b[90m${time}\\x1b[0m ${methodColor}${\n req.method\n }\\x1b[0m ${decodeURIComponent(req.originalUrl)} ${statusColor}${\n res.statusCode\n }\\x1b[0m \\x1b[35m${duration}ms\\x1b[0m`\n );\n // Keep the commented-out example as it is\n // console.info(\n // `[\\x1b[36mINFO\\x1b[0m] ${dayName} ${dayOfMonth} ${time} ${methodColor}${req.method}\\x1b[0m ${req.originalUrl} \\x1b[32m${res.statusCode}\\x1b[0m \\x1b[35m${duration}ms\\x1b[0m`\n // );\n });\n\n next(); // Pass control to the next middleware or route handler\n}\n\n// Overload for 'auth'\nexport function handleRequestBodyValidationAndTransformation<T extends object>(\n schemaOrDtoClass?: ClassConstructor<T>,\n classValidatorValidationOptions?: ValidatorOptions\n): ArkosRequestHandler;\n\n// Overload for other models\nexport function handleRequestBodyValidationAndTransformation<T extends object>(\n schemaOrDtoClass?: ZodSchema<T>\n): ArkosRequestHandler;\n\n// Implementation\nexport function handleRequestBodyValidationAndTransformation<T extends object>(\n schemaOrDtoClass?: ZodSchema<T> | ClassConstructor<T>,\n classValidatorValidationOptions?: ValidatorOptions\n) {\n return catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n const validationConfigs = getArkosConfig()?.validation;\n let body = req.body;\n\n if (validationConfigs?.resolver === \"class-validator\" && schemaOrDtoClass)\n req.body = await validateDto(\n schemaOrDtoClass as ClassConstructor<T>,\n body,\n deepmerge(\n {\n whitelist: true,\n ...classValidatorValidationOptions,\n },\n validationConfigs?.validationOptions || {}\n )\n );\n else if (validationConfigs?.resolver === \"zod\" && schemaOrDtoClass)\n req.body = await validateSchema(schemaOrDtoClass as ZodSchema<T>, body);\n\n next();\n }\n );\n}\n"]}
1
+ {"version":3,"file":"base.middlewares.js","sourceRoot":"","sources":["../../../../src/modules/base/base.middlewares.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,SAAS,MAAM,sCAAsC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,cAAc,MAAM,6BAA6B,CAAC;AAKzD,MAAM,UAAU,QAAQ,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;IACtE,IAAI,EAAE,CAAC;AACT,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,GAAiB,EACjB,GAAkB,EAClB,IAAkB;IAElB,IAAI,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,KAAK,GAAG;QACrC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SAC5C,IAAI,GAAG,CAAC,YAAY,IAAI,GAAG,EAAE,cAAc;QAC9C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;SAC5D,IAAI,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY;QACvD,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;;QAE/C,GAAG;aACA,MAAM,CAAC,GAAG,CAAC;aACX,IAAI,CAAC,EAAE,OAAO,EA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AAI,EACJ,SAAS,CACP;gBACE,SAAS,EAAE,IAAI;gBACf,GAAG,+BAA+B;aACnC,EACD,iBAAiB,EAAE,iBAAiB,IAAI,EAAE,CAC3C,CACF,CAAC;aACC,IAAI,iBAAiB,EAAE,QAAQ,KAAK,KAAK,IAAI,gBAAgB;YAChE,GAAG,CAAC,IAAI,GAAG,MAAM,cAAc,CAAC,gBAAgC,EAAE,IAAI,CAAC,CAAC;QAE1E,IAAI,EAAE,CAAC;IACT,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport {\n PrismaQueryOptions,\n ArkosNextFunction,\n ArkosRequest,\n ArkosRequestHandler,\n ArkosResponse,\n} from \"../../types\";\nimport { getArkosConfig } from \"../../server\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { catchAsync } from \"../../exports/error-handler\";\nimport validateDto from \"../../utils/validate-dto\";\nimport validateSchema from \"../../utils/validate-schema\";\nimport { ZodSchema } from \"zod\";\nimport { ClassConstructor } from \"class-transformer\";\nimport { ValidatorOptions } from \"class-validator\";\n\nexport function callNext(req: Request, res: Response, next: NextFunction) {\n next();\n}\n\nexport function sendResponse(\n req: ArkosRequest,\n res: ArkosResponse,\n next: NextFunction\n) {\n if (Number(req?.responseStatus) === 204)\n res.status(Number(req?.responseStatus)).send();\n else if (req.responseData && req?.responseStatus)\n res.status(Number(req?.responseStatus)).json(req.responseData);\n else if (Number(req?.responseStatus) && !req.responseData)\n res.status(Number(req?.responseStatus)).send();\n else\n res\n .status(500)\n .json({ message: \"No status or data attached to the response\" });\n}\n\nexport function addRouteMiddlwaresAndConfigs() {}\n\n/**\n * Middleware to add Prisma query options to the request's query parameters.\n *\n * @template T - The type of the Prisma model.\n * @param {PrismaQueryOptions<T>} prismaQueryOptions - The Prisma query options to attach.\n * @param {ControllerActions} action - The controller action to apply.\n * @returns A middleware function that attaches the query options to the request.\n */\nexport function addPrismaQueryOptionsToRequest<T extends Record<string, any>>(\n prismaQueryOptions: PrismaQueryOptions<T>,\n action: keyof PrismaQueryOptions<T>\n) {\n return (req: ArkosRequest, res: ArkosResponse, next: NextFunction) => {\n const configs = getArkosConfig();\n\n // const firstMerge = deepmerge(\n // prismaQueryOptions?.queryOptions || {},\n // prismaQueryOptions?.[action] || {}\n // ) as Record<string, any>;\n\n console.log(prismaQueryOptions?.queryOptions, prismaQueryOptions?.[action]);\n\n // console.log(\"firstMerge\", JSON.stringify(firstMerge));\n\n // req.prismaQueryOptions = deepmerge(\n // firstMerge,\n // JSON.parse(\n // configs?.request?.parameters?.allowDangerousPrismaQueryOptions\n // ? (req.query?.prismaQueryOptions as string)\n // : \"{}\"\n // )\n // );\n\n // console.log(\"secondMerge\", JSON.stringify(req.prismaQueryOptions));\n console.log(req.prismaQueryOptions);\n\n next();\n };\n}\n\n/**\n * Logs request events with colored text such as errors, requests responses.\n *\n */\nexport function handleRequestLogs(\n req: Request,\n res: Response,\n next: NextFunction\n) {\n // if (process.env.NODE_ENV === \"production\") return next()\n const startTime = Date.now(); // Capture the start time\n\n // Define colors for each HTTP method\n const methodColors = {\n GET: \"\\x1b[36m\", // Cyan\n POST: \"\\x1b[32m\", // Green\n PUT: \"\\x1b[33m\", // Orange/Yellow\n PATCH: \"\\x1b[33m\", // Orange/Yellow\n DELETE: \"\\x1b[31m\", // Red\n HEAD: \"\\x1b[34m\", // Blue\n OPTIONS: \"\\x1b[34m\", // Blue\n };\n\n // Function to determine status code color\n const getStatusColor = (statusCode: number) => {\n if (statusCode >= 200 && statusCode < 300) return \"\\x1b[32m\"; // Green\n if (statusCode >= 300 && statusCode < 400) return \"\\x1b[33m\"; // Orange/Yellow\n if (statusCode >= 400 && statusCode < 500) return \"\\x1b[33m\"; // Red\n if (statusCode >= 500) return \"\\x1b[31m\"; // White on Red background\n return \"\\x1b[0m\"; // Default (no color)\n };\n\n res.on(\"finish\", () => {\n const duration = Date.now() - startTime; // Calculate the time taken to process the request\n\n // Get the current date and time\n const now = new Date();\n const dayNames = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"];\n const dayName = dayNames[now.getDay()];\n const dayOfMonth = now.getDate();\n const time = now.toTimeString().split(\" \")[0]; // Format as HH:MM:SS\n\n const methodColor =\n methodColors[req.method as keyof typeof methodColors] || \"\\x1b[0m\"; // Default to no color\n const statusColor = getStatusColor(res.statusCode); // Get the color for the status code\n\n console.info(\n `[\\x1b[36mINFO\\x1b[0m] \\x1b[90m${time}\\x1b[0m ${methodColor}${\n req.method\n }\\x1b[0m ${decodeURIComponent(req.originalUrl)} ${statusColor}${\n res.statusCode\n }\\x1b[0m \\x1b[35m${duration}ms\\x1b[0m`\n );\n // Keep the commented-out example as it is\n // console.info(\n // `[\\x1b[36mINFO\\x1b[0m] ${dayName} ${dayOfMonth} ${time} ${methodColor}${req.method}\\x1b[0m ${req.originalUrl} \\x1b[32m${res.statusCode}\\x1b[0m \\x1b[35m${duration}ms\\x1b[0m`\n // );\n });\n\n next(); // Pass control to the next middleware or route handler\n}\n\n// Overload for 'auth'\nexport function handleRequestBodyValidationAndTransformation<T extends object>(\n schemaOrDtoClass?: ClassConstructor<T>,\n classValidatorValidationOptions?: ValidatorOptions\n): ArkosRequestHandler;\n\n// Overload for other models\nexport function handleRequestBodyValidationAndTransformation<T extends object>(\n schemaOrDtoClass?: ZodSchema<T>\n): ArkosRequestHandler;\n\n// Implementation\nexport function handleRequestBodyValidationAndTransformation<T extends object>(\n schemaOrDtoClass?: ZodSchema<T> | ClassConstructor<T>,\n classValidatorValidationOptions?: ValidatorOptions\n) {\n return catchAsync(\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n const validationConfigs = getArkosConfig()?.validation;\n let body = req.body;\n\n if (validationConfigs?.resolver === \"class-validator\" && schemaOrDtoClass)\n req.body = await validateDto(\n schemaOrDtoClass as ClassConstructor<T>,\n body,\n deepmerge(\n {\n whitelist: true,\n ...classValidatorValidationOptions,\n },\n validationConfigs?.validationOptions || {}\n )\n );\n else if (validationConfigs?.resolver === \"zod\" && schemaOrDtoClass)\n req.body = await validateSchema(schemaOrDtoClass as ZodSchema<T>, body);\n\n next();\n }\n );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkos",
3
- "version": "1.1.26-test",
3
+ "version": "1.1.27-test",
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",