create-arkos 0.0.23-beta → 0.0.25-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/project-config-inquirer.js +4 -3
- package/dist/utils/project-config-inquirer.js.map +1 -1
- package/dist/utils/template-compiler.js +10 -0
- package/dist/utils/template-compiler.js.map +1 -1
- package/package.json +1 -1
- package/templates/basic/prisma/schema/user.prisma.hbs +11 -10
- package/templates/basic/src/modules/auth/auth.query.ts.hbs +3 -0
- package/templates/basic/src/modules/auth/dtos/update-password.dto.ts.hbs +14 -0
- package/templates/basic/src/modules/auth/schemas/login.schema.ts.hbs +4 -0
- package/templates/basic/src/modules/auth/schemas/signup.schema.ts.hbs +4 -0
- package/templates/basic/src/modules/auth/schemas/update-password.schema.ts.hbs +15 -0
- package/templates/basic/src/modules/auth-permission/dtos/create-auth-permission.dto.ts.hbs +39 -0
- package/templates/basic/src/modules/auth-permission/dtos/update-auth-permission.dto.ts.hbs +29 -0
- package/templates/basic/src/modules/auth-permission/schemas/create-auth-permission.ts.hbs +28 -0
- package/templates/basic/src/modules/auth-permission/schemas/update-auth-permission.ts.hbs +25 -0
- package/templates/basic/src/modules/auth-role/dtos/create-auth-role.dto.ts.hbs +46 -0
- package/templates/basic/src/modules/auth-role/dtos/update-auth-role.dto.ts.hbs +55 -0
- package/templates/basic/src/modules/auth-role/schemas/create-auth-role.schema.ts.hbs +18 -0
- package/templates/basic/src/modules/auth-role/schemas/update-auth-role.schema.ts.hbs +18 -0
- package/templates/basic/src/modules/user/dtos/create-user.dto.ts.hbs +0 -1
- package/templates/basic/src/modules/user/dtos/update-user.dto.ts.hbs +6 -2
- package/templates/basic/src/modules/user/schemas/create-user.schema.ts.hbs +4 -1
- package/templates/basic/src/modules/user/schemas/update-user.schema.ts.hbs +8 -0
- package/templates/basic/src/modules/user/user.query.ts.hbs +3 -0
package/dist/index.js
CHANGED
|
@@ -30,7 +30,6 @@ 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));
|
|
34
33
|
const templatesDir = path_1.default.join(__dirname, `../templates/basic`);
|
|
35
34
|
yield template_compiler_1.default.compile(templatesDir, config);
|
|
36
35
|
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,E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AAC,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,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 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"]}
|
|
@@ -206,8 +206,9 @@ class ProjectConfigInquirer {
|
|
|
206
206
|
usernameField: usernameField === "define later" ? "custom" : usernameField,
|
|
207
207
|
multipleRoles: false,
|
|
208
208
|
};
|
|
209
|
-
if (authenticationType !== "define later"
|
|
210
|
-
this.config.prisma.provider !== "sqlite"
|
|
209
|
+
if (authenticationType !== "define later" ||
|
|
210
|
+
(this.config.prisma.provider !== "sqlite" &&
|
|
211
|
+
authenticationType !== "static")) {
|
|
211
212
|
const { multipleRoles } = yield inquirer_1.default.prompt([
|
|
212
213
|
{
|
|
213
214
|
type: "confirm",
|
|
@@ -219,7 +220,7 @@ class ProjectConfigInquirer {
|
|
|
219
220
|
this.config.authentication = Object.assign(Object.assign({}, this.config.authentication), { multipleRoles });
|
|
220
221
|
}
|
|
221
222
|
else if (this.config.prisma.provider === "sqlite") {
|
|
222
|
-
console.info(`\nSkipping multiple roles option because it is not supported with sqlite prisma provider...`);
|
|
223
|
+
console.info(`\nSkipping multiple roles option because it is not supported with sqlite prisma provider and static authentication...`);
|
|
223
224
|
}
|
|
224
225
|
}
|
|
225
226
|
});
|
|
@@ -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/B,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAClC,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAElC,MAAM,WAAW,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YACzE,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;YAEtC,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC;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rB,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,mCACrB,IAAI,CAAC,MAAM,CAAC,cAAc,KAC7B,aAAa,GACd,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.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"]}
|
|
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/B,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAClC,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC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AO,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,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ;wBACvC,kBAAkB,KAAK,QAAQ,CAAC,EAClC;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,mCACrB,IAAI,CAAC,MAAM,CAAC,cAAc,KAC7B,aAAa,GACd,CAAC;iBACH;qBAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE;oBACnD,OAAO,CAAC,IAAI,CACV,uHAAuH,CACxH,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.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 authenticationType !== \"static\")\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 and static authentication...`\n );\n }\n }\n }\n}\n\nconst projectConfigInquirer = new ProjectConfigInquirer();\n\nexport default projectConfigInquirer;\n"]}
|
|
@@ -29,11 +29,21 @@ class TemplateCompiler {
|
|
|
29
29
|
"login.schema.ts.hbs",
|
|
30
30
|
"signup.schema.ts.hbs",
|
|
31
31
|
"update-password.schema.ts.hbs",
|
|
32
|
+
"update-me.schema.ts.hbs",
|
|
33
|
+
"create-auth-permission.schema.ts.hbs",
|
|
34
|
+
"update-auth-permission.schema.ts.hbs",
|
|
35
|
+
"create-auth-role.schema.ts.hbs",
|
|
36
|
+
"update-auth-role.schema.ts.hbs",
|
|
32
37
|
];
|
|
33
38
|
const classValidatorAuthDtoFiles = [
|
|
34
39
|
"login.dto.ts.hbs",
|
|
35
40
|
"signup.dto.ts.hbs",
|
|
36
41
|
"update-password.dto.ts.hbs",
|
|
42
|
+
"update-me.dto.ts.hbs",
|
|
43
|
+
"create-auth-permission.dto.ts.hbs",
|
|
44
|
+
"update-auth-permission.dto.ts.hbs",
|
|
45
|
+
"create-auth-role.dto.ts.hbs",
|
|
46
|
+
"update-auth-role.dto.ts.hbs",
|
|
37
47
|
];
|
|
38
48
|
const zodUserSchemaFiles = [
|
|
39
49
|
"create-user.schema.ts.hbs",
|
|
@@ -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;QAC3B,MAAM,kBAAkB,GAAG;YACzB,qBAAqB;YACrB,sBAAsB;YACtB,+BAA+B;SAChC,CAAC;QAEF,MAAM,0BAA0B,GAAG;YACjC,kBAAkB;YAClB,mBAAmB;YACnB,4BAA4B;SAC7B,CAAC;QAEF,MAAM,kBAAkB,GAAG;YACzB,2BAA2B;YAC3B,2BAA2B;SAC5B,CAAC;QAEF,MAAM,6BAA6B,GAAG;YACpC,wBAAwB;YACxB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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"]}
|
|
1
|
+
{"version":3,"file":"template-compiler.js","sourceRoot":"","sources":["../../src/utils/template-compiler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAuJA,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;YAC/B,yBAAyB;YACzB,sCAAsC;YACtC,sCAAsC;YACtC,gCAAgC;YAChC,gCAAgC;SACjC,CAAC;QAEF,MAAM,0BAA0B,GAAG;YACjC,kBAAkB;YAClB,mBAAmB;YACnB,4BAA4B;YAC5B,sBAAsB;YACtB,mCAAmC;YACnC,mCAAmC;YACnC,6BAA6B;YAC7B,6BAA6B;SAC9B,CAAC;QAEF,MAAM,kBAAkB,GAAG;YACzB,2BAA2B;YAC3B,2BAA2B;SAC5B,CAAC;QAEF,MAAM,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AU,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\";\n// import path from \"path\";\n// import fs from \"fs\";\n// import handlebars from \"handlebars\";\n// import { getNpmPackageVersion } from \"./helpers/npm.helpers\";\n\n// class 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// \"update-me.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// \"update-me.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\n// const templateCompiler = new TemplateCompiler();\n\n// export default templateCompiler;\nimport { 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 \"update-me.schema.ts.hbs\",\n \"create-auth-permission.schema.ts.hbs\",\n \"update-auth-permission.schema.ts.hbs\",\n \"create-auth-role.schema.ts.hbs\",\n \"update-auth-role.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 \"update-me.dto.ts.hbs\",\n \"create-auth-permission.dto.ts.hbs\",\n \"update-auth-permission.dto.ts.hbs\",\n \"create-auth-role.dto.ts.hbs\",\n \"update-auth-role.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
|
@@ -9,25 +9,26 @@ model User {
|
|
|
9
9
|
deletedSelfAccountAt DateTime?
|
|
10
10
|
isActive Boolean @default(true)
|
|
11
11
|
{{#if authentication.multipleRoles}}
|
|
12
|
-
|
|
12
|
+
{{#if (eq prisma.provider "sqlite")}}
|
|
13
|
+
{{#if (eq authentication.type "static")}}
|
|
13
14
|
role String @default("User") // Roles examples: Admin, User
|
|
14
|
-
|
|
15
|
+
{{else}}
|
|
15
16
|
roles UserRole[]
|
|
16
|
-
|
|
17
|
+
{{/if}}
|
|
18
|
+
{{/if}}
|
|
17
19
|
{{else}}
|
|
18
|
-
|
|
20
|
+
{{#if (eq authentication.type "dynamic")}}
|
|
19
21
|
role UserRole?
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
{{else}}
|
|
23
|
+
{{#if (eq prisma.provider "sqlite")}}
|
|
22
24
|
role String @default("User") // Roles examples: Admin, User
|
|
23
|
-
|
|
25
|
+
{{else}}
|
|
24
26
|
role UserRole @default(User)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
{{/if}}
|
|
28
|
+
{{/if}}
|
|
27
29
|
{{/if}}
|
|
28
30
|
createdAt DateTime @default(now())
|
|
29
31
|
updatedAt DateTime @updatedAt
|
|
30
|
-
|
|
31
32
|
// other fields for your application
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -4,6 +4,9 @@ import { AuthPrismaQueryOptions } from 'arkos/prisma';
|
|
|
4
4
|
|
|
5
5
|
const authQueryOptions: AuthPrismaQueryOptions<typeof prisma.user> = {
|
|
6
6
|
{{else}}
|
|
7
|
+
/**
|
|
8
|
+
* @type {import("arkos/prisma").PrismaQueryOptions<typeof import('../../utils/prisma').prisma.user>}
|
|
9
|
+
*/
|
|
7
10
|
const authQueryOptions = {
|
|
8
11
|
{{/if}}
|
|
9
12
|
getMe: {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IsString, MinLength, Matches, IsNotEmpty } from 'class-validator'
|
|
2
|
+
import "reflect-metadata"
|
|
3
|
+
|
|
4
|
+
export default class UpdatePasswordDto {
|
|
5
|
+
@IsString()
|
|
6
|
+
@IsNotEmpty()
|
|
7
|
+
currentPassword: 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
|
+
newPassword: string
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
|
|
3
|
+
const UpdatePasswordSchema = z.object({
|
|
4
|
+
currentPassword: z.string(),
|
|
5
|
+
newPassword: 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 UpdatePasswordSchema
|
|
12
|
+
|
|
13
|
+
{{#if typescript}}
|
|
14
|
+
export type UpdatePasswordSchemaType = z.infer<typeof UpdatePasswordSchema>
|
|
15
|
+
{{/if}}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IsString, IsNotEmpty, IsOptional, IsEnum, ValidateNested } from 'class-validator';
|
|
2
|
+
import { Type, Transform } from 'class-transformer';
|
|
3
|
+
import 'reflect-metadata'
|
|
4
|
+
{{#if (eq prisma.provider "sqlite")}}
|
|
5
|
+
|
|
6
|
+
export enum AuthPermissionAction {
|
|
7
|
+
View = 'View',
|
|
8
|
+
Create = 'Create',
|
|
9
|
+
Update = 'Update',
|
|
10
|
+
Delete = 'Delete'
|
|
11
|
+
}
|
|
12
|
+
{{else}}
|
|
13
|
+
import { AuthPermissionAction } from "@prisma/client"
|
|
14
|
+
{{/if}}
|
|
15
|
+
|
|
16
|
+
class RoleConnectDto {
|
|
17
|
+
@IsString()
|
|
18
|
+
@IsNotEmpty({ message: 'Role ID is required' })
|
|
19
|
+
id: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default class CreateAuthPermissionDto {
|
|
23
|
+
@IsString()
|
|
24
|
+
@IsNotEmpty({ message: 'Resource is required' })
|
|
25
|
+
resource: string;
|
|
26
|
+
|
|
27
|
+
@IsEnum(AuthPermissionAction)
|
|
28
|
+
@Transform(({ value }) => value || AuthPermissionAction.View)
|
|
29
|
+
action: AuthPermissionAction = AuthPermissionAction.View;
|
|
30
|
+
|
|
31
|
+
@ValidateNested()
|
|
32
|
+
@Type(() => RoleConnectDto)
|
|
33
|
+
role: RoleConnectDto;
|
|
34
|
+
|
|
35
|
+
@IsOptional()
|
|
36
|
+
@IsString()
|
|
37
|
+
@Transform(({ value }) => value || "Allows to create a permission for a given role.")
|
|
38
|
+
description?: string = "Allows to create a permission for a given role.";
|
|
39
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IsString, IsOptional, IsEnum } from 'class-validator';
|
|
2
|
+
import { Transform } from 'class-transformer';
|
|
3
|
+
import 'reflect-metadata'
|
|
4
|
+
{{#if (eq prisma.provider "sqlite")}}
|
|
5
|
+
|
|
6
|
+
export enum AuthPermissionAction {
|
|
7
|
+
View = 'View',
|
|
8
|
+
Create = 'Create',
|
|
9
|
+
Update = 'Update',
|
|
10
|
+
Delete = 'Delete'
|
|
11
|
+
}
|
|
12
|
+
{{else}}
|
|
13
|
+
import { AuthPermissionAction } from "@prisma/client"
|
|
14
|
+
{{/if}}
|
|
15
|
+
|
|
16
|
+
export default class UpdateAuthPermissionDto {
|
|
17
|
+
@IsOptional()
|
|
18
|
+
@IsString()
|
|
19
|
+
resource?: string;
|
|
20
|
+
|
|
21
|
+
@IsOptional()
|
|
22
|
+
@IsEnum(AuthPermissionAction)
|
|
23
|
+
@Transform(({ value }) => value || AuthPermissionAction.View)
|
|
24
|
+
action?: AuthPermissionAction = AuthPermissionAction.View;
|
|
25
|
+
|
|
26
|
+
@IsOptional()
|
|
27
|
+
@IsString()
|
|
28
|
+
description?: string;
|
|
29
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
{{#if (eq prisma.provider "sqlite")}}
|
|
3
|
+
|
|
4
|
+
export const AuthPermissionActionEnum = z.enum([
|
|
5
|
+
'View',
|
|
6
|
+
'Create',
|
|
7
|
+
'Update',
|
|
8
|
+
'Delete'
|
|
9
|
+
]);
|
|
10
|
+
{{else}}
|
|
11
|
+
import { AuthPermissionAction } from "@prisma/client"
|
|
12
|
+
export const AuthPermissionActionEnum = z.nativeEnum(AuthPermissionAction);
|
|
13
|
+
{{/if}}
|
|
14
|
+
|
|
15
|
+
const CreateAuthPermissionSchema = z.object({
|
|
16
|
+
resource: z.string().min(1, 'Resource is required'),
|
|
17
|
+
action: AuthPermissionActionEnum.default('View'),
|
|
18
|
+
role: z.object({
|
|
19
|
+
id: z.string().min(1, 'Role ID is required'),
|
|
20
|
+
}),
|
|
21
|
+
description: z.string().optional().default("Allows to create a permission for a given role."),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export default CreateAuthPermissionSchema
|
|
25
|
+
|
|
26
|
+
{{#if typescript}}
|
|
27
|
+
export type CreateAuthPermissionSchemaType = z.infer<typeof CreateAuthPermissionSchema>;
|
|
28
|
+
{{/if}}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
{{#if (eq prisma.provider "sqlite")}}
|
|
3
|
+
|
|
4
|
+
export const AuthPermissionActionEnum = z.enum([
|
|
5
|
+
'View',
|
|
6
|
+
'Create',
|
|
7
|
+
'Update',
|
|
8
|
+
'Delete'
|
|
9
|
+
]);
|
|
10
|
+
{{else}}
|
|
11
|
+
import { AuthPermissionAction } from "@prisma/client"
|
|
12
|
+
export const AuthPermissionActionEnum = z.nativeEnum(AuthPermissionAction);
|
|
13
|
+
{{/if}}
|
|
14
|
+
|
|
15
|
+
const UpdateAuthPermissionSchema = z.object({
|
|
16
|
+
resource: z.string().optional(),
|
|
17
|
+
action: AuthPermissionActionEnum.default('View'),
|
|
18
|
+
description: z.string().optional(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export default UpdateAuthPermissionSchema
|
|
22
|
+
|
|
23
|
+
{{#if typescript}}
|
|
24
|
+
export type UpdateAuthPermissionSchemaType = z.infer<typeof UpdateAuthPermissionSchema>;
|
|
25
|
+
{{/if}}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { IsString, IsNotEmpty, IsOptional, IsArray, ValidateNested, IsEnum } from 'class-validator';
|
|
2
|
+
import { Type, Transform } from 'class-transformer';
|
|
3
|
+
import 'reflect-metadata'
|
|
4
|
+
{{#if (eq prisma.provider "sqlite")}}
|
|
5
|
+
|
|
6
|
+
export enum AuthPermissionAction {
|
|
7
|
+
View = 'View',
|
|
8
|
+
Create = 'Create',
|
|
9
|
+
Update = 'Update',
|
|
10
|
+
Delete = 'Delete'
|
|
11
|
+
}
|
|
12
|
+
{{else}}
|
|
13
|
+
import { AuthPermissionAction } from "@prisma/client"
|
|
14
|
+
{{/if}}
|
|
15
|
+
|
|
16
|
+
class CreatePermissionForRoleDto {
|
|
17
|
+
@IsString()
|
|
18
|
+
@IsNotEmpty({ message: 'Resource is required' })
|
|
19
|
+
resource: string;
|
|
20
|
+
|
|
21
|
+
@IsEnum(AuthPermissionAction)
|
|
22
|
+
@Transform(({ value }) => value || AuthPermissionAction.View)
|
|
23
|
+
action: AuthPermissionAction = AuthPermissionAction.View;
|
|
24
|
+
|
|
25
|
+
@IsOptional()
|
|
26
|
+
@IsString()
|
|
27
|
+
@Transform(({ value }) => value || "Allows to create a permission for a given role.")
|
|
28
|
+
description?: string = "Allows to create a permission for a given role.";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default class CreateAuthRoleDto {
|
|
32
|
+
@IsString()
|
|
33
|
+
@IsNotEmpty({ message: 'Role name is required' })
|
|
34
|
+
name: string;
|
|
35
|
+
|
|
36
|
+
@IsOptional()
|
|
37
|
+
@IsString()
|
|
38
|
+
description?: string;
|
|
39
|
+
|
|
40
|
+
@IsOptional()
|
|
41
|
+
@IsArray()
|
|
42
|
+
@ValidateNested({ each: true })
|
|
43
|
+
@Type(() => CreatePermissionForRoleDto)
|
|
44
|
+
@Transform(({ value }) => value || [])
|
|
45
|
+
permissions?: CreatePermissionForRoleDto[] = [];
|
|
46
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { IsString, IsNotEmpty, IsOptional, IsArray, ValidateNested, IsEnum } from 'class-validator';
|
|
2
|
+
import { Type, Transform } from 'class-transformer';
|
|
3
|
+
import 'reflect-metadata'
|
|
4
|
+
{{#if (eq prisma.provider "sqlite")}}
|
|
5
|
+
|
|
6
|
+
export enum AuthPermissionAction {
|
|
7
|
+
View = 'View',
|
|
8
|
+
Create = 'Create',
|
|
9
|
+
Update = 'Update',
|
|
10
|
+
Delete = 'Delete'
|
|
11
|
+
}
|
|
12
|
+
{{else}}
|
|
13
|
+
import { AuthPermissionAction } from "@prisma/client"
|
|
14
|
+
{{/if}}
|
|
15
|
+
|
|
16
|
+
export enum ApiAction {
|
|
17
|
+
connect = 'connect',
|
|
18
|
+
delete = 'delete'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
class UpdatePermissionForRoleDto {
|
|
22
|
+
@IsString()
|
|
23
|
+
@IsNotEmpty({ message: 'Resource is required' })
|
|
24
|
+
resource: string;
|
|
25
|
+
|
|
26
|
+
@IsEnum(AuthPermissionAction)
|
|
27
|
+
@Transform(({ value }) => value || AuthPermissionAction.View)
|
|
28
|
+
action: AuthPermissionAction = AuthPermissionAction.View;
|
|
29
|
+
|
|
30
|
+
@IsOptional()
|
|
31
|
+
@IsString()
|
|
32
|
+
@Transform(({ value }) => value || "Allows to create a permission for a given role.")
|
|
33
|
+
description?: string = "Allows to create a permission for a given role.";
|
|
34
|
+
|
|
35
|
+
@IsEnum(ApiAction)
|
|
36
|
+
@IsOptional()
|
|
37
|
+
apiAction: ApiAction;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default class UpdateAuthRoleDto {
|
|
41
|
+
@IsString()
|
|
42
|
+
@IsNotEmpty({ message: 'Role name is required' })
|
|
43
|
+
name: string;
|
|
44
|
+
|
|
45
|
+
@IsOptional()
|
|
46
|
+
@IsString()
|
|
47
|
+
description?: string;
|
|
48
|
+
|
|
49
|
+
@IsOptional()
|
|
50
|
+
@IsArray()
|
|
51
|
+
@ValidateNested({ each: true })
|
|
52
|
+
@Type(() => UpdatePermissionForRoleDto)
|
|
53
|
+
@Transform(({ value }) => value || [])
|
|
54
|
+
permissions?: UpdatePermissionForRoleDto[] = [];
|
|
55
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
{{#if typescript}}
|
|
3
|
+
import CreateAuthPermissionSchema from "../../auth-permission/schemas/create-auth-permission"
|
|
4
|
+
{{else}}
|
|
5
|
+
import CreateAuthPermissionSchema from "../../auth-permission/schemas/create-auth-permission.js"
|
|
6
|
+
{{/if}}
|
|
7
|
+
|
|
8
|
+
const CreateAuthRoleSchema = z.object({
|
|
9
|
+
name: z.string().min(1, 'Role name is required'),
|
|
10
|
+
description: z.string().optional(),
|
|
11
|
+
permissions: z.array(CreatePermissionSchema.omit({ role: true })).optional().default([]),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export default CreateAuthRoleSchema
|
|
15
|
+
|
|
16
|
+
{{#if typescript}}
|
|
17
|
+
export type CreateAuthRoleSchemaType = z.infer<typeof CreateAuthRoleSchema>;
|
|
18
|
+
{{/if}}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
{{#if typescript}}
|
|
3
|
+
import CreateAuthPermissionSchema from "../../auth-permission/schemas/create-auth-permission"
|
|
4
|
+
{{else}}
|
|
5
|
+
import CreateAuthPermissionSchema from "../../auth-permission/schemas/create-auth-permission.js"
|
|
6
|
+
{{/if}}
|
|
7
|
+
|
|
8
|
+
const UpdateAuthRoleSchema = z.object({
|
|
9
|
+
name: z.string().min(1, 'Role name is required'),
|
|
10
|
+
description: z.string().optional(),
|
|
11
|
+
permissions: z.array(CreatePermissionSchema.omit({ role: true }).merge({ apiAction: z.enum(['connect', 'delete']).optional() })).optional().default([]),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export default UpdateAuthRoleSchema
|
|
15
|
+
|
|
16
|
+
{{#if typescript}}
|
|
17
|
+
export type UpdateAuthRoleSchemaType = z.infer<typeof UpdateAuthRoleSchema>;
|
|
18
|
+
{{/if}}
|
|
@@ -11,11 +11,15 @@ import {
|
|
|
11
11
|
Type,
|
|
12
12
|
IsEnum
|
|
13
13
|
} from 'class-validator'
|
|
14
|
+
{{#if typescript}}
|
|
14
15
|
import apiActions from "../../../utils/validation/api-actions"
|
|
16
|
+
{{else}}
|
|
17
|
+
import apiActions from "../../../utils/validation/api-actions.js"
|
|
18
|
+
{{/if}}
|
|
15
19
|
{{#if (eq authentication.type "static")}}
|
|
16
|
-
{{#if (neq prisma.provider "sqlite")}}
|
|
20
|
+
{{#if (neq prisma.provider "sqlite")}}
|
|
17
21
|
import { UserRole } from "@prisma/client"
|
|
18
|
-
{{/if}}
|
|
22
|
+
{{/if}}
|
|
19
23
|
{{/if}}
|
|
20
24
|
|
|
21
25
|
{{#if (eq authentication.type "dynamic")}}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { z } from "zod"
|
|
2
|
-
import apiActions from "../../../utils/validation/api-actions"
|
|
3
2
|
{{#if (eq authentication.type "static")}}
|
|
4
3
|
{{#if (neq prisma.provider "sqlite")}}
|
|
5
4
|
import { UserRole } from "@prisma/client"
|
|
@@ -44,3 +43,7 @@ const CreateUserSchema = z.object({
|
|
|
44
43
|
})
|
|
45
44
|
|
|
46
45
|
export default CreateUserSchema
|
|
46
|
+
|
|
47
|
+
{{#if typescript}}
|
|
48
|
+
export type CreateUserSchemaType = z.infer<typeof CreateUserSchema>
|
|
49
|
+
{{/if}}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { z } from "zod"
|
|
2
|
+
{{#if typescript}}
|
|
2
3
|
import apiActions from "../../../utils/validation/api-actions"
|
|
4
|
+
{{else}}
|
|
5
|
+
import apiActions from "../../../utils/validation/api-actions.js"
|
|
6
|
+
{{/if}}
|
|
3
7
|
{{#if (eq authentication.type "static")}}
|
|
4
8
|
{{#if (neq prisma.provider "sqlite")}}
|
|
5
9
|
import { UserRole } from "@prisma/client"
|
|
@@ -44,3 +48,7 @@ const UpdateUserSchema = z.object({
|
|
|
44
48
|
})
|
|
45
49
|
|
|
46
50
|
export default UpdateUserSchema
|
|
51
|
+
|
|
52
|
+
{{#if typescript}}
|
|
53
|
+
export type UpdateUserSchemaType = z.infer<typeof UpdateUserSchema>
|
|
54
|
+
{{/if}}
|
|
@@ -4,6 +4,9 @@ import { PrismaQueryOptions } from 'arkos/prisma';
|
|
|
4
4
|
|
|
5
5
|
const userQueryOptions: PrismaQueryOptions<typeof prisma.user> = {
|
|
6
6
|
{{else}}
|
|
7
|
+
/**
|
|
8
|
+
* @type {import("arkos/prisma").PrismaQueryOptions<typeof import('../../utils/prisma').prisma.user>}
|
|
9
|
+
*/
|
|
7
10
|
const userQueryOptions = {
|
|
8
11
|
{{/if}}
|
|
9
12
|
global: {},
|