create-arkos 0.0.21 → 0.0.23-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.
Files changed (26) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +2 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/utils/project-config-inquirer.js +6 -8
  5. package/dist/utils/project-config-inquirer.js.map +1 -1
  6. package/dist/utils/template-compiler.js +39 -3
  7. package/dist/utils/template-compiler.js.map +1 -1
  8. package/package.json +1 -2
  9. package/templates/basic/package.json.hbs +2 -2
  10. package/templates/basic/prisma/schema/user.prisma.hbs +3 -3
  11. package/templates/basic/src/modules/auth/auth.middlewares.ts.hbs +103 -0
  12. package/templates/basic/src/modules/auth/auth.query.ts.hbs +21 -0
  13. package/templates/basic/src/modules/auth/dtos/login.dto.ts.hbs +13 -0
  14. package/templates/basic/src/modules/auth/dtos/signup.dto.ts.hbs +14 -0
  15. package/templates/basic/src/modules/auth/schemas/login.schema.ts.hbs +11 -0
  16. package/templates/basic/src/modules/auth/schemas/signup.schema.ts.hbs +12 -0
  17. package/templates/basic/src/modules/file-upload/file-upload.middlewares.ts.hbs +77 -0
  18. package/templates/basic/src/modules/user/dtos/create-user.dto.ts.hbs +87 -0
  19. package/templates/basic/src/modules/user/dtos/update-user.dto.ts.hbs +95 -0
  20. package/templates/basic/src/modules/user/schemas/create-user.schema.ts.hbs +46 -0
  21. package/templates/basic/src/modules/user/schemas/update-user.schema.ts.hbs +46 -0
  22. package/templates/basic/src/modules/user/user.middlewares.ts.hbs +163 -0
  23. package/templates/basic/src/modules/user/user.query.ts.hbs +35 -0
  24. package/templates/basic/src/modules/user/user.service.ts.hbs +19 -0
  25. package/templates/basic/src/utils/prisma/index.ts.hbs +1 -1
  26. package/templates/basic/src/utils/validation/api-actions.ts.hbs +11 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Uanela Como
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ function main() {
30
30
  const projectPath = config.projectPath;
31
31
  fs_1.default.mkdirSync(projectPath, { recursive: true });
32
32
  console.info(`\nCreating a new ${chalk_1.default.bold(chalk_1.default.cyan("Arkos.js"))} project under ${chalk_1.default.green(`./${config.projectName}`)}`);
33
+ console.log(JSON.stringify(config));
33
34
  const templatesDir = path_1.default.join(__dirname, `../templates/basic`);
34
35
  yield template_compiler_1.default.compile(templatesDir, config);
35
36
  process.chdir(projectPath);
@@ -39,7 +40,7 @@ function main() {
39
40
  dependencies.forEach((dependency) => console.info(`- ${dependency}`));
40
41
  console.info(chalk_1.default.bold("\ndevDependencies:"));
41
42
  devDependencies.forEach((devDependency) => console.info(`- ${devDependency}`));
42
- console.info("\nInstalling dependencies...");
43
+ console.info(chalk_1.default.bold("\nInstalling dependencies..."));
43
44
  console.info(`Using ${packageManager}.\n`);
44
45
  (0, child_process_1.execSync)(`${packageManager} install`, { stdio: "inherit" });
45
46
  process.chdir(projectPath);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,4CAAoB;AACpB,gDAAwB;AACxB,kDAA0B;AAC1B,iDAAyC;AACzC,8FAAoE;AACpE,kFAAyD;AACzD,4DAAoC;AACpC,6CAAmE;AACnE,6DAAgF;AAEhF,oBAAU,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AACnD,oBAAU,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAEpD,SAAe,IAAI;;QACjB,MAAM,MAAM,GAAG,MAAM,iCAAqB,CAAC,GAAG,EAAE,CAAC;QAEjD,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QAEvC,YAAE,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAE/C,OAAO,CAAC,IAAI,CACV,oBAAoB,eAAK,CAAC,IAAI,CAAC,eAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,kBAAkB,eAAK,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,WAAW,EAAE,CAAC,EAAE,CACjH,CAAC;QAEF,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;QAChE,MAAM,2BAAgB,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAErD,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAE3B,MAAM,cAAc,GAAG,IAAA,+CAAiC,GAAE,CAAC;QAC3D,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,GACrC,IAAA,0CAAgC,EAAC,WAAW,CAAC,CAAC;QAEhD,OAAO,CAAC,IAAI,CAAC,eAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;QAC5C,YAAY,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,UAAU,EAAE,CAAC,CAAC,CAAC;QAEtE,OAAO,CAAC,IAAI,CAAC,eAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;QAC/C,eAAe,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE,CACxC,OAAO,CAAC,IAAI,CAAC,KAAK,aAAa,EAAE,CAAC,CACnC,CAAC;QAEF,OAAO,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;QAC7C,OAAO,CAAC,IAAI,CAAC,SAAS,cAAc,KAAK,CAAC,CAAC;QAE3C,IAAA,wBAAQ,EAAC,GAAG,cAAc,UAAU,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAE5D,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;QACjD,IAAA,wBAAQ,EAAC,qBAAqB,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAEtD,OAAO,CAAC,IAAI,CAAC;IACX,eAAK,CAAC,IAAI,CAAC,eAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;;;UAG5B,MAAM,CAAC,WAAW;kBACV,eAAK,CAAC,IAAI,CAAC,cAAc,CAAC;;OAErC,cAAc;KAChB,CAAC,CAAC;IACP,CAAC;CAAA;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\nimport fs from \"fs\";\nimport path from \"path\";\nimport chalk from \"chalk\";\nimport { execSync } from \"child_process\";\nimport projectConfigInquirer from \"./utils/project-config-inquirer\";\nimport templateCompiler from \"./utils/template-compiler\";\nimport Handlebars from \"handlebars\";\nimport { getProcjetPackageJsonDependecies } from \"./utils/helpers\";\nimport { detectPackageManagerFromUserAgent } from \"./utils/helpers/npm.helpers\";\n\nHandlebars.registerHelper(\"eq\", (a, b) => a === b);\nHandlebars.registerHelper(\"neq\", (a, b) => a !== b);\n\nasync function main() {\n const config = await projectConfigInquirer.run();\n\n const projectPath = config.projectPath;\n\n fs.mkdirSync(projectPath, { recursive: true });\n\n console.info(\n `\\nCreating a new ${chalk.bold(chalk.cyan(\"Arkos.js\"))} project under ${chalk.green(`./${config.projectName}`)}`\n );\n\n const templatesDir = path.join(__dirname, `../templates/basic`);\n await templateCompiler.compile(templatesDir, config);\n\n process.chdir(projectPath);\n\n const packageManager = detectPackageManagerFromUserAgent();\n const { dependencies, devDependencies } =\n getProcjetPackageJsonDependecies(projectPath);\n\n console.info(chalk.bold(\"\\ndependencies:\"));\n dependencies.forEach((dependency) => console.info(`- ${dependency}`));\n\n console.info(chalk.bold(\"\\ndevDependencies:\"));\n devDependencies.forEach((devDependency) =>\n console.info(`- ${devDependency}`)\n );\n\n console.info(\"\\nInstalling dependencies...\");\n console.info(`Using ${packageManager}.\\n`);\n\n execSync(`${packageManager} install`, { stdio: \"inherit\" });\n\n process.chdir(projectPath);\n console.info(\"\\nRunning npx prisma generate...\");\n execSync(`npx prisma generate`, { stdio: \"inherit\" });\n\n console.info(`\n ${chalk.bold(chalk.cyan(\"Arkos.js\"))} project created successfully!\n\n Next steps:\n 1. cd ${config.projectName}\n 2. setup your ${chalk.cyan(\"DATABASE_URL\")} under .env\n 3. npx prisma db push\n 4. ${packageManager} run dev\n `);\n}\n\nmain().catch(console.error);\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,4CAAoB;AACpB,gDAAwB;AACxB,kDAA0B;AAC1B,iDAAyC;AACzC,8FAAoE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C,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,UAAU,EAAE,CAAC,CAAC,CAAC;QAEtE,OAAO,CAAC,IAAI,CAAC,eAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;QAC/C,eAAe,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE,CACxC,OAAO,CAAC,IAAI,CAAC,KAAK,aAAa,EAAE,CAAC,CACnC,CAAC;QAEF,OAAO,CAAC,IAAI,CAAC,eAAK,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,SAAS,cAAc,KAAK,CAAC,CAAC;QAE3C,IAAA,wBAAQ,EAAC,GAAG,cAAc,UAAU,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAE5D,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;QACjD,IAAA,wBAAQ,EAAC,qBAAqB,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAEtD,OAAO,CAAC,IAAI,CAAC;IACX,eAAK,CAAC,IAAI,CAAC,eAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;;;UAG5B,MAAM,CAAC,WAAW;kBACV,eAAK,CAAC,IAAI,CAAC,cAAc,CAAC;;OAErC,cAAc;KAChB,CAAC,CAAC;IACP,CAAC;CAAA;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\nimport fs from \"fs\";\nimport path from \"path\";\nimport chalk from \"chalk\";\nimport { execSync } from \"child_process\";\nimport projectConfigInquirer from \"./utils/project-config-inquirer\";\nimport templateCompiler from \"./utils/template-compiler\";\nimport Handlebars from \"handlebars\";\nimport { getProcjetPackageJsonDependecies } from \"./utils/helpers\";\nimport { detectPackageManagerFromUserAgent } from \"./utils/helpers/npm.helpers\";\n\nHandlebars.registerHelper(\"eq\", (a, b) => a === b);\nHandlebars.registerHelper(\"neq\", (a, b) => a !== b);\n\nasync function main() {\n const config = await projectConfigInquirer.run();\n\n const projectPath = config.projectPath;\n\n fs.mkdirSync(projectPath, { recursive: true });\n\n console.info(\n `\\nCreating a new ${chalk.bold(chalk.cyan(\"Arkos.js\"))} project under ${chalk.green(`./${config.projectName}`)}`\n );\n\n console.log(JSON.stringify(config));\n const templatesDir = path.join(__dirname, `../templates/basic`);\n await templateCompiler.compile(templatesDir, config);\n\n process.chdir(projectPath);\n\n const packageManager = detectPackageManagerFromUserAgent();\n const { dependencies, devDependencies } =\n getProcjetPackageJsonDependecies(projectPath);\n\n console.info(chalk.bold(\"\\ndependencies:\"));\n dependencies.forEach((dependency) => console.info(`- ${dependency}`));\n\n console.info(chalk.bold(\"\\ndevDependencies:\"));\n devDependencies.forEach((devDependency) =>\n console.info(`- ${devDependency}`)\n );\n\n console.info(chalk.bold(\"\\nInstalling dependencies...\"));\n console.info(`Using ${packageManager}.\\n`);\n\n execSync(`${packageManager} install`, { stdio: \"inherit\" });\n\n process.chdir(projectPath);\n console.info(\"\\nRunning npx prisma generate...\");\n execSync(`npx prisma generate`, { stdio: \"inherit\" });\n\n console.info(`\n ${chalk.bold(chalk.cyan(\"Arkos.js\"))} project created successfully!\n\n Next steps:\n 1. cd ${config.projectName}\n 2. setup your ${chalk.cyan(\"DATABASE_URL\")} under .env\n 3. npx prisma db push\n 4. ${packageManager} run dev\n `);\n}\n\nmain().catch(console.error);\n"]}
