arkos 1.4.0-canary.92 → 1.4.1-canary.10
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/index.js.map +1 -1
- package/dist/cjs/modules/auth/auth.controller.js +1 -1
- package/dist/cjs/modules/auth/auth.controller.js.map +1 -1
- package/dist/cjs/modules/auth/auth.service.js +3 -4
- package/dist/cjs/modules/auth/auth.service.js.map +1 -1
- package/dist/cjs/modules/auth/utils/services/auth-action.service.js +56 -8
- package/dist/cjs/modules/auth/utils/services/auth-action.service.js.map +1 -1
- package/dist/cjs/modules/base/base.controller.js +6 -3
- package/dist/cjs/modules/base/base.controller.js.map +1 -1
- package/dist/cjs/modules/base/base.middlewares.js +17 -5
- package/dist/cjs/modules/base/base.middlewares.js.map +1 -1
- package/dist/cjs/modules/error-handler/error-handler.controller.js +2 -2
- package/dist/cjs/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/cjs/modules/error-handler/utils/catch-async.js.map +1 -1
- package/dist/cjs/modules/swagger/swagger.router.js +6 -4
- package/dist/cjs/modules/swagger/swagger.router.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/built-in-route-path-object-manager.js +7 -0
- package/dist/cjs/modules/swagger/utils/built-in-route-path-object-manager.js.map +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +308 -183
- package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-file-upload-json-schema-paths.js +357 -288
- package/dist/cjs/modules/swagger/utils/helpers/get-file-upload-json-schema-paths.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-swagger-default-configs.js +1 -5
- package/dist/cjs/modules/swagger/utils/helpers/get-swagger-default-configs.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js +280 -243
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js +3 -0
- package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js +8 -6
- package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -1
- package/dist/cjs/server.js +17 -15
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/new-arkos-config.js.map +1 -1
- package/dist/cjs/utils/arkos-router/index.js +50 -10
- package/dist/cjs/utils/arkos-router/index.js.map +1 -1
- package/dist/cjs/utils/arkos-router/types/index.js.map +1 -1
- package/dist/cjs/utils/arkos-router/utils/helpers/index.js +11 -0
- package/dist/cjs/utils/arkos-router/utils/helpers/index.js.map +1 -1
- package/dist/cjs/utils/cli/dev.js +13 -55
- package/dist/cjs/utils/cli/dev.js.map +1 -1
- package/dist/cjs/utils/cli/export-auth-action.js +1 -1
- package/dist/cjs/utils/cli/export-auth-action.js.map +1 -1
- package/dist/cjs/utils/cli/generate.js +3 -3
- package/dist/cjs/utils/cli/generate.js.map +1 -1
- package/dist/cjs/utils/cli/index.js +1 -1
- package/dist/cjs/utils/cli/index.js.map +1 -1
- package/dist/cjs/utils/cli/start.js +19 -12
- package/dist/cjs/utils/cli/start.js.map +1 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/cjs/utils/cli/utils/runtime-cli-commander.js +51 -6
- package/dist/cjs/utils/cli/utils/runtime-cli-commander.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/class-validator/create-dto-template.js +3 -3
- package/dist/cjs/utils/cli/utils/template-generator/templates/class-validator/create-dto-template.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/class-validator/update-dto-template.js +3 -3
- package/dist/cjs/utils/cli/utils/template-generator/templates/class-validator/update-dto-template.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/middlewares-template.js +6 -3
- package/dist/cjs/utils/cli/utils/template-generator/templates/middlewares-template.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/router-template.js +3 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/router-template.js.map +1 -1
- package/dist/cjs/utils/dotenv.helpers.js +15 -7
- package/dist/cjs/utils/dotenv.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/api.features.helpers.js +174 -81
- package/dist/cjs/utils/helpers/api.features.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/prisma.helpers.js +40 -1
- package/dist/cjs/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/routers.helpers.js +0 -1
- package/dist/cjs/utils/helpers/routers.helpers.js.map +1 -1
- package/dist/cjs/utils/prisma/prisma-json-schema-generator.js +13 -4
- package/dist/cjs/utils/prisma/prisma-json-schema-generator.js.map +1 -1
- package/dist/cjs/utils/validate-dto.js +1 -5
- package/dist/cjs/utils/validate-dto.js.map +1 -1
- package/dist/cjs/utils/validate-schema.js +2 -7
- package/dist/cjs/utils/validate-schema.js.map +1 -1
- package/dist/esm/app.js +1 -1
- package/dist/esm/app.js.map +1 -1
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/modules/auth/auth.controller.js +1 -1
- package/dist/esm/modules/auth/auth.controller.js.map +1 -1
- package/dist/esm/modules/auth/auth.service.js +4 -5
- package/dist/esm/modules/auth/auth.service.js.map +1 -1
- package/dist/esm/modules/auth/utils/services/auth-action.service.js +56 -5
- package/dist/esm/modules/auth/utils/services/auth-action.service.js.map +1 -1
- package/dist/esm/modules/base/base.controller.js +6 -3
- package/dist/esm/modules/base/base.controller.js.map +1 -1
- package/dist/esm/modules/base/base.middlewares.js +17 -5
- package/dist/esm/modules/base/base.middlewares.js.map +1 -1
- package/dist/esm/modules/error-handler/error-handler.controller.js +2 -2
- package/dist/esm/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/esm/modules/error-handler/utils/catch-async.js.map +1 -1
- package/dist/esm/modules/swagger/swagger.router.js +6 -4
- package/dist/esm/modules/swagger/swagger.router.js.map +1 -1
- package/dist/esm/modules/swagger/utils/built-in-route-path-object-manager.js +5 -0
- package/dist/esm/modules/swagger/utils/built-in-route-path-object-manager.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +308 -183
- package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/get-file-upload-json-schema-paths.js +357 -288
- package/dist/esm/modules/swagger/utils/helpers/get-file-upload-json-schema-paths.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/get-swagger-default-configs.js +1 -2
- package/dist/esm/modules/swagger/utils/helpers/get-swagger-default-configs.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js +280 -243
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/missing-json-schemas-generator.js +3 -0
- package/dist/esm/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js +8 -6
- package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -1
- package/dist/esm/server.js +17 -15
- package/dist/esm/server.js.map +1 -1
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/new-arkos-config.js.map +1 -1
- package/dist/esm/utils/arkos-router/index.js +51 -11
- package/dist/esm/utils/arkos-router/index.js.map +1 -1
- package/dist/esm/utils/arkos-router/types/index.js.map +1 -1
- package/dist/esm/utils/arkos-router/utils/helpers/index.js +10 -0
- package/dist/esm/utils/arkos-router/utils/helpers/index.js.map +1 -1
- package/dist/esm/utils/cli/dev.js +14 -56
- package/dist/esm/utils/cli/dev.js.map +1 -1
- package/dist/esm/utils/cli/export-auth-action.js +1 -1
- package/dist/esm/utils/cli/export-auth-action.js.map +1 -1
- package/dist/esm/utils/cli/generate.js +3 -3
- package/dist/esm/utils/cli/generate.js.map +1 -1
- package/dist/esm/utils/cli/index.js +1 -1
- package/dist/esm/utils/cli/index.js.map +1 -1
- package/dist/esm/utils/cli/start.js +19 -12
- package/dist/esm/utils/cli/start.js.map +1 -1
- package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/esm/utils/cli/utils/runtime-cli-commander.js +52 -7
- package/dist/esm/utils/cli/utils/runtime-cli-commander.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/class-validator/create-dto-template.js +3 -3
- package/dist/esm/utils/cli/utils/template-generator/templates/class-validator/create-dto-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/class-validator/update-dto-template.js +3 -3
- package/dist/esm/utils/cli/utils/template-generator/templates/class-validator/update-dto-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/middlewares-template.js +6 -3
- package/dist/esm/utils/cli/utils/template-generator/templates/middlewares-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/router-template.js +3 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/router-template.js.map +1 -1
- package/dist/esm/utils/dotenv.helpers.js +15 -7
- package/dist/esm/utils/dotenv.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/api.features.helpers.js +174 -81
- package/dist/esm/utils/helpers/api.features.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/prisma.helpers.js +39 -1
- package/dist/esm/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/routers.helpers.js +0 -1
- package/dist/esm/utils/helpers/routers.helpers.js.map +1 -1
- package/dist/esm/utils/prisma/prisma-json-schema-generator.js +13 -4
- package/dist/esm/utils/prisma/prisma-json-schema-generator.js.map +1 -1
- package/dist/esm/utils/validate-dto.js +1 -2
- package/dist/esm/utils/validate-dto.js.map +1 -1
- package/dist/esm/utils/validate-schema.js +2 -4
- package/dist/esm/utils/validate-schema.js.map +1 -1
- package/dist/types/exports/index.d.ts +2 -1
- package/dist/types/modules/auth/auth.router.d.ts +1 -1
- package/dist/types/modules/auth/auth.service.d.ts +2 -2
- package/dist/types/modules/base/base.router.d.ts +1 -1
- package/dist/types/modules/swagger/utils/built-in-route-path-object-manager.d.ts +4 -0
- package/dist/types/modules/swagger/utils/helpers/get-authentication-json-schema-paths.d.ts +1 -1
- package/dist/types/modules/swagger/utils/helpers/get-file-upload-json-schema-paths.d.ts +1 -1
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.d.ts +1 -1
- package/dist/types/modules/swagger/utils/helpers/swagger.router.helpers.d.ts +1 -1
- package/dist/types/types/index.d.ts +5 -5
- package/dist/types/types/new-arkos-config.d.ts +1 -1
- package/dist/types/utils/arkos-router/index.d.ts +2 -1
- package/dist/types/utils/arkos-router/types/index.d.ts +15 -14
- package/dist/types/utils/arkos-router/utils/helpers/index.d.ts +1 -0
- package/dist/types/utils/cli/dev.d.ts +1 -1
- package/dist/types/utils/cli/start.d.ts +1 -1
- package/dist/types/utils/helpers/prisma.helpers.d.ts +1 -0
- package/package.json +2 -2
|
@@ -13,7 +13,7 @@ const watermark_stamper_1 = __importDefault(require("./utils/watermark-stamper")
|
|
|
13
13
|
async function exportAuthActionCommand(options) {
|
|
14
14
|
process.env.CLI_COMMAND = "EXPORT_AUTH_ACTION";
|
|
15
15
|
process.env.CLI_COMMAND_OPTIONS = JSON.stringify(options);
|
|
16
|
-
if (
|
|
16
|
+
if (!process.env.NODE_ENV)
|
|
17
17
|
process.env.NODE_ENV = "development";
|
|
18
18
|
const envFiles = (0, dotenv_helpers_1.loadEnvironmentVariables)() || [];
|
|
19
19
|
let child = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export-auth-action.js","sourceRoot":"","sources":["../../../../src/utils/cli/export-auth-action.ts"],"names":[],"mappings":";;;;;AAOA,
|
|
1
|
+
{"version":3,"file":"export-auth-action.js","sourceRoot":"","sources":["../../../../src/utils/cli/export-auth-action.ts"],"names":[],"mappings":";;;;;AAOA,0CAkFC;AAzFD,iDAAoD;AACpD,sDAA6D;AAC7D,sDAA6D;AAC7D,gDAAwB;AACxB,4CAAoB;AACpB,kFAAyD;AAE1C,KAAK,UAAU,uBAAuB,CAAC,OAGrD;IACC,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,oBAAoB,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,mBAAmB,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAE1D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ;QAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,aAAa,CAAC;IAEhE,MAAM,QAAQ,GAAG,IAAA,yCAAwB,GAAE,IAAI,EAAE,CAAC;IAClD,IAAI,KAAK,GAAwB,IAAI,CAAC;IAEtC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAA,iCAAoB,GAAE,CAAC;QACvC,MAAM,UAAU,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,WAAW,OAAO,EAAE,CAAC,CAAC;QAErE,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/B,OAAO,CAAC,KAAK,CAAC,6CAA6C,UAAU,EAAE,CAAC,CAAC;YACzE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,MAAM,MAAM,GAAG,GAAG,EAAE,CAClB,CAAC;YACC,QAAQ,EAAE,aAAa;YACvB,GAAG,OAAO,CAAC,GAAG;YACd,GAAG,EAAE,OAAO;SACb,CAA4B,CAAC;QAEhC,MAAM,WAAW,GAAG,GAA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,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;QAE5D,IAAI,KAAK,EAAE,CAAC;YACT,KAAsB,EAAE,IAAI,EAAE,EAAE,CAAC;YAClC,KAAK,GAAG,IAAI,CAAC;QACf,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC","sourcesContent":["import { ChildProcess, spawn } from \"child_process\";\nimport { loadEnvironmentVariables } from \"../dotenv.helpers\";\nimport { getUserFileExtension } from \"../helpers/fs.helpers\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport watermarkStamper from \"./utils/watermark-stamper\";\n\nexport default async function exportAuthActionCommand(options: {\n overwrite?: boolean;\n path?: string;\n}) {\n process.env.CLI_COMMAND = \"EXPORT_AUTH_ACTION\";\n process.env.CLI_COMMAND_OPTIONS = JSON.stringify(options);\n\n if (!process.env.NODE_ENV) process.env.NODE_ENV = \"development\";\n\n const envFiles = loadEnvironmentVariables() || [];\n let child: ChildProcess | null = null;\n\n try {\n const fileExt = getUserFileExtension();\n const entryPoint = path.resolve(process.cwd(), `src/app.${fileExt}`);\n\n if (!fs.existsSync(entryPoint)) {\n console.error(`Could not find application entry point at ${entryPoint}`);\n process.exit(1);\n }\n\n const getEnv = () =>\n ({\n NODE_ENV: \"development\",\n ...process.env,\n CLI: \"false\",\n }) as { [x: string]: string };\n\n const startServer = () => {\n if (child) {\n child.kill();\n child = null;\n }\n\n const env = getEnv();\n\n child = spawn(\"npx\", [\"tsx-strict\", \"--no-type-check\", entryPoint], {\n stdio: \"inherit\",\n env,\n shell: true,\n });\n\n if (child)\n child.on(\"error\", (error) => {\n console.error(\"Failed to start server:\", error);\n });\n };\n\n startServer();\n\n watermarkStamper.stamp({\n envFiles,\n });\n\n const cleanup = () => {\n if (child) {\n child.kill(\"SIGTERM\");\n setTimeout(() => {\n if (child && !child.killed) child.kill(\"SIGKILL\");\n }, 5000);\n }\n\n process.exit(0);\n };\n\n process.on(\"SIGINT\", cleanup);\n process.on(\"SIGTERM\", cleanup);\n\n process.on(\"uncaughtException\", (error) => {\n console.error(\"Uncaught Exception:\", error);\n cleanup();\n });\n } catch (error) {\n console.error(\"Development server failed to start:\", error);\n\n if (child) {\n (child as ChildProcess)?.kill?.();\n child = null;\n }\n\n process.exit(1);\n }\n}\n"]}
|
|
@@ -55,10 +55,10 @@ const generateFile = async (options, config) => {
|
|
|
55
55
|
};
|
|
56
56
|
const content = (0, template_generators_1.generateTemplate)(config.templateName, templateData);
|
|
57
57
|
if (fs_1.default.existsSync(filePath))
|
|
58
|
-
throw new Error(`${(0, text_helpers_1.capitalize)(humamReadableTemplateName.toLowerCase())} for ${
|
|
58
|
+
throw new Error(`${(0, text_helpers_1.capitalize)(humamReadableTemplateName.toLowerCase())} for ${names.kebab.replace("-", "")} already exists.`);
|
|
59
59
|
fs_1.default.writeFileSync(filePath, content);
|
|
60
60
|
console.info("");
|
|
61
|
-
sheu_1.default.done(`${humamReadableTemplateName} for ${
|
|
61
|
+
sheu_1.default.done(`${humamReadableTemplateName} for ${names.kebab.replace("-", "")} generated under ${(0, fs_helpers_1.fullCleanCwd)(filePath)}`);
|
|
62
62
|
}
|
|
63
63
|
catch (err) {
|
|
64
64
|
console.info("");
|
|
@@ -84,7 +84,7 @@ exports.generateCommand = {
|
|
|
84
84
|
customImports: () => ({
|
|
85
85
|
baseService: "arkos/services",
|
|
86
86
|
}),
|
|
87
|
-
allowedModules: knownModules,
|
|
87
|
+
allowedModules: [...knownModules, "email"],
|
|
88
88
|
});
|
|
89
89
|
},
|
|
90
90
|
router: async (options) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../../src/utils/cli/generate.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,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,MAAM,EAAE,SAAS;YACjB,cAAc,EAAE,MAAM;SACvB,CAAC,CAAC;IACL,CAAC;IAED,YAAY,EAAE,KAAK,EAAE,OAAwB,EAAE,EAAE;QAC/C,MAAM,YAAY,CAAC,OAAO,EAAE;YAC1B,YAAY,EAAE,eAAe;YAC7B,UAAU,EAAE,QAAQ;YACpB,UAAU,EAAE,qCAAqC;YACjD,MAAM,EAAE,SAAS;YACjB,cAAc,EAAE,MAAM;SACvB,CAAC,CAAC;IACL,CAAC;IAED,SAAS,EAAE,KAAK,EAAE,OAAwB,EAAE,EAAE;QAC5C,MAAM,YAAY,CAAC,OAAO,EAAE;YAC1B,YAAY,EAAE,YAAY;YAC1B,UAAU,EAAE,KAAK;YACjB,UAAU,EAAE,kCAAkC;YAC9C,MAAM,EAAE,SAAS;YACjB,cAAc,EAAE,MAAM;SACvB,CAAC,CAAC;IACL,CAAC;IAED,SAAS,EAAE,KAAK,EAAE,OAAwB,EAAE,EAAE;QAC5C,MAAM,YAAY,CAAC,OAAO,EAAE;YAC1B,YAAY,EAAE,YAAY;YAC1B,UAAU,EAAE,KAAK;YACjB,UAAU,EAAE,kCAAkC;YAC9C,MAAM,EAAE,SAAS;YACjB,cAAc,EAAE,MAAM;SACvB,CAAC,CAAC;IACL,CAAC;IAED,YAAY,EAAE,KAAK,EAAE,OAAwB,EAAE,EAAE;QAC/C,MAAM,YAAY,CAAC,OAAO,EAAE;YAC1B,YAAY,EAAE,eAAe;YAC7B,UAAU,EAAE,OAAO;YACnB,cAAc,EAAE,YAAY;SAC7B,CAAC,CAAC;IACL,CAAC;CACF,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport { generateTemplate } from \"./utils/template-generators\";\nimport { ensureDirectoryExists } from \"./utils/cli.helpers\";\nimport {\n camelCase,\n kebabCase,\n pascalCase,\n} from \"../helpers/change-case.helpers\";\nimport { fullCleanCwd, getUserFileExtension } from \"../helpers/fs.helpers\";\nimport sheu from \"../sheu\";\nimport { capitalize } from \"../helpers/text.helpers\";\nimport prismaSchemaParser from \"../prisma/prisma-schema-parser\";\nimport { kebabToHuman } from \"../../modules/swagger/utils/helpers/swagger.router.helpers\";\n\nconst models = prismaSchemaParser\n .getModelsAsArrayOfStrings()\n .map((val) => kebabCase(val));\n\nconst knownModules = [...models, \"file-upload\", \"auth\"];\n\ninterface GenerateOptions {\n path?: string;\n model?: string;\n module?: string;\n}\n\ninterface GenerateConfig {\n templateName: string;\n fileSuffix: string;\n customValidation?: (modelName: string) => void;\n customImports?: (names: any) => any;\n customPath?: string;\n prefix?: string;\n allowedModules: string[];\n}\n\nconst generateFile = async (\n options: GenerateOptions,\n config: GenerateConfig\n) => {\n const modelName = options.module || options.model;\n\n if (options.module && options.model)\n throw Error(\n \"You must either pass --module or --model, prefer --module to align with future updates.\"\n );\n\n if (!modelName?.trim()) throw new Error(\"Module name is required!\");\n\n const isAllowedModule = config.allowedModules.includes(kebabCase(modelName));\n const isKnowModule = config.allowedModules.includes(kebabCase(modelName));\n\n if (!isKnowModule)\n throw new Error(\n `Generate command are only available for know modules such as all prisma models, file-upload and auth. And you passed ${modelName}.`\n );\n else if (!isAllowedModule)\n throw Error(\n `${kebabToHuman(kebabCase(config.templateName))} are not available for module ${modelName}`\n );\n\n if (config.customValidation) config.customValidation(modelName);\n\n const { path: customPath = \"src/modules/{{module-name}}\" } = options;\n\n const names = {\n pascal: pascalCase(modelName),\n camel: camelCase(modelName),\n kebab: kebabCase(modelName),\n };\n\n const ext = getUserFileExtension();\n\n const resolvedPath = (config.customPath || customPath).replaceAll(\n \"{{module-name}}\",\n names.kebab\n );\n\n const modulePath = path.join(process.cwd(), resolvedPath);\n\n const fileName = config.prefix\n ? `${config.prefix}${names.kebab}.${config.fileSuffix}.${ext}`\n : `${names.kebab}.${config.fileSuffix}.${ext}`;\n\n const filePath = path.join(modulePath, fileName);\n\n const humamReadableTemplateName =\n config.templateName.charAt(0).toUpperCase() +\n config.templateName.slice(1).replaceAll(\"-\", \" \");\n\n try {\n ensureDirectoryExists(modulePath);\n\n const templateData = {\n modelName: names,\n ...(config.customImports && { imports: config.customImports(names) }),\n };\n\n const content = generateTemplate(config.templateName, templateData);\n if (fs.existsSync(filePath))\n throw new Error(\n `${capitalize(humamReadableTemplateName.toLowerCase())} for ${options.model} already exists.`\n );\n fs.writeFileSync(filePath, content);\n\n console.info(\"\");\n sheu.done(\n `${humamReadableTemplateName} for ${options.model} generated under ${fullCleanCwd(filePath)}`\n );\n } catch (err: any) {\n console.info(\"\");\n sheu.error(\n `Failed because of ${err?.message?.toLowerCase() || \"unknown reason\"}`\n );\n process.exit(1);\n }\n};\n\nexport const generateCommand = {\n controller: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"controller\",\n fileSuffix: \"controller\",\n customImports: () => ({\n baseController: \"arkos/controllers\",\n }),\n allowedModules: knownModules,\n });\n },\n\n service: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"service\",\n fileSuffix: \"service\",\n customImports: () => ({\n baseService: \"arkos/services\",\n }),\n allowedModules: knownModules,\n });\n },\n\n router: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"router\",\n fileSuffix: \"router\",\n customImports: (names) => ({\n baseRouter: \"arkos\",\n controller: `./${names.kebab}.controller`,\n }),\n allowedModules: knownModules,\n });\n },\n\n interceptors: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"interceptors\",\n fileSuffix: \"interceptors\",\n allowedModules: knownModules,\n });\n },\n\n authConfigs: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"auth-configs\",\n fileSuffix: \"auth\",\n allowedModules: knownModules,\n });\n },\n\n hooks: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"hooks\",\n fileSuffix: \"hooks\",\n allowedModules: knownModules,\n });\n },\n\n createSchema: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"create-schema\",\n fileSuffix: \"schema\",\n customPath: \"src/modules/{{module-name}}/schemas\",\n prefix: \"create-\",\n allowedModules: models,\n });\n },\n\n updateSchema: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"update-schema\",\n fileSuffix: \"schema\",\n customPath: \"src/modules/{{module-name}}/schemas\",\n prefix: \"update-\",\n allowedModules: models,\n });\n },\n\n createDto: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"create-dto\",\n fileSuffix: \"dto\",\n customPath: \"src/modules/{{module-name}}/dtos\",\n prefix: \"create-\",\n allowedModules: models,\n });\n },\n\n updateDto: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"update-dto\",\n fileSuffix: \"dto\",\n customPath: \"src/modules/{{module-name}}/dtos\",\n prefix: \"update-\",\n allowedModules: models,\n });\n },\n\n queryOptions: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"query-options\",\n fileSuffix: \"query\",\n allowedModules: knownModules,\n });\n },\n};\n"]}
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../../src/utils/cli/generate.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,qEAA+D;AAC/D,qDAA4D;AAC5D,wEAIwC;AACxC,sDAA2E;AAC3E,mDAA2B;AAC3B,0DAAqD;AACrD,0FAAgE;AAChE,uGAA0F;AAE1F,MAAM,MAAM,GAAG,8BAAkB;KAC9B,yBAAyB,EAAE;KAC3B,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,+BAAS,EAAC,GAAG,CAAC,CAAC,CAAC;AAEhC,MAAM,YAAY,GAAG,CAAC,GAAG,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;AAkBxD,MAAM,YAAY,GAAG,KAAK,EACxB,OAAwB,EACxB,MAAsB,EACtB,EAAE;IACF,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,KAAK,CAAC;IAElD,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,KAAK;QACjC,MAAM,KAAK,CACT,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K;YACjB,UAAU,EAAE,kCAAkC;YAC9C,MAAM,EAAE,SAAS;YACjB,cAAc,EAAE,MAAM;SACvB,CAAC,CAAC;IACL,CAAC;IAED,SAAS,EAAE,KAAK,EAAE,OAAwB,EAAE,EAAE;QAC5C,MAAM,YAAY,CAAC,OAAO,EAAE;YAC1B,YAAY,EAAE,YAAY;YAC1B,UAAU,EAAE,KAAK;YACjB,UAAU,EAAE,kCAAkC;YAC9C,MAAM,EAAE,SAAS;YACjB,cAAc,EAAE,MAAM;SACvB,CAAC,CAAC;IACL,CAAC;IAED,YAAY,EAAE,KAAK,EAAE,OAAwB,EAAE,EAAE;QAC/C,MAAM,YAAY,CAAC,OAAO,EAAE;YAC1B,YAAY,EAAE,eAAe;YAC7B,UAAU,EAAE,OAAO;YACnB,cAAc,EAAE,YAAY;SAC7B,CAAC,CAAC;IACL,CAAC;CACF,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport { generateTemplate } from \"./utils/template-generators\";\nimport { ensureDirectoryExists } from \"./utils/cli.helpers\";\nimport {\n camelCase,\n kebabCase,\n pascalCase,\n} from \"../helpers/change-case.helpers\";\nimport { fullCleanCwd, getUserFileExtension } from \"../helpers/fs.helpers\";\nimport sheu from \"../sheu\";\nimport { capitalize } from \"../helpers/text.helpers\";\nimport prismaSchemaParser from \"../prisma/prisma-schema-parser\";\nimport { kebabToHuman } from \"../../modules/swagger/utils/helpers/swagger.router.helpers\";\n\nconst models = prismaSchemaParser\n .getModelsAsArrayOfStrings()\n .map((val) => kebabCase(val));\n\nconst knownModules = [...models, \"file-upload\", \"auth\"];\n\ninterface GenerateOptions {\n path?: string;\n model?: string;\n module?: string;\n}\n\ninterface GenerateConfig {\n templateName: string;\n fileSuffix: string;\n customValidation?: (modelName: string) => void;\n customImports?: (names: any) => any;\n customPath?: string;\n prefix?: string;\n allowedModules: string[];\n}\n\nconst generateFile = async (\n options: GenerateOptions,\n config: GenerateConfig\n) => {\n const modelName = options.module || options.model;\n\n if (options.module && options.model)\n throw Error(\n \"You must either pass --module or --model, prefer --module to align with future updates.\"\n );\n\n if (!modelName?.trim()) throw new Error(\"Module name is required!\");\n\n const isAllowedModule = config.allowedModules.includes(kebabCase(modelName));\n const isKnowModule = config.allowedModules.includes(kebabCase(modelName));\n\n if (!isKnowModule)\n throw new Error(\n `Generate command are only available for know modules such as all prisma models, file-upload and auth. And you passed ${modelName}.`\n );\n else if (!isAllowedModule)\n throw Error(\n `${kebabToHuman(kebabCase(config.templateName))} are not available for module ${modelName}`\n );\n\n if (config.customValidation) config.customValidation(modelName);\n\n const { path: customPath = \"src/modules/{{module-name}}\" } = options;\n\n const names = {\n pascal: pascalCase(modelName),\n camel: camelCase(modelName),\n kebab: kebabCase(modelName),\n };\n\n const ext = getUserFileExtension();\n\n const resolvedPath = (config.customPath || customPath).replaceAll(\n \"{{module-name}}\",\n names.kebab\n );\n\n const modulePath = path.join(process.cwd(), resolvedPath);\n\n const fileName = config.prefix\n ? `${config.prefix}${names.kebab}.${config.fileSuffix}.${ext}`\n : `${names.kebab}.${config.fileSuffix}.${ext}`;\n\n const filePath = path.join(modulePath, fileName);\n\n const humamReadableTemplateName =\n config.templateName.charAt(0).toUpperCase() +\n config.templateName.slice(1).replaceAll(\"-\", \" \");\n\n try {\n ensureDirectoryExists(modulePath);\n\n const templateData = {\n modelName: names,\n ...(config.customImports && { imports: config.customImports(names) }),\n };\n\n const content = generateTemplate(config.templateName, templateData);\n if (fs.existsSync(filePath))\n throw new Error(\n `${capitalize(humamReadableTemplateName.toLowerCase())} for ${names.kebab.replace(\"-\", \"\")} already exists.`\n );\n fs.writeFileSync(filePath, content);\n\n console.info(\"\");\n sheu.done(\n `${humamReadableTemplateName} for ${names.kebab.replace(\"-\", \"\")} generated under ${fullCleanCwd(filePath)}`\n );\n } catch (err: any) {\n console.info(\"\");\n sheu.error(\n `Failed because of ${err?.message?.toLowerCase() || \"unknown reason\"}`\n );\n process.exit(1);\n }\n};\n\nexport const generateCommand = {\n controller: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"controller\",\n fileSuffix: \"controller\",\n customImports: () => ({\n baseController: \"arkos/controllers\",\n }),\n allowedModules: knownModules,\n });\n },\n\n service: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"service\",\n fileSuffix: \"service\",\n customImports: () => ({\n baseService: \"arkos/services\",\n }),\n allowedModules: [...knownModules, \"email\"],\n });\n },\n\n router: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"router\",\n fileSuffix: \"router\",\n customImports: (names) => ({\n baseRouter: \"arkos\",\n controller: `./${names.kebab}.controller`,\n }),\n allowedModules: knownModules,\n });\n },\n\n interceptors: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"interceptors\",\n fileSuffix: \"interceptors\",\n allowedModules: knownModules,\n });\n },\n\n authConfigs: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"auth-configs\",\n fileSuffix: \"auth\",\n allowedModules: knownModules,\n });\n },\n\n hooks: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"hooks\",\n fileSuffix: \"hooks\",\n allowedModules: knownModules,\n });\n },\n\n createSchema: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"create-schema\",\n fileSuffix: \"schema\",\n customPath: \"src/modules/{{module-name}}/schemas\",\n prefix: \"create-\",\n allowedModules: models,\n });\n },\n\n updateSchema: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"update-schema\",\n fileSuffix: \"schema\",\n customPath: \"src/modules/{{module-name}}/schemas\",\n prefix: \"update-\",\n allowedModules: models,\n });\n },\n\n createDto: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"create-dto\",\n fileSuffix: \"dto\",\n customPath: \"src/modules/{{module-name}}/dtos\",\n prefix: \"create-\",\n allowedModules: models,\n });\n },\n\n updateDto: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"update-dto\",\n fileSuffix: \"dto\",\n customPath: \"src/modules/{{module-name}}/dtos\",\n prefix: \"update-\",\n allowedModules: models,\n });\n },\n\n queryOptions: async (options: GenerateOptions) => {\n await generateFile(options, {\n templateName: \"query-options\",\n fileSuffix: \"query\",\n allowedModules: knownModules,\n });\n },\n};\n"]}
|
|
@@ -140,7 +140,7 @@ program
|
|
|
140
140
|
.command("auth-action")
|
|
141
141
|
.description("Export file with an array containing all auth-actions")
|
|
142
142
|
.option("-o, --overwrite", "Overwrites all the changes on the object")
|
|
143
|
-
.option("-p, --path <path>", "Custom path for auth-actions", "
|
|
143
|
+
.option("-p, --path <path>", "Custom path for auth-actions", "src/modules/auth/utils")
|
|
144
144
|
.action(export_auth_action_1.default);
|
|
145
145
|
program.parse(process.argv);
|
|
146
146
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/cli/index.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAoC;AACpC,mCAAuC;AA4MrB,6FA5MT,oBAAY,OA4MS;AA3M9B,+BAAmC;AA2MH,2FA3MvB,gBAAU,OA2MuB;AA1M1C,mCAAuC;AA0MK,6FA1MnC,oBAAY,OA0MmC;AAzMxD,yCAA6C;AAyMa,gGAzMjD,0BAAe,OAyMiD;AAxMzE,qDAAiD;AACjD,wEAAsD;AACtD,8EAA2D;AAE3D,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAoMrB,0BAAO;AAlMhB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,IAAA,wBAAU,GAAE,CAAC,CAAC;AAExE,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,0BAA0B,CAAC;KACvC,MAAM,CAAC,qBAAqB,EAAE,0BAA0B,EAAE,KAAK,CAAC;KAChE,MAAM,CAAC,oBAAY,CAAC,CAAC;AAExB,OAAO;KACJ,OAAO,CAAC,KAAK,CAAC;K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AAC,IAAI,CAAC;KACX,WAAW,CACV,mEAAmE,CACpE;KACA,MAAM,CAAC,qBAAqB,EAAE,aAAa,CAAC;KAC5C,MAAM,CAAC,gBAAgB,EAAE,kCAAkC,CAAC;KAC5D,MAAM,CACL,mBAAmB,EACnB,uBAAuB,EACvB,6BAA6B,CAC9B;KACA,MAAM,CAAC,0BAAe,CAAC,SAAS,CAAC,CAAC;AAErC,OAAO;KACJ,OAAO,CAAC,QAAQ,CAAC;KACjB,OAAO,CAAC,UAAU,CAAC;KACnB,WAAW,CAAC,0DAA0D,CAAC;KACvE,MAAM,CAAC,yBAAqB,CAAC,CAAC;AAEjC,OAAO;KACJ,OAAO,CAAC,QAAQ,CAAC;KACjB,OAAO,CAAC,aAAa,CAAC;KACtB,WAAW,CAAC,uDAAuD,CAAC;KACpE,MAAM,CAAC,iBAAiB,EAAE,0CAA0C,CAAC;KACrE,MAAM,CAAC,mBAAmB,EAAE,8BAA8B,EAAE,YAAY,CAAC;KACzE,MAAM,CAAC,4BAAuB,CAAC,CAAC;AAEnC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC","sourcesContent":["import { Command } from \"commander\";\nimport { buildCommand } from \"./build\";\nimport { devCommand } from \"./dev\";\nimport { startCommand } from \"./start\";\nimport { generateCommand } from \"./generate\";\nimport { getVersion } from \"./utils/cli.helpers\";\nimport prismaGenerateCommand from \"./prisma-generate\";\nimport exportAuthActionCommand from \"./export-auth-action\";\n\nconst program = new Command();\n\nprogram.name(\"arkos\").description(\"Arkos.js CLI\").version(getVersion());\n\nprogram\n .command(\"build\")\n .description(\"Build your Arkos project\")\n .option(\"-m, --module <type>\", \"Module type (cjs or esm)\", \"cjs\")\n .action(buildCommand);\n\nprogram\n .command(\"dev\")\n .description(\"Run development server\")\n .option(\"-p, --port <number>\", \"Port number\")\n .option(\"-h, --host <host>\", \"Host to bind to\")\n .action(devCommand);\n\nprogram\n .command(\"start\")\n .description(\"Run production server\")\n .option(\"-p, --port <number>\", \"Port number\")\n .option(\"-h, --host <host>\", \"Host to bind to\")\n .action(startCommand);\n\nconst generate = program\n .command(\"generate\")\n .alias(\"g\")\n .description(\"Generate arkos components\");\n\ngenerate\n .command(\"controller\")\n .alias(\"c\")\n .description(\"Generate a new controller\")\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for the controller\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.controller);\n\ngenerate\n .command(\"service\")\n .alias(\"s\")\n .description(\"Generate a new service\")\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for the service\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.service);\n\ngenerate\n .command(\"router\")\n .alias(\"r\")\n .description(\"Generate a new router\")\n\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for the router\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.router);\n\ngenerate\n .command(\"auth-configs\")\n .alias(\"a\")\n .description(\"Generate auth configuration\")\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for the router\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.authConfigs);\n\ngenerate\n .command(\"query-options\")\n .alias(\"q\")\n .description(\"Generate prisma query options\")\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for query options\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.queryOptions);\n\ngenerate\n .command(\"interceptors\")\n .alias(\"i\")\n .alias(\"middlewares\")\n .alias(\"m\")\n .description(\"Generate a new interceptors file\")\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for interceptors\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.interceptors);\n\ngenerate\n .command(\"hooks\")\n .alias(\"h\")\n .description(\"Generate a new service hooks file\")\n\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for hooks\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.hooks);\n\ngenerate\n .command(\"create-schema\")\n .alias(\"cs\")\n .description(\"Generate a new zod create schema file for a prisma model\")\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for hooks\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.createSchema);\n\ngenerate\n .command(\"update-schema\")\n .alias(\"us\")\n .description(\"Generate a new zod update schema file for a prisma model\")\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for hooks\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.updateSchema);\n\ngenerate\n .command(\"create-dto\")\n .alias(\"cd\")\n .description(\n \"Generate a new class-validator create dto file for a prisma model\"\n )\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for hooks\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.createDto);\n\ngenerate\n .command(\"update-dto\")\n .alias(\"ud\")\n .description(\n \"Generate a new class-validator update dto file for a prisma model\"\n )\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for hooks\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.updateDto);\n\nprogram\n .command(\"prisma\")\n .command(\"generate\")\n .description(\"Generate your @prisma/client and BaseService class types\")\n .action(prismaGenerateCommand);\n\nprogram\n .command(\"export\")\n .command(\"auth-action\")\n .description(\"Export file with an array containing all auth-actions\")\n .option(\"-o, --overwrite\", \"Overwrites all the changes on the object\")\n .option(\"-p, --path <path>\", \"Custom path for auth-actions\", \"cache/auth\")\n .action(exportAuthActionCommand);\n\nprogram.parse(process.argv);\n\nexport { program, buildCommand, devCommand, startCommand, generateCommand };\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/cli/index.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAoC;AACpC,mCAAuC;AAgNrB,6FAhNT,oBAAY,OAgNS;AA/M9B,+BAAmC;AA+MH,2FA/MvB,gBAAU,OA+MuB;AA9M1C,mCAAuC;AA8MK,6FA9MnC,oBAAY,OA8MmC;AA7MxD,yCAA6C;AA6Ma,gGA7MjD,0BAAe,OA6MiD;AA5MzE,qDAAiD;AACjD,wEAAsD;AACtD,8EAA2D;AAE3D,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAwMrB,0BAAO;AAtMhB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,IAAA,wBAAU,GAAE,CAAC,CAAC;AAExE,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,0BAA0B,CAAC;KACvC,MAAM,CAAC,qBAAqB,EAAE,0BAA0B,EAAE,KAAK,CAAC;KAChE,MAAM,CAAC,oBAAY,CAAC,CAAC;AAExB,OAAO;KACJ,OAAO,CAAC,KAAK,CAAC;KACd,WAAW,CAAC,wBAAwB,CAAC;KACrC,MAAM,CAAC,qBAAqB,EAAE,aAAa,CAAC;KAC5C,MAAM,CAAC,mBAAmB,EAAE,iBAAiB,CAAC;KAC9C,MAAM,CAAC,gBAAU,CAAC,CAAC;AAEtB,OAAO;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AuB,EACvB,6BAA6B,CAC9B;KACA,MAAM,CAAC,0BAAe,CAAC,SAAS,CAAC,CAAC;AAErC,OAAO;KACJ,OAAO,CAAC,QAAQ,CAAC;KACjB,OAAO,CAAC,UAAU,CAAC;KACnB,WAAW,CAAC,0DAA0D,CAAC;KACvE,MAAM,CAAC,yBAAqB,CAAC,CAAC;AAEjC,OAAO;KACJ,OAAO,CAAC,QAAQ,CAAC;KACjB,OAAO,CAAC,aAAa,CAAC;KACtB,WAAW,CAAC,uDAAuD,CAAC;KACpE,MAAM,CAAC,iBAAiB,EAAE,0CAA0C,CAAC;KACrE,MAAM,CACL,mBAAmB,EACnB,8BAA8B,EAC9B,wBAAwB,CACzB;KACA,MAAM,CAAC,4BAAuB,CAAC,CAAC;AAEnC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC","sourcesContent":["import { Command } from \"commander\";\nimport { buildCommand } from \"./build\";\nimport { devCommand } from \"./dev\";\nimport { startCommand } from \"./start\";\nimport { generateCommand } from \"./generate\";\nimport { getVersion } from \"./utils/cli.helpers\";\nimport prismaGenerateCommand from \"./prisma-generate\";\nimport exportAuthActionCommand from \"./export-auth-action\";\n\nconst program = new Command();\n\nprogram.name(\"arkos\").description(\"Arkos.js CLI\").version(getVersion());\n\nprogram\n .command(\"build\")\n .description(\"Build your Arkos project\")\n .option(\"-m, --module <type>\", \"Module type (cjs or esm)\", \"cjs\")\n .action(buildCommand);\n\nprogram\n .command(\"dev\")\n .description(\"Run development server\")\n .option(\"-p, --port <number>\", \"Port number\")\n .option(\"-h, --host <host>\", \"Host to bind to\")\n .action(devCommand);\n\nprogram\n .command(\"start\")\n .description(\"Run production server\")\n .option(\"-p, --port <number>\", \"Port number\")\n .option(\"-h, --host <host>\", \"Host to bind to\")\n .action(startCommand);\n\nconst generate = program\n .command(\"generate\")\n .alias(\"g\")\n .description(\"Generate arkos components\");\n\ngenerate\n .command(\"controller\")\n .alias(\"c\")\n .description(\"Generate a new controller\")\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for the controller\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.controller);\n\ngenerate\n .command(\"service\")\n .alias(\"s\")\n .description(\"Generate a new service\")\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for the service\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.service);\n\ngenerate\n .command(\"router\")\n .alias(\"r\")\n .description(\"Generate a new router\")\n\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for the router\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.router);\n\ngenerate\n .command(\"auth-configs\")\n .alias(\"a\")\n .description(\"Generate auth configuration\")\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for the router\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.authConfigs);\n\ngenerate\n .command(\"query-options\")\n .alias(\"q\")\n .description(\"Generate prisma query options\")\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for query options\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.queryOptions);\n\ngenerate\n .command(\"interceptors\")\n .alias(\"i\")\n .alias(\"middlewares\")\n .alias(\"m\")\n .description(\"Generate a new interceptors file\")\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for interceptors\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.interceptors);\n\ngenerate\n .command(\"hooks\")\n .alias(\"h\")\n .description(\"Generate a new service hooks file\")\n\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for hooks\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.hooks);\n\ngenerate\n .command(\"create-schema\")\n .alias(\"cs\")\n .description(\"Generate a new zod create schema file for a prisma model\")\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for hooks\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.createSchema);\n\ngenerate\n .command(\"update-schema\")\n .alias(\"us\")\n .description(\"Generate a new zod update schema file for a prisma model\")\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for hooks\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.updateSchema);\n\ngenerate\n .command(\"create-dto\")\n .alias(\"cd\")\n .description(\n \"Generate a new class-validator create dto file for a prisma model\"\n )\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for hooks\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.createDto);\n\ngenerate\n .command(\"update-dto\")\n .alias(\"ud\")\n .description(\n \"Generate a new class-validator update dto file for a prisma model\"\n )\n .option(\"-m, --module <name>\", \"Module name\")\n .option(\"--model <name>\", \"Module name (alias for --module)\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for hooks\",\n \"src/modules/{{module-name}}\"\n )\n .action(generateCommand.updateDto);\n\nprogram\n .command(\"prisma\")\n .command(\"generate\")\n .description(\"Generate your @prisma/client and BaseService class types\")\n .action(prismaGenerateCommand);\n\nprogram\n .command(\"export\")\n .command(\"auth-action\")\n .description(\"Export file with an array containing all auth-actions\")\n .option(\"-o, --overwrite\", \"Overwrites all the changes on the object\")\n .option(\n \"-p, --path <path>\",\n \"Custom path for auth-actions\",\n \"src/modules/auth/utils\"\n )\n .action(exportAuthActionCommand);\n\nprogram.parse(process.argv);\n\nexport { program, buildCommand, devCommand, startCommand, generateCommand };\n"]}
|
|
@@ -10,12 +10,12 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
10
10
|
const child_process_1 = require("child_process");
|
|
11
11
|
const dotenv_helpers_1 = require("../dotenv.helpers");
|
|
12
12
|
const fs_helpers_1 = require("../helpers/fs.helpers");
|
|
13
|
-
const port_and_host_allocator_1 = __importDefault(require("../features/port-and-host-allocator"));
|
|
14
13
|
const watermark_stamper_1 = __importDefault(require("./utils/watermark-stamper"));
|
|
14
|
+
const sheu_1 = __importDefault(require("../sheu"));
|
|
15
15
|
let child = null;
|
|
16
16
|
let envFiles;
|
|
17
|
-
|
|
18
|
-
if (
|
|
17
|
+
function startCommand(options = {}) {
|
|
18
|
+
if (!process.env.NODE_ENV)
|
|
19
19
|
process.env.NODE_ENV = "production";
|
|
20
20
|
process.env.ARKOS_BUILD = "true";
|
|
21
21
|
envFiles = (0, dotenv_helpers_1.loadEnvironmentVariables)();
|
|
@@ -23,7 +23,7 @@ async function startCommand(options = {}) {
|
|
|
23
23
|
const { port, host } = options;
|
|
24
24
|
const entryPoint = path_1.default.join(process.cwd(), ".build", "src", "app.js");
|
|
25
25
|
if (!fs_1.default.existsSync(path_1.default.join(entryPoint))) {
|
|
26
|
-
|
|
26
|
+
sheu_1.default.error(`Could not find built application entry point at ${(0, fs_helpers_1.fullCleanCwd)(entryPoint)}`);
|
|
27
27
|
process.exit(1);
|
|
28
28
|
}
|
|
29
29
|
const env = {
|
|
@@ -34,6 +34,19 @@ async function startCommand(options = {}) {
|
|
|
34
34
|
ARKOS_BUILD: "true",
|
|
35
35
|
CLI: "false",
|
|
36
36
|
};
|
|
37
|
+
env.__HOST =
|
|
38
|
+
env?.CLI_HOST ||
|
|
39
|
+
env?.HOST ||
|
|
40
|
+
(env.ARKOS_BUILD !== "true" ? "0.0.0.0" : "127.0.0.1");
|
|
41
|
+
env.__PORT =
|
|
42
|
+
env?.CLI_PORT ||
|
|
43
|
+
env?.PORT ||
|
|
44
|
+
"8000";
|
|
45
|
+
watermark_stamper_1.default.stamp({
|
|
46
|
+
envFiles,
|
|
47
|
+
port: env.__PORT,
|
|
48
|
+
host: env.__HOST,
|
|
49
|
+
});
|
|
37
50
|
child = (0, child_process_1.spawn)("node", [entryPoint], {
|
|
38
51
|
stdio: "inherit",
|
|
39
52
|
env,
|
|
@@ -44,16 +57,10 @@ async function startCommand(options = {}) {
|
|
|
44
57
|
child.kill();
|
|
45
58
|
process.exit(0);
|
|
46
59
|
});
|
|
47
|
-
const hostAndPort = await port_and_host_allocator_1.default.getHostAndAvailablePort(env, {
|
|
48
|
-
logWarning: true,
|
|
49
|
-
});
|
|
50
|
-
watermark_stamper_1.default.stamp({
|
|
51
|
-
envFiles,
|
|
52
|
-
...hostAndPort,
|
|
53
|
-
});
|
|
54
60
|
}
|
|
55
61
|
catch (error) {
|
|
56
|
-
|
|
62
|
+
sheu_1.default.error("Production server failed to start:");
|
|
63
|
+
console.error(error);
|
|
57
64
|
process.exit(1);
|
|
58
65
|
}
|
|
59
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../../src/utils/cli/start.ts"],"names":[],"mappings":";;;;;AAmBA,
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../../src/utils/cli/start.ts"],"names":[],"mappings":";;;;;AAmBA,oCA6DC;AAKD,4EAGC;AAxFD,gDAAwB;AACxB,4CAAoB;AACpB,iDAAoD;AACpD,sDAA6D;AAC7D,sDAAqD;AACrD,kFAAyD;AACzD,mDAA2B;AAO3B,IAAI,KAAK,GAAwB,IAAI,CAAC;AACtC,IAAI,QAA8B,CAAC;AAKnC,SAAgB,YAAY,CAAC,UAAwB,EAAE;IACrD,IAAI,CAAC,OAAO,CAAC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AG,CAAC,MAAM;YAChB,IAAI,EAAE,GAAG,CAAC,MAAM;SACjB,CAAC,CAAC;QAEH,KAAK,GAAG,IAAA,qBAAK,EAAC,MAAM,EAAE,CAAC,UAAU,CAAC,EAAE;YAClC,KAAK,EAAE,SAAS;YAChB,GAAG;YACH,KAAK,EAAE,IAAI;SACZ,CAAC,CAAC;QAEH,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;YACxB,IAAI,KAAK;gBAAE,KAAK,CAAC,IAAI,EAAE,CAAC;YAExB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,cAAI,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACjD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAKD,SAAgB,gCAAgC;IAC7C,KAAsB,EAAE,IAAI,EAAE,EAAE,CAAC;IAClC,KAAK,GAAG,IAAI,CAAC;AACf,CAAC","sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport { ChildProcess, spawn } from \"child_process\";\nimport { loadEnvironmentVariables } from \"../dotenv.helpers\";\nimport { fullCleanCwd } from \"../helpers/fs.helpers\";\nimport watermarkStamper from \"./utils/watermark-stamper\";\nimport sheu from \"../sheu\";\n\ninterface StartOptions {\n port?: string;\n host?: string;\n}\n\nlet child: ChildProcess | null = null;\nlet envFiles: string[] | undefined;\n\n/**\n * Production start command for the arkos CLI\n */\nexport function startCommand(options: StartOptions = {}) {\n if (!process.env.NODE_ENV) process.env.NODE_ENV = \"production\";\n process.env.ARKOS_BUILD = \"true\";\n\n envFiles = loadEnvironmentVariables();\n\n try {\n const { port, host } = options;\n\n const entryPoint = path.join(process.cwd(), \".build\", \"src\", \"app.js\");\n\n if (!fs.existsSync(path.join(entryPoint))) {\n sheu.error(\n `Could not find built application entry point at ${fullCleanCwd(entryPoint)}`\n );\n process.exit(1);\n }\n\n const env: { [x: string]: string } = {\n NODE_ENV: \"production\",\n ...process.env,\n ...(port && { CLI_PORT: port }),\n ...(host && { CLI_HOST: host }),\n ARKOS_BUILD: \"true\",\n CLI: \"false\",\n };\n\n env.__HOST =\n env?.CLI_HOST ||\n // config?.host ||\n env?.HOST ||\n (env.ARKOS_BUILD !== \"true\" ? \"0.0.0.0\" : \"127.0.0.1\");\n\n env.__PORT =\n env?.CLI_PORT ||\n // || config?.port\n env?.PORT ||\n \"8000\";\n\n watermarkStamper.stamp({\n envFiles,\n port: env.__PORT,\n host: env.__HOST,\n });\n\n child = spawn(\"node\", [entryPoint], {\n stdio: \"inherit\",\n env,\n shell: true,\n });\n\n process.on(\"SIGINT\", () => {\n if (child) child.kill();\n\n process.exit(0);\n });\n } catch (error) {\n sheu.error(\"Production server failed to start:\");\n console.error(error);\n process.exit(1);\n }\n}\n\n/**\n * Help function to help other processes to terminate the production server child process\n */\nexport function killProductionServerChildProcess() {\n (child as ChildProcess)?.kill?.();\n child = null;\n}\n"]}
|
|
@@ -9,7 +9,6 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const sheu_1 = __importDefault(require("../../sheu"));
|
|
10
10
|
const fs_helpers_1 = require("../../helpers/fs.helpers");
|
|
11
11
|
const global_helpers_1 = require("../../helpers/global.helpers");
|
|
12
|
-
const deepmerge_helper_1 = __importDefault(require("../../helpers/deepmerge.helper"));
|
|
13
12
|
const dev_1 = require("../dev");
|
|
14
13
|
class RuntimeCliCommander {
|
|
15
14
|
getOptions() {
|
|
@@ -27,19 +26,65 @@ class RuntimeCliCommander {
|
|
|
27
26
|
async exportAuthAction() {
|
|
28
27
|
const options = this.getOptions();
|
|
29
28
|
const authActions = services_1.authActionService.getAll();
|
|
30
|
-
const
|
|
29
|
+
const ext = (0, fs_helpers_1.getUserFileExtension)();
|
|
30
|
+
const targetPath = path_1.default.join(process.cwd(), options.path || "", `auth-actions.${ext}`);
|
|
31
31
|
let finalAuthActions = authActions;
|
|
32
32
|
let isUpdate = false;
|
|
33
33
|
if (!options.overwrite) {
|
|
34
34
|
try {
|
|
35
35
|
const existingModule = await (0, global_helpers_1.importModule)(targetPath);
|
|
36
36
|
const existingActions = existingModule.default || existingModule;
|
|
37
|
-
|
|
37
|
+
const rolesChanges = [];
|
|
38
|
+
for (const newAction of authActions) {
|
|
39
|
+
const existingAction = existingActions.find((existing) => existing.action === newAction.action &&
|
|
40
|
+
existing.resource === newAction.resource);
|
|
41
|
+
if (existingAction) {
|
|
42
|
+
const existingRoles = existingAction.roles
|
|
43
|
+
? [...existingAction.roles].sort()
|
|
44
|
+
: [];
|
|
45
|
+
const newRoles = newAction.roles ? [...newAction.roles].sort() : [];
|
|
46
|
+
const rolesMatch = existingRoles.length === newRoles.length &&
|
|
47
|
+
existingRoles.every((role, index) => role === newRoles[index]);
|
|
48
|
+
if (!rolesMatch) {
|
|
49
|
+
rolesChanges.push(` - ${newAction.action}:${newAction.resource}: [${existingRoles.join(", ")}] → [${newRoles.join(", ")}]`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (rolesChanges.length > 0) {
|
|
54
|
+
const warningMessage = `Roles for the following permissions will be updated:\n${rolesChanges.join("\n")}`;
|
|
55
|
+
sheu_1.default.warn(warningMessage);
|
|
56
|
+
const answer = await new Promise((resolve) => {
|
|
57
|
+
process.stdout.write(`\n${sheu_1.default.green("?", { bold: true })} Do you want to proceed with updating these roles? (Y/n): `);
|
|
58
|
+
process.stdin.once("data", (data) => {
|
|
59
|
+
const result = data.toString().trim().toLowerCase();
|
|
60
|
+
process.stdin.pause();
|
|
61
|
+
resolve(result === "y" || result.length === 0);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
if (!answer) {
|
|
65
|
+
throw new Error(`Auth action export cancelled. Roles were not updated to preserve existing permissions., if you would like to overwrite existing auth actions run:
|
|
66
|
+
|
|
67
|
+
npx arkos export auth-action --overwrite
|
|
68
|
+
`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
finalAuthActions = [...authActions, ...existingActions].map((newAction) => {
|
|
72
|
+
const existingAction = existingActions.find((existing) => existing.action === newAction.action &&
|
|
73
|
+
existing.resource === newAction.resource);
|
|
74
|
+
if (existingAction) {
|
|
75
|
+
return {
|
|
76
|
+
...newAction,
|
|
77
|
+
...existingAction,
|
|
78
|
+
roles: newAction.roles,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return newAction;
|
|
82
|
+
});
|
|
38
83
|
isUpdate = true;
|
|
39
84
|
}
|
|
40
85
|
catch (error) { }
|
|
41
86
|
}
|
|
42
|
-
const fileContent = `const authActions = ${JSON.stringify(finalAuthActions, null, 2)};
|
|
87
|
+
const fileContent = `const authActions = ${JSON.stringify(finalAuthActions, null, 2)}${ext === "ts" ? " as const" : ""};
|
|
43
88
|
|
|
44
89
|
export default authActions;
|
|
45
90
|
`;
|
|
@@ -47,9 +92,9 @@ export default authActions;
|
|
|
47
92
|
await promises_1.default.writeFile(targetPath, fileContent, "utf-8");
|
|
48
93
|
console.info("");
|
|
49
94
|
if (isUpdate)
|
|
50
|
-
sheu_1.default.done(
|
|
95
|
+
sheu_1.default.done(`Auth actions updated and exported successfully at ${(0, fs_helpers_1.fullCleanCwd)(targetPath)}`);
|
|
51
96
|
else
|
|
52
|
-
sheu_1.default.done(
|
|
97
|
+
sheu_1.default.done(`Auth actions exported successfully at ${(0, fs_helpers_1.fullCleanCwd)(targetPath)}`);
|
|
53
98
|
this.end();
|
|
54
99
|
}
|
|
55
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-cli-commander.js","sourceRoot":"","sources":["../../../../../src/utils/cli/utils/runtime-cli-commander.ts"],"names":[],"mappings":";;;;;AAAA,wDAA8D;AAC9D,2DAA6B;AAC7B,gDAAwB;AACxB,sDAA8B;AAC9B,yDAAgE;A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B,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC;;;CAGvF,CAAC;QAEE,MAAM,kBAAE,CAAC,KAAK,CAAC,cAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9D,MAAM,kBAAE,CAAC,SAAS,CAAC,UAAU,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;QAErD,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACjB,IAAI,QAAQ;YAAE,cAAI,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC;;YACtE,cAAI,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC;QAEtD,IAAI,CAAC,GAAG,EAAE,CAAC;IACb,CAAC;CACF;AAOD,MAAM,mBAAmB,GAAwB,IAAI,mBAAmB,EAAE,CAAC;AAE3E,kBAAe,mBAAmB,CAAC","sourcesContent":["import { authActionService } from \"../../../exports/services\";\nimport fs from \"fs/promises\";\nimport path from \"path\";\nimport sheu from \"../../sheu\";\nimport { getUserFileExtension } from \"../../helpers/fs.helpers\";\nimport { importModule } from \"../../helpers/global.helpers\";\nimport deepmerge from \"../../helpers/deepmerge.helper\";\nimport { killDevelopmentServerChildProcess } from \"../dev\";\n\n/**\n * Runtime CLI Commander class for handling command-line interface commands\n * during runtime execution. Provides methods for executing various CLI commands\n * and managing their lifecycle.\n *\n * @class RuntimeCliCommander\n */\nclass RuntimeCliCommander {\n /**\n * Parses and returns CLI command options from environment variables\n *\n * @returns {Object} Parsed CLI command options object\n *\n * @example\n * // Returns { overwrite: true, path: './exports' }\n * getOptions();\n */\n getOptions(): { overwrite?: boolean; path: string } {\n return JSON.parse(process.env.CLI_COMMAND_OPTIONS || \"{}\");\n }\n\n /**\n * Terminates the development server child process and exits the current process\n *\n * @returns {void}\n */\n end(): void {\n killDevelopmentServerChildProcess();\n process.exit(1);\n }\n\n /**\n * Main command handler that routes to specific command implementations\n * based on the CLI_COMMAND environment variable\n *\n * @returns {Promise<void>}\n *\n * @example\n * // Handles EXPORT_AUTH_ACTION command\n * await handle();\n */\n async handle(): Promise<void> {\n const command = process.env.CLI_COMMAND;\n if (command === \"EXPORT_AUTH_ACTION\") await this.exportAuthAction();\n }\n\n /**\n * Exports authentication actions to a file, with options for merging with existing\n * actions and specifying output path\n *\n * @param {Object} [options] - Export configuration options\n * @param {boolean} [options.overwrite] - Whether to overwrite existing file (default: false)\n * @param {string} [options.path] - Custom output directory path\n * @returns {Promise<void>}\n *\n * @example\n * // Export with default options (merge if exists)\n * await exportAuthAction();\n *\n * @example\n * // Export with overwrite and custom path\n * await exportAuthAction({ overwrite: true, path: './custom-exports' });\n */\n async exportAuthAction(): Promise<void> {\n const options = this.getOptions() as { overwrite?: boolean; path?: string };\n const authActions = authActionService.getAll();\n\n const targetPath = path.join(\n process.cwd(),\n options.path || \"\",\n `auth-actions.${getUserFileExtension()}`\n );\n\n let finalAuthActions = authActions;\n let isUpdate = false;\n\n if (!options.overwrite) {\n try {\n const existingModule = await importModule(targetPath);\n const existingActions = existingModule.default || existingModule;\n finalAuthActions = deepmerge(existingActions, authActions);\n isUpdate = true;\n } catch (error) {}\n }\n\n const fileContent = `const authActions = ${JSON.stringify(finalAuthActions, null, 2)};\n\nexport default authActions;\n`;\n\n await fs.mkdir(path.dirname(targetPath), { recursive: true });\n await fs.writeFile(targetPath, fileContent, \"utf-8\");\n\n console.info(\"\");\n if (isUpdate) sheu.done(\"Auth actions updated and exported successfully!\");\n else sheu.done(\"Auth actions exported successfully!\");\n\n this.end();\n }\n}\n\n/**\n * Singleton instance of RuntimeCliCommander\n *\n * @type {RuntimeCliCommander}\n */\nconst runtimeCliCommander: RuntimeCliCommander = new RuntimeCliCommander();\n\nexport default runtimeCliCommander;\n"]}
|
|
1
|
+
{"version":3,"file":"runtime-cli-commander.js","sourceRoot":"","sources":["../../../../../src/utils/cli/utils/runtime-cli-commander.ts"],"names":[],"mappings":";;;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CAAC,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE;;;CAGzH,CAAC;QAEE,MAAM,kBAAE,CAAC,KAAK,CAAC,cAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9D,MAAM,kBAAE,CAAC,SAAS,CAAC,UAAU,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;QAErD,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACjB,IAAI,QAAQ;YACV,cAAI,CAAC,IAAI,CACP,qDAAqD,IAAA,yBAAY,EAAC,UAAU,CAAC,EAAE,CAChF,CAAC;;YAEF,cAAI,CAAC,IAAI,CACP,yCAAyC,IAAA,yBAAY,EAAC,UAAU,CAAC,EAAE,CACpE,CAAC;QAEJ,IAAI,CAAC,GAAG,EAAE,CAAC;IACb,CAAC;CACF;AAOD,MAAM,mBAAmB,GAAwB,IAAI,mBAAmB,EAAE,CAAC;AAE3E,kBAAe,mBAAmB,CAAC","sourcesContent":["import { authActionService } from \"../../../exports/services\";\nimport fs from \"fs/promises\";\nimport path from \"path\";\nimport sheu from \"../../sheu\";\nimport { fullCleanCwd, getUserFileExtension } from \"../../helpers/fs.helpers\";\nimport { importModule } from \"../../helpers/global.helpers\";\nimport { killDevelopmentServerChildProcess } from \"../dev\";\n\n/**\n * Runtime CLI Commander class for handling command-line interface commands\n * during runtime execution. Provides methods for executing various CLI commands\n * and managing their lifecycle.\n *\n * @class RuntimeCliCommander\n */\nclass RuntimeCliCommander {\n /**\n * Parses and returns CLI command options from environment variables\n *\n * @returns {Object} Parsed CLI command options object\n *\n * @example\n * // Returns { overwrite: true, path: './exports' }\n * getOptions();\n */\n getOptions(): { overwrite?: boolean; path: string } {\n return JSON.parse(process.env.CLI_COMMAND_OPTIONS || \"{}\");\n }\n\n /**\n * Terminates the development server child process and exits the current process\n *\n * @returns {void}\n */\n end(): void {\n killDevelopmentServerChildProcess();\n process.exit(1);\n }\n\n /**\n * Main command handler that routes to specific command implementations\n * based on the CLI_COMMAND environment variable\n *\n * @returns {Promise<void>}\n *\n * @example\n * // Handles EXPORT_AUTH_ACTION command\n * await handle();\n */\n async handle(): Promise<void> {\n const command = process.env.CLI_COMMAND;\n if (command === \"EXPORT_AUTH_ACTION\") await this.exportAuthAction();\n }\n\n /**\n * Exports authentication actions to a file, with options for merging with existing\n * actions and specifying output path\n *\n * @param {Object} [options] - Export configuration options\n * @param {boolean} [options.overwrite] - Whether to overwrite existing file (default: false)\n * @param {string} [options.path] - Custom output directory path\n * @returns {Promise<void>}\n *\n * @example\n * // Export with default options (merge if exists)\n * await exportAuthAction();\n *\n * @example\n * // Export with overwrite and custom path\n * await exportAuthAction({ overwrite: true, path: './custom-exports' });\n */\n async exportAuthAction(): Promise<void> {\n const options = this.getOptions() as { overwrite?: boolean; path?: string };\n const authActions = authActionService.getAll();\n const ext = getUserFileExtension();\n\n const targetPath = path.join(\n process.cwd(),\n options.path || \"\",\n `auth-actions.${ext}`\n );\n\n let finalAuthActions = authActions;\n let isUpdate = false;\n\n if (!options.overwrite) {\n try {\n const existingModule = await importModule(targetPath);\n const existingActions = existingModule.default || existingModule;\n\n const rolesChanges: string[] = [];\n\n for (const newAction of authActions) {\n const existingAction = existingActions.find(\n (existing: any) =>\n existing.action === newAction.action &&\n existing.resource === newAction.resource\n );\n\n if (existingAction) {\n const existingRoles = existingAction.roles\n ? [...existingAction.roles].sort()\n : [];\n const newRoles = newAction.roles ? [...newAction.roles].sort() : [];\n\n const rolesMatch =\n existingRoles.length === newRoles.length &&\n existingRoles.every((role, index) => role === newRoles[index]);\n\n if (!rolesMatch) {\n rolesChanges.push(\n ` - ${newAction.action}:${newAction.resource}: [${existingRoles.join(\", \")}] → [${newRoles.join(\", \")}]`\n );\n }\n }\n }\n\n if (rolesChanges.length > 0) {\n const warningMessage = `Roles for the following permissions will be updated:\\n${rolesChanges.join(\"\\n\")}`;\n\n sheu.warn(warningMessage);\n\n const answer = await new Promise<boolean>((resolve) => {\n process.stdout.write(\n `\\n${sheu.green(\"?\", { bold: true })} Do you want to proceed with updating these roles? (Y/n): `\n );\n process.stdin.once(\"data\", (data) => {\n const result = data.toString().trim().toLowerCase();\n process.stdin.pause();\n resolve(result === \"y\" || result.length === 0);\n });\n });\n\n if (!answer) {\n throw new Error(\n `Auth action export cancelled. Roles were not updated to preserve existing permissions., if you would like to overwrite existing auth actions run:\n\nnpx arkos export auth-action --overwrite\n`\n );\n }\n }\n\n finalAuthActions = [...authActions, ...existingActions].map(\n (newAction) => {\n const existingAction = existingActions.find(\n (existing: any) =>\n existing.action === newAction.action &&\n existing.resource === newAction.resource\n );\n\n if (existingAction) {\n return {\n ...newAction,\n ...existingAction,\n roles: newAction.roles,\n };\n }\n\n return newAction;\n }\n );\n\n isUpdate = true;\n } catch (error) {}\n }\n\n const fileContent = `const authActions = ${JSON.stringify(finalAuthActions, null, 2)}${ext === \"ts\" ? \" as const\" : \"\"};\n\nexport default authActions;\n`;\n\n await fs.mkdir(path.dirname(targetPath), { recursive: true });\n await fs.writeFile(targetPath, fileContent, \"utf-8\");\n\n console.info(\"\");\n if (isUpdate)\n sheu.done(\n `Auth actions updated and exported successfully at ${fullCleanCwd(targetPath)}`\n );\n else\n sheu.done(\n `Auth actions exported successfully at ${fullCleanCwd(targetPath)}`\n );\n\n this.end();\n }\n}\n\n/**\n * Singleton instance of RuntimeCliCommander\n *\n * @type {RuntimeCliCommander}\n */\nconst runtimeCliCommander: RuntimeCliCommander = new RuntimeCliCommander();\n\nexport default runtimeCliCommander;\n"]}
|
package/dist/cjs/utils/cli/utils/template-generator/templates/class-validator/create-dto-template.js
CHANGED
|
@@ -121,7 +121,7 @@ function generateClassValidatorField(field, isUserModule, validatorsUsed) {
|
|
|
121
121
|
}
|
|
122
122
|
function getValidatorsForType(field, isUserModule) {
|
|
123
123
|
const validators = [];
|
|
124
|
-
const arrayEach = field.isArray ? "
|
|
124
|
+
const arrayEach = field.isArray ? "{ each: true }" : "";
|
|
125
125
|
if (isUserModule) {
|
|
126
126
|
if (field.name === "email") {
|
|
127
127
|
return ["@IsEmail()"];
|
|
@@ -141,7 +141,7 @@ function getValidatorsForType(field, isUserModule) {
|
|
|
141
141
|
case "Int":
|
|
142
142
|
case "Float":
|
|
143
143
|
case "Decimal":
|
|
144
|
-
validators.push(`@IsNumber(
|
|
144
|
+
validators.push(`@IsNumber(${arrayEach})`);
|
|
145
145
|
break;
|
|
146
146
|
case "Boolean":
|
|
147
147
|
validators.push(`@IsBoolean(${arrayEach})`);
|
|
@@ -150,7 +150,7 @@ function getValidatorsForType(field, isUserModule) {
|
|
|
150
150
|
validators.push(`@IsDate(${arrayEach})`);
|
|
151
151
|
break;
|
|
152
152
|
case "BigInt":
|
|
153
|
-
validators.push(`@IsNumber(
|
|
153
|
+
validators.push(`@IsNumber(${arrayEach})`);
|
|
154
154
|
break;
|
|
155
155
|
case "Json":
|
|
156
156
|
validators.push(`@IsObject(${arrayEach})`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-dto-template.js","sourceRoot":"","sources":["../../../../../../../../src/utils/cli/utils/template-generator/templates/class-validator/create-dto-template.ts"],"names":[],"mappings":";;;;;AAKA,8DA4GC;AAjHD,sGAA4E;AAE5E,kEAAyE;AAGzE,SAAgB,yBAAyB,CAAC,OAAwB;IAChE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAE9B,IAAI,CAAC,SAAS;QACZ,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IAErE,MAAM,KAAK,GAAG,8BAAkB,CAAC,MAAM,CAAC,IAAI,CAC1C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAC/D,CAAC;IAEF,IAAI,CAAC,K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,KAAK,OAAO,CAAC;QACb,KAAK,SAAS;YACZ,OAAO,QAAQ,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,UAAU;YACb,OAAO,MAAM,CAAC;QAChB,KAAK,MAAM;YACT,OAAO,KAAK,CAAC;QACf,KAAK,OAAO;YACV,OAAO,QAAQ,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB;YAEE,OAAO,8BAAkB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC;IACtE,CAAC;AACH,CAAC","sourcesContent":["import prismaSchemaParser from \"../../../../../prisma/prisma-schema-parser\";\nimport { PrismaField, PrismaModel } from \"../../../../../prisma/types\";\nimport { getUserFileExtension } from \"../../../../../helpers/fs.helpers\";\nimport { TemplateOptions } from \"../../../template-generators\";\n\nexport function generateCreateDtoTemplate(options: TemplateOptions): string {\n const { modelName } = options;\n\n if (!modelName)\n throw new Error(\"Module name is required for create-dto template\");\n\n const model = prismaSchemaParser.models.find(\n (m) => m.name.toLowerCase() === modelName.pascal.toLowerCase()\n );\n\n if (!model)\n throw new Error(`Model ${modelName.pascal} not found in Prisma schema`);\n\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n const restrictedFields = [\"id\", \"createdAt\", \"updatedAt\", \"deletedAt\"];\n const isUserModule = modelName.kebab === \"user\";\n const enumsUsed = new Set<string>();\n const validatorsUsed = new Set<string>();\n const transformersUsed = new Set<string>();\n const nestedDtoClasses: string[] = [];\n\n let dtoFields: string[] = [];\n\n for (const field of model.fields) {\n if (field.isId || restrictedFields.includes(field.name)) {\n continue;\n }\n\n const isForeignKey = model.fields.some(\n (f) => f.foreignKeyField === field.name\n );\n if (isForeignKey) {\n continue;\n }\n\n if (field.isRelation) {\n if (field.isArray) continue;\n\n const referencedModel = prismaSchemaParser.models.find(\n (m) => m.name === field.type\n );\n\n if (referencedModel) {\n const isOptional = field.isOptional || field.defaultValue !== undefined;\n const optionalDecorator = isOptional ? \" @IsOptional()\\n\" : \"\";\n const typeModifier = isTypeScript ? (isOptional ? \"?\" : \"!\") : \"\";\n\n validatorsUsed.add(\"IsOptional\");\n validatorsUsed.add(\"ValidateNested\");\n transformersUsed.add(\"Type\");\n\n const relationDtoName = `${referencedModel.name}ForCreate${modelName.pascal}Dto`;\n\n // Generate the nested DTO class inline\n const nestedDtoClass = generateNestedDtoClass(\n field,\n referencedModel,\n relationDtoName,\n validatorsUsed,\n enumsUsed,\n isTypeScript\n );\n nestedDtoClasses.push(nestedDtoClass);\n\n dtoFields.push(\n `${optionalDecorator} @ValidateNested()\\n @Type(() => ${relationDtoName})\\n ${field.name}${typeModifier}: ${relationDtoName};`\n );\n }\n continue;\n }\n\n if (prismaSchemaParser.isEnum(field.type)) {\n enumsUsed.add(field.type);\n }\n\n const { decorators, type } = generateClassValidatorField(\n field,\n isUserModule,\n validatorsUsed\n );\n const isOptional = field.isOptional || field.defaultValue !== undefined;\n const typeModifier = isTypeScript ? (isOptional ? \"?\" : \"!\") : \"\";\n dtoFields.push(`${decorators} ${field.name}${typeModifier}: ${type};`);\n }\n\n const enumImports =\n enumsUsed.size > 0\n ? `import { ${Array.from(enumsUsed).join(\", \")} } from \"@prisma/client\";\\n`\n : \"\";\n\n const validatorImports =\n validatorsUsed.size > 0\n ? `import { ${Array.from(validatorsUsed).join(\", \")} } from \"class-validator\";\\n`\n : \"\";\n\n const transformerImports =\n transformersUsed.size > 0\n ? `import { ${Array.from(transformersUsed).join(\", \")} } from \"class-transformer\";\\n`\n : \"\";\n\n const nestedDtoSection =\n nestedDtoClasses.length > 0 ? `\\n${nestedDtoClasses.join(\"\\n\\n\")}\\n` : \"\";\n\n return `${validatorImports}${transformerImports}${enumImports}${nestedDtoSection}\nexport default class Create${modelName.pascal}Dto {\n${dtoFields.join(\"\\n\\n\")}\n}`;\n}\n\nfunction generateNestedDtoClass(\n field: PrismaField,\n referencedModel: PrismaModel,\n dtoName: string,\n validatorsUsed: Set<string>,\n enumsUsed: Set<string>,\n isTypeScript: boolean\n): string {\n const fields: string[] = [];\n\n const refFieldName = field.foreignReferenceField || \"id\";\n const refFieldAsPrismaField = referencedModel.fields.find(\n (f) => f.name === refFieldName\n );\n\n if (refFieldAsPrismaField) {\n if (prismaSchemaParser.isEnum(refFieldAsPrismaField.type))\n enumsUsed.add(refFieldAsPrismaField.type);\n\n const { decorators, type } = generateClassValidatorField(\n refFieldAsPrismaField,\n false,\n validatorsUsed\n );\n const typeModifier = isTypeScript ? \"!\" : \"\";\n fields.push(\n `${decorators} ${refFieldAsPrismaField.name}${typeModifier}: ${type};`\n );\n }\n\n return `class ${dtoName} {\n${fields.join(\"\\n\\n\")}\n}`;\n}\n\nfunction generateClassValidatorField(\n field: PrismaField,\n isUserModule: boolean,\n validatorsUsed: Set<string>\n): { decorators: string; type: string } {\n let decorators: string[] = [];\n let type = mapPrismaTypeToTS(field.type);\n\n const isOptional = field.isOptional || field.defaultValue !== undefined;\n if (isOptional) {\n decorators.push(\"@IsOptional()\");\n validatorsUsed.add(\"IsOptional\");\n }\n\n if (field.isArray) {\n decorators.push(\"@IsArray()\");\n validatorsUsed.add(\"IsArray\");\n type = `${type}[]`;\n }\n\n if (prismaSchemaParser.isEnum(field.type)) {\n decorators.push(\n `@IsEnum(${field.type}${field.isArray ? \", { each: true }\" : \"\"})`\n );\n validatorsUsed.add(\"IsEnum\");\n type = field.isArray ? `${field.type}[]` : field.type;\n } else {\n const fieldValidators = getValidatorsForType(field, isUserModule);\n decorators.push(...fieldValidators);\n fieldValidators.forEach((decorator) => {\n const validatorName = decorator.match(/@(\\w+)/)?.[1];\n if (validatorName) validatorsUsed.add(validatorName);\n });\n }\n\n return {\n decorators:\n decorators.map((d) => ` ${d}`).join(\"\\n\") +\n (decorators.length > 0 ? \"\\n\" : \"\"),\n type,\n };\n}\n\nfunction getValidatorsForType(\n field: PrismaField,\n isUserModule: boolean\n): string[] {\n const validators: string[] = [];\n const arrayEach = field.isArray ? \", { each: true }\" : \"\";\n\n // User module special cases - return early to override default validators\n if (isUserModule) {\n if (field.name === \"email\") {\n return [\"@IsEmail()\"]; // Only IsEmail, no IsString\n } else if (field.name === \"password\") {\n return [\n \"@IsString()\",\n \"@MinLength(8)\",\n '@Matches(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\\\\d)/, { message: \"Password must contain at least one uppercase letter, one lowercase letter, and one number\" })',\n ];\n }\n }\n\n switch (field.type) {\n case \"String\":\n validators.push(`@IsString(${arrayEach})`);\n break;\n case \"Int\":\n case \"Float\":\n case \"Decimal\":\n validators.push(`@IsNumber({}${arrayEach})`);\n break;\n case \"Boolean\":\n validators.push(`@IsBoolean(${arrayEach})`);\n break;\n case \"DateTime\":\n validators.push(`@IsDate(${arrayEach})`);\n break;\n case \"BigInt\":\n validators.push(`@IsNumber({}${arrayEach})`);\n break;\n case \"Json\":\n validators.push(`@IsObject(${arrayEach})`);\n break;\n case \"Bytes\":\n break;\n default:\n break;\n }\n\n return validators;\n}\n\nfunction mapPrismaTypeToTS(prismaType: string): string {\n switch (prismaType) {\n case \"String\":\n return \"string\";\n case \"Int\":\n case \"Float\":\n case \"Decimal\":\n return \"number\";\n case \"Boolean\":\n return \"boolean\";\n case \"DateTime\":\n return \"Date\";\n case \"Json\":\n return \"any\";\n case \"Bytes\":\n return \"Buffer\";\n case \"BigInt\":\n return \"bigint\";\n default:\n // For enums and unknown types, return as any\n return prismaSchemaParser.isEnum(prismaType) ? prismaType : \"any\";\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"create-dto-template.js","sourceRoot":"","sources":["../../../../../../../../src/utils/cli/utils/template-generator/templates/class-validator/create-dto-template.ts"],"names":[],"mappings":";;;;;AAKA,8DA4GC;AAjHD,sGAA4E;AAE5E,kEAAyE;AAGzE,SAAgB,yBAAyB,CAAC,OAAwB;IAChE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAE9B,IAAI,CAAC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SAAS,GAAG,CAAC,CAAC;YAC3C,MAAM;QACR,KAAK,OAAO;YACV,MAAM;QACR;YACE,MAAM;IACV,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,iBAAiB,CAAC,UAAkB;IAC3C,QAAQ,UAAU,EAAE,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,KAAK,CAAC;QACX,KAAK,OAAO,CAAC;QACb,KAAK,SAAS;YACZ,OAAO,QAAQ,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,UAAU;YACb,OAAO,MAAM,CAAC;QAChB,KAAK,MAAM;YACT,OAAO,KAAK,CAAC;QACf,KAAK,OAAO;YACV,OAAO,QAAQ,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB;YAEE,OAAO,8BAAkB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC;IACtE,CAAC;AACH,CAAC","sourcesContent":["import prismaSchemaParser from \"../../../../../prisma/prisma-schema-parser\";\nimport { PrismaField, PrismaModel } from \"../../../../../prisma/types\";\nimport { getUserFileExtension } from \"../../../../../helpers/fs.helpers\";\nimport { TemplateOptions } from \"../../../template-generators\";\n\nexport function generateCreateDtoTemplate(options: TemplateOptions): string {\n const { modelName } = options;\n\n if (!modelName)\n throw new Error(\"Module name is required for create-dto template\");\n\n const model = prismaSchemaParser.models.find(\n (m) => m.name.toLowerCase() === modelName.pascal.toLowerCase()\n );\n\n if (!model)\n throw new Error(`Model ${modelName.pascal} not found in Prisma schema`);\n\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n const restrictedFields = [\"id\", \"createdAt\", \"updatedAt\", \"deletedAt\"];\n const isUserModule = modelName.kebab === \"user\";\n const enumsUsed = new Set<string>();\n const validatorsUsed = new Set<string>();\n const transformersUsed = new Set<string>();\n const nestedDtoClasses: string[] = [];\n\n let dtoFields: string[] = [];\n\n for (const field of model.fields) {\n if (field.isId || restrictedFields.includes(field.name)) {\n continue;\n }\n\n const isForeignKey = model.fields.some(\n (f) => f.foreignKeyField === field.name\n );\n if (isForeignKey) {\n continue;\n }\n\n if (field.isRelation) {\n if (field.isArray) continue;\n\n const referencedModel = prismaSchemaParser.models.find(\n (m) => m.name === field.type\n );\n\n if (referencedModel) {\n const isOptional = field.isOptional || field.defaultValue !== undefined;\n const optionalDecorator = isOptional ? \" @IsOptional()\\n\" : \"\";\n const typeModifier = isTypeScript ? (isOptional ? \"?\" : \"!\") : \"\";\n\n validatorsUsed.add(\"IsOptional\");\n validatorsUsed.add(\"ValidateNested\");\n transformersUsed.add(\"Type\");\n\n const relationDtoName = `${referencedModel.name}ForCreate${modelName.pascal}Dto`;\n\n // Generate the nested DTO class inline\n const nestedDtoClass = generateNestedDtoClass(\n field,\n referencedModel,\n relationDtoName,\n validatorsUsed,\n enumsUsed,\n isTypeScript\n );\n nestedDtoClasses.push(nestedDtoClass);\n\n dtoFields.push(\n `${optionalDecorator} @ValidateNested()\\n @Type(() => ${relationDtoName})\\n ${field.name}${typeModifier}: ${relationDtoName};`\n );\n }\n continue;\n }\n\n if (prismaSchemaParser.isEnum(field.type)) {\n enumsUsed.add(field.type);\n }\n\n const { decorators, type } = generateClassValidatorField(\n field,\n isUserModule,\n validatorsUsed\n );\n const isOptional = field.isOptional || field.defaultValue !== undefined;\n const typeModifier = isTypeScript ? (isOptional ? \"?\" : \"!\") : \"\";\n dtoFields.push(`${decorators} ${field.name}${typeModifier}: ${type};`);\n }\n\n const enumImports =\n enumsUsed.size > 0\n ? `import { ${Array.from(enumsUsed).join(\", \")} } from \"@prisma/client\";\\n`\n : \"\";\n\n const validatorImports =\n validatorsUsed.size > 0\n ? `import { ${Array.from(validatorsUsed).join(\", \")} } from \"class-validator\";\\n`\n : \"\";\n\n const transformerImports =\n transformersUsed.size > 0\n ? `import { ${Array.from(transformersUsed).join(\", \")} } from \"class-transformer\";\\n`\n : \"\";\n\n const nestedDtoSection =\n nestedDtoClasses.length > 0 ? `\\n${nestedDtoClasses.join(\"\\n\\n\")}\\n` : \"\";\n\n return `${validatorImports}${transformerImports}${enumImports}${nestedDtoSection}\nexport default class Create${modelName.pascal}Dto {\n${dtoFields.join(\"\\n\\n\")}\n}`;\n}\n\nfunction generateNestedDtoClass(\n field: PrismaField,\n referencedModel: PrismaModel,\n dtoName: string,\n validatorsUsed: Set<string>,\n enumsUsed: Set<string>,\n isTypeScript: boolean\n): string {\n const fields: string[] = [];\n\n const refFieldName = field.foreignReferenceField || \"id\";\n const refFieldAsPrismaField = referencedModel.fields.find(\n (f) => f.name === refFieldName\n );\n\n if (refFieldAsPrismaField) {\n if (prismaSchemaParser.isEnum(refFieldAsPrismaField.type))\n enumsUsed.add(refFieldAsPrismaField.type);\n\n const { decorators, type } = generateClassValidatorField(\n refFieldAsPrismaField,\n false,\n validatorsUsed\n );\n const typeModifier = isTypeScript ? \"!\" : \"\";\n fields.push(\n `${decorators} ${refFieldAsPrismaField.name}${typeModifier}: ${type};`\n );\n }\n\n return `class ${dtoName} {\n${fields.join(\"\\n\\n\")}\n}`;\n}\n\nfunction generateClassValidatorField(\n field: PrismaField,\n isUserModule: boolean,\n validatorsUsed: Set<string>\n): { decorators: string; type: string } {\n let decorators: string[] = [];\n let type = mapPrismaTypeToTS(field.type);\n\n const isOptional = field.isOptional || field.defaultValue !== undefined;\n if (isOptional) {\n decorators.push(\"@IsOptional()\");\n validatorsUsed.add(\"IsOptional\");\n }\n\n if (field.isArray) {\n decorators.push(\"@IsArray()\");\n validatorsUsed.add(\"IsArray\");\n type = `${type}[]`;\n }\n\n if (prismaSchemaParser.isEnum(field.type)) {\n decorators.push(\n `@IsEnum(${field.type}${field.isArray ? \", { each: true }\" : \"\"})`\n );\n validatorsUsed.add(\"IsEnum\");\n type = field.isArray ? `${field.type}[]` : field.type;\n } else {\n const fieldValidators = getValidatorsForType(field, isUserModule);\n decorators.push(...fieldValidators);\n fieldValidators.forEach((decorator) => {\n const validatorName = decorator.match(/@(\\w+)/)?.[1];\n if (validatorName) validatorsUsed.add(validatorName);\n });\n }\n\n return {\n decorators:\n decorators.map((d) => ` ${d}`).join(\"\\n\") +\n (decorators.length > 0 ? \"\\n\" : \"\"),\n type,\n };\n}\n\nfunction getValidatorsForType(\n field: PrismaField,\n isUserModule: boolean\n): string[] {\n const validators: string[] = [];\n const arrayEach = field.isArray ? \"{ each: true }\" : \"\";\n\n // User module special cases - return early to override default validators\n if (isUserModule) {\n if (field.name === \"email\") {\n return [\"@IsEmail()\"]; // Only IsEmail, no IsString\n } else if (field.name === \"password\") {\n return [\n \"@IsString()\",\n \"@MinLength(8)\",\n '@Matches(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\\\\d)/, { message: \"Password must contain at least one uppercase letter, one lowercase letter, and one number\" })',\n ];\n }\n }\n\n switch (field.type) {\n case \"String\":\n validators.push(`@IsString(${arrayEach})`);\n break;\n case \"Int\":\n case \"Float\":\n case \"Decimal\":\n validators.push(`@IsNumber(${arrayEach})`);\n break;\n case \"Boolean\":\n validators.push(`@IsBoolean(${arrayEach})`);\n break;\n case \"DateTime\":\n validators.push(`@IsDate(${arrayEach})`);\n break;\n case \"BigInt\":\n validators.push(`@IsNumber(${arrayEach})`);\n break;\n case \"Json\":\n validators.push(`@IsObject(${arrayEach})`);\n break;\n case \"Bytes\":\n break;\n default:\n break;\n }\n\n return validators;\n}\n\nfunction mapPrismaTypeToTS(prismaType: string): string {\n switch (prismaType) {\n case \"String\":\n return \"string\";\n case \"Int\":\n case \"Float\":\n case \"Decimal\":\n return \"number\";\n case \"Boolean\":\n return \"boolean\";\n case \"DateTime\":\n return \"Date\";\n case \"Json\":\n return \"any\";\n case \"Bytes\":\n return \"Buffer\";\n case \"BigInt\":\n return \"bigint\";\n default:\n // For enums and unknown types, return as any\n return prismaSchemaParser.isEnum(prismaType) ? prismaType : \"any\";\n }\n}\n"]}
|
package/dist/cjs/utils/cli/utils/template-generator/templates/class-validator/update-dto-template.js
CHANGED
|
@@ -115,7 +115,7 @@ function generateClassValidatorField(field, isUserModule, validatorsUsed) {
|
|
|
115
115
|
}
|
|
116
116
|
function getValidatorsForType(field, isUserModule) {
|
|
117
117
|
const validators = [];
|
|
118
|
-
const arrayEach = field.isArray ? "
|
|
118
|
+
const arrayEach = field.isArray ? "{ each: true }" : "";
|
|
119
119
|
if (isUserModule) {
|
|
120
120
|
if (field.name === "email") {
|
|
121
121
|
return ["@IsEmail()"];
|
|
@@ -135,7 +135,7 @@ function getValidatorsForType(field, isUserModule) {
|
|
|
135
135
|
case "Int":
|
|
136
136
|
case "Float":
|
|
137
137
|
case "Decimal":
|
|
138
|
-
validators.push(`@IsNumber(
|
|
138
|
+
validators.push(`@IsNumber(${arrayEach})`);
|
|
139
139
|
break;
|
|
140
140
|
case "Boolean":
|
|
141
141
|
validators.push(`@IsBoolean(${arrayEach})`);
|
|
@@ -144,7 +144,7 @@ function getValidatorsForType(field, isUserModule) {
|
|
|
144
144
|
validators.push(`@IsDate(${arrayEach})`);
|
|
145
145
|
break;
|
|
146
146
|
case "BigInt":
|
|
147
|
-
validators.push(`@IsNumber(
|
|
147
|
+
validators.push(`@IsNumber(${arrayEach})`);
|
|
148
148
|
break;
|
|
149
149
|
case "Json":
|
|
150
150
|
validators.push(`@IsObject(${arrayEach})`);
|