arkos 1.0.18-beta → 1.0.20-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/app.js +1 -1
- package/dist/cjs/app.js.map +1 -1
- package/dist/cjs/exports/middlewares/index.js +7 -0
- package/dist/cjs/exports/middlewares/index.js.map +1 -0
- package/dist/cjs/exports/utils/index.js.map +1 -1
- package/dist/cjs/modules/auth/auth.controller.js +38 -37
- package/dist/cjs/modules/auth/auth.controller.js.map +1 -1
- package/dist/cjs/modules/auth/auth.router.js +4 -5
- package/dist/cjs/modules/auth/auth.router.js.map +1 -1
- package/dist/cjs/modules/auth/auth.service.js +27 -24
- package/dist/cjs/modules/auth/auth.service.js.map +1 -1
- package/dist/cjs/modules/auth/utils/helpers/auth.controller.helpers.js +8 -12
- package/dist/cjs/modules/auth/utils/helpers/auth.controller.helpers.js.map +1 -1
- package/dist/cjs/modules/auth/utils/helpers/auth.helpers.js +19 -0
- package/dist/cjs/modules/auth/utils/helpers/auth.helpers.js.map +1 -0
- package/dist/cjs/modules/base/base.controller.js +2 -29
- package/dist/cjs/modules/base/base.controller.js.map +1 -1
- package/dist/cjs/modules/base/base.middlewares.js +42 -1
- package/dist/cjs/modules/base/base.middlewares.js.map +1 -1
- package/dist/cjs/modules/base/base.router.js +2 -2
- package/dist/cjs/modules/base/base.router.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.helpers.js +183 -0
- package/dist/cjs/modules/base/utils/helpers/base.helpers.js.map +1 -0
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +2 -3
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js +9 -11
- package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js.map +1 -1
- package/dist/cjs/modules/error-handler/error-handler.controller.js +2 -0
- package/dist/cjs/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/cjs/modules/error-handler/utils/catch-async.js +1 -1
- package/dist/cjs/modules/error-handler/utils/catch-async.js.map +1 -1
- package/dist/cjs/modules/file-uploader/file-uploader.service.js +4 -4
- package/dist/cjs/modules/file-uploader/file-uploader.service.js.map +1 -1
- package/dist/cjs/modules/file-uploader/utils/helpers/file-uploader.helpers.js +7 -5
- package/dist/cjs/modules/file-uploader/utils/helpers/file-uploader.helpers.js.map +1 -1
- package/dist/cjs/server.js +1 -1
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/types/arkos-config.js.map +1 -1
- package/dist/cjs/types/auth.js.map +1 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/prisma-model-router-config.js +3 -0
- package/dist/cjs/types/prisma-model-router-config.js.map +1 -0
- package/dist/cjs/utils/features/api.features.js +3 -2
- package/dist/cjs/utils/features/api.features.js.map +1 -1
- package/dist/cjs/utils/helpers/api.features.helpers.js +4 -3
- package/dist/cjs/utils/helpers/api.features.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/base.controller.helpers.js +77 -35
- package/dist/cjs/utils/helpers/base.controller.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/change-case.helpers.js +3 -3
- package/dist/cjs/utils/helpers/change-case.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/fs.helpers.js +14 -45
- package/dist/cjs/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/models.helpers.js +35 -30
- package/dist/cjs/utils/helpers/models.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/prisma.helpers.js +5 -3
- package/dist/cjs/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/cjs/utils/scripts/export-prisma-types.js +3 -3
- package/dist/cjs/utils/scripts/export-prisma-types.js.map +1 -1
- package/dist/cjs/utils/scripts/generate-insomnia-collection.js +228 -0
- package/dist/cjs/utils/scripts/generate-insomnia-collection.js.map +1 -0
- package/dist/cjs/utils/scripts/generate-zod-schemas.js +4 -3
- package/dist/cjs/utils/scripts/generate-zod-schemas.js.map +1 -1
- package/dist/cjs/utils/scripts/index.js +12 -0
- package/dist/cjs/utils/scripts/index.js.map +1 -0
- package/dist/es2020/app.js +1 -1
- package/dist/es2020/app.js.map +1 -1
- package/dist/es2020/exports/middlewares/index.js +2 -0
- package/dist/es2020/exports/middlewares/index.js.map +1 -0
- package/dist/es2020/exports/utils/index.js.map +1 -1
- package/dist/es2020/modules/auth/auth.controller.js +39 -38
- package/dist/es2020/modules/auth/auth.controller.js.map +1 -1
- package/dist/es2020/modules/auth/auth.router.js +1 -2
- package/dist/es2020/modules/auth/auth.router.js.map +1 -1
- package/dist/es2020/modules/auth/auth.service.js +27 -24
- package/dist/es2020/modules/auth/auth.service.js.map +1 -1
- package/dist/es2020/modules/auth/utils/helpers/auth.controller.helpers.js +8 -12
- package/dist/es2020/modules/auth/utils/helpers/auth.controller.helpers.js.map +1 -1
- package/dist/es2020/modules/auth/utils/helpers/auth.helpers.js +12 -0
- package/dist/es2020/modules/auth/utils/helpers/auth.helpers.js.map +1 -0
- package/dist/es2020/modules/base/base.controller.js +2 -29
- package/dist/es2020/modules/base/base.controller.js.map +1 -1
- package/dist/es2020/modules/base/base.middlewares.js +38 -1
- package/dist/es2020/modules/base/base.middlewares.js.map +1 -1
- package/dist/es2020/modules/base/base.router.js +2 -2
- package/dist/es2020/modules/base/base.router.js.map +1 -1
- package/dist/es2020/modules/base/utils/helpers/base.helpers.js +177 -0
- package/dist/es2020/modules/base/utils/helpers/base.helpers.js.map +1 -0
- package/dist/es2020/modules/base/utils/helpers/base.router.helpers.js +1 -2
- package/dist/es2020/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/es2020/modules/base/utils/helpers/base.service.helpers.js +9 -11
- package/dist/es2020/modules/base/utils/helpers/base.service.helpers.js.map +1 -1
- package/dist/es2020/modules/error-handler/error-handler.controller.js +2 -0
- package/dist/es2020/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/es2020/modules/error-handler/utils/catch-async.js +1 -1
- package/dist/es2020/modules/error-handler/utils/catch-async.js.map +1 -1
- package/dist/es2020/modules/file-uploader/file-uploader.service.js +4 -4
- package/dist/es2020/modules/file-uploader/file-uploader.service.js.map +1 -1
- package/dist/es2020/modules/file-uploader/utils/helpers/file-uploader.helpers.js +7 -5
- package/dist/es2020/modules/file-uploader/utils/helpers/file-uploader.helpers.js.map +1 -1
- package/dist/es2020/server.js +1 -1
- package/dist/es2020/server.js.map +1 -1
- package/dist/es2020/types/arkos-config.js.map +1 -1
- package/dist/es2020/types/auth.js.map +1 -1
- package/dist/es2020/types/index.js.map +1 -1
- package/dist/es2020/types/prisma-model-router-config.js +2 -0
- package/dist/es2020/types/prisma-model-router-config.js.map +1 -0
- package/dist/es2020/utils/features/api.features.js +3 -2
- package/dist/es2020/utils/features/api.features.js.map +1 -1
- package/dist/es2020/utils/helpers/api.features.helpers.js +4 -3
- package/dist/es2020/utils/helpers/api.features.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/base.controller.helpers.js +75 -31
- package/dist/es2020/utils/helpers/base.controller.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/change-case.helpers.js +3 -3
- package/dist/es2020/utils/helpers/change-case.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/fs.helpers.js +13 -44
- package/dist/es2020/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/models.helpers.js +36 -31
- package/dist/es2020/utils/helpers/models.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/prisma.helpers.js +6 -4
- package/dist/es2020/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/es2020/utils/scripts/export-prisma-types.js +3 -3
- package/dist/es2020/utils/scripts/export-prisma-types.js.map +1 -1
- package/dist/es2020/utils/scripts/generate-insomnia-collection.js +189 -0
- package/dist/es2020/utils/scripts/generate-insomnia-collection.js.map +1 -0
- package/dist/es2020/utils/scripts/generate-zod-schemas.js +4 -3
- package/dist/es2020/utils/scripts/generate-zod-schemas.js.map +1 -1
- package/dist/es2020/utils/scripts/index.js +10 -0
- package/dist/es2020/utils/scripts/index.js.map +1 -0
- package/dist/types/exports/middlewares/index.d.ts +1 -0
- package/dist/types/exports/utils/index.d.ts +1 -0
- package/dist/types/modules/auth/auth.service.d.ts +3 -3
- package/dist/types/modules/auth/utils/helpers/auth.helpers.d.ts +2 -0
- package/dist/types/modules/base/base.middlewares.d.ts +6 -1
- package/dist/types/modules/base/utils/helpers/base.helpers.d.ts +5 -0
- package/dist/types/modules/base/utils/helpers/base.service.helpers.d.ts +1 -1
- package/dist/types/types/arkos-config.d.ts +5 -0
- package/dist/types/types/auth.d.ts +9 -8
- package/dist/types/types/index.d.ts +2 -1
- package/dist/types/types/prisma-model-router-config.d.ts +18 -0
- package/dist/types/utils/helpers/base.controller.helpers.d.ts +4 -6
- package/dist/types/utils/helpers/fs.helpers.d.ts +2 -2
- package/dist/types/utils/scripts/generate-insomnia-collection.d.ts +1 -0
- package/dist/types/utils/scripts/index.d.ts +2 -0
- package/package.json +55 -34
|
@@ -1,40 +1,82 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
const deepmerge_helper_1 = __importDefault(require("../../utils/helpers/deepmerge.helper"));
|
|
3
|
+
exports.getAppRoutes = void 0;
|
|
17
4
|
const server_1 = require("../../server");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const error_handler_1 = require("../../exports/error-handler");
|
|
23
|
-
function handleRequestBodyValidationAndTransformation(modelName, action) {
|
|
24
|
-
return (0, error_handler_1.catchAsync)((req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
5
|
+
const getAppRoutes = () => {
|
|
6
|
+
const app = (0, server_1.getExpressApp)();
|
|
7
|
+
const routes = [];
|
|
8
|
+
app._router.stack.forEach((middleware) => {
|
|
25
9
|
var _a;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
else if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
10
|
+
if (middleware.route) {
|
|
11
|
+
Object.keys(middleware.route.methods).forEach((method) => {
|
|
12
|
+
routes.push({
|
|
13
|
+
method: method.toUpperCase(),
|
|
14
|
+
path: middleware.route.path,
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
else if (middleware.handle && middleware.handle.stack) {
|
|
19
|
+
let basePath = "";
|
|
20
|
+
if (middleware.regexp) {
|
|
21
|
+
const regexpStr = middleware.regexp.toString();
|
|
22
|
+
if ((_a = regexpStr.includes) === null || _a === void 0 ? void 0 : _a.call(regexpStr, "/?(?=")) {
|
|
23
|
+
const match = regexpStr.match(/\/\^(\\\/[^?]+)/);
|
|
24
|
+
if (match) {
|
|
25
|
+
basePath = match[1].replace(/\\\//g, "/");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const simpleMatch = regexpStr.match(/\/\^(\\\/[^\\]+)/);
|
|
30
|
+
if (simpleMatch) {
|
|
31
|
+
basePath = simpleMatch[1].replace(/\\\//g, "/");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
middleware.handle.stack.forEach((routerMiddleware) => {
|
|
36
|
+
if (routerMiddleware.route) {
|
|
37
|
+
Object.keys(routerMiddleware.route.methods).forEach((method) => {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
let routePath = routerMiddleware.route.path;
|
|
40
|
+
let fullPath;
|
|
41
|
+
if ((_a = routePath.includes) === null || _a === void 0 ? void 0 : _a.call(routePath, "/?(?=")) {
|
|
42
|
+
const pathMatch = routePath.match(/\/\^?(\\\/[^?]+|\/[^?]+)/);
|
|
43
|
+
if (pathMatch) {
|
|
44
|
+
const cleanPath = pathMatch[1].replace(/\\\//g, "/");
|
|
45
|
+
fullPath = basePath ? basePath + cleanPath : cleanPath;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const fallbackMatch = routePath.match(/\?\(\?=([^)]+)/);
|
|
49
|
+
if (fallbackMatch) {
|
|
50
|
+
fullPath = fallbackMatch[1];
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
fullPath = routePath;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
fullPath = basePath
|
|
59
|
+
? basePath.replace(/\/$/, "") +
|
|
60
|
+
(routePath.startsWith("/") ? routePath : "/" + routePath)
|
|
61
|
+
: routePath;
|
|
62
|
+
}
|
|
63
|
+
fullPath = fullPath
|
|
64
|
+
.replace(/\\\//g, "/")
|
|
65
|
+
.replace(/\^/g, "")
|
|
66
|
+
.replace(/\$/g, "");
|
|
67
|
+
if ((_b = fullPath.includes) === null || _b === void 0 ? void 0 : _b.call(fullPath, "/?(?=")) {
|
|
68
|
+
fullPath = fullPath.replace(/\/\?\(\?=[^)]*\)/g, "");
|
|
69
|
+
}
|
|
70
|
+
routes.push({
|
|
71
|
+
method: method.toUpperCase(),
|
|
72
|
+
path: fullPath,
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return routes;
|
|
80
|
+
};
|
|
81
|
+
exports.getAppRoutes = getAppRoutes;
|
|
40
82
|
//# sourceMappingURL=base.controller.helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.controller.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/base.controller.helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base.controller.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/base.controller.helpers.ts"],"names":[],"mappings":";;;AAAA,yCAA6C;AAEtC,MAAM,YAAY,GAAG,GAAG,EAAE;IAC/B,MAAM,GAAG,GAAG,IAAA,sBAAa,GAAE,CAAC;IAC5B,MAAM,MAAM,GAAuC,EAAE,CAAC;IAEtD,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,UAAe,EAAE,EAAE;;QAC5C,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;YAErB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;gBACvD,MAAM,CAAC,IAAI,CAAC;oBACV,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE;oBAC5B,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,IAAI;iBAC5B,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;aAAM,IAAI,UAAU,CAAC,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAExD,IAAI,QAAQ,GAAG,EAAE,CAAC;YAClB,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC;gBAEtB,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;gBAG/C,IAAI,MAAA,SAA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;gCAEN,MAAM,aAAa,GAAG,SAAS,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;gCACxD,IAAI,aAAa,EAAE,CAAC;oCAClB,QAAQ,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;gCAC9B,CAAC;qCAAM,CAAC;oCACN,QAAQ,GAAG,SAAS,CAAC;gCACvB,CAAC;4BACH,CAAC;wBACH,CAAC;6BAAM,CAAC;4BAEN,QAAQ,GAAG,QAAQ;gCACjB,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;oCAC3B,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,SAAS,CAAC;gCAC3D,CAAC,CAAC,SAAS,CAAC;wBAChB,CAAC;wBAGD,QAAQ,GAAG,QAAQ;6BAChB,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;6BACrB,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;6BAClB,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;wBAGtB,IAAI,MAAA,QAAQ,CAAC,QAAQ,yDAAG,OAAO,CAAC,EAAE,CAAC;4BACjC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;wBACvD,CAAC;wBAED,MAAM,CAAC,IAAI,CAAC;4BACV,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE;4BAC5B,IAAI,EAAE,QAAQ;yBACf,CAAC,CAAC;oBACL,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA1FW,QAAA,YAAY,gBA0FvB","sourcesContent":["import { getExpressApp } from \"../../server\";\n\nexport const getAppRoutes = () => {\n const app = getExpressApp();\n const routes: { method: string; path: string }[] = [];\n\n app._router.stack.forEach((middleware: any) => {\n if (middleware.route) {\n // Direct routes on the app\n Object.keys(middleware.route.methods).forEach((method) => {\n routes.push({\n method: method.toUpperCase(),\n path: middleware.route.path,\n });\n });\n } else if (middleware.handle && middleware.handle.stack) {\n // Extract the base path from the middleware's regexp pattern\n let basePath = \"\";\n if (middleware.regexp) {\n // Handle pattern like /^\\/api\\/?(?=\\/|$)/i\n const regexpStr = middleware.regexp.toString();\n\n // More robust pattern matching\n if (regexpStr.includes?.(\"/?(?=\")) {\n // Extract everything between the start and the '/?(?=' pattern\n const match = regexpStr.match(/\\/\\^(\\\\\\/[^?]+)/);\n if (match) {\n // Clean up the extracted path\n basePath = match[1].replace(/\\\\\\//g, \"/\");\n }\n } else {\n // Handle other regexp patterns\n const simpleMatch = regexpStr.match(/\\/\\^(\\\\\\/[^\\\\]+)/);\n if (simpleMatch) {\n basePath = simpleMatch[1].replace(/\\\\\\//g, \"/\");\n }\n }\n }\n\n // Process routes in the middleware's router\n middleware.handle.stack.forEach((routerMiddleware: any) => {\n if (routerMiddleware.route) {\n Object.keys(routerMiddleware.route.methods).forEach((method) => {\n let routePath = routerMiddleware.route.path;\n let fullPath;\n\n // Check if routePath already contains regex artifacts\n if (routePath.includes?.(\"/?(?=\")) {\n // Extract the actual path from the regex pattern\n const pathMatch = routePath.match(/\\/\\^?(\\\\\\/[^?]+|\\/[^?]+)/);\n if (pathMatch) {\n const cleanPath = pathMatch[1].replace(/\\\\\\//g, \"/\");\n fullPath = basePath ? basePath + cleanPath : cleanPath;\n } else {\n // If we can't clean it, at least extract what's after '/?(?='\n const fallbackMatch = routePath.match(/\\?\\(\\?=([^)]+)/);\n if (fallbackMatch) {\n fullPath = fallbackMatch[1];\n } else {\n fullPath = routePath; // Use as is if no pattern matches\n }\n }\n } else {\n // Normal path joining\n fullPath = basePath\n ? basePath.replace(/\\/$/, \"\") +\n (routePath.startsWith(\"/\") ? routePath : \"/\" + routePath)\n : routePath;\n }\n\n // Clean up any remaining regex artifacts\n fullPath = fullPath\n .replace(/\\\\\\//g, \"/\")\n .replace(/\\^/g, \"\")\n .replace(/\\$/g, \"\");\n\n // Remove any \"/?(?=\" patterns that might remain\n if (fullPath.includes?.(\"/?(?=\")) {\n fullPath = fullPath.replace(/\\/\\?\\(\\?=[^)]*\\)/g, \"\");\n }\n\n routes.push({\n method: method.toUpperCase(),\n path: fullPath,\n });\n });\n }\n });\n }\n });\n\n return routes;\n};\n"]}
|
|
@@ -157,7 +157,7 @@ function pascalCaseTransformFactory(lower, upper) {
|
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
159
|
function splitPrefixSuffix(input, options = {}) {
|
|
160
|
-
var _a, _b, _c;
|
|
160
|
+
var _a, _b, _c, _d, _e;
|
|
161
161
|
const splitFn = (_a = options.split) !== null && _a !== void 0 ? _a : (options.separateNumbers ? splitSeparateNumbers : split);
|
|
162
162
|
const prefixCharacters = (_b = options.prefixCharacters) !== null && _b !== void 0 ? _b : DEFAULT_PREFIX_SUFFIX_CHARACTERS;
|
|
163
163
|
const suffixCharacters = (_c = options.suffixCharacters) !== null && _c !== void 0 ? _c : DEFAULT_PREFIX_SUFFIX_CHARACTERS;
|
|
@@ -165,14 +165,14 @@ function splitPrefixSuffix(input, options = {}) {
|
|
|
165
165
|
let suffixIndex = input.length;
|
|
166
166
|
while (prefixIndex < input.length) {
|
|
167
167
|
const char = input.charAt(prefixIndex);
|
|
168
|
-
if (!prefixCharacters.includes(char))
|
|
168
|
+
if (!((_d = prefixCharacters === null || prefixCharacters === void 0 ? void 0 : prefixCharacters.includes) === null || _d === void 0 ? void 0 : _d.call(prefixCharacters, char)))
|
|
169
169
|
break;
|
|
170
170
|
prefixIndex++;
|
|
171
171
|
}
|
|
172
172
|
while (suffixIndex > prefixIndex) {
|
|
173
173
|
const index = suffixIndex - 1;
|
|
174
174
|
const char = input.charAt(index);
|
|
175
|
-
if (!suffixCharacters.includes(char))
|
|
175
|
+
if (!((_e = suffixCharacters === null || suffixCharacters === void 0 ? void 0 : suffixCharacters.includes) === null || _e === void 0 ? void 0 : _e.call(suffixCharacters, char)))
|
|
176
176
|
break;
|
|
177
177
|
suffixIndex = index;
|
|
178
178
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"change-case.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/change-case.helpers.ts"],"names":[],"mappings":";;AA6CA,sBAkBC;AAKD,oDAWC;AAKD,wBAOC;AAKD,8BAiBC;AAKD,gCAQC;AAKD,0CAEC;AAKD,kCAWC;AAKD,oCAOC;AAKD,0BAEC;AAKD,8BAEC;AAKD,4BAEC;AAKD,oCAeC;AAKD,8BAEC;AAKD,8BAEC;AAvND,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AACtD,MAAM,oBAAoB,GAAG,8BAA8B,CAAC;AAG5D,MAAM,wBAAwB,GAAG,uBAAuB,CAAC;AAGzD,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAG9C,MAAM,mBAAmB,GAAG,QAAQ,CAAC;AAGrC,MAAM,gCAAgC,GAAG,EAAE,CAAC;AA+B5C,SAAgB,KAAK,CAAC,KAAa;IACjC,IAAI,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAE1B,MAAM,GAAG,MAAM;SACZ,OAAO,CAAC,oBAAoB,EAAE,mBAAmB,CAAC;SAClD,OAAO,CAAC,oBAAoB,EAAE,mBAAmB,CAAC,CAAC;IAEtD,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;IAEpD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;IAGxB,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,IAAI;QAAE,KAAK,EAAE,CAAC;IAC9C,IAAI,KAAK,KAAK,GAAG;QAAE,OAAO,EAAE,CAAC;IAC7B,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CA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C;IACtB,CAAC;IAED,OAAO;QACL,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC;QAC3B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QAC9C,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC;KACzB,CAAC;AACJ,CAAC","sourcesContent":["// Regexps involved with splitting words in various case formats.\nconst SPLIT_LOWER_UPPER_RE = /([\\p{Ll}\\d])(\\p{Lu})/gu;\nconst SPLIT_UPPER_UPPER_RE = /(\\p{Lu})([\\p{Lu}][\\p{Ll}])/gu;\n\n// Used to iterate over the initial split result and separate numbers.\nconst SPLIT_SEPARATE_NUMBER_RE = /(\\d)\\p{Ll}|(\\p{L})\\d/u;\n\n// Regexp involved with stripping non-word characters from the result.\nconst DEFAULT_STRIP_REGEXP = /[^\\p{L}\\d]+/giu;\n\n// The replacement value for splits.\nconst SPLIT_REPLACE_VALUE = \"$1\\0$2\";\n\n// The default characters to keep after transforming case.\nconst DEFAULT_PREFIX_SUFFIX_CHARACTERS = \"\";\n\n/**\n * Supported locale values. Use `false` to ignore locale.\n * Defaults to `undefined`, which uses the host environment.\n */\nexport type Locale = string[] | string | false | undefined;\n\n/**\n * Options used for converting strings to pascal/camel case.\n */\nexport interface PascalCaseOptions extends Options {\n mergeAmbiguousCharacters?: boolean;\n}\n\n/**\n * Options used for converting strings to any case.\n */\nexport interface Options {\n locale?: Locale;\n split?: (value: string) => string[];\n /** @deprecated Pass `split: splitSeparateNumbers` instead. */\n separateNumbers?: boolean;\n delimiter?: string;\n prefixCharacters?: string;\n suffixCharacters?: string;\n}\n\n/**\n * Split any cased input strings into an array of words.\n */\nexport function split(value: string) {\n let result = value.trim();\n\n result = result\n .replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE)\n .replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);\n\n result = result.replace(DEFAULT_STRIP_REGEXP, \"\\0\");\n\n let start = 0;\n let end = result.length;\n\n // Trim the delimiter from around the output string.\n while (result.charAt(start) === \"\\0\") start++;\n if (start === end) return [];\n while (result.charAt(end - 1) === \"\\0\") end--;\n\n return result.slice(start, end).split(/\\0/g);\n}\n\n/**\n * Split the input string into an array of words, separating numbers.\n */\nexport function splitSeparateNumbers(value: string) {\n const words = split(value);\n for (let i = 0; i < words.length; i++) {\n const word = words[i];\n const match = SPLIT_SEPARATE_NUMBER_RE.exec(word);\n if (match) {\n const offset = match.index + (match[1] ?? match[2]).length;\n words.splice(i, 1, word.slice(0, offset), word.slice(offset));\n }\n }\n return words;\n}\n\n/**\n * Convert a string to space separated lower case (`foo bar`).\n */\nexport function noCase(input: string, options?: Options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n return (\n prefix +\n words.map(lowerFactory(options?.locale)).join(options?.delimiter ?? \" \") +\n suffix\n );\n}\n\n/**\n * Convert a string to camel case (`fooBar`).\n */\nexport function camelCase(input: string, options?: PascalCaseOptions) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = options?.mergeAmbiguousCharacters\n ? capitalCaseTransformFactory(lower, upper)\n : pascalCaseTransformFactory(lower, upper);\n return (\n prefix +\n words\n .map((word, index) => {\n if (index === 0) return lower(word);\n return transform(word, index);\n })\n .join(options?.delimiter ?? \"\") +\n suffix\n );\n}\n\n/**\n * Convert a string to pascal case (`FooBar`).\n */\nexport function pascalCase(input: string, options?: PascalCaseOptions) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = options?.mergeAmbiguousCharacters\n ? capitalCaseTransformFactory(lower, upper)\n : pascalCaseTransformFactory(lower, upper);\n return prefix + words.map(transform).join(options?.delimiter ?? \"\") + suffix;\n}\n\n/**\n * Convert a string to pascal snake case (`Foo_Bar`).\n */\nexport function pascalSnakeCase(input: string, options?: Options) {\n return capitalCase(input, { delimiter: \"_\", ...options });\n}\n\n/**\n * Convert a string to capital case (`Foo Bar`).\n */\nexport function capitalCase(input: string, options?: Options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n return (\n prefix +\n words\n .map(capitalCaseTransformFactory(lower, upper))\n .join(options?.delimiter ?? \" \") +\n suffix\n );\n}\n\n/**\n * Convert a string to constant case (`FOO_BAR`).\n */\nexport function constantCase(input: string, options?: Options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n return (\n prefix +\n words.map(upperFactory(options?.locale)).join(options?.delimiter ?? \"_\") +\n suffix\n );\n}\n\n/**\n * Convert a string to dot case (`foo.bar`).\n */\nexport function dotCase(input: string, options?: Options) {\n return noCase(input, { delimiter: \".\", ...options });\n}\n\n/**\n * Convert a string to kebab case (`foo-bar`).\n */\nexport function kebabCase(input: string, options?: Options) {\n return noCase(input, { delimiter: \"-\", ...options });\n}\n\n/**\n * Convert a string to path case (`foo/bar`).\n */\nexport function pathCase(input: string, options?: Options) {\n return noCase(input, { delimiter: \"/\", ...options });\n}\n\n/**\n * Convert a string to path case (`Foo bar`).\n */\nexport function sentenceCase(input: string, options?: Options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = capitalCaseTransformFactory(lower, upper);\n return (\n prefix +\n words\n .map((word, index) => {\n if (index === 0) return transform(word);\n return lower(word);\n })\n .join(options?.delimiter ?? \" \") +\n suffix\n );\n}\n\n/**\n * Convert a string to snake case (`foo_bar`).\n */\nexport function snakeCase(input: string, options?: Options) {\n return noCase(input, { delimiter: \"_\", ...options });\n}\n\n/**\n * Convert a string to header case (`Foo-Bar`).\n */\nexport function trainCase(input: string, options?: Options) {\n return capitalCase(input, { delimiter: \"-\", ...options });\n}\n\nfunction lowerFactory(locale: Locale): (input: string) => string {\n return locale === false\n ? (input: string) => input.toLowerCase()\n : (input: string) => input.toLocaleLowerCase(locale);\n}\n\nfunction upperFactory(locale: Locale): (input: string) => string {\n return locale === false\n ? (input: string) => input.toUpperCase()\n : (input: string) => input.toLocaleUpperCase(locale);\n}\n\nfunction capitalCaseTransformFactory(\n lower: (input: string) => string,\n upper: (input: string) => string\n) {\n return (word: string) => `${upper(word[0])}${lower(word.slice(1))}`;\n}\n\nfunction pascalCaseTransformFactory(\n lower: (input: string) => string,\n upper: (input: string) => string\n) {\n return (word: string, index: number) => {\n const char0 = word[0];\n const initial =\n index > 0 && char0 >= \"0\" && char0 <= \"9\" ? \"_\" + char0 : upper(char0);\n return initial + lower(word.slice(1));\n };\n}\n\nfunction splitPrefixSuffix(\n input: string,\n options: Options = {}\n): [string, string[], string] {\n const splitFn =\n options.split ?? (options.separateNumbers ? splitSeparateNumbers : split);\n const prefixCharacters =\n options.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;\n const suffixCharacters =\n options.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;\n let prefixIndex = 0;\n let suffixIndex = input.length;\n\n while (prefixIndex < input.length) {\n const char = input.charAt(prefixIndex);\n if (!prefixCharacters.includes(char)) break;\n prefixIndex++;\n }\n\n while (suffixIndex > prefixIndex) {\n const index = suffixIndex - 1;\n const char = input.charAt(index);\n if (!suffixCharacters.includes(char)) break;\n suffixIndex = index;\n }\n\n return [\n input.slice(0, prefixIndex),\n splitFn(input.slice(prefixIndex, suffixIndex)),\n input.slice(suffixIndex),\n ];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"change-case.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/change-case.helpers.ts"],"names":[],"mappings":";;AA6CA,sBAkBC;AAKD,oDAWC;AAKD,wBAOC;AAKD,8BAiBC;AAKD,gCAQC;AAKD,0CAEC;AAKD,kCAWC;AAKD,oCAOC;AAKD,0BAEC;AAKD,8BAEC;AAKD,4BAEC;AAKD,oCAeC;AAKD,8BAEC;AA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{Lu})/gu;\nconst SPLIT_UPPER_UPPER_RE = /(\\p{Lu})([\\p{Lu}][\\p{Ll}])/gu;\n\n// Used to iterate over the initial split result and separate numbers.\nconst SPLIT_SEPARATE_NUMBER_RE = /(\\d)\\p{Ll}|(\\p{L})\\d/u;\n\n// Regexp involved with stripping non-word characters from the result.\nconst DEFAULT_STRIP_REGEXP = /[^\\p{L}\\d]+/giu;\n\n// The replacement value for splits.\nconst SPLIT_REPLACE_VALUE = \"$1\\0$2\";\n\n// The default characters to keep after transforming case.\nconst DEFAULT_PREFIX_SUFFIX_CHARACTERS = \"\";\n\n/**\n * Supported locale values. Use `false` to ignore locale.\n * Defaults to `undefined`, which uses the host environment.\n */\nexport type Locale = string[] | string | false | undefined;\n\n/**\n * Options used for converting strings to pascal/camel case.\n */\nexport interface PascalCaseOptions extends Options {\n mergeAmbiguousCharacters?: boolean;\n}\n\n/**\n * Options used for converting strings to any case.\n */\nexport interface Options {\n locale?: Locale;\n split?: (value: string) => string[];\n /** @deprecated Pass `split: splitSeparateNumbers` instead. */\n separateNumbers?: boolean;\n delimiter?: string;\n prefixCharacters?: string;\n suffixCharacters?: string;\n}\n\n/**\n * Split any cased input strings into an array of words.\n */\nexport function split(value: string) {\n let result = value.trim();\n\n result = result\n .replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE)\n .replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);\n\n result = result.replace(DEFAULT_STRIP_REGEXP, \"\\0\");\n\n let start = 0;\n let end = result.length;\n\n // Trim the delimiter from around the output string.\n while (result.charAt(start) === \"\\0\") start++;\n if (start === end) return [];\n while (result.charAt(end - 1) === \"\\0\") end--;\n\n return result.slice(start, end).split(/\\0/g);\n}\n\n/**\n * Split the input string into an array of words, separating numbers.\n */\nexport function splitSeparateNumbers(value: string) {\n const words = split(value);\n for (let i = 0; i < words.length; i++) {\n const word = words[i];\n const match = SPLIT_SEPARATE_NUMBER_RE.exec(word);\n if (match) {\n const offset = match.index + (match[1] ?? match[2]).length;\n words.splice(i, 1, word.slice(0, offset), word.slice(offset));\n }\n }\n return words;\n}\n\n/**\n * Convert a string to space separated lower case (`foo bar`).\n */\nexport function noCase(input: string, options?: Options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n return (\n prefix +\n words.map(lowerFactory(options?.locale)).join(options?.delimiter ?? \" \") +\n suffix\n );\n}\n\n/**\n * Convert a string to camel case (`fooBar`).\n */\nexport function camelCase(input: string, options?: PascalCaseOptions) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = options?.mergeAmbiguousCharacters\n ? capitalCaseTransformFactory(lower, upper)\n : pascalCaseTransformFactory(lower, upper);\n return (\n prefix +\n words\n .map((word, index) => {\n if (index === 0) return lower(word);\n return transform(word, index);\n })\n .join(options?.delimiter ?? \"\") +\n suffix\n );\n}\n\n/**\n * Convert a string to pascal case (`FooBar`).\n */\nexport function pascalCase(input: string, options?: PascalCaseOptions) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = options?.mergeAmbiguousCharacters\n ? capitalCaseTransformFactory(lower, upper)\n : pascalCaseTransformFactory(lower, upper);\n return prefix + words.map(transform).join(options?.delimiter ?? \"\") + suffix;\n}\n\n/**\n * Convert a string to pascal snake case (`Foo_Bar`).\n */\nexport function pascalSnakeCase(input: string, options?: Options) {\n return capitalCase(input, { delimiter: \"_\", ...options });\n}\n\n/**\n * Convert a string to capital case (`Foo Bar`).\n */\nexport function capitalCase(input: string, options?: Options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n return (\n prefix +\n words\n .map(capitalCaseTransformFactory(lower, upper))\n .join(options?.delimiter ?? \" \") +\n suffix\n );\n}\n\n/**\n * Convert a string to constant case (`FOO_BAR`).\n */\nexport function constantCase(input: string, options?: Options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n return (\n prefix +\n words.map(upperFactory(options?.locale)).join(options?.delimiter ?? \"_\") +\n suffix\n );\n}\n\n/**\n * Convert a string to dot case (`foo.bar`).\n */\nexport function dotCase(input: string, options?: Options) {\n return noCase(input, { delimiter: \".\", ...options });\n}\n\n/**\n * Convert a string to kebab case (`foo-bar`).\n */\nexport function kebabCase(input: string, options?: Options) {\n return noCase(input, { delimiter: \"-\", ...options });\n}\n\n/**\n * Convert a string to path case (`foo/bar`).\n */\nexport function pathCase(input: string, options?: Options) {\n return noCase(input, { delimiter: \"/\", ...options });\n}\n\n/**\n * Convert a string to path case (`Foo bar`).\n */\nexport function sentenceCase(input: string, options?: Options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = capitalCaseTransformFactory(lower, upper);\n return (\n prefix +\n words\n .map((word, index) => {\n if (index === 0) return transform(word);\n return lower(word);\n })\n .join(options?.delimiter ?? \" \") +\n suffix\n );\n}\n\n/**\n * Convert a string to snake case (`foo_bar`).\n */\nexport function snakeCase(input: string, options?: Options) {\n return noCase(input, { delimiter: \"_\", ...options });\n}\n\n/**\n * Convert a string to header case (`Foo-Bar`).\n */\nexport function trainCase(input: string, options?: Options) {\n return capitalCase(input, { delimiter: \"-\", ...options });\n}\n\nfunction lowerFactory(locale: Locale): (input: string) => string {\n return locale === false\n ? (input: string) => input.toLowerCase()\n : (input: string) => input.toLocaleLowerCase(locale);\n}\n\nfunction upperFactory(locale: Locale): (input: string) => string {\n return locale === false\n ? (input: string) => input.toUpperCase()\n : (input: string) => input.toLocaleUpperCase(locale);\n}\n\nfunction capitalCaseTransformFactory(\n lower: (input: string) => string,\n upper: (input: string) => string\n) {\n return (word: string) => `${upper(word[0])}${lower(word.slice(1))}`;\n}\n\nfunction pascalCaseTransformFactory(\n lower: (input: string) => string,\n upper: (input: string) => string\n) {\n return (word: string, index: number) => {\n const char0 = word[0];\n const initial =\n index > 0 && char0 >= \"0\" && char0 <= \"9\" ? \"_\" + char0 : upper(char0);\n return initial + lower(word.slice(1));\n };\n}\n\nfunction splitPrefixSuffix(\n input: string,\n options: Options = {}\n): [string, string[], string] {\n const splitFn =\n options.split ?? (options.separateNumbers ? splitSeparateNumbers : split);\n const prefixCharacters =\n options.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;\n const suffixCharacters =\n options.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;\n let prefixIndex = 0;\n let suffixIndex = input.length;\n\n while (prefixIndex < input.length) {\n const char = input.charAt(prefixIndex);\n if (!prefixCharacters?.includes?.(char)) break;\n prefixIndex++;\n }\n\n while (suffixIndex > prefixIndex) {\n const index = suffixIndex - 1;\n const char = input.charAt(index);\n if (!suffixCharacters?.includes?.(char)) break;\n suffixIndex = index;\n }\n\n return [\n input.slice(0, prefixIndex),\n splitFn(input.slice(prefixIndex, suffixIndex)),\n input.slice(suffixIndex),\n ];\n}\n"]}
|
|
@@ -3,57 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
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
9
|
exports.statAsync = (0, util_1.promisify)(fs_1.default.stat);
|
|
10
10
|
exports.accessAsync = (0, util_1.promisify)(fs_1.default.access);
|
|
11
11
|
exports.mkdirAsync = (0, util_1.promisify)(fs_1.default.mkdir);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
if (typeof process !== "undefined" && process.env) {
|
|
17
|
-
currentFile = __filename || "";
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
if (typeof (global === null || global === void 0 ? void 0 : global.document) === "undefined") {
|
|
21
|
-
currentFile = new Function("return typeof import.meta !== 'undefined' ? import.meta.url : ''")();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
}
|
|
27
|
-
if (currentFile.endsWith(".ts") || currentFile.endsWith(".tsx")) {
|
|
28
|
-
return "ts";
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
const globalObj = globalThis;
|
|
32
|
-
if (typeof globalObj.Deno !== "undefined" && globalObj.Deno.emit) {
|
|
33
|
-
return "ts";
|
|
34
|
-
}
|
|
35
|
-
if (typeof globalObj.Bun !== "undefined") {
|
|
36
|
-
return "ts";
|
|
37
|
-
}
|
|
38
|
-
if (typeof process !== "undefined" &&
|
|
39
|
-
process.versions &&
|
|
40
|
-
parseInt(process.versions.node.split(".")[0]) >= 18) {
|
|
41
|
-
const isUsingTypeScript = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.includes(".ts:");
|
|
42
|
-
if (isUsingTypeScript)
|
|
43
|
-
return "ts";
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
}
|
|
48
|
-
return "js";
|
|
49
|
-
})();
|
|
50
|
-
exports.userFileExtension = (() => {
|
|
12
|
+
const getUserFileExtension = () => {
|
|
13
|
+
if (exports.userFileExtension)
|
|
14
|
+
return exports.userFileExtension;
|
|
51
15
|
try {
|
|
52
16
|
const fs = require("fs");
|
|
53
17
|
const path = require("path");
|
|
54
18
|
const projectRoot = process.cwd();
|
|
55
19
|
if (fs.existsSync(path.join(projectRoot, "tsconfig.json"))) {
|
|
56
|
-
|
|
20
|
+
exports.userFileExtension = "ts";
|
|
21
|
+
return exports.userFileExtension;
|
|
57
22
|
}
|
|
58
23
|
const srcDirs = ["src", "source", "app", "lib"]
|
|
59
24
|
.map((dir) => path.join(projectRoot, dir))
|
|
@@ -62,13 +27,17 @@ exports.userFileExtension = (() => {
|
|
|
62
27
|
for (const dir of srcDirs) {
|
|
63
28
|
const files = fs.readdirSync(dir);
|
|
64
29
|
if (files.some((file) => file.endsWith(".ts") || file.endsWith(".tsx"))) {
|
|
65
|
-
|
|
30
|
+
exports.userFileExtension = "ts";
|
|
31
|
+
return exports.userFileExtension;
|
|
66
32
|
}
|
|
67
33
|
}
|
|
68
|
-
|
|
34
|
+
exports.userFileExtension = "js";
|
|
35
|
+
return exports.userFileExtension;
|
|
69
36
|
}
|
|
70
37
|
catch (e) {
|
|
71
|
-
|
|
38
|
+
exports.userFileExtension = "js";
|
|
39
|
+
return exports.userFileExtension;
|
|
72
40
|
}
|
|
73
|
-
}
|
|
41
|
+
};
|
|
42
|
+
exports.getUserFileExtension = getUserFileExtension;
|
|
74
43
|
//# sourceMappingURL=fs.helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/fs.helpers.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAiC;AACjC,4CAAoB;AAEP,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;
|
|
1
|
+
{"version":3,"file":"fs.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/fs.helpers.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAiC;AACjC,4CAAoB;AAEP,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,U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,CAAC;YAC3B,CAAC;QACH,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;AA5CW,QAAA,oBAAoB,wBA4C/B","sourcesContent":["import { promisify } from \"util\";\nimport fs from \"fs\";\n\nexport const statAsync = promisify(fs.stat);\nexport const accessAsync = promisify(fs.access);\nexport const mkdirAsync = promisify(fs.mkdir);\n\n// // Runtime-agnostic approach with proper TypeScript support\n// export const extension = (() => {\n// // Safely detect environment without direct import.meta reference\n// let currentFile = \"\";\n\n// // Try to determine the current file using environment-specific approaches\n// try {\n// if (typeof process !== \"undefined\" && process.env) {\n// // Node.js environment - use __filename\n// currentFile = __filename || \"\";\n// } else {\n// // Handle other environments (browser, Deno, etc.)\n// // This branch won't be reached in CommonJS builds\n// if (typeof (global as any)?.document === \"undefined\") {\n// // Non-browser environment that might support import.meta\n// // We'll use eval to prevent direct parsing of import.meta\n// currentFile = new Function(\n// \"return typeof import.meta !== 'undefined' ? import.meta.url : ''\"\n// )();\n// }\n// }\n// } catch (e) {\n// // Ignore errors during detection\n// }\n\n// // Check file extension\n// if (currentFile.endsWith(\".ts\") || currentFile.endsWith(\".tsx\")) {\n// return \"ts\";\n// }\n\n// // Use \"any\" type and conditional checks to avoid TypeScript errors\n// try {\n// // Check for Deno\n// const globalObj = globalThis as any;\n// if (typeof globalObj.Deno !== \"undefined\" && globalObj.Deno.emit) {\n// return \"ts\";\n// }\n\n// // Check for Bun\n// if (typeof globalObj.Bun !== \"undefined\") {\n// return \"ts\";\n// }\n\n// // Check for newer Node with TS support\n// if (\n// typeof process !== \"undefined\" &&\n// process.versions &&\n// parseInt((process.versions as any).node.split(\".\")[0]) >= 18\n// ) {\n// const isUsingTypeScript = new Error().stack?.includes?.(\".ts:\");\n// if (isUsingTypeScript) return \"ts\";\n// }\n// } catch (e) {\n// // Ignore errors during detection\n// }\n\n// return \"js\";\n// })();\n\nexport let userFileExtension: \"ts\" | \"js\" | undefined;\n\n/**\n * Immediately detects if the user's project uses TypeScript or JavaScript\n * @returns 'ts' | 'js'\n */\nexport const getUserFileExtension = (): \"ts\" | \"js\" => {\n if (userFileExtension) return userFileExtension;\n\n try {\n // Only works in Node.js environment\n const fs = require(\"fs\");\n const path = require(\"path\");\n\n // Get the project root\n const projectRoot = process.cwd();\n\n // Check for tsconfig.json in project root as the fastest check\n if (fs.existsSync(path.join(projectRoot, \"tsconfig.json\"))) {\n userFileExtension = \"ts\";\n return userFileExtension;\n }\n\n // Check common src directories\n const srcDirs = [\"src\", \"source\", \"app\", \"lib\"]\n .map((dir) => path.join(projectRoot, dir))\n .filter((dir) => fs.existsSync(dir) && fs.statSync(dir).isDirectory());\n\n // Add project root to directories to check\n srcDirs.push(projectRoot);\n\n // Check each directory for .ts files\n for (const dir of srcDirs) {\n const files = fs.readdirSync(dir);\n if (\n files.some((file: any) => file.endsWith(\".ts\") || file.endsWith(\".tsx\"))\n ) {\n userFileExtension = \"ts\";\n return userFileExtension;\n }\n }\n\n // Default to js if no TypeScript indicators found\n userFileExtension = \"js\";\n return userFileExtension;\n } catch (e) {\n // Fallback to js if any errors occur\n userFileExtension = \"js\";\n return userFileExtension;\n }\n};\n"]}
|
|
@@ -68,40 +68,41 @@ function getFileModelModulesFileStructure(modelName) {
|
|
|
68
68
|
const kebabModelName = (0, change_case_helpers_1.kebabCase)(modelName).toLowerCase();
|
|
69
69
|
const lowerModelName = kebabModelName.toLowerCase();
|
|
70
70
|
const isAuthModule = modelName.toLowerCase() === "auth";
|
|
71
|
+
const ext = (0, fs_helpers_1.getUserFileExtension)();
|
|
71
72
|
return {
|
|
72
73
|
core: {
|
|
73
|
-
service: `${kebabModelName}.service.${
|
|
74
|
-
controller: `${kebabModelName}.controller.${
|
|
75
|
-
middlewares: `${kebabModelName}.middlewares.${
|
|
76
|
-
authConfigs: `${kebabModelName}.auth-configs.${
|
|
77
|
-
prismaQueryOptions: `${kebabModelName}.prisma-query-options.${
|
|
78
|
-
router: `${kebabModelName}.router.${
|
|
74
|
+
service: `${kebabModelName}.service.${ext}`,
|
|
75
|
+
controller: `${kebabModelName}.controller.${ext}`,
|
|
76
|
+
middlewares: `${kebabModelName}.middlewares.${ext}`,
|
|
77
|
+
authConfigs: `${kebabModelName}.auth-configs.${ext}`,
|
|
78
|
+
prismaQueryOptions: `${kebabModelName}.prisma-query-options.${ext}`,
|
|
79
|
+
router: `${kebabModelName}.router.${ext}`,
|
|
79
80
|
},
|
|
80
81
|
dtos: isAuthModule
|
|
81
82
|
? {
|
|
82
|
-
login: `login.dto.${
|
|
83
|
-
signup: `signup.dto.${
|
|
84
|
-
updateMe: `update-me.dto.${
|
|
85
|
-
updatePassword: `update-password.dto.${
|
|
83
|
+
login: `login.dto.${ext}`,
|
|
84
|
+
signup: `signup.dto.${ext}`,
|
|
85
|
+
updateMe: `update-me.dto.${ext}`,
|
|
86
|
+
updatePassword: `update-password.dto.${ext}`,
|
|
86
87
|
}
|
|
87
88
|
: {
|
|
88
|
-
model: `${lowerModelName}.dto.${
|
|
89
|
-
create: `create-${lowerModelName}.dto.${
|
|
90
|
-
update: `update-${lowerModelName}.dto.${
|
|
91
|
-
query: `query-${lowerModelName}.dto.${
|
|
89
|
+
model: `${lowerModelName}.dto.${ext}`,
|
|
90
|
+
create: `create-${lowerModelName}.dto.${ext}`,
|
|
91
|
+
update: `update-${lowerModelName}.dto.${ext}`,
|
|
92
|
+
query: `query-${lowerModelName}.dto.${ext}`,
|
|
92
93
|
},
|
|
93
94
|
schemas: isAuthModule
|
|
94
95
|
? {
|
|
95
|
-
login: `login.schema.${
|
|
96
|
-
signup: `signup.schema.${
|
|
97
|
-
updateMe: `update-me.schema.${
|
|
98
|
-
updatePassword: `update-password.schema.${
|
|
96
|
+
login: `login.schema.${ext}`,
|
|
97
|
+
signup: `signup.schema.${ext}`,
|
|
98
|
+
updateMe: `update-me.schema.${ext}`,
|
|
99
|
+
updatePassword: `update-password.schema.${ext}`,
|
|
99
100
|
}
|
|
100
101
|
: {
|
|
101
|
-
model: `${lowerModelName}.schema.${
|
|
102
|
-
create: `create-${lowerModelName}.schema.${
|
|
103
|
-
update: `update-${lowerModelName}.schema.${
|
|
104
|
-
query: `query-${lowerModelName}.schema.${
|
|
102
|
+
model: `${lowerModelName}.schema.${ext}`,
|
|
103
|
+
create: `create-${lowerModelName}.schema.${ext}`,
|
|
104
|
+
update: `update-${lowerModelName}.schema.${ext}`,
|
|
105
|
+
query: `query-${lowerModelName}.schema.${ext}`,
|
|
105
106
|
},
|
|
106
107
|
};
|
|
107
108
|
}
|
|
@@ -190,17 +191,19 @@ const modelRegex = /model\s+(\w+)\s*{/g;
|
|
|
190
191
|
exports.models = [];
|
|
191
192
|
exports.prismaModelsUniqueFields = [];
|
|
192
193
|
function initializePrismaModels(testName) {
|
|
194
|
+
var _a, _b, _c, _d, _e;
|
|
193
195
|
const prismaContent = [];
|
|
194
196
|
const files = getAllPrismaFiles("./prisma");
|
|
195
197
|
for (const file of files) {
|
|
196
198
|
const content = fs_1.default.readFileSync(file, "utf-8");
|
|
197
|
-
if (!prismaContent.includes(content))
|
|
199
|
+
if (!((_a = prismaContent === null || prismaContent === void 0 ? void 0 : prismaContent.includes) === null || _a === void 0 ? void 0 : _a.call(prismaContent, content)))
|
|
198
200
|
prismaContent.push(content);
|
|
199
201
|
}
|
|
200
202
|
const content = prismaContent
|
|
201
203
|
.join("\n")
|
|
202
204
|
.replace(modelRegex, (_, modelName) => {
|
|
203
|
-
|
|
205
|
+
var _a;
|
|
206
|
+
if (!((_a = exports.models === null || exports.models === void 0 ? void 0 : exports.models.includes) === null || _a === void 0 ? void 0 : _a.call(exports.models, modelName)))
|
|
204
207
|
exports.models.push((0, change_case_helpers_1.camelCase)(modelName.trim()));
|
|
205
208
|
return `model ${modelName} {`;
|
|
206
209
|
});
|
|
@@ -221,7 +224,7 @@ function initializePrismaModels(testName) {
|
|
|
221
224
|
trimmedLine.startsWith("//"))
|
|
222
225
|
continue;
|
|
223
226
|
const [fieldName, type] = trimmedLine.split(/\s+/);
|
|
224
|
-
const isUnique = trimmedLine.includes("@unique");
|
|
227
|
+
const isUnique = (_b = trimmedLine === null || trimmedLine === void 0 ? void 0 : trimmedLine.includes) === null || _b === void 0 ? void 0 : _b.call(trimmedLine, "@unique");
|
|
225
228
|
if (isUnique) {
|
|
226
229
|
const existingFields = exports.prismaModelsUniqueFields[model] || [];
|
|
227
230
|
const alreadyExists = existingFields.some((field) => field.name === fieldName &&
|
|
@@ -235,12 +238,14 @@ function initializePrismaModels(testName) {
|
|
|
235
238
|
}
|
|
236
239
|
}
|
|
237
240
|
const cleanType = type === null || type === void 0 ? void 0 : type.replace("[]", "").replace("?", "");
|
|
238
|
-
if (trimmedLine.includes("@relation") ||
|
|
241
|
+
if (((_c = trimmedLine === null || trimmedLine === void 0 ? void 0 : trimmedLine.includes) === null || _c === void 0 ? void 0 : _c.call(trimmedLine, "@relation")) ||
|
|
239
242
|
trimmedLine.match(/\s+\w+(\[\])?(\s+@|$)/) ||
|
|
240
|
-
exports.models.includes((0, change_case_helpers_1.camelCase)(cleanType || ""))) {
|
|
241
|
-
const
|
|
243
|
+
((_d = exports.models === null || exports.models === void 0 ? void 0 : exports.models.includes) === null || _d === void 0 ? void 0 : _d.call(exports.models, (0, change_case_helpers_1.camelCase)(cleanType || "")))) {
|
|
244
|
+
const enumStart = content.indexOf(`enum ${cleanType} {`);
|
|
245
|
+
const typeStart = content.indexOf(`type ${cleanType} {`);
|
|
242
246
|
if (!cleanType ||
|
|
243
|
-
|
|
247
|
+
enumStart >= 0 ||
|
|
248
|
+
typeStart >= 0 ||
|
|
244
249
|
cleanType === "String" ||
|
|
245
250
|
cleanType === "Int" ||
|
|
246
251
|
cleanType === "Float" ||
|
|
@@ -252,7 +257,7 @@ function initializePrismaModels(testName) {
|
|
|
252
257
|
cleanType === "Json") {
|
|
253
258
|
continue;
|
|
254
259
|
}
|
|
255
|
-
if (!(type === null || type === void 0 ? void 0 : type.includes("[]"))) {
|
|
260
|
+
if (!((_e = type === null || type === void 0 ? void 0 : type.includes) === null || _e === void 0 ? void 0 : _e.call(type, "[]"))) {
|
|
256
261
|
relations.singular.push({
|
|
257
262
|
name: fieldName,
|
|
258
263
|
type: cleanType,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/models.helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,0CAEC;AAED,4EAyCC;AAED,sCAwDC;AASD,4DA2CC;AA2BD,8CAgBC;AAOD,wDA2HC;AAUD,0DAKC;AAmBQ,8BAAS;AAAE,oDAAoB;AAzXxC,gDAAwB;AACxB,4CAAoB;AACpB,iFAIiD;AACjD,6CAAiD;AACjD,qDAAgD;AAErC,QAAA,mBAAmB,GAG1B,EAAE,CAAC;AAEP,SAAgB,eAAe,CAAC,SAAiB;IAC/C,OAAO,2BAAmB,CAAC,IAAA,+BAAS,EAAC,SAAS,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,SAAgB,gCAAgC,CAAC,SAAiB;IAChE,MAAM,cAAc,GAAG,IAAA,+BAAS,EAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;IAC1D,MAAM,cAAc,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;IACpD,MAAM,YAAY,GAAG,SAAS,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC;IAExD,OAAO;QACL,IAAI,EAAE;YACJ,OAAO,EAAE,GAAG,cAAc,YAAY,8BAAiB,EAAE;YACzD,UAAU,EAAE,GAAG,cAAc,eAAe,8BAAiB,EAAE;YAC/D,WAAW,EAAE,GAAG,cAAc,gBAAgB,8BAAiB,EAAE;YACjE,WAAW,EAAE,GAAG,cAAc,iBA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,OAAO;IACtD,OAAO,iCAAyB,CAAC,SAAS,CAAC,CAAC;AAC9C,CAAC;AAOD,SAAS,SAAS;IAChB,OAAO,cAAM,CAAC;AAChB,CAAC;AAMD,SAAS,oBAAoB,CAAC,SAAiB;IAC7C,OAAO,gCAAwB,CAAC,SAAS,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport {\n camelCase,\n kebabCase,\n pascalCase,\n} from \"../../utils/helpers/change-case.helpers\";\nimport { userFileExtension } from \"./fs.helpers\";\nimport { importModule } from \"./global.helpers\";\n\nexport let prismaModelsModules: Record<\n string,\n Awaited<ReturnType<typeof importPrismaModelModules>>\n> = {};\n\nexport function getModelModules(modelName: string) {\n return prismaModelsModules[kebabCase(modelName)];\n}\n\nexport function getFileModelModulesFileStructure(modelName: string) {\n const kebabModelName = kebabCase(modelName).toLowerCase();\n const lowerModelName = kebabModelName.toLowerCase();\n const isAuthModule = modelName.toLowerCase() === \"auth\";\n\n return {\n core: {\n service: `${kebabModelName}.service.${userFileExtension}`,\n controller: `${kebabModelName}.controller.${userFileExtension}`,\n middlewares: `${kebabModelName}.middlewares.${userFileExtension}`,\n authConfigs: `${kebabModelName}.auth-configs.${userFileExtension}`,\n prismaQueryOptions: `${kebabModelName}.prisma-query-options.${userFileExtension}`,\n router: `${kebabModelName}.router.${userFileExtension}`,\n },\n dtos: isAuthModule\n ? {\n login: `login.dto.${userFileExtension}`,\n signup: `signup.dto.${userFileExtension}`,\n updateMe: `update-me.dto.${userFileExtension}`,\n updatePassword: `update-password.dto.${userFileExtension}`,\n }\n : {\n model: `${lowerModelName}.dto.${userFileExtension}`,\n create: `create-${lowerModelName}.dto.${userFileExtension}`,\n update: `update-${lowerModelName}.dto.${userFileExtension}`,\n query: `query-${lowerModelName}.dto.${userFileExtension}`,\n },\n schemas: isAuthModule\n ? {\n login: `login.schema.${userFileExtension}`,\n signup: `signup.schema.${userFileExtension}`,\n updateMe: `update-me.schema.${userFileExtension}`,\n updatePassword: `update-password.schema.${userFileExtension}`,\n }\n : {\n model: `${lowerModelName}.schema.${userFileExtension}`,\n create: `create-${lowerModelName}.schema.${userFileExtension}`,\n update: `update-${lowerModelName}.schema.${userFileExtension}`,\n query: `query-${lowerModelName}.schema.${userFileExtension}`,\n },\n };\n}\n\nexport async function processSubdir(\n modelName: string,\n type: \"dtos\" | \"schemas\",\n result: Record<string, any>\n) {\n const moduleDir = path.resolve(\n process.cwd(),\n \"src\",\n \"modules\",\n kebabCase(modelName)\n );\n\n const subdir = path.join(moduleDir, type);\n const pascalModelName = pascalCase(modelName);\n const fileStructure = getFileModelModulesFileStructure(modelName);\n const isAuthModule = modelName.toLowerCase() === \"auth\";\n\n // Skip if directory doesn't exist\n try {\n await fs.promises.access(subdir).catch(() => {\n return; // Directory doesn't exist\n });\n\n await Promise.all(\n Object.entries(fileStructure[type]).map(async ([key, fileName]) => {\n const filePath = path.join(subdir, fileName);\n try {\n const module = await import(filePath).catch(() => null);\n if (module) {\n if (isAuthModule) {\n // Auth module uses different naming conventions\n const pascalKey = key.charAt(0).toUpperCase() + key.slice(1);\n const expectedName = `${pascalKey}${\n type === \"dtos\" ? \"Dto\" : \"Schema\"\n }`;\n result[type][key] = module.default;\n } else {\n // Standard modules\n const expectedName =\n key === \"model\"\n ? `${pascalModelName}${type === \"dtos\" ? \"Dto\" : \"Schema\"}`\n : `${\n key.charAt(0).toUpperCase() + key.slice(1)\n }${pascalModelName}${type === \"dtos\" ? \"Dto\" : \"Schema\"}`;\n\n result[type][key] = module.default;\n }\n }\n } catch (error) {\n // Silent fail - file might not exist\n }\n })\n );\n } catch (error) {\n // Directory doesn't exist, continue silently\n }\n}\n\n/**\n * Dynamically imports model-specific modules for a given model with optimized file handling.\n * Includes special handling for the Auth module.\n *\n * @param {string} modelName - The name of the model (e.g., \"User\", \"Post\", \"Auth\").\n * @returns {Promise<Object>} An object containing the imported modules\n */\nexport async function importPrismaModelModules(\n modelName: string\n): Promise<Record<string, any>> {\n const moduleDir = path.resolve(process.cwd(), \"src\", \"modules\", modelName);\n\n const result: {\n service?: any;\n controller?: any;\n middlewares?: any;\n authConfigs?: any;\n prismaQueryOptions?: any;\n router?: any;\n dtos: Record<string, any>;\n schemas: Record<string, any>;\n } = {\n dtos: {},\n schemas: {},\n };\n\n const fileStructure = getFileModelModulesFileStructure(modelName);\n // Batch process core files\n await Promise.all(\n Object.entries(fileStructure.core).map(async ([key, fileName]) => {\n const filePath = path.join(moduleDir, fileName);\n try {\n const module = await importModule(filePath).catch(() => null);\n if (module) {\n if (key === \"middlewares\") result[key] = module;\n else result[key as keyof typeof result] = module.default || module;\n }\n } catch {}\n })\n );\n\n await Promise.all([\n processSubdir(modelName, \"dtos\", result),\n processSubdir(modelName, \"schemas\", result),\n ]);\n\n // Cache the result\n prismaModelsModules[modelName] = result;\n\n return result;\n}\n\nexport type ModelFieldDefition = {\n name: string;\n type: string;\n isUnique: boolean;\n};\n\n/**\n * Represents the structure of relation fields for Prisma models.\n * It includes both singular (one-to-one) and list (one-to-many) relationships.\n *\n * @typedef {Object} RelationFields\n * @property {Array<{name: string, type: string}>} singular - List of singular relationships.\n * @property {Array<{name: string, type: string}>} list - List of list relationships.\n */\nexport type RelationFields = {\n singular: Omit<ModelFieldDefition, \"isUnique\">[];\n list: Omit<ModelFieldDefition, \"isUnique\">[];\n};\n\n/**\n * Reads the Prisma schema files and extracts all model definitions,\n * identifying their relations (one-to-one and one-to-many).\n */\nexport const prismaModelRelationFields: Record<string, RelationFields> = {};\n\nexport function getAllPrismaFiles(dirPath: string, fileList: string[] = []) {\n const files = fs.readdirSync(dirPath);\n\n files?.forEach((file) => {\n const filePath = path.join(dirPath, file);\n const stat = fs.statSync(filePath);\n\n // Skip migrations folder\n if (stat.isDirectory() && file !== \"migrations\") {\n fileList = getAllPrismaFiles(filePath, fileList);\n } else if (stat.isFile() && file.endsWith(\".prisma\")) {\n fileList.push(filePath);\n }\n });\n\n return fileList;\n}\n\nconst modelRegex = /model\\s+(\\w+)\\s*{/g;\nexport const models: string[] = [];\nexport const prismaModelsUniqueFields: Record<string, ModelFieldDefition[]> =\n [] as any;\n\nexport function initializePrismaModels(testName?: string) {\n const prismaContent: string[] = [];\n\n const files = getAllPrismaFiles(\"./prisma\");\n\n for (const file of files) {\n const content = fs.readFileSync(file, \"utf-8\");\n\n if (!prismaContent.includes(content)) prismaContent.push(content);\n }\n\n const content = prismaContent\n .join(\"\\n\")\n .replace(modelRegex, (_, modelName) => {\n if (!models.includes(modelName)) models.push(camelCase(modelName.trim()));\n return `model ${modelName} {`;\n });\n\n for (const model of models) {\n const modelName = pascalCase(model);\n\n // let modelFile;\n // for (const file of files) {\n // const filePath = path.join(file);\n // const stats = fs.statSync(filePath);\n\n // if (stats.isFile()) {\n // const content = fs.readFileSync(filePath, \"utf-8\");\n // prismaContent.push(content);\n // if (content.includes(`model ${modelName} {`)) {\n // modelFile = file;\n // break;\n // }\n // }\n // }\n\n // if (!modelFile) {\n // return;\n // }\n\n // const content = fs.readFileSync(path.join(modelFile), \"utf-8\");\n const modelStart = content.indexOf(`model ${modelName} {`);\n const modelEnd = content.indexOf(\"}\", modelStart);\n const modelDefinition = content.slice(modelStart, modelEnd);\n\n const relations: RelationFields = {\n singular: [],\n list: [],\n };\n const lines = modelDefinition.split(\"\\n\");\n\n for (const line of lines) {\n const trimmedLine = line.trim();\n\n if (\n !trimmedLine ||\n trimmedLine.startsWith(\"model\") ||\n trimmedLine.startsWith(\"//\")\n )\n continue;\n\n const [fieldName, type] = trimmedLine.split(/\\s+/);\n const isUnique = trimmedLine.includes(\"@unique\");\n\n if (isUnique) {\n const existingFields = prismaModelsUniqueFields[model] || [];\n\n const alreadyExists = existingFields.some(\n (field) =>\n field.name === fieldName &&\n field.type === type &&\n field.isUnique === isUnique\n );\n\n if (!alreadyExists) {\n prismaModelsUniqueFields[model] = [\n ...existingFields,\n { name: fieldName, type, isUnique },\n ];\n }\n }\n\n const cleanType = type?.replace(\"[]\", \"\").replace(\"?\", \"\");\n\n if (\n trimmedLine.includes(\"@relation\") ||\n trimmedLine.match(/\\s+\\w+(\\[\\])?(\\s+@|$)/) ||\n models.includes(camelCase(cleanType || \"\"))\n ) {\n const modelStart = content.indexOf(`enum ${cleanType} {`);\n\n if (\n !cleanType ||\n modelStart >= 0 ||\n cleanType === \"String\" ||\n cleanType === \"Int\" ||\n cleanType === \"Float\" ||\n cleanType === \"Boolean\" ||\n cleanType === \"DateTime\" ||\n cleanType === \"Bytes\" ||\n cleanType === \"Decimal\" ||\n cleanType === \"BigInt\" ||\n cleanType === \"Json\"\n ) {\n continue;\n }\n\n if (!type?.includes(\"[]\")) {\n relations.singular.push({\n name: fieldName,\n type: cleanType,\n });\n } else {\n relations.list.push({\n name: fieldName,\n type: cleanType,\n });\n }\n }\n\n prismaModelRelationFields[modelName] = relations;\n }\n }\n}\n\ninitializePrismaModels();\n\n/**\n * Retrieves the relations for a given Prisma model.\n *\n * @param {string} modelName - The name of the model (e.g., \"User\").\n * @returns {RelationFields|undefined} The relation fields for the model, or `undefined` if no relations are found.\n */\nexport function getPrismaModelRelations(modelName: string) {\n modelName = pascalCase(modelName);\n\n if (!(modelName in prismaModelRelationFields)) return;\n return prismaModelRelationFields[modelName];\n}\n\n/**\n * Retrieves all the model names from the Prisma schema.\n *\n * @returns {string[]} An array of model names (e.g., [\"User\", \"Post\"]).\n */\nfunction getModels() {\n return models;\n}\n\n/** Retuns a given model unique fields\n * @param {string} modelName - The name of model in PascalCase\n * @returns {string[]} An array of all unique fields,\n */\nfunction getModelUniqueFields(modelName: string) {\n return prismaModelsUniqueFields[modelName];\n}\n\nexport { getModels, getModelUniqueFields };\n"]}
|
|
1
|
+
{"version":3,"file":"models.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/models.helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,0CAEC;AAED,4EA0CC;AAED,sCAwDC;AASD,4DA2CC;AA2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wB,CAAC,SAAS,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport {\n camelCase,\n kebabCase,\n pascalCase,\n} from \"../../utils/helpers/change-case.helpers\";\nimport { getUserFileExtension } from \"./fs.helpers\";\nimport { importModule } from \"./global.helpers\";\n\nexport let prismaModelsModules: Record<\n string,\n Awaited<ReturnType<typeof importPrismaModelModules>>\n> = {};\n\nexport function getModelModules(modelName: string) {\n return prismaModelsModules[kebabCase(modelName)];\n}\n\nexport function getFileModelModulesFileStructure(modelName: string) {\n const kebabModelName = kebabCase(modelName).toLowerCase();\n const lowerModelName = kebabModelName.toLowerCase();\n const isAuthModule = modelName.toLowerCase() === \"auth\";\n const ext = getUserFileExtension();\n\n return {\n core: {\n service: `${kebabModelName}.service.${ext}`,\n controller: `${kebabModelName}.controller.${ext}`,\n middlewares: `${kebabModelName}.middlewares.${ext}`,\n authConfigs: `${kebabModelName}.auth-configs.${ext}`,\n prismaQueryOptions: `${kebabModelName}.prisma-query-options.${ext}`,\n router: `${kebabModelName}.router.${ext}`,\n },\n dtos: isAuthModule\n ? {\n login: `login.dto.${ext}`,\n signup: `signup.dto.${ext}`,\n updateMe: `update-me.dto.${ext}`,\n updatePassword: `update-password.dto.${ext}`,\n }\n : {\n model: `${lowerModelName}.dto.${ext}`,\n create: `create-${lowerModelName}.dto.${ext}`,\n update: `update-${lowerModelName}.dto.${ext}`,\n query: `query-${lowerModelName}.dto.${ext}`,\n },\n schemas: isAuthModule\n ? {\n login: `login.schema.${ext}`,\n signup: `signup.schema.${ext}`,\n updateMe: `update-me.schema.${ext}`,\n updatePassword: `update-password.schema.${ext}`,\n }\n : {\n model: `${lowerModelName}.schema.${ext}`,\n create: `create-${lowerModelName}.schema.${ext}`,\n update: `update-${lowerModelName}.schema.${ext}`,\n query: `query-${lowerModelName}.schema.${ext}`,\n },\n };\n}\n\nexport async function processSubdir(\n modelName: string,\n type: \"dtos\" | \"schemas\",\n result: Record<string, any>\n) {\n const moduleDir = path.resolve(\n process.cwd(),\n \"src\",\n \"modules\",\n kebabCase(modelName)\n );\n\n const subdir = path.join(moduleDir, type);\n const pascalModelName = pascalCase(modelName);\n const fileStructure = getFileModelModulesFileStructure(modelName);\n const isAuthModule = modelName.toLowerCase() === \"auth\";\n\n // Skip if directory doesn't exist\n try {\n await fs.promises.access(subdir).catch(() => {\n return; // Directory doesn't exist\n });\n\n await Promise.all(\n Object.entries(fileStructure[type]).map(async ([key, fileName]) => {\n const filePath = path.join(subdir, fileName);\n try {\n const module = await import(filePath).catch(() => null);\n if (module) {\n if (isAuthModule) {\n // Auth module uses different naming conventions\n const pascalKey = key.charAt(0).toUpperCase() + key.slice(1);\n const expectedName = `${pascalKey}${\n type === \"dtos\" ? \"Dto\" : \"Schema\"\n }`;\n result[type][key] = module.default;\n } else {\n // Standard modules\n const expectedName =\n key === \"model\"\n ? `${pascalModelName}${type === \"dtos\" ? \"Dto\" : \"Schema\"}`\n : `${\n key.charAt(0).toUpperCase() + key.slice(1)\n }${pascalModelName}${type === \"dtos\" ? \"Dto\" : \"Schema\"}`;\n\n result[type][key] = module.default;\n }\n }\n } catch (error) {\n // Silent fail - file might not exist\n }\n })\n );\n } catch (error) {\n // Directory doesn't exist, continue silently\n }\n}\n\n/**\n * Dynamically imports model-specific modules for a given model with optimized file handling.\n * Includes special handling for the Auth module.\n *\n * @param {string} modelName - The name of the model (e.g., \"User\", \"Post\", \"Auth\").\n * @returns {Promise<Object>} An object containing the imported modules\n */\nexport async function importPrismaModelModules(\n modelName: string\n): Promise<Record<string, any>> {\n const moduleDir = path.resolve(process.cwd(), \"src\", \"modules\", modelName);\n\n const result: {\n service?: any;\n controller?: any;\n middlewares?: any;\n authConfigs?: any;\n prismaQueryOptions?: any;\n router?: any;\n dtos: Record<string, any>;\n schemas: Record<string, any>;\n } = {\n dtos: {},\n schemas: {},\n };\n\n const fileStructure = getFileModelModulesFileStructure(modelName);\n // Batch process core files\n await Promise.all(\n Object.entries(fileStructure.core).map(async ([key, fileName]) => {\n const filePath = path.join(moduleDir, fileName);\n try {\n const module = await importModule(filePath).catch(() => null);\n if (module) {\n if (key === \"middlewares\") result[key] = module;\n else result[key as keyof typeof result] = module.default || module;\n }\n } catch {}\n })\n );\n\n await Promise.all([\n processSubdir(modelName, \"dtos\", result),\n processSubdir(modelName, \"schemas\", result),\n ]);\n\n // Cache the result\n prismaModelsModules[modelName] = result;\n\n return result;\n}\n\nexport type ModelFieldDefition = {\n name: string;\n type: string;\n isUnique: boolean;\n};\n\n/**\n * Represents the structure of relation fields for Prisma models.\n * It includes both singular (one-to-one) and list (one-to-many) relationships.\n *\n * @typedef {Object} RelationFields\n * @property {Array<{name: string, type: string}>} singular - List of singular relationships.\n * @property {Array<{name: string, type: string}>} list - List of list relationships.\n */\nexport type RelationFields = {\n singular: Omit<ModelFieldDefition, \"isUnique\">[];\n list: Omit<ModelFieldDefition, \"isUnique\">[];\n};\n\n/**\n * Reads the Prisma schema files and extracts all model definitions,\n * identifying their relations (one-to-one and one-to-many).\n */\nexport const prismaModelRelationFields: Record<string, RelationFields> = {};\n\nexport function getAllPrismaFiles(dirPath: string, fileList: string[] = []) {\n const files = fs.readdirSync(dirPath);\n\n files?.forEach((file) => {\n const filePath = path.join(dirPath, file);\n const stat = fs.statSync(filePath);\n\n // Skip migrations folder\n if (stat.isDirectory() && file !== \"migrations\") {\n fileList = getAllPrismaFiles(filePath, fileList);\n } else if (stat.isFile() && file.endsWith(\".prisma\")) {\n fileList.push(filePath);\n }\n });\n\n return fileList;\n}\n\nconst modelRegex = /model\\s+(\\w+)\\s*{/g;\nexport const models: string[] = [];\nexport const prismaModelsUniqueFields: Record<string, ModelFieldDefition[]> =\n [] as any;\n\nexport function initializePrismaModels(testName?: string) {\n const prismaContent: string[] = [];\n\n const files = getAllPrismaFiles(\"./prisma\");\n\n for (const file of files) {\n const content = fs.readFileSync(file, \"utf-8\");\n\n if (!prismaContent?.includes?.(content)) prismaContent.push(content);\n }\n\n const content = prismaContent\n .join(\"\\n\")\n .replace(modelRegex, (_, modelName) => {\n if (!models?.includes?.(modelName))\n models.push(camelCase(modelName.trim()));\n return `model ${modelName} {`;\n });\n\n for (const model of models) {\n const modelName = pascalCase(model);\n\n const modelStart = content.indexOf(`model ${modelName} {`);\n const modelEnd = content.indexOf(\"}\", modelStart);\n const modelDefinition = content.slice(modelStart, modelEnd);\n\n const relations: RelationFields = {\n singular: [],\n list: [],\n };\n const lines = modelDefinition.split(\"\\n\");\n\n for (const line of lines) {\n const trimmedLine = line.trim();\n\n if (\n !trimmedLine ||\n trimmedLine.startsWith(\"model\") ||\n trimmedLine.startsWith(\"//\")\n )\n continue;\n\n const [fieldName, type] = trimmedLine.split(/\\s+/);\n const isUnique = trimmedLine?.includes?.(\"@unique\");\n\n if (isUnique) {\n const existingFields = prismaModelsUniqueFields[model] || [];\n\n const alreadyExists = existingFields.some(\n (field) =>\n field.name === fieldName &&\n field.type === type &&\n field.isUnique === isUnique\n );\n\n if (!alreadyExists) {\n prismaModelsUniqueFields[model] = [\n ...existingFields,\n { name: fieldName, type, isUnique },\n ];\n }\n }\n\n const cleanType = type?.replace(\"[]\", \"\").replace(\"?\", \"\");\n\n if (\n trimmedLine?.includes?.(\"@relation\") ||\n trimmedLine.match(/\\s+\\w+(\\[\\])?(\\s+@|$)/) ||\n models?.includes?.(camelCase(cleanType || \"\"))\n ) {\n const enumStart = content.indexOf(`enum ${cleanType} {`);\n const typeStart = content.indexOf(`type ${cleanType} {`);\n\n if (\n !cleanType ||\n enumStart >= 0 ||\n typeStart >= 0 ||\n cleanType === \"String\" ||\n cleanType === \"Int\" ||\n cleanType === \"Float\" ||\n cleanType === \"Boolean\" ||\n cleanType === \"DateTime\" ||\n cleanType === \"Bytes\" ||\n cleanType === \"Decimal\" ||\n cleanType === \"BigInt\" ||\n cleanType === \"Json\"\n\n // && !content.includes?.(`model ${cleanType} {`)\n ) {\n continue;\n }\n\n if (!type?.includes?.(\"[]\")) {\n relations.singular.push({\n name: fieldName,\n type: cleanType,\n });\n } else {\n relations.list.push({\n name: fieldName,\n type: cleanType,\n });\n }\n }\n\n prismaModelRelationFields[modelName] = relations;\n }\n }\n}\n\ninitializePrismaModels();\n\n/**\n * Retrieves the relations for a given Prisma model.\n *\n * @param {string} modelName - The name of the model (e.g., \"User\").\n * @returns {RelationFields|undefined} The relation fields for the model, or `undefined` if no relations are found.\n */\nexport function getPrismaModelRelations(modelName: string) {\n modelName = pascalCase(modelName);\n\n if (!(modelName in prismaModelRelationFields)) return;\n return prismaModelRelationFields[modelName];\n}\n\n/**\n * Retrieves all the model names from the Prisma schema.\n *\n * @returns {string[]} An array of model names (e.g., [\"User\", \"Post\"]).\n */\nfunction getModels() {\n return models;\n}\n\n/** Retuns a given model unique fields\n * @param {string} modelName - The name of model in PascalCase\n * @returns {string[]} An array of all unique fields,\n */\nfunction getModelUniqueFields(modelName: string) {\n return prismaModelsUniqueFields[modelName];\n}\n\nexport { getModels, getModelUniqueFields };\n"]}
|