@@ -87,7 +87,7 @@ class ProjectConfigInquirer {
87
87
  {
88
88
  type: "confirm",
89
89
  name: "typescript",
90
- message: `Would you like to use ${chalk_1.default.cyan("TypeScript")}?`,
90
+ message: `Would you like to use ${chalk_1.default.blue("TypeScript")}?`,
91
91
  default: false,
92
92
  },
93
93
  ]);
@@ -100,7 +100,7 @@ class ProjectConfigInquirer {
100
100
  {
101
101
  type: "list",
102
102
  name: "prismaProvider",
103
- message: `What db provider will be used for ${chalk_1.default.cyan("Prisma")}?`,
103
+ message: `What db provider will be used for ${chalk_1.default.blue("Prisma")}?`,
104
104
  choices: [
105
105
  "postgresql",
106
106
  "mongodb",
@@ -155,7 +155,7 @@ class ProjectConfigInquirer {
155
155
  {
156
156
  type: "confirm",
157
157
  name: "useValidation",
158
- message: `Would you like to set up ${chalk_1.default.cyan("Validation")}?`,
158
+ message: `Would you like to set up ${chalk_1.default.blue("Validation")}?`,
159
159
  default: true,
160
160
  },
161
161
  ]);
@@ -180,7 +180,7 @@ class ProjectConfigInquirer {
180
180
  {
181
181
  type: "confirm",
182
182
  name: "useAuthentication",
183
- message: `Would you like to set up ${chalk_1.default.cyan("Authentication")}?`,
183
+ message: `Would you like to set up ${chalk_1.default.blue("Authentication")}?`,
184
184
  default: true,
185
185
  },
186
186
  ]);
@@ -213,12 +213,10 @@ class ProjectConfigInquirer {
213
213
  type: "confirm",
214
214
  name: "multipleRoles",
215
215
  default: true,
216
- message: `Would you like to use authentication with ${chalk_1.default.cyan("Multiple Roles")}?`,
216
+ message: `Would you like to use authentication with ${chalk_1.default.blue("Multiple Roles")}?`,
217
217
  },
218
218
  ]);
219
- this.config.authentication = {
220
- multipleRoles,
221
- };
219
+ this.config.authentication = Object.assign(Object.assign({}, this.config.authentication), { multipleRoles });
222
220
  }
223
221
  else if (this.config.prisma.provider === "sqlite") {
224
222
  console.info(`\nSkipping multiple roles option because it is not supported with sqlite prisma provider...`);
@@ -1 +1 @@
1
- {"version":3,"file":"project-config-inquirer.js","sourceRoot":"","sources":["../../src/utils/project-config-inquirer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,wDAAgC;AAChC,kDAA0B;AA2B1B,MAAM,qBAAqB;IAGzB;QACE,IAAI,CAAC,MAAM,GAAG,EAAmB,CAAC;IACpC,CAAC;IAEK,GAAG;;YACP,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC/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,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC;oBAC9C;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,eAAe;wBACrB,OAAO,EAAE,0CAA0C;wBACnD,OAAO,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,cAAc,CAAC;qBAC/C;iBACF,CAAC,CAAC;gBAEH,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG;oBAC3B,IAAI,EAAE,kBAAkB;oBACxB,aAAa,EACX,aAAa,KAAK,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa;oBAC7D,aAAa,EAAE,KAAK;iBACrB,CAAC;gBAEF,IACE,kBAAkB,KAAK,cAAc;oBACrC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,EACxC;oBACA,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC;wBAC9C;4BACE,IAAI,EAAE,SAAS;4BACf,IAAI,EAAE,eAAe;4BACrB,OAAO,EAAE,IAAI;4BACb,OAAO,EAAE,6CAA6C,eAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG;yBACtF;qBACF,CAAC,CAAC;oBAEH,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG;wBAC3B,aAAa;qBACd,CAAC;iBACH;qBAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE;oBACnD,OAAO,CAAC,IAAI,CACV,6FAA6F,CAC9F,CAAC;iBACH;aACF;QACH,CAAC;KAAA;CACF;AAED,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,EAAE,CAAC;AAE1D,kBAAe,qBAAqB,CAAC","sourcesContent":["import path from \"path\";\nimport inquirer from \"inquirer\";\nimport chalk from \"chalk\";\n\nexport interface ProjectConfig {\n projectName: string;\n typescript: boolean;\n validation: {\n type?: \"zod\" | \"class-validator\";\n };\n authentication: {\n type?: \"static\" | \"dynamic\" | \"define later\";\n usernameField?: \"username\" | \"email\" | \"custom\";\n multipleRoles: boolean;\n };\n prisma: {\n provider:\n | \"postgresql\"\n | \"mysql\"\n | \"sqlite\"\n | \"sqlserver\"\n | \"cockroachdb\"\n | \"mongodb\";\n idDatabaseType: string;\n defaultDBurl: string;\n };\n projectPath: string;\n}\n\nclass ProjectConfigInquirer {\n private config: ProjectConfig;\n\n constructor() {\n this.config = {} as ProjectConfig;\n }\n\n async run() {\n await this.promptProjectName();\n await this.promptTypescript();\n await this.promptPrismaProvider();\n await this.promptValidation();\n await this.promptAuthentication();\n\n const projectPath = path.resolve(process.cwd(), this.config.projectName);\n this.config.projectPath = projectPath;\n\n return this.config;\n }\n\n private async promptProjectName() {\n let projectName = process.argv[2];\n\n // If user passed \".\", use current directory name\n if (projectName === \".\") {\n projectName = path.basename(process.cwd());\n }\n\n if (!projectName) {\n const result = await inquirer.prompt([\n {\n type: \"input\",\n name: \"projectName\",\n message: \"What is the name of your project?\",\n default: \"my-arkos-project\",\n validate: this.validateProjectName,\n },\n ]);\n projectName = result.projectName;\n } else {\n // Validate the project name from command line args\n const validation = this.validateProjectName(projectName);\n if (validation !== true) {\n console.error(chalk.red(`Error: ${validation}`));\n process.exit(1);\n }\n }\n\n this.config.projectName = projectName;\n }\n\n private validateProjectName(input: string): boolean | string {\n if (!input || input.length === 0) {\n return \"Project name cannot be empty\";\n }\n\n // Check for valid characters (letters, numbers, hyphens, underscores)\n if (!/^[a-zA-Z0-9_-]+$/.test(input)) {\n return \"Project name can only contain letters, numbers, hyphens, and underscores\";\n }\n\n // Check if it starts with a letter or number (not hyphen or underscore)\n if (!/^[a-zA-Z0-9]/.test(input)) {\n return \"Project name must start with a letter or number\";\n }\n\n // Check if it ends with a letter or number (not hyphen or underscore)\n if (!/[a-zA-Z0-9]$/.test(input)) {\n return \"Project name must end with a letter or number\";\n }\n\n // Check length (reasonable limits)\n if (input.length > 50) {\n return \"Project name must be 50 characters or less\";\n }\n\n // Check for reserved names\n const reservedNames = [\"node_modules\"];\n if (reservedNames.includes(input.toLowerCase())) {\n return \"Project name cannot be a reserved name\";\n }\n\n return true;\n }\n\n private async promptTypescript() {\n const { typescript } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"typescript\",\n message: `Would you like to use ${chalk.cyan(\"TypeScript\")}?`,\n default: false,\n },\n ]);\n this.config.typescript = typescript;\n }\n\n private async promptPrismaProvider() {\n const { prismaProvider } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"prismaProvider\",\n message: `What db provider will be used for ${chalk.cyan(\"Prisma\")}?`,\n choices: [\n \"postgresql\",\n \"mongodb\",\n \"mysql\",\n \"sqlite\",\n \"sqlserver\",\n \"cockroachdb\",\n ],\n },\n ]);\n\n // Set the correct idDatabaseType based on provider\n let idDatabaseType: string;\n let defaultDBurl: string;\n\n switch (prismaProvider) {\n case \"mongodb\":\n idDatabaseType = '@id @default(auto()) @map(\"_id\") @db.ObjectId';\n defaultDBurl = `mongodb://localhost:27017/${this.config.projectName}`;\n break;\n case \"sqlite\":\n idDatabaseType = \"@id @default(cuid())\";\n defaultDBurl = \"file:../../file.db\";\n break;\n case \"mysql\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `mysql://username:password@localhost:3306/${this.config.projectName}`;\n break;\n case \"postgresql\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `postgresql://username:password@localhost:5432/${this.config.projectName}`;\n break;\n case \"sqlserver\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `sqlserver://localhost:1433;database=${this.config.projectName};username=sa;password=password;encrypt=DANGER_PLAINTEXT`;\n break;\n case \"cockroachdb\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `postgresql://username:password@localhost:26257/${this.config.projectName}?sslmode=require`;\n break;\n default:\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `postgresql://username:password@localhost:5432/${this.config.projectName}`;\n }\n\n this.config.prisma = {\n provider: prismaProvider,\n idDatabaseType: idDatabaseType,\n defaultDBurl: defaultDBurl,\n };\n }\n\n private async promptValidation() {\n const { useValidation } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"useValidation\",\n message: `Would you like to set up ${chalk.cyan(\"Validation\")}?`,\n default: true,\n },\n ]);\n\n if (useValidation) {\n const { validationType } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"validationType\",\n message: \"Choose validation library:\",\n choices: [\"zod\", \"class-validator\"],\n },\n ]);\n this.config.validation = {\n type: validationType,\n };\n }\n }\n\n private async promptAuthentication() {\n const { useAuthentication } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"useAuthentication\",\n message: `Would you like to set up ${chalk.cyan(\"Authentication\")}?`,\n default: true,\n },\n ]);\n\n if (useAuthentication) {\n const { authenticationType } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"authenticationType\",\n message: \"Choose authentication type:\",\n choices: [\"static\", \"dynamic\", \"define later\"],\n },\n ]);\n\n const { usernameField } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"usernameField\",\n message: \"Choose default username field for login:\",\n choices: [\"email\", \"username\", \"define later\"],\n },\n ]);\n\n this.config.authentication = {\n type: authenticationType,\n usernameField:\n usernameField === \"define later\" ? \"custom\" : usernameField,\n multipleRoles: false,\n };\n\n if (\n authenticationType !== \"define later\" &&\n this.config.prisma.provider !== \"sqlite\"\n ) {\n const { multipleRoles } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"multipleRoles\",\n default: true,\n message: `Would you like to use authentication with ${chalk.cyan(\"Multiple Roles\")}?`,\n },\n ]);\n\n this.config.authentication = {\n multipleRoles,\n };\n } else if (this.config.prisma.provider === \"sqlite\") {\n console.info(\n `\\nSkipping multiple roles option because it is not supported with sqlite prisma provider...`\n );\n }\n }\n }\n}\n\nconst projectConfigInquirer = new ProjectConfigInquirer();\n\nexport default projectConfigInquirer;\n"]}
1
+ {"version":3,"file":"project-config-inquirer.js","sourceRoot":"","sources":["../../src/utils/project-config-inquirer.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C;KAAA;CACF;AAED,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,EAAE,CAAC;AAE1D,kBAAe,qBAAqB,CAAC","sourcesContent":["import path from \"path\";\nimport inquirer from \"inquirer\";\nimport chalk from \"chalk\";\n\nexport interface ProjectConfig {\n projectName: string;\n typescript: boolean;\n validation: {\n type?: \"zod\" | \"class-validator\";\n };\n authentication: {\n type?: \"static\" | \"dynamic\" | \"define later\";\n usernameField?: \"username\" | \"email\" | \"custom\";\n multipleRoles: boolean;\n };\n prisma: {\n provider:\n | \"postgresql\"\n | \"mysql\"\n | \"sqlite\"\n | \"sqlserver\"\n | \"cockroachdb\"\n | \"mongodb\";\n idDatabaseType: string;\n defaultDBurl: string;\n };\n projectPath: string;\n}\n\nclass ProjectConfigInquirer {\n private config: ProjectConfig;\n\n constructor() {\n this.config = {} as ProjectConfig;\n }\n\n async run() {\n await this.promptProjectName();\n await this.promptTypescript();\n await this.promptPrismaProvider();\n await this.promptValidation();\n await this.promptAuthentication();\n\n const projectPath = path.resolve(process.cwd(), this.config.projectName);\n this.config.projectPath = projectPath;\n\n return this.config;\n }\n\n private async promptProjectName() {\n let projectName = process.argv[2];\n\n // If user passed \".\", use current directory name\n if (projectName === \".\") {\n projectName = path.basename(process.cwd());\n }\n\n if (!projectName) {\n const result = await inquirer.prompt([\n {\n type: \"input\",\n name: \"projectName\",\n message: \"What is the name of your project?\",\n default: \"my-arkos-project\",\n validate: this.validateProjectName,\n },\n ]);\n projectName = result.projectName;\n } else {\n // Validate the project name from command line args\n const validation = this.validateProjectName(projectName);\n if (validation !== true) {\n console.error(chalk.red(`Error: ${validation}`));\n process.exit(1);\n }\n }\n\n this.config.projectName = projectName;\n }\n\n private validateProjectName(input: string): boolean | string {\n if (!input || input.length === 0) {\n return \"Project name cannot be empty\";\n }\n\n // Check for valid characters (letters, numbers, hyphens, underscores)\n if (!/^[a-zA-Z0-9_-]+$/.test(input)) {\n return \"Project name can only contain letters, numbers, hyphens, and underscores\";\n }\n\n // Check if it starts with a letter or number (not hyphen or underscore)\n if (!/^[a-zA-Z0-9]/.test(input)) {\n return \"Project name must start with a letter or number\";\n }\n\n // Check if it ends with a letter or number (not hyphen or underscore)\n if (!/[a-zA-Z0-9]$/.test(input)) {\n return \"Project name must end with a letter or number\";\n }\n\n // Check length (reasonable limits)\n if (input.length > 50) {\n return \"Project name must be 50 characters or less\";\n }\n\n // Check for reserved names\n const reservedNames = [\"node_modules\"];\n if (reservedNames.includes(input.toLowerCase())) {\n return \"Project name cannot be a reserved name\";\n }\n\n return true;\n }\n\n private async promptTypescript() {\n const { typescript } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"typescript\",\n message: `Would you like to use ${chalk.blue(\"TypeScript\")}?`,\n default: false,\n },\n ]);\n this.config.typescript = typescript;\n }\n\n private async promptPrismaProvider() {\n const { prismaProvider } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"prismaProvider\",\n message: `What db provider will be used for ${chalk.blue(\"Prisma\")}?`,\n choices: [\n \"postgresql\",\n \"mongodb\",\n \"mysql\",\n \"sqlite\",\n \"sqlserver\",\n \"cockroachdb\",\n ],\n },\n ]);\n\n // Set the correct idDatabaseType based on provider\n let idDatabaseType: string;\n let defaultDBurl: string;\n\n switch (prismaProvider) {\n case \"mongodb\":\n idDatabaseType = '@id @default(auto()) @map(\"_id\") @db.ObjectId';\n defaultDBurl = `mongodb://localhost:27017/${this.config.projectName}`;\n break;\n case \"sqlite\":\n idDatabaseType = \"@id @default(cuid())\";\n defaultDBurl = \"file:../../file.db\";\n break;\n case \"mysql\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `mysql://username:password@localhost:3306/${this.config.projectName}`;\n break;\n case \"postgresql\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `postgresql://username:password@localhost:5432/${this.config.projectName}`;\n break;\n case \"sqlserver\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `sqlserver://localhost:1433;database=${this.config.projectName};username=sa;password=password;encrypt=DANGER_PLAINTEXT`;\n break;\n case \"cockroachdb\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `postgresql://username:password@localhost:26257/${this.config.projectName}?sslmode=require`;\n break;\n default:\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `postgresql://username:password@localhost:5432/${this.config.projectName}`;\n }\n\n this.config.prisma = {\n provider: prismaProvider,\n idDatabaseType: idDatabaseType,\n defaultDBurl: defaultDBurl,\n };\n }\n\n private async promptValidation() {\n const { useValidation } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"useValidation\",\n message: `Would you like to set up ${chalk.blue(\"Validation\")}?`,\n default: true,\n },\n ]);\n\n if (useValidation) {\n const { validationType } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"validationType\",\n message: \"Choose validation library:\",\n choices: [\"zod\", \"class-validator\"],\n },\n ]);\n this.config.validation = {\n type: validationType,\n };\n }\n }\n\n private async promptAuthentication() {\n const { useAuthentication } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"useAuthentication\",\n message: `Would you like to set up ${chalk.blue(\"Authentication\")}?`,\n default: true,\n },\n ]);\n\n if (useAuthentication) {\n const { authenticationType } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"authenticationType\",\n message: \"Choose authentication type:\",\n choices: [\"static\", \"dynamic\", \"define later\"],\n },\n ]);\n\n const { usernameField } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"usernameField\",\n message: \"Choose default username field for login:\",\n choices: [\"email\", \"username\", \"define later\"],\n },\n ]);\n\n this.config.authentication = {\n type: authenticationType,\n usernameField:\n usernameField === \"define later\" ? \"custom\" : usernameField,\n multipleRoles: false,\n };\n\n if (\n authenticationType !== \"define later\" &&\n this.config.prisma.provider !== \"sqlite\"\n ) {\n const { multipleRoles } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"multipleRoles\",\n default: true,\n message: `Would you like to use authentication with ${chalk.blue(\"Multiple Roles\")}?`,\n },\n ]);\n\n this.config.authentication = {\n ...this.config.authentication,\n multipleRoles,\n };\n } else if (this.config.prisma.provider === \"sqlite\") {\n console.info(\n `\\nSkipping multiple roles option because it is not supported with sqlite prisma provider...`\n );\n }\n }\n }\n}\n\nconst projectConfigInquirer = new ProjectConfigInquirer();\n\nexport default projectConfigInquirer;\n"]}
@@ -23,16 +23,52 @@ class TemplateCompiler {
23
23
  });
24
24
  }
25
25
  filesToBeSkipped(config) {
26
- var _a, _b;
26
+ var _a, _b, _c;
27
27
  const files = [];
28
+ const zodAuthSchemaFiles = [
29
+ "login.schema.ts.hbs",
30
+ "signup.schema.ts.hbs",
31
+ "update-password.schema.ts.hbs",
32
+ ];
33
+ const classValidatorAuthDtoFiles = [
34
+ "login.dto.ts.hbs",
35
+ "signup.dto.ts.hbs",
36
+ "update-password.dto.ts.hbs",
37
+ ];
38
+ const zodUserSchemaFiles = [
39
+ "create-user.schema.ts.hbs",
40
+ "update-user.schema.ts.hbs",
41
+ ];
42
+ const classValidatorUserSchemaFiles = [
43
+ "create-user.dto.ts.hbs",
44
+ "update-user.dto.ts.hbs",
45
+ ];
46
+ const userComponents = [
47
+ "user.middlewares.ts.hbs",
48
+ "user.query.ts.hbs",
49
+ "user.service.ts.hbs",
50
+ "user.prisma.hbs",
51
+ ];
52
+ const authComponents = [
53
+ "auth.middlewares.ts.hbs",
54
+ "auth.query.ts.hbs",
55
+ "auth-role.prisma.hbs",
56
+ "auth-permission.prisma.hbs",
57
+ "user-role.prisma.hbs",
58
+ ];
28
59
  if (((_a = config.authentication) === null || _a === void 0 ? void 0 : _a.type) === "define later")
29
- files.push(...["user.prisma.hbs"]);
30
- if (((_b = config.authentication) === null || _b === void 0 ? void 0 : _b.type) === "static")
60
+ files.push(...userComponents, ...authComponents, ...zodAuthSchemaFiles, ...classValidatorAuthDtoFiles, ...zodUserSchemaFiles, ...classValidatorUserSchemaFiles);
61
+ if (((_b = config.authentication) === null || _b === void 0 ? void 0 : _b.type) === "static" ||
62
+ ((_c = config.authentication) === null || _c === void 0 ? void 0 : _c.type) === "define later")
31
63
  files.push(...[
32
64
  "auth-role.prisma.hbs",
33
65
  "auth-permission.prisma.hbs",
34
66
  "user-role.prisma.hbs",
35
67
  ]);
68
+ if (config.validation.type !== "zod")
69
+ files.push(...zodUserSchemaFiles, ...zodAuthSchemaFiles);
70
+ if (config.validation.type !== "class-validator")
71
+ files.push(...classValidatorUserSchemaFiles, ...classValidatorAuthDtoFiles);
36
72
  if (!config.typescript)
37
73
  files.push(...["tsconfig.json.hbs"]);
38
74
  if (config === null || config === void 0 ? void 0 : config.typescript)
@@ -1 +1 @@
1
- {"version":3,"file":"template-compiler.js","sourceRoot":"","sources":["../../src/utils/template-compiler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,gDAAwB;AACxB,4CAAoB;AACpB,4DAAoC;AACpC,uDAA6D;AAE7D,MAAM,gBAAgB;IACd,iCAAiC,CAAC,MAAqB;;YAC3D,OAAO,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;QACjC,CAAC;KAAA;IAED,gBAAgB,CAAC,MAAqB;;QACpC,MAAM,KAAK,GAAa,EAAE,CAAC;QAE3B,IAAI,CAAA,MAAA,MAAM,CAAC,cAAc,0CAAE,IAAI,MAAK,cAAc;YAChD,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC;QAErC,IAAI,CAAA,MAAA,MAAM,CAAC,cAAc,0CAAE,IAAI,MAAK,QAAQ;YAC1C,KAAK,CAAC,IAAI,CACR,GAAG;gBACD,sBAAsB;gBACtB,4BAA4B;gBAC5B,sBAAsB;aACvB,CACF,CAAC;QAEJ,IAAI,CAAC,MAAM,CAAC,UAAU;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAE7D,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAA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K,CAAC;wBAEzC,IAAI,UAAU,GAAG,cAAI,CAAC,IAAI,CACxB,SAAS,EACT,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CACjC,CAAC;wBACF,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;4BACjC,UAAU,GAAG,cAAI,CAAC,IAAI,CACpB,SAAS,EACT,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CACrC,CAAC;wBAEJ,YAAE,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;wBAC5D,YAAE,CAAC,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;qBACvC;gBACH,CAAC,CAAA,CAAC,CAAC;YACL,CAAC;YAED,gBAAgB,CAAC,YAAY,CAAC,CAAC;QACjC,CAAC;KAAA;CACF;AAED,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAEhD,kBAAe,gBAAgB,CAAC","sourcesContent":["import { ProjectConfig } from \"./project-config-inquirer\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport handlebars from \"handlebars\";\nimport { getNpmPackageVersion } from \"./helpers/npm.helpers\";\n\nclass TemplateCompiler {\n async canCompileAuthenticationTemplates(config: ProjectConfig) {\n return !!config.authentication;\n }\n\n filesToBeSkipped(config: ProjectConfig) {\n const files: string[] = [];\n\n if (config.authentication?.type === \"define later\")\n files.push(...[\"user.prisma.hbs\"]);\n\n if (config.authentication?.type === \"static\")\n files.push(\n ...[\n \"auth-role.prisma.hbs\",\n \"auth-permission.prisma.hbs\",\n \"user-role.prisma.hbs\",\n ]\n );\n\n if (!config.typescript) files.push(...[\"tsconfig.json.hbs\"]);\n\n if (config?.typescript) files.push(...[\"jsconfig.json.hbs\"]);\n\n return files;\n }\n /**\n * Compiles the Arkos.js project with handlebars templates\n *\n * @param templatesDir {string} templates location\n * @param config {ProjectConfig} the project configuration\n * @returns void\n * */\n async compile(templatesDir: string, config: ProjectConfig) {\n const outputDir = config.projectPath;\n const isTypescript = config.typescript;\n const filesToBeSkipped = this.filesToBeSkipped(config);\n\n function processTemplates(dir: string, relativeDir = \"\") {\n fs.readdirSync(dir, { withFileTypes: true }).forEach(async (dirent) => {\n if (filesToBeSkipped.includes(dirent.name)) return;\n\n const fullPath = path.join(dir, dirent.name);\n const relativePath = path.join(relativeDir, dirent.name);\n\n if (dirent.isDirectory()) {\n processTemplates(fullPath, relativePath);\n } else if (dirent.name.endsWith(\".hbs\")) {\n const templatePath = fullPath;\n const template = handlebars.compile(\n fs.readFileSync(templatePath, \"utf8\")\n );\n\n let arkosCurrentVersion = getNpmPackageVersion(\"arkos\");\n\n const content = template({ ...config, arkosCurrentVersion });\n const ext = isTypescript ? \".ts\" : \".js\";\n\n let outputPath = path.join(\n outputDir,\n relativePath.replace(\".hbs\", \"\")\n );\n if (dirent.name.endsWith(\".ts.hbs\"))\n outputPath = path.join(\n outputDir,\n relativePath.replace(\".ts.hbs\", ext)\n );\n\n fs.mkdirSync(path.dirname(outputPath), { recursive: true });\n fs.writeFileSync(outputPath, content);\n }\n });\n }\n\n processTemplates(templatesDir);\n }\n}\n\nconst templateCompiler = new TemplateCompiler();\n\nexport default templateCompiler;\n"]}
1
+ {"version":3,"file":"template-compiler.js","sourceRoot":"","sources":["../../src/utils/template-compiler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,gDAAwB;AACxB,4CAAoB;AACpB,4DAAoC;AACpC,uDAA6D;AAE7D,MAAM,gBAAgB;IACd,iCAAiC,CAAC,MAAqB;;YAC3D,OAAO,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;QACjC,CAAC;KAAA;IAED,gBAAgB,CAAC,MAAqB;;QACpC,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,MAAM,kBAAkB,GAAG;YACzB,qBAAqB;YACrB,sBAAsB;YACtB,+BAA+B;SAChC,C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,MAAM,OAAO,GAAG,QAAQ,iCAAM,MAAM,KAAE,mBAAmB,IAAG,CAAC;wBAC7D,MAAM,GAAG,GAAG,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;wBAEzC,IAAI,UAAU,GAAG,cAAI,CAAC,IAAI,CACxB,SAAS,EACT,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CACjC,CAAC;wBACF,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;4BACjC,UAAU,GAAG,cAAI,CAAC,IAAI,CACpB,SAAS,EACT,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CACrC,CAAC;wBAEJ,YAAE,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;wBAC5D,YAAE,CAAC,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;qBACvC;gBACH,CAAC,CAAA,CAAC,CAAC;YACL,CAAC;YAED,gBAAgB,CAAC,YAAY,CAAC,CAAC;QACjC,CAAC;KAAA;CACF;AAED,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAEhD,kBAAe,gBAAgB,CAAC","sourcesContent":["import { ProjectConfig } from \"./project-config-inquirer\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport handlebars from \"handlebars\";\nimport { getNpmPackageVersion } from \"./helpers/npm.helpers\";\n\nclass TemplateCompiler {\n async canCompileAuthenticationTemplates(config: ProjectConfig) {\n return !!config.authentication;\n }\n\n filesToBeSkipped(config: ProjectConfig) {\n const files: string[] = [];\n const zodAuthSchemaFiles = [\n \"login.schema.ts.hbs\",\n \"signup.schema.ts.hbs\",\n \"update-password.schema.ts.hbs\",\n ];\n\n const classValidatorAuthDtoFiles = [\n \"login.dto.ts.hbs\",\n \"signup.dto.ts.hbs\",\n \"update-password.dto.ts.hbs\",\n ];\n\n const zodUserSchemaFiles = [\n \"create-user.schema.ts.hbs\",\n \"update-user.schema.ts.hbs\",\n ];\n\n const classValidatorUserSchemaFiles = [\n \"create-user.dto.ts.hbs\",\n \"update-user.dto.ts.hbs\",\n ];\n\n const userComponents = [\n \"user.middlewares.ts.hbs\",\n \"user.query.ts.hbs\",\n \"user.service.ts.hbs\",\n \"user.prisma.hbs\",\n ];\n\n const authComponents = [\n \"auth.middlewares.ts.hbs\",\n \"auth.query.ts.hbs\",\n \"auth-role.prisma.hbs\",\n \"auth-permission.prisma.hbs\",\n \"user-role.prisma.hbs\",\n ];\n\n // Ignoring auth relation files when auth is set to define later\n if (config.authentication?.type === \"define later\")\n files.push(\n ...userComponents,\n ...authComponents,\n ...zodAuthSchemaFiles,\n ...classValidatorAuthDtoFiles,\n ...zodUserSchemaFiles,\n ...classValidatorUserSchemaFiles\n );\n\n // Ignoring prisma models required only on dynamic authentication\n if (\n config.authentication?.type === \"static\" ||\n config.authentication?.type === \"define later\"\n )\n files.push(\n ...[\n \"auth-role.prisma.hbs\",\n \"auth-permission.prisma.hbs\",\n \"user-role.prisma.hbs\",\n ]\n );\n\n // Ignore zod related files when validation is class-validator\n if (config.validation.type !== \"zod\")\n files.push(...zodUserSchemaFiles, ...zodAuthSchemaFiles);\n\n // Ignore class-validator related files when validation is zod\n if (config.validation.type !== \"class-validator\")\n files.push(\n ...classValidatorUserSchemaFiles,\n ...classValidatorAuthDtoFiles\n );\n\n // Ignoring typescript related files when typescript false\n if (!config.typescript) files.push(...[\"tsconfig.json.hbs\"]);\n\n // Ignoring javascript related files when typescript true\n if (config?.typescript) files.push(...[\"jsconfig.json.hbs\"]);\n\n return files;\n }\n /**\n * Compiles the Arkos.js project with handlebars templates\n *\n * @param templatesDir {string} templates location\n * @param config {ProjectConfig} the project configuration\n * @returns void\n * */\n async compile(templatesDir: string, config: ProjectConfig) {\n const outputDir = config.projectPath;\n const isTypescript = config.typescript;\n const filesToBeSkipped = this.filesToBeSkipped(config);\n\n function processTemplates(dir: string, relativeDir = \"\") {\n fs.readdirSync(dir, { withFileTypes: true }).forEach(async (dirent) => {\n if (filesToBeSkipped.includes(dirent.name)) return;\n\n const fullPath = path.join(dir, dirent.name);\n const relativePath = path.join(relativeDir, dirent.name);\n\n if (dirent.isDirectory()) {\n processTemplates(fullPath, relativePath);\n } else if (dirent.name.endsWith(\".hbs\")) {\n const templatePath = fullPath;\n const template = handlebars.compile(\n fs.readFileSync(templatePath, \"utf8\")\n );\n\n let arkosCurrentVersion = getNpmPackageVersion(\"arkos\");\n\n const content = template({ ...config, arkosCurrentVersion });\n const ext = isTypescript ? \".ts\" : \".js\";\n\n let outputPath = path.join(\n outputDir,\n relativePath.replace(\".hbs\", \"\")\n );\n if (dirent.name.endsWith(\".ts.hbs\"))\n outputPath = path.join(\n outputDir,\n relativePath.replace(\".ts.hbs\", ext)\n );\n\n fs.mkdirSync(path.dirname(outputPath), { recursive: true });\n fs.writeFileSync(outputPath, content);\n }\n });\n }\n\n processTemplates(templatesDir);\n }\n}\n\nconst templateCompiler = new TemplateCompiler();\n\nexport default templateCompiler;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-arkos",
3
- "version": "0.0.21",
3
+ "version": "0.0.23-beta",
4
4
  "description": "CLI for creating Arkos.js projects, see docs at www.arkosjs.com",
5
5
  "bin": {
6
6
  "create-arkos": "./dist/index.js"
@@ -26,7 +26,6 @@
26
26
  "@types/inquirer": "^8.1.0",
27
27
  "@types/node": "^16.18.126",
28
28
  "ts-node": "^10.9.2",
29
- "tsup": "^8.5.0",
30
29
  "typescript": "^4.9.5"
31
30
  },
32
31
  "dependencies": {
@@ -18,14 +18,13 @@
18
18
  "devDependencies": {
19
19
  {{#if typescript}}
20
20
  "typescript": "^5.7.3",
21
- "ts-node": "^10.9.2",
22
21
  "ts-node-dev": "^2.0.0",
23
22
  "@types/node": "^24.0.12",
24
23
  "@types/express": "^5.0.0",
25
24
  "@types/swagger-jsdoc": "^6.0.4",
26
25
  "@types/swagger-ui-express": "^4.1.8",
27
26
  {{else}}
28
- "nodemon": "^2.0.12",
27
+ "node-dev": "^8.0.0",
29
28
  {{/if}}
30
29
  "prisma": "^6.11.1"
31
30
  },
@@ -36,6 +35,7 @@
36
35
  "swagger-jsdoc": "^6.2.8",
37
36
  "swagger-ui-express": "^5.0.1",
38
37
  {{#if (eq validation.type "class-validator")}}
38
+ "reflect-metadata": "^0.2.2",
39
39
  "class-transformer": "^0.5.1",
40
40
  "class-validator": "^0.14.1",
41
41
  "class-validator-jsonschema": "^5.0.2",
@@ -10,7 +10,7 @@ model User {
10
10
  isActive Boolean @default(true)
11
11
  {{#if authentication.multipleRoles}}
12
12
  {{#if (eq prisma.provider "sqlite")}}
13
- role String // Roles examples: Admin, User
13
+ role String @default("User") // Roles examples: Admin, User
14
14
  {{else}}
15
15
  roles UserRole[]
16
16
  {{/if}}
@@ -19,9 +19,9 @@ model User {
19
19
  role UserRole?
20
20
  {{else}}
21
21
  {{#if (eq prisma.provider "sqlite")}}
22
- role String // Roles examples: Admin, User
22
+ role String @default("User") // Roles examples: Admin, User
23
23
  {{else}}
24
- role UserRole
24
+ role UserRole @default(User)
25
25
  {{/if}}
26
26
  {{/if}}
27
27
  {{/if}}
@@ -0,0 +1,103 @@
1
+ {{#if typescript}}
2
+ import { ArkosRequest, ArkosResponse, ArkosNextFunction } from "arkos";
3
+
4
+ // export const beforeGetMe = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
5
+ // // Your logic here
6
+ // next();
7
+ // };
8
+ //
9
+ // export const afterGetMe = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
10
+ // // Your logic here
11
+ // next();
12
+ // };
13
+ //
14
+ // export const beforeLogin = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
15
+ // // Your logic here
16
+ // next();
17
+ // };
18
+ //
19
+ // export const afterLogin = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
20
+ // // Your logic here
21
+ // next();
22
+ // };
23
+ //
24
+ // export const beforeLogout = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
25
+ // // Your logic here
26
+ // next();
27
+ // };
28
+ //
29
+ // export const afterLogout = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
30
+ // // Your logic here
31
+ // next();
32
+ // };
33
+ //
34
+ // export const beforeSignup = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
35
+ // // Your logic here
36
+ // next();
37
+ // };
38
+ //
39
+ // export const afterSignup = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
40
+ // // Your logic here
41
+ // next();
42
+ // };
43
+ //
44
+ // export const beforeUpdatePassword = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
45
+ // // Your logic here
46
+ // next();
47
+ // };
48
+ //
49
+ // export const afterUpdatePassword = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
50
+ // // Your logic here
51
+ // next();
52
+ // };
53
+ {{else}}
54
+ // export const beforeGetMe = async (req, res, next) => {
55
+ // // Your logic here
56
+ // next();
57
+ // };
58
+ //
59
+ // export const afterGetMe = async (req, res, next) => {
60
+ // // Your logic here
61
+ // next();
62
+ // };
63
+ //
64
+ // export const beforeLogin = async (req, res, next) => {
65
+ // // Your logic here
66
+ // next();
67
+ // };
68
+ //
69
+ // export const afterLogin = async (req, res, next) => {
70
+ // // Your logic here
71
+ // next();
72
+ // };
73
+ //
74
+ // export const beforeLogout = async (req, res, next) => {
75
+ // // Your logic here
76
+ // next();
77
+ // };
78
+ //
79
+ // export const afterLogout = async (req, res, next) => {
80
+ // // Your logic here
81
+ // next();
82
+ // };
83
+ //
84
+ // export const beforeSignup = async (req, res, next) => {
85
+ // // Your logic here
86
+ // next();
87
+ // };
88
+ //
89
+ // export const afterSignup = async (req, res, next) => {
90
+ // // Your logic here
91
+ // next();
92
+ // };
93
+ //
94
+ // export const beforeUpdatePassword = async (req, res, next) => {
95
+ // // Your logic here
96
+ // next();
97
+ // };
98
+ //
99
+ // export const afterUpdatePassword = async (req, res, next) => {
100
+ // // Your logic here
101
+ // next();
102
+ // };
103
+ // {{/if}}
@@ -0,0 +1,21 @@
1
+ {{#if typescript}}
2
+ import prisma from "../../utils/prisma";
3
+ import { AuthPrismaQueryOptions } from 'arkos/prisma';
4
+
5
+ const authQueryOptions: AuthPrismaQueryOptions<typeof prisma.user> = {
6
+ {{else}}
7
+ const authQueryOptions = {
8
+ {{/if}}
9
+ getMe: {
10
+ include: {
11
+ password: false,
12
+ },
13
+ },
14
+ updateMe: {},
15
+ deleteMe: {},
16
+ login: {},
17
+ signup: {},
18
+ updatePassword: {},
19
+ }
20
+
21
+ export default authQueryOptions;
@@ -0,0 +1,13 @@
1
+ import { IsString, MinLength, Matches } from 'class-validator'
2
+ import "reflect-metadata"
3
+
4
+ export default class LoginDto {
5
+ @IsString()
6
+ {{authentication.usernameField}}: string
7
+
8
+ @IsString()
9
+ @MinLength(8, { message: 'Password must be at least 8 characters long' })
10
+ @Matches(/[a-z]/, { message: 'Password must contain at least one lowercase letter' })
11
+ @Matches(/[A-Z]/, { message: 'Password must contain at least one uppercase letter' })
12
+ password: string
13
+ }
@@ -0,0 +1,14 @@
1
+ import { IsString, MinLength, Matches, IsNotEmpty } from 'class-validator'
2
+ import "reflect-metadata"
3
+
4
+ export default class SignupDto {
5
+ @IsString()
6
+ @IsNotEmpty({ message: '{{authentication.usernameField}} is required' })
7
+ {{authentication.usernameField}}: string
8
+
9
+ @IsString()
10
+ @MinLength(8, { message: 'Password must be at least 8 characters long' })
11
+ @Matches(/[a-z]/, { message: 'Password must contain at least one lowercase letter' })
12
+ @Matches(/[A-Z]/, { message: 'Password must contain at least one uppercase letter' })
13
+ password: string
14
+ }
@@ -0,0 +1,11 @@
1
+ import { z } from "zod"
2
+
3
+ const LoginSchema = z.object({
4
+ {{authentication.usernameField}}: z.string(),
5
+ password: z.string()
6
+ .min(8, "Password must be at least 8 characters long")
7
+ .regex(/[a-z]/, "Password must contain at least one lowercase letter")
8
+ .regex(/[A-Z]/, "Password must contain at least one uppercase letter"),
9
+ })
10
+
11
+ export default LoginSchema
@@ -0,0 +1,12 @@
1
+ import { z } from "zod"
2
+
3
+ const SignupSchema = z.object({
4
+ {{authentication.usernameField}}: z.string()
5
+ .min(1, "{{authentication.usernameField}} is required"),
6
+ password: z.string()
7
+ .min(8, "Password must be at least 8 characters long")
8
+ .regex(/[a-z]/, "Password must contain at least one lowercase letter")
9
+ .regex(/[A-Z]/, "Password must contain at least one uppercase letter"),
10
+ })
11
+
12
+ export default SignupSchema
@@ -0,0 +1,77 @@
1
+ {{#if typescript}}
2
+ import { ArkosRequest, ArkosResponse, ArkosNextFunction } from "arkos";
3
+
4
+ // export const beforeFindFile = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
5
+ // // Your logic here
6
+ // next();
7
+ // };
8
+ //
9
+ // // There is not afterFindFile: because the main handler is handled by express.static()
10
+ //
11
+ // export const beforeUploadFile = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
12
+ // // Your logic here
13
+ // next();
14
+ // };
15
+ //
16
+ // export const afterUploadFile = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
17
+ // // Your logic here
18
+ // next();
19
+ // };
20
+ //
21
+ // export const beforeUpdateFile = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
22
+ // // Your logic here
23
+ // next();
24
+ // };
25
+ //
26
+ // export const afterUpdateFile = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
27
+ // // Your logic here
28
+ // next();
29
+ // };
30
+ //
31
+ // export const beforeDeleteFile = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
32
+ // // Your logic here
33
+ // next();
34
+ // };
35
+ //
36
+ // export const afterDeleteFile = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
37
+ // // Your logic here
38
+ // next();
39
+ // };
40
+ {{else}}
41
+ // export const beforeFindFile = async (req, res, next) => {
42
+ // // Your logic here
43
+ // next();
44
+ // };
45
+ //
46
+ // // There is not afterFindFile: because the main handler is handled by express.static()
47
+ //
48
+ // export const beforeUploadFile = async (req, res, next) => {
49
+ // // Your logic here
50
+ // next();
51
+ // };
52
+ //
53
+ // export const afterUploadFile = async (req, res, next) => {
54
+ // // Your logic here
55
+ // next();
56
+ // };
57
+ //
58
+ // export const beforeUpdateFile = async (req, res, next) => {
59
+ // // Your logic here
60
+ // next();
61
+ // };
62
+ //
63
+ // export const afterUpdateFile = async (req, res, next) => {
64
+ // // Your logic here
65
+ // next();
66
+ // };
67
+ //
68
+ // export const beforeDeleteFile = async (req, res, next) => {
69
+ // // Your logic here
70
+ // next();
71
+ // };
72
+ //
73
+ // export const afterDeleteFile = async (req, res, next) => {
74
+ // // Your logic here
75
+ // next();
76
+ // };
77
+ {{/if}}
@@ -0,0 +1,87 @@
1
+ import 'reflect-metadata'
2
+ import {
3
+ IsString,
4
+ MinLength,
5
+ Matches,
6
+ IsNotEmpty,
7
+ IsBoolean,
8
+ IsOptional,
9
+ IsArray,
10
+ ValidateNested,
11
+ Type,
12
+ IsEnum
13
+ } from 'class-validator'
14
+ import apiActions from "../../../utils/validation/api-actions"
15
+ {{#if (eq authentication.type "static")}}
16
+ {{#if (neq prisma.provider "sqlite")}}
17
+ import { UserRole } from "@prisma/client"
18
+ {{/if}}
19
+ {{/if}}
20
+
21
+ {{#if (eq authentication.type "dynamic")}}
22
+ class RoleConnectDto {
23
+ @IsString()
24
+ @IsNotEmpty()
25
+ id: string
26
+ }
27
+
28
+ class RoleConnectionDto {
29
+ @ValidateNested()
30
+ @Type(() => RoleConnectDto)
31
+ role: RoleConnectDto
32
+ }
33
+ {{/if}}
34
+
35
+ export default class CreateUserDto {
36
+ @IsString()
37
+ @IsNotEmpty({ message: '{{authentication.usernameField}} is required' })
38
+ {{authentication.usernameField}}: string
39
+
40
+ @IsString()
41
+ @MinLength(8, { message: 'Password must be at least 8 characters long' })
42
+ @Matches(/[a-z]/, { message: 'Password must contain at least one lowercase letter' })
43
+ @Matches(/[A-Z]/, { message: 'Password must contain at least one uppercase letter' })
44
+ password: string
45
+
46
+ @IsBoolean()
47
+ @IsOptional()
48
+ isSuperUser?: boolean = false
49
+
50
+ @IsBoolean()
51
+ @IsOptional()
52
+ isStaff?: boolean = false
53
+
54
+ @IsBoolean()
55
+ @IsOptional()
56
+ isActive?: boolean = true
57
+
58
+ {{#if (eq authentication.type "static")}}
59
+ {{#if (eq prisma.provider "sqlite")}}
60
+ @IsString()
61
+ @IsNotEmpty()
62
+ role: string
63
+ {{else}}
64
+ {{#if authentication.multipleRoles}}
65
+ @IsArray()
66
+ @IsEnum(UserRole, { each: true })
67
+ roles: UserRole[]
68
+ {{else}}
69
+ @IsEnum(UserRole)
70
+ role: UserRole
71
+ {{/if}}
72
+ {{/if}}
73
+ {{else}}
74
+ {{#if authentication.multipleRoles}}
75
+ @IsArray()
76
+ @ValidateNested({ each: true })
77
+ @Type(() => RoleConnectionDto)
78
+ @IsOptional()
79
+ roles?: RoleConnectionDto[]
80
+ {{else}}
81
+ @ValidateNested()
82
+ @Type(() => RoleConnectionDto)
83
+ @IsOptional()
84
+ role?: RoleConnectionDto
85
+ {{/if}}
86
+ {{/if}}
87
+ }
@@ -0,0 +1,95 @@
1
+ import 'reflect-metadata'
2
+ import {
3
+ IsString,
4
+ MinLength,
5
+ Matches,
6
+ IsNotEmpty,
7
+ IsBoolean,
8
+ IsOptional,
9
+ IsArray,
10
+ ValidateNested,
11
+ Type,
12
+ IsEnum
13
+ } from 'class-validator'
14
+ import apiActions from "../../../utils/validation/api-actions"
15
+ {{#if (eq authentication.type "static")}}
16
+ {{#if (neq prisma.provider "sqlite")}}
17
+ import { UserRole } from "@prisma/client"
18
+ {{/if}}
19
+ {{/if}}
20
+
21
+ {{#if (eq authentication.type "dynamic")}}
22
+ class RoleConnectDto {
23
+ @IsString()
24
+ @IsNotEmpty()
25
+ @IsOptional()
26
+ id: string
27
+ }
28
+
29
+ class RoleConnectionDto {
30
+ @IsString()
31
+ @IsOptional()
32
+ id: string
33
+
34
+ @IsEnum(apiActions)
35
+ @IsOptional()
36
+ apiAction: string
37
+
38
+ @ValidateNested()
39
+ @Type(() => RoleConnectDto)
40
+ @IsOptional()
41
+ role: RoleConnectDto
42
+ }
43
+ {{/if}}
44
+
45
+ export default class UpdateUserDto {
46
+ @IsString()
47
+ @IsNotEmpty({ message: '{{authentication.usernameField}} is required' })
48
+ @IsOptional()
49
+ {{authentication.usernameField}}: string
50
+
51
+ @IsBoolean()
52
+ @IsOptional()
53
+ isSuperUser?: boolean = false
54
+
55
+ @IsBoolean()
56
+ @IsOptional()
57
+ isStaff?: boolean = false
58
+
59
+ @IsBoolean()
60
+ @IsOptional()
61
+ isActive?: boolean = true
62
+
63
+ {{#if (eq authentication.type "static")}}
64
+ {{#if (eq prisma.provider "sqlite")}}
65
+ @IsString()
66
+ @IsNotEmpty()
67
+ @IsOptional()
68
+ role: string
69
+ {{else}}
70
+ {{#if authentication.multipleRoles}}
71
+ @IsArray()
72
+ @IsEnum(UserRole, { each: true })
73
+ @IsOptional()
74
+ roles: UserRole[]
75
+ {{else}}
76
+ @IsEnum(UserRole)
77
+ @IsOptional()
78
+ role: UserRole
79
+ {{/if}}
80
+ {{/if}}
81
+ {{else}}
82
+ {{#if authentication.multipleRoles}}
83
+ @IsArray()
84
+ @ValidateNested({ each: true })
85
+ @Type(() => RoleConnectionDto)
86
+ @IsOptional()
87
+ roles?: RoleConnectionDto[]
88
+ {{else}}
89
+ @ValidateNested()
90
+ @Type(() => RoleConnectionDto)
91
+ @IsOptional()
92
+ role?: RoleConnectionDto
93
+ {{/if}}
94
+ {{/if}}
95
+ }
@@ -0,0 +1,46 @@
1
+ import { z } from "zod"
2
+ import apiActions from "../../../utils/validation/api-actions"
3
+ {{#if (eq authentication.type "static")}}
4
+ {{#if (neq prisma.provider "sqlite")}}
5
+ import { UserRole } from "@prisma/client"
6
+ {{/if}}
7
+ {{/if}}
8
+
9
+ const CreateUserSchema = z.object({
10
+ {{authentication.usernameField}}: z.string()
11
+ .min(1, "{{authentication.usernameField}} is required"),
12
+ password: z.string()
13
+ .min(8, "Password must be at least 8 characters long")
14
+ .regex(/[a-z]/, "Password must contain at least one lowercase letter")
15
+ .regex(/[A-Z]/, "Password must contain at least one uppercase letter"),
16
+ isSuperUser: z.boolean().optional().default(false),
17
+ isStaff: z.boolean().optional().default(false),
18
+ isActive: z.boolean().optional().default(true),
19
+ {{#if (eq authentication.type "static")}}
20
+ {{#if (eq prisma.provider "sqlite")}}
21
+ role: z.string(),
22
+ {{else}}
23
+ {{#if authentication.multipleRoles}}
24
+ roles: z.array(z.nativeEnum(UserRole)),
25
+ {{else}}
26
+ role: z.nativeEnum(UserRole),
27
+ {{/if}}
28
+ {{/if}}
29
+ {{else}}
30
+ {{#if authentication.multipleRoles}}
31
+ roles: z.array(z.object({
32
+ role: z.object({
33
+ id: z.string(),
34
+ })
35
+ })).optional(),
36
+ {{else}}
37
+ role: z.object({
38
+ role: z.object({
39
+ id: z.string(),
40
+ })
41
+ }).optional(),
42
+ {{/if}}
43
+ {{/if}}
44
+ })
45
+
46
+ export default CreateUserSchema
@@ -0,0 +1,46 @@
1
+ import { z } from "zod"
2
+ import apiActions from "../../../utils/validation/api-actions"
3
+ {{#if (eq authentication.type "static")}}
4
+ {{#if (neq prisma.provider "sqlite")}}
5
+ import { UserRole } from "@prisma/client"
6
+ {{/if}}
7
+ {{/if}}
8
+
9
+ const UpdateUserSchema = z.object({
10
+ {{authentication.usernameField}}: z.string()
11
+ .optional(),
12
+ isSuperUser: z.boolean().optional(),
13
+ isStaff: z.boolean().optional(),
14
+ isActive: z.boolean().optional(),
15
+ {{#if (eq authentication.type "static")}}
16
+ {{#if (eq prisma.provider "sqlite")}}
17
+ role: z.string().optional(),
18
+ {{else}}
19
+ {{#if authentication.multipleRoles}}
20
+ roles: z.array(z.nativeEnum(UserRole)).optional(),
21
+ {{else}}
22
+ role: z.nativeEnum(UserRole).optional(),
23
+ {{/if}}
24
+ {{/if}}
25
+ {{else}}
26
+ {{#if authentication.multipleRoles}}
27
+ roles: z.array(z.object({
28
+ id: z.string().optional(),
29
+ apiAction: z.enum(apiActions).optional(),
30
+ role: z.object({
31
+ id: z.string(),
32
+ }).optional()
33
+ })).optional(),
34
+ {{else}}
35
+ role: z.object({
36
+ id: z.string().optional(),
37
+ apiAction: z.enum(apiActions).optional(),
38
+ role: z.object({
39
+ id: z.string(),
40
+ })
41
+ }).optional(),
42
+ {{/if}}
43
+ {{/if}}
44
+ })
45
+
46
+ export default UpdateUserSchema
@@ -0,0 +1,163 @@
1
+ {{#if typescript}}
2
+ import { ArkosRequest, ArkosResponse, ArkosNextFunction } from "arkos";
3
+
4
+ // export const beforeCreateOne = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
5
+ // // Your logic here
6
+ // next();
7
+ // };
8
+ //
9
+ // export const afterCreateOne = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
10
+ // // Your logic here
11
+ // next();
12
+ // };
13
+ //
14
+ // export const beforeFindOne = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
15
+ // // Your logic here
16
+ // next();
17
+ // };
18
+ //
19
+ // export const afterFindOne = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
20
+ // // Your logic here
21
+ // next();
22
+ // };
23
+ //
24
+ // export const beforeFindMany = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
25
+ // // Your logic here
26
+ // next();
27
+ // };
28
+ //
29
+ // export const afterFindMany = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
30
+ // // Your logic here
31
+ // next();
32
+ // };
33
+ //
34
+ // export const beforeUpdateOne = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
35
+ // // Your logic here
36
+ // next();
37
+ // };
38
+ //
39
+ // export const afterUpdateOne = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
40
+ // // Your logic here
41
+ // next();
42
+ // };
43
+ //
44
+ // export const beforeDeleteOne = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
45
+ // // Your logic here
46
+ // next();
47
+ // };
48
+ //
49
+ // export const afterDeleteOne = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
50
+ // // Your logic here
51
+ // next();
52
+ // };
53
+ //
54
+ // export const beforeCreateMany = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
55
+ // // Your logic here
56
+ // next();
57
+ // };
58
+ //
59
+ // export const afterCreateMany = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
60
+ // // Your logic here
61
+ // next();
62
+ // };
63
+ //
64
+ // export const beforeUpdateMany = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
65
+ // // Your logic here
66
+ // next();
67
+ // };
68
+ //
69
+ // export const afterUpdateMany = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
70
+ // // Your logic here
71
+ // next();
72
+ // };
73
+ //
74
+ // export const beforeDeleteMany = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
75
+ // // Your logic here
76
+ // next();
77
+ // };
78
+ //
79
+ // export const afterDeleteMany = async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {
80
+ // // Your logic here
81
+ // next();
82
+ // };
83
+ {{else}}
84
+ // export const beforeCreateOne = async (req, res, next) => {
85
+ // // Your logic here
86
+ // next();
87
+ // };
88
+ //
89
+ // export const afterCreateOne = async (req, res, next) => {
90
+ // // Your logic here
91
+ // next();
92
+ // };
93
+ //
94
+ // export const beforeFindOne = async (req, res, next) => {
95
+ // // Your logic here
96
+ // next();
97
+ // };
98
+ //
99
+ // export const afterFindOne = async (req, res, next) => {
100
+ // // Your logic here
101
+ // next();
102
+ // };
103
+ //
104
+ // export const beforeFindMany = async (req, res, next) => {
105
+ // // Your logic here
106
+ // next();
107
+ // };
108
+ //
109
+ // export const afterFindMany = async (req, res, next) => {
110
+ // // Your logic here
111
+ // next();
112
+ // };
113
+ //
114
+ // export const beforeUpdateOne = async (req, res, next) => {
115
+ // // Your logic here
116
+ // next();
117
+ // };
118
+ //
119
+ // export const afterUpdateOne = async (req, res, next) => {
120
+ // // Your logic here
121
+ // next();
122
+ // };
123
+ //
124
+ // export const beforeDeleteOne = async (req, res, next) => {
125
+ // // Your logic here
126
+ // next();
127
+ // };
128
+ //
129
+ // export const afterDeleteOne = async (req, res, next) => {
130
+ // // Your logic here
131
+ // next();
132
+ // };
133
+ //
134
+ // export const beforeCreateMany = async (req, res, next) => {
135
+ // // Your logic here
136
+ // next();
137
+ // };
138
+ //
139
+ // export const afterCreateMany = async (req, res, next) => {
140
+ // // Your logic here
141
+ // next();
142
+ // };
143
+ //
144
+ // export const beforeUpdateMany = async (req, res, next) => {
145
+ // // Your logic here
146
+ // next();
147
+ // };
148
+ //
149
+ // export const afterUpdateMany = async (req, res, next) => {
150
+ // // Your logic here
151
+ // next();
152
+ // };
153
+ //
154
+ // export const beforeDeleteMany = async (req, res, next) => {
155
+ // // Your logic here
156
+ // next();
157
+ // };
158
+ //
159
+ // export const afterDeleteMany = async (req, res, next) => {
160
+ // // Your logic here
161
+ // next();
162
+ // };
163
+ {{/if}}
@@ -0,0 +1,35 @@
1
+ {{#if typescript}}
2
+ import prisma from "../../utils/prisma";
3
+ import { PrismaQueryOptions } from 'arkos/prisma';
4
+
5
+ const userQueryOptions: PrismaQueryOptions<typeof prisma.user> = {
6
+ {{else}}
7
+ const userQueryOptions = {
8
+ {{/if}}
9
+ global: {},
10
+ find: {
11
+ include: {
12
+ password: false,
13
+ },
14
+ },
15
+ findOne: {},
16
+ findMany: {},
17
+ udpate: {},
18
+ updateMany: {},
19
+ updateOne: {},
20
+ create: {},
21
+ createMany: {},
22
+ createOne: {},
23
+ save: {
24
+ include: {
25
+ password: false,
26
+ },
27
+ },
28
+ saveMany: {},
29
+ saveOne: {},
30
+ delete: {},
31
+ deleteMany: {},
32
+ deleteOne: {},
33
+ }
34
+
35
+ export default userQueryOptions;
@@ -0,0 +1,19 @@
1
+ {{#if typescript}}
2
+ import prisma from "../../utils/prisma";
3
+ import { BaseService } from "arkos/services";
4
+
5
+ class UserService extends BaseService<typeof prisma.user> {
6
+ {{else}}
7
+ import { BaseService } from "arkos/services";
8
+
9
+ class UserService extends BaseService {
10
+ {{/if}}
11
+ constructor() {
12
+ super("user");
13
+ }
14
+ // Add your custom service methods here
15
+ }
16
+
17
+ const userService = new UserService();
18
+
19
+ export default userService;
@@ -1,5 +1,5 @@
1
1
  import { PrismaClient } from "@prisma/client";
2
2
 
3
- const prisma = new PrismaClient();
3
+ export const prisma = new PrismaClient();
4
4
 
5
5
  export default prisma;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * A simple array of available `apiAction` field when using auto generate API (That uses BaseService)
3
+ * class behind the scenes.
4
+ *
5
+ * Is worth mentioning that this will be addded into `arkos` as an util.
6
+ *
7
+ * @see {@link https://www.arkosjs.com/docs/advanced-guide/handling-relation-fields-in-prisma-body-requests#the-apiaction-property}
8
+ */
9
+ const apiActions = ["connect", "disconnect", "delete", "update", "create"];
10
+
11
+ export default apiActions