arkos 1.3.2-canary.4 → 1.3.3-beta.1
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/README.md +8 -4
- package/dist/cjs/app.js +39 -4
- package/dist/cjs/app.js.map +1 -1
- package/dist/cjs/exports/utils/index.js +5 -25
- package/dist/cjs/exports/utils/index.js.map +1 -1
- package/dist/cjs/modules/auth/auth.controller.js +18 -0
- package/dist/cjs/modules/auth/auth.controller.js.map +1 -1
- package/dist/cjs/modules/auth/auth.router.js +2 -0
- package/dist/cjs/modules/auth/auth.router.js.map +1 -1
- package/dist/cjs/modules/base/base.controller.js +49 -11
- package/dist/cjs/modules/base/base.controller.js.map +1 -1
- package/dist/cjs/modules/base/base.middlewares.js.map +1 -1
- package/dist/cjs/modules/base/base.service.js +108 -0
- package/dist/cjs/modules/base/base.service.js.map +1 -1
- package/dist/cjs/modules/base/types/base.service.types.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +29 -14
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js +2 -2
- package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js.map +1 -1
- package/dist/cjs/modules/base/utils/router-validator.js +1 -4
- package/dist/cjs/modules/base/utils/router-validator.js.map +1 -1
- package/dist/cjs/modules/base/utils/service-hooks-manager.js.map +1 -1
- package/dist/cjs/modules/debugger/debugger.service.js +82 -0
- package/dist/cjs/modules/debugger/debugger.service.js.map +1 -0
- package/dist/cjs/modules/debugger/utils/loaded-components-logger.js +55 -0
- package/dist/cjs/modules/debugger/utils/loaded-components-logger.js.map +1 -0
- package/dist/cjs/modules/file-upload/file-upload.controller.js +4 -0
- package/dist/cjs/modules/file-upload/file-upload.controller.js.map +1 -1
- package/dist/cjs/modules/file-upload/file-upload.router.js +3 -1
- package/dist/cjs/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/cjs/modules/swagger/swagger.router.js +2 -1
- package/dist/cjs/modules/swagger/swagger.router.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +2 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +12 -8
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js +3 -3
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js +2 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js +3 -3
- package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -1
- package/dist/cjs/server.js +11 -0
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/types/arkos-config.js.map +1 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/utils/cli/generate.js +9 -4
- package/dist/cjs/utils/cli/generate.js.map +1 -1
- package/dist/cjs/utils/cli/prisma-generate.js +1 -2
- package/dist/cjs/utils/cli/prisma-generate.js.map +1 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/auth-configs-template.js +34 -10
- package/dist/cjs/utils/cli/utils/template-generator/templates/auth-configs-template.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/controller-template.js +2 -6
- package/dist/cjs/utils/cli/utils/template-generator/templates/controller-template.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/hooks-template.js +31 -36
- package/dist/cjs/utils/cli/utils/template-generator/templates/hooks-template.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/middlewares-template.js +0 -2
- package/dist/cjs/utils/cli/utils/template-generator/templates/middlewares-template.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/query-options-template.js +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/query-options-template.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/router-template.js +7 -10
- package/dist/cjs/utils/cli/utils/template-generator/templates/router-template.js.map +1 -1
- package/dist/cjs/utils/dynamic-loader.js +11 -2
- package/dist/cjs/utils/dynamic-loader.js.map +1 -1
- package/dist/cjs/utils/features/api.features.js +130 -73
- package/dist/cjs/utils/features/api.features.js.map +1 -1
- package/dist/cjs/utils/helpers/deepmerge.helper.js.map +1 -1
- package/dist/cjs/utils/helpers/prisma.helpers.js +8 -4
- package/dist/cjs/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/cjs/utils/prisma/prisma-json-schema-generator.js.map +1 -1
- package/dist/cjs/utils/sheu.js +11 -0
- package/dist/cjs/utils/sheu.js.map +1 -1
- package/dist/esm/app.js +6 -4
- package/dist/esm/app.js.map +1 -1
- package/dist/esm/exports/utils/index.js +2 -2
- package/dist/esm/exports/utils/index.js.map +1 -1
- package/dist/esm/modules/auth/auth.controller.js +18 -0
- package/dist/esm/modules/auth/auth.controller.js.map +1 -1
- package/dist/esm/modules/auth/auth.router.js +3 -1
- package/dist/esm/modules/auth/auth.router.js.map +1 -1
- package/dist/esm/modules/base/base.controller.js +49 -11
- package/dist/esm/modules/base/base.controller.js.map +1 -1
- package/dist/esm/modules/base/base.middlewares.js.map +1 -1
- package/dist/esm/modules/base/base.service.js +108 -0
- package/dist/esm/modules/base/base.service.js.map +1 -1
- package/dist/esm/modules/base/types/base.service.types.js.map +1 -1
- package/dist/esm/modules/base/utils/helpers/base.router.helpers.js +29 -15
- package/dist/esm/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/esm/modules/base/utils/helpers/base.service.helpers.js +2 -2
- package/dist/esm/modules/base/utils/helpers/base.service.helpers.js.map +1 -1
- package/dist/esm/modules/base/utils/router-validator.js +1 -4
- package/dist/esm/modules/base/utils/router-validator.js.map +1 -1
- package/dist/esm/modules/base/utils/service-hooks-manager.js.map +1 -1
- package/dist/esm/modules/debugger/debugger.service.js +77 -0
- package/dist/esm/modules/debugger/debugger.service.js.map +1 -0
- package/dist/esm/modules/debugger/utils/loaded-components-logger.js +50 -0
- package/dist/esm/modules/debugger/utils/loaded-components-logger.js.map +1 -0
- package/dist/esm/modules/file-upload/file-upload.controller.js +4 -0
- package/dist/esm/modules/file-upload/file-upload.controller.js.map +1 -1
- package/dist/esm/modules/file-upload/file-upload.router.js +3 -1
- package/dist/esm/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/esm/modules/swagger/swagger.router.js +2 -1
- package/dist/esm/modules/swagger/swagger.router.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +2 -1
- package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +12 -8
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js +3 -3
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js +2 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/missing-json-schemas-generator.js +3 -3
- package/dist/esm/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -1
- package/dist/esm/server.js +11 -0
- package/dist/esm/server.js.map +1 -1
- package/dist/esm/types/arkos-config.js.map +1 -1
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/utils/cli/generate.js +9 -4
- package/dist/esm/utils/cli/generate.js.map +1 -1
- package/dist/esm/utils/cli/prisma-generate.js +1 -2
- package/dist/esm/utils/cli/prisma-generate.js.map +1 -1
- package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/auth-configs-template.js +34 -10
- package/dist/esm/utils/cli/utils/template-generator/templates/auth-configs-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/controller-template.js +2 -6
- package/dist/esm/utils/cli/utils/template-generator/templates/controller-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/hooks-template.js +31 -36
- package/dist/esm/utils/cli/utils/template-generator/templates/hooks-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/middlewares-template.js +0 -2
- package/dist/esm/utils/cli/utils/template-generator/templates/middlewares-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/query-options-template.js +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/query-options-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/router-template.js +7 -7
- package/dist/esm/utils/cli/utils/template-generator/templates/router-template.js.map +1 -1
- package/dist/esm/utils/dynamic-loader.js +11 -2
- package/dist/esm/utils/dynamic-loader.js.map +1 -1
- package/dist/esm/utils/features/api.features.js +130 -72
- package/dist/esm/utils/features/api.features.js.map +1 -1
- package/dist/esm/utils/helpers/deepmerge.helper.js.map +1 -1
- package/dist/esm/utils/helpers/prisma.helpers.js +8 -4
- package/dist/esm/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/esm/utils/prisma/prisma-json-schema-generator.js.map +1 -1
- package/dist/esm/utils/sheu.js +11 -0
- package/dist/esm/utils/sheu.js.map +1 -1
- package/dist/types/exports/utils/index.d.ts +2 -2
- package/dist/types/modules/base/base.controller.d.ts +2 -0
- package/dist/types/modules/base/base.service.d.ts +5 -0
- package/dist/types/modules/base/types/base.service.types.d.ts +8 -8
- package/dist/types/modules/base/utils/helpers/base.router.helpers.d.ts +3 -1
- package/dist/types/modules/base/utils/service-hooks-manager.d.ts +1 -1
- package/dist/types/modules/debugger/debugger.service.d.ts +15 -0
- package/dist/types/modules/debugger/utils/loaded-components-logger.d.ts +9 -0
- package/dist/types/types/arkos-config.d.ts +14 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/utils/dynamic-loader.d.ts +33 -13
- package/dist/types/utils/features/api.features.d.ts +3 -5
- package/dist/types/utils/sheu.d.ts +8 -0
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getUserFileExtension } from "../../../../helpers/fs.helpers.js";
|
|
2
|
+
import { capitalize } from "../../../../helpers/text.helpers.js";
|
|
2
3
|
export function generateAuthConfigsTemplate(options) {
|
|
3
4
|
const { modelName } = options;
|
|
4
5
|
const ext = getUserFileExtension();
|
|
@@ -10,20 +11,43 @@ export function generateAuthConfigsTemplate(options) {
|
|
|
10
11
|
: "";
|
|
11
12
|
const typeAnnotation = isTypeScript ? `: AuthConfigs` : "";
|
|
12
13
|
return `${imports}
|
|
14
|
+
import { authService } from "arkos/services";
|
|
15
|
+
|
|
16
|
+
export const ${modelName.camel}Permissions = {
|
|
17
|
+
canCreate: authService.permission("Create", "${modelName.kebab}"),
|
|
18
|
+
canUpdate: authService.permission("Update", "${modelName.kebab}"),
|
|
19
|
+
canDelete: authService.permission("Delete", "${modelName.kebab}"),
|
|
20
|
+
canView: authService.permission("View", "${modelName.kebab}"),
|
|
21
|
+
}
|
|
22
|
+
|
|
13
23
|
const ${modelName.camel}AuthConfigs${typeAnnotation} = {
|
|
14
24
|
authenticationControl: {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
Create: true,
|
|
26
|
+
Update: true,
|
|
27
|
+
Delete: true,
|
|
28
|
+
View: true,
|
|
19
29
|
},
|
|
20
|
-
|
|
21
|
-
// Only when using Static RBAC
|
|
22
30
|
accessControl: {
|
|
23
|
-
// Create:
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
31
|
+
// Create: {
|
|
32
|
+
// roles: [],
|
|
33
|
+
// name: "Create ${capitalize(modelName.kebab.replaceAll("-", ""))}",
|
|
34
|
+
// description: "Permission to create new ${modelName.kebab.replaceAll("-", " ")} records"
|
|
35
|
+
// },
|
|
36
|
+
// Update: {
|
|
37
|
+
// roles: [],
|
|
38
|
+
// name: "Update ${capitalize(modelName.kebab.replaceAll("-", ""))}",
|
|
39
|
+
// description: "Permission to update existing ${modelName.kebab.replaceAll("-", " ")} records"
|
|
40
|
+
// },
|
|
41
|
+
// Delete: {
|
|
42
|
+
// roles: [],
|
|
43
|
+
// name: "Delete ${capitalize(modelName.kebab.replaceAll("-", ""))}",
|
|
44
|
+
// description: "Permission to delete ${modelName.kebab.replaceAll("-", " ")} records"
|
|
45
|
+
// },
|
|
46
|
+
// View: {
|
|
47
|
+
// roles: [],
|
|
48
|
+
// name: "View ${capitalize(modelName.kebab.replaceAll("-", ""))}",
|
|
49
|
+
// description: "Permission to view ${modelName.kebab.replaceAll("-", " ")} records"
|
|
50
|
+
// },
|
|
27
51
|
},
|
|
28
52
|
};
|
|
29
53
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-configs-template.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/auth-configs-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"auth-configs-template.js","sourceRoot":"","sources":["../../../../../../../src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,GAAG,EAAE,GAAG,CAAC;;;;uBAI3D,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;4CAC1B,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC;;;;;iBAK/D,SAAS,CAAC,KAAK;CAC/B,CAAC;AACF,CAAC","sourcesContent":["import { getUserFileExtension } from \"../../../../helpers/fs.helpers\";\nimport { capitalize } from \"../../../../helpers/text.helpers\";\nimport { TemplateOptions } from \"../../template-generators\";\n\nexport function generateAuthConfigsTemplate(options: TemplateOptions): string {\n const { modelName } = options;\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n\n if (!modelName)\n throw new Error(\"Model name is required for auth config template\");\n\n // Generate imports for TypeScript\n const imports = isTypeScript\n ? `import { AuthConfigs } from 'arkos/auth';\\n`\n : \"\";\n\n // Generate type annotation for TypeScript\n const typeAnnotation = isTypeScript ? `: AuthConfigs` : \"\";\n\n return `${imports}\nimport { authService } from \"arkos/services\";\n\nexport const ${modelName.camel}Permissions = {\n canCreate: authService.permission(\"Create\", \"${modelName.kebab}\"),\n canUpdate: authService.permission(\"Update\", \"${modelName.kebab}\"),\n canDelete: authService.permission(\"Delete\", \"${modelName.kebab}\"),\n canView: authService.permission(\"View\", \"${modelName.kebab}\"),\n}\n\nconst ${modelName.camel}AuthConfigs${typeAnnotation} = {\n authenticationControl: {\n Create: true,\n Update: true,\n Delete: true,\n View: true,\n },\n accessControl: {\n // Create: {\n // roles: [],\n // name: \"Create ${capitalize(modelName.kebab.replaceAll(\"-\", \"\"))}\",\n // description: \"Permission to create new ${modelName.kebab.replaceAll(\"-\", \" \")} records\"\n // },\n // Update: {\n // roles: [],\n // name: \"Update ${capitalize(modelName.kebab.replaceAll(\"-\", \"\"))}\",\n // description: \"Permission to update existing ${modelName.kebab.replaceAll(\"-\", \" \")} records\"\n // },\n // Delete: {\n // roles: [],\n // name: \"Delete ${capitalize(modelName.kebab.replaceAll(\"-\", \"\"))}\",\n // description: \"Permission to delete ${modelName.kebab.replaceAll(\"-\", \" \")} records\"\n // },\n // View: {\n // roles: [],\n // name: \"View ${capitalize(modelName.kebab.replaceAll(\"-\", \"\"))}\",\n // description: \"Permission to view ${modelName.kebab.replaceAll(\"-\", \" \")} records\"\n // },\n },\n};\n\nexport default ${modelName.camel}AuthConfigs;\n`;\n}\n"]}
|
|
@@ -4,13 +4,9 @@ export function generateControllerTemplate(options) {
|
|
|
4
4
|
throw new Error("Model name is required for controller template");
|
|
5
5
|
return `import { BaseController } from "${imports?.baseController || "arkos/controllers"}";
|
|
6
6
|
|
|
7
|
-
class ${modelName.pascal}Controller extends BaseController {
|
|
8
|
-
constructor() {
|
|
9
|
-
super("${modelName.kebab}");
|
|
10
|
-
}
|
|
11
|
-
}
|
|
7
|
+
class ${modelName.pascal}Controller extends BaseController {}
|
|
12
8
|
|
|
13
|
-
const ${modelName.camel}Controller = new ${modelName.pascal}Controller();
|
|
9
|
+
const ${modelName.camel}Controller = new ${modelName.pascal}Controller("${modelName.kebab}");
|
|
14
10
|
|
|
15
11
|
export default ${modelName.camel}Controller;
|
|
16
12
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-template.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/controller-template.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,0BAA0B,CAAC,OAAwB;IACjE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAEvC,IAAI,CAAC,SAAS;QACZ,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IAEpE,OAAO,mCACL,OAAO,EAAE,cAAc,IAAI,mBAC7B;;QAEM,SAAS,CAAC,MAAM;;
|
|
1
|
+
{"version":3,"file":"controller-template.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/controller-template.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,0BAA0B,CAAC,OAAwB;IACjE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAEvC,IAAI,CAAC,SAAS;QACZ,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IAEpE,OAAO,mCACL,OAAO,EAAE,cAAc,IAAI,mBAC7B;;QAEM,SAAS,CAAC,MAAM;;QAEhB,SAAS,CAAC,KAAK,oBAAoB,SAAS,CAAC,MAAM,eAAe,SAAS,CAAC,KAAK;;iBAExE,SAAS,CAAC,KAAK;GAC7B,CAAC;AACJ,CAAC","sourcesContent":["import { TemplateOptions } from \"../../template-generators\";\n\nexport function generateControllerTemplate(options: TemplateOptions): string {\n const { modelName, imports } = options;\n\n if (!modelName)\n throw new Error(\"Model name is required for controller template\");\n\n return `import { BaseController } from \"${\n imports?.baseController || \"arkos/controllers\"\n }\";\n \nclass ${modelName.pascal}Controller extends BaseController {}\n\nconst ${modelName.camel}Controller = new ${modelName.pascal}Controller(\"${modelName.kebab}\");\n\nexport default ${modelName.camel}Controller;\n `;\n}\n"]}
|
|
@@ -4,7 +4,7 @@ export default function generateHooksTemplate(options) {
|
|
|
4
4
|
const ext = getUserFileExtension();
|
|
5
5
|
const isTypeScript = ext === "ts";
|
|
6
6
|
if (!modelName)
|
|
7
|
-
throw new Error("
|
|
7
|
+
throw new Error("Module name is required for hooks template");
|
|
8
8
|
const baseImports = isTypeScript
|
|
9
9
|
? `// import {
|
|
10
10
|
// BeforeFindOneHookArgs,
|
|
@@ -37,43 +37,39 @@ export default function generateHooksTemplate(options) {
|
|
|
37
37
|
// OnDeleteManyErrorHookArgs
|
|
38
38
|
// } from "arkos/services";`
|
|
39
39
|
: ``;
|
|
40
|
-
const prismaImport = `"../../utils/prisma${ext === "ts" ? "" : "." + "js"}";`;
|
|
41
40
|
const serviceImport = `"./${modelName.kebab}.service${ext === "ts" ? "" : "." + "js"}";`;
|
|
42
|
-
const delegateExport = isTypeScript
|
|
43
|
-
? `\nexport type ${modelName.pascal}Delegate = typeof prisma.${modelName.camel};`
|
|
44
|
-
: "";
|
|
45
41
|
const getHookArgsType = (hookName) => {
|
|
46
42
|
if (!isTypeScript)
|
|
47
43
|
return "";
|
|
48
44
|
const typeMap = {
|
|
49
|
-
beforeFindOne: `BeforeFindOneHookArgs
|
|
50
|
-
afterFindOne: `AfterFindOneHookArgs
|
|
51
|
-
beforeUpdateOne: `BeforeUpdateOneHookArgs
|
|
52
|
-
afterUpdateOne: `AfterUpdateOneHookArgs
|
|
53
|
-
beforeCreateOne: `BeforeCreateOneHookArgs
|
|
54
|
-
afterCreateOne: `AfterCreateOneHookArgs
|
|
55
|
-
beforeCreateMany: `BeforeCreateManyHookArgs
|
|
56
|
-
afterCreateMany: `AfterCreateManyHookArgs
|
|
57
|
-
beforeCount: `BeforeCountHookArgs
|
|
58
|
-
afterCount: `AfterCountHookArgs
|
|
59
|
-
beforeFindMany: `BeforeFindManyHookArgs
|
|
60
|
-
afterFindMany: `AfterFindManyHookArgs
|
|
61
|
-
beforeUpdateMany: `BeforeUpdateManyHookArgs
|
|
62
|
-
afterUpdateMany: `AfterUpdateManyHookArgs
|
|
63
|
-
beforeDeleteOne: `BeforeDeleteOneHookArgs
|
|
64
|
-
afterDeleteOne: `AfterDeleteOneHookArgs
|
|
65
|
-
beforeDeleteMany: `BeforeDeleteManyHookArgs
|
|
66
|
-
afterDeleteMany: `AfterDeleteManyHookArgs
|
|
67
|
-
onCreateOneError: `OnCreateOneErrorHookArgs
|
|
68
|
-
onCreateManyError: `OnCreateManyErrorHookArgs
|
|
69
|
-
onCountError: `OnCountErrorHookArgs
|
|
70
|
-
onFindManyError: `OnFindManyErrorHookArgs
|
|
71
|
-
onFindByIdError: `OnFindByIdErrorHookArgs
|
|
72
|
-
onFindOneError: `OnFindOneErrorHookArgs
|
|
73
|
-
onUpdateOneError: `OnUpdateOneErrorHookArgs
|
|
74
|
-
onUpdateManyError: `OnUpdateManyErrorHookArgs
|
|
75
|
-
onDeleteOneError: `OnDeleteOneErrorHookArgs
|
|
76
|
-
onDeleteManyError: `OnDeleteManyErrorHookArgs
|
|
45
|
+
beforeFindOne: `BeforeFindOneHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
46
|
+
afterFindOne: `AfterFindOneHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
47
|
+
beforeUpdateOne: `BeforeUpdateOneHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
48
|
+
afterUpdateOne: `AfterUpdateOneHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
49
|
+
beforeCreateOne: `BeforeCreateOneHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
50
|
+
afterCreateOne: `AfterCreateOneHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
51
|
+
beforeCreateMany: `BeforeCreateManyHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
52
|
+
afterCreateMany: `AfterCreateManyHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
53
|
+
beforeCount: `BeforeCountHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
54
|
+
afterCount: `AfterCountHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
55
|
+
beforeFindMany: `BeforeFindManyHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
56
|
+
afterFindMany: `AfterFindManyHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
57
|
+
beforeUpdateMany: `BeforeUpdateManyHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
58
|
+
afterUpdateMany: `AfterUpdateManyHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
59
|
+
beforeDeleteOne: `BeforeDeleteOneHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
60
|
+
afterDeleteOne: `AfterDeleteOneHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
61
|
+
beforeDeleteMany: `BeforeDeleteManyHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
62
|
+
afterDeleteMany: `AfterDeleteManyHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
63
|
+
onCreateOneError: `OnCreateOneErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
64
|
+
onCreateManyError: `OnCreateManyErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
65
|
+
onCountError: `OnCountErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
66
|
+
onFindManyError: `OnFindManyErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
67
|
+
onFindByIdError: `OnFindByIdErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
68
|
+
onFindOneError: `OnFindOneErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
69
|
+
onUpdateOneError: `OnUpdateOneErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
70
|
+
onUpdateManyError: `OnUpdateManyErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
71
|
+
onDeleteOneError: `OnDeleteOneErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
72
|
+
onDeleteManyError: `OnDeleteManyErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,
|
|
77
73
|
};
|
|
78
74
|
return typeMap[hookName];
|
|
79
75
|
};
|
|
@@ -82,7 +78,7 @@ export default function generateHooksTemplate(options) {
|
|
|
82
78
|
const args = isTypeScript
|
|
83
79
|
? `{ ${params.join(", ")} }: ${argsType}`
|
|
84
80
|
: `{ ${params.join(", ")} }`;
|
|
85
|
-
return `async function
|
|
81
|
+
return `async function (${args}) {}`;
|
|
86
82
|
};
|
|
87
83
|
const hooks = `
|
|
88
84
|
// export const beforeFindOne = [
|
|
@@ -194,9 +190,8 @@ export default function generateHooksTemplate(options) {
|
|
|
194
190
|
// ];
|
|
195
191
|
`;
|
|
196
192
|
return `${baseImports}
|
|
197
|
-
// import
|
|
193
|
+
// import { Prisma } from "@prisma/client"
|
|
198
194
|
// import ${modelName.camel}Service from ${serviceImport}
|
|
199
|
-
${delegateExport}
|
|
200
195
|
|
|
201
196
|
${hooks}`;
|
|
202
197
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks-template.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/hooks-template.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAKtE,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAC3C,OAAwB;IAGxB,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAE9B,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;IAEnC,MAAM,YAAY,GAAG,GAAG,KAAK,IAAI,CAAC;IAGlC,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAG7E,MAAM,WAAW,GAAG,YAAY;QAC9B,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BA6BsB;QACxB,CAAC,CAAC,EAAE,CAAC;IAGP,MAAM,YAAY,GAAG,sBAAsB,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC;IAG9E,MAAM,aAAa,GAAG,MAAM,SAAS,CAAC,KAAK,WAAW,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC;IAGzF,MAAM,cAAc,GAAG,YAAY;QACjC,CAAC,CAAC,iBAAiB,SAAS,CAAC,MAAM,4BAA4B,SAAS,CAAC,KAAK,GAAG;QACjF,CAAC,CAAC,EAAE,CAAC;IAGP,MAAM,eAAe,GAAG,CAAC,QAAgB,EAAE,EAAE;QAE3C,IAAI,CAAC,YAAY;YAAE,OAAO,EAAE,CAAC;QAG7B,MAAM,OAAO,GAA2B;YACtC,aAAa,EAAE,yBAAyB,SAAS,CAAC,MAAM,WAAW;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iB,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;;;;OAIjG,oBAAoB,CAAC,mBAAmB,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;;;;OAIlG,oBAAoB,CAAC,iBAAiB,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;;;;OAI/D,oBAAoB,CAAC,gBAAgB,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;;;;OAIxE,oBAAoB,CAAC,kBAAkB,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;;;;OAIzE,oBAAoB,CAAC,kBAAkB,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;;;;OAIhE,oBAAoB,CAAC,iBAAiB,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;;;;OAIzE,oBAAoB,CAAC,mBAAmB,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;;CAEhF,CAAC;IAGA,OAAO,GAAG,WAAW;wBACC,YAAY;YACxB,SAAS,CAAC,KAAK,gBAAgB,aAAa;EACtD,cAAc;;EAEd,KAAK,EAAE,CAAC;AACV,CAAC","sourcesContent":["// Import helper function to get user's file extension preference\nimport { getUserFileExtension } from \"../../../../helpers/fs.helpers\";\n// Import template options interface\nimport { TemplateOptions } from \"../../template-generators\";\n\n// Main function to generate hooks template based on provided options\nexport default function generateHooksTemplate(\n options: TemplateOptions\n): string {\n // Destructure modelName from options\n const { modelName } = options;\n // Get user's preferred file extension (ts or js)\n const ext = getUserFileExtension();\n // Check if user is using TypeScript\n const isTypeScript = ext === \"ts\";\n\n // Throw error if modelName is not provided\n if (!modelName) throw new Error(\"Model name is required for hooks template\");\n\n // Define base imports for TypeScript - includes all hook argument types\n const baseImports = isTypeScript\n ? `// import { \n// BeforeFindOneHookArgs, \n// AfterFindOneHookArgs, \n// BeforeUpdateOneHookArgs, \n// AfterUpdateOneHookArgs,\n// BeforeCreateOneHookArgs,\n// AfterCreateOneHookArgs,\n// BeforeCreateManyHookArgs,\n// AfterCreateManyHookArgs,\n// BeforeCountHookArgs,\n// AfterCountHookArgs,\n// BeforeFindManyHookArgs,\n// AfterFindManyHookArgs,\n// BeforeUpdateManyHookArgs,\n// AfterUpdateManyHookArgs,\n// BeforeDeleteOneHookArgs,\n// AfterDeleteOneHookArgs,\n// BeforeDeleteManyHookArgs,\n// AfterDeleteManyHookArgs,\n// OnCreateOneErrorHookArgs,\n// OnCreateManyErrorHookArgs,\n// OnCountErrorHookArgs,\n// OnFindManyErrorHookArgs,\n// OnFindByIdErrorHookArgs,\n// OnFindOneErrorHookArgs,\n// OnUpdateOneErrorHookArgs,\n// OnUpdateManyErrorHookArgs,\n// OnDeleteOneErrorHookArgs,\n// OnDeleteManyErrorHookArgs\n// } from \"arkos/services\";`\n : ``;\n\n // Define prisma import path based on file extension\n const prismaImport = `\"../../utils/prisma${ext === \"ts\" ? \"\" : \".\" + \"js\"}\";`;\n\n // Define service import path based on file extension\n const serviceImport = `\"./${modelName.kebab}.service${ext === \"ts\" ? \"\" : \".\" + \"js\"}\";`;\n\n // Export delegate type for TypeScript only\n const delegateExport = isTypeScript\n ? `\\nexport type ${modelName.pascal}Delegate = typeof prisma.${modelName.camel};`\n : \"\";\n\n // Function to get the appropriate TypeScript type for each hook\n const getHookArgsType = (hookName: string) => {\n // Return empty string for JavaScript\n if (!isTypeScript) return \"\";\n\n // Map hook names to their corresponding TypeScript types\n const typeMap: Record<string, string> = {\n beforeFindOne: `BeforeFindOneHookArgs<${modelName.pascal}Delegate>`,\n afterFindOne: `AfterFindOneHookArgs<${modelName.pascal}Delegate>`,\n beforeUpdateOne: `BeforeUpdateOneHookArgs<${modelName.pascal}Delegate>`,\n afterUpdateOne: `AfterUpdateOneHookArgs<${modelName.pascal}Delegate>`,\n beforeCreateOne: `BeforeCreateOneHookArgs<${modelName.pascal}Delegate>`,\n afterCreateOne: `AfterCreateOneHookArgs<${modelName.pascal}Delegate>`,\n beforeCreateMany: `BeforeCreateManyHookArgs<${modelName.pascal}Delegate>`,\n afterCreateMany: `AfterCreateManyHookArgs<${modelName.pascal}Delegate>`,\n beforeCount: `BeforeCountHookArgs<${modelName.pascal}Delegate>`,\n afterCount: `AfterCountHookArgs<${modelName.pascal}Delegate>`,\n beforeFindMany: `BeforeFindManyHookArgs<${modelName.pascal}Delegate>`,\n afterFindMany: `AfterFindManyHookArgs<${modelName.pascal}Delegate>`,\n beforeUpdateMany: `BeforeUpdateManyHookArgs<${modelName.pascal}Delegate>`,\n afterUpdateMany: `AfterUpdateManyHookArgs<${modelName.pascal}Delegate>`,\n beforeDeleteOne: `BeforeDeleteOneHookArgs<${modelName.pascal}Delegate>`,\n afterDeleteOne: `AfterDeleteOneHookArgs<${modelName.pascal}Delegate>`,\n beforeDeleteMany: `BeforeDeleteManyHookArgs<${modelName.pascal}Delegate>`,\n afterDeleteMany: `AfterDeleteManyHookArgs<${modelName.pascal}Delegate>`,\n // Error hook types\n onCreateOneError: `OnCreateOneErrorHookArgs<${modelName.pascal}Delegate>`,\n onCreateManyError: `OnCreateManyErrorHookArgs<${modelName.pascal}Delegate>`,\n onCountError: `OnCountErrorHookArgs<${modelName.pascal}Delegate>`,\n onFindManyError: `OnFindManyErrorHookArgs<${modelName.pascal}Delegate>`,\n onFindByIdError: `OnFindByIdErrorHookArgs<${modelName.pascal}Delegate>`,\n onFindOneError: `OnFindOneErrorHookArgs<${modelName.pascal}Delegate>`,\n onUpdateOneError: `OnUpdateOneErrorHookArgs<${modelName.pascal}Delegate>`,\n onUpdateManyError: `OnUpdateManyErrorHookArgs<${modelName.pascal}Delegate>`,\n onDeleteOneError: `OnDeleteOneErrorHookArgs<${modelName.pascal}Delegate>`,\n onDeleteManyError: `OnDeleteManyErrorHookArgs<${modelName.pascal}Delegate>`,\n };\n\n // Return the corresponding type for the hook name\n return typeMap[hookName];\n };\n\n // Function to generate a hook function with proper TypeScript types\n const generateHookFunction = (hookName: string, params: string[]) => {\n // Get the TypeScript type for this hook\n const argsType = getHookArgsType(hookName);\n // Create function parameters with or without TypeScript types\n const args = isTypeScript\n ? `{ ${params.join(\", \")} }: ${argsType}`\n : `{ ${params.join(\", \")} }`;\n\n // Return the complete function definition\n return `async function ${hookName}(${args}) {}`;\n };\n\n // Generate all hook exports with their respective functions\n const hooks = `\n// export const beforeFindOne = [\n// ${generateHookFunction(\"beforeFindOne\", [\"context\", \"filters\", \"queryOptions\"])}\n// ];\n\n// export const afterFindOne = [\n// ${generateHookFunction(\"afterFindOne\", [\"context\", \"result\", \"filters\", \"queryOptions\"])}\n// ];\n\n// export const onFindOneError = [\n// ${generateHookFunction(\"onFindOneError\", [\"context\", \"error\", \"filters\", \"queryOptions\"])}\n// ];\n\n// export const beforeUpdateOne = [\n// ${generateHookFunction(\"beforeUpdateOne\", [\"context\", \"filters\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const afterUpdateOne = [\n// ${generateHookFunction(\"afterUpdateOne\", [\"context\", \"result\", \"filters\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const onUpdateOneError = [\n// ${generateHookFunction(\"onUpdateOneError\", [\"context\", \"error\", \"filters\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const beforeCreateOne = [\n// ${generateHookFunction(\"beforeCreateOne\", [\"context\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const afterCreateOne = [\n// ${generateHookFunction(\"afterCreateOne\", [\"context\", \"result\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const onCreateOneError = [\n// ${generateHookFunction(\"onCreateOneError\", [\"context\", \"error\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const beforeCreateMany = [\n// ${generateHookFunction(\"beforeCreateMany\", [\"context\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const afterCreateMany = [\n// ${generateHookFunction(\"afterCreateMany\", [\"context\", \"result\", \"queryOptions\"])}\n// ];\n\n// export const onCreateManyError = [\n// ${generateHookFunction(\"onCreateManyError\", [\"context\", \"error\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const beforeCount = [\n// ${generateHookFunction(\"beforeCount\", [\"context\", \"filters\"])}\n// ];\n\n// export const afterCount = [\n// ${generateHookFunction(\"afterCount\", [\"context\", \"result\", \"filters\"])}\n// ];\n\n// export const onCountError = [\n// ${generateHookFunction(\"onCountError\", [\"context\", \"error\", \"filters\"])}\n// ];\n\n// export const beforeFindMany = [\n// ${generateHookFunction(\"beforeFindMany\", [\"context\", \"filters\", \"queryOptions\"])}\n// ];\n\n// export const afterFindMany = [\n// ${generateHookFunction(\"afterFindMany\", [\"context\", \"result\", \"filters\", \"queryOptions\"])}\n// ];\n\n// export const onFindManyError = [\n// ${generateHookFunction(\"onFindManyError\", [\"context\", \"error\", \"filters\", \"queryOptions\"])}\n// ];\n\n// export const beforeUpdateMany = [\n// ${generateHookFunction(\"beforeUpdateMany\", [\"context\", \"filters\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const afterUpdateMany = [\n// ${generateHookFunction(\"afterUpdateMany\", [\"context\", \"result\", \"filters\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const onUpdateManyError = [\n// ${generateHookFunction(\"onUpdateManyError\", [\"context\", \"error\", \"filters\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const beforeDeleteOne = [\n// ${generateHookFunction(\"beforeDeleteOne\", [\"context\", \"filters\"])}\n// ];\n\n// export const afterDeleteOne = [\n// ${generateHookFunction(\"afterDeleteOne\", [\"context\", \"result\", \"filters\"])}\n// ];\n\n// export const onDeleteOneError = [\n// ${generateHookFunction(\"onDeleteOneError\", [\"context\", \"error\", \"filters\"])}\n// ];\n\n// export const beforeDeleteMany = [\n// ${generateHookFunction(\"beforeDeleteMany\", [\"context\", \"filters\"])}\n// ];\n\n// export const afterDeleteMany = [\n// ${generateHookFunction(\"afterDeleteMany\", [\"context\", \"result\", \"filters\"])}\n// ];\n\n// export const onDeleteManyError = [\n// ${generateHookFunction(\"onDeleteManyError\", [\"context\", \"error\", \"filters\"])}\n// ];\n`;\n\n // Return the complete template with imports, exports, and hook functions\n return `${baseImports}\n// import prisma from ${prismaImport}\n// import ${modelName.camel}Service from ${serviceImport}\n${delegateExport}\n\n${hooks}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hooks-template.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/hooks-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAItE,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAC3C,OAAwB;IAExB,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC9B,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;IACnC,MAAM,YAAY,GAAG,GAAG,KAAK,IAAI,CAAC;IAElC,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAE9E,MAAM,WAAW,GAAG,YAAY;QAC9B,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BA6BsB;QACxB,CAAC,CAAC,EAAE,CAAC;IAEP,MAAM,aAAa,GAAG,MAAM,SAAS,CAAC,KAAK,WAAW,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC;IAEzF,MAAM,eAAe,GAAG,CAAC,QAAgB,EAAE,EAAE;QAC3C,IAAI,CAAC,YAAY;YAAE,OAAO,EAAE,CAAC;QAE7B,MAAM,OAAO,GAA2B;YACtC,aAAa,EAAE,gCAAgC,SAAS,CAAC,MAAM,WAAW;YAC1E,YAAY,EAAE,+BAA+B,SAAS,CAAC,MAAM,WAAW;YACxE,eAAe,EAAE,kCAAkC,SAAS,CAAC,MAAM,WAAW;YAC9E,cAAc,EAAE,iCAAiC,SAAS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AE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;;;;OAIlG,oBAAoB,CAAC,iBAAiB,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;;;;OAI/D,oBAAoB,CAAC,gBAAgB,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;;;;OAIxE,oBAAoB,CAAC,kBAAkB,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;;;;OAIzE,oBAAoB,CAAC,kBAAkB,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;;;;OAIhE,oBAAoB,CAAC,iBAAiB,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;;;;OAIzE,oBAAoB,CAAC,mBAAmB,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;;CAEhF,CAAC;IAEA,OAAO,GAAG,WAAW;;YAEX,SAAS,CAAC,KAAK,gBAAgB,aAAa;;EAEtD,KAAK,EAAE,CAAC;AACV,CAAC","sourcesContent":["import { getUserFileExtension } from \"../../../../helpers/fs.helpers\";\nimport { TemplateOptions } from \"../../template-generators\";\n\n// Main function to generate hooks template based on provided options\nexport default function generateHooksTemplate(\n options: TemplateOptions\n): string {\n const { modelName } = options;\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n\n if (!modelName) throw new Error(\"Module name is required for hooks template\");\n\n const baseImports = isTypeScript\n ? `// import { \n// BeforeFindOneHookArgs, \n// AfterFindOneHookArgs, \n// BeforeUpdateOneHookArgs, \n// AfterUpdateOneHookArgs,\n// BeforeCreateOneHookArgs,\n// AfterCreateOneHookArgs,\n// BeforeCreateManyHookArgs,\n// AfterCreateManyHookArgs,\n// BeforeCountHookArgs,\n// AfterCountHookArgs,\n// BeforeFindManyHookArgs,\n// AfterFindManyHookArgs,\n// BeforeUpdateManyHookArgs,\n// AfterUpdateManyHookArgs,\n// BeforeDeleteOneHookArgs,\n// AfterDeleteOneHookArgs,\n// BeforeDeleteManyHookArgs,\n// AfterDeleteManyHookArgs,\n// OnCreateOneErrorHookArgs,\n// OnCreateManyErrorHookArgs,\n// OnCountErrorHookArgs,\n// OnFindManyErrorHookArgs,\n// OnFindByIdErrorHookArgs,\n// OnFindOneErrorHookArgs,\n// OnUpdateOneErrorHookArgs,\n// OnUpdateManyErrorHookArgs,\n// OnDeleteOneErrorHookArgs,\n// OnDeleteManyErrorHookArgs\n// } from \"arkos/services\";`\n : ``;\n\n const serviceImport = `\"./${modelName.kebab}.service${ext === \"ts\" ? \"\" : \".\" + \"js\"}\";`;\n\n const getHookArgsType = (hookName: string) => {\n if (!isTypeScript) return \"\";\n\n const typeMap: Record<string, string> = {\n beforeFindOne: `BeforeFindOneHookArgs<Prisma.${modelName.pascal}Delegate>`,\n afterFindOne: `AfterFindOneHookArgs<Prisma.${modelName.pascal}Delegate>`,\n beforeUpdateOne: `BeforeUpdateOneHookArgs<Prisma.${modelName.pascal}Delegate>`,\n afterUpdateOne: `AfterUpdateOneHookArgs<Prisma.${modelName.pascal}Delegate>`,\n beforeCreateOne: `BeforeCreateOneHookArgs<Prisma.${modelName.pascal}Delegate>`,\n afterCreateOne: `AfterCreateOneHookArgs<Prisma.${modelName.pascal}Delegate>`,\n beforeCreateMany: `BeforeCreateManyHookArgs<Prisma.${modelName.pascal}Delegate>`,\n afterCreateMany: `AfterCreateManyHookArgs<Prisma.${modelName.pascal}Delegate>`,\n beforeCount: `BeforeCountHookArgs<Prisma.${modelName.pascal}Delegate>`,\n afterCount: `AfterCountHookArgs<Prisma.${modelName.pascal}Delegate>`,\n beforeFindMany: `BeforeFindManyHookArgs<Prisma.${modelName.pascal}Delegate>`,\n afterFindMany: `AfterFindManyHookArgs<Prisma.${modelName.pascal}Delegate>`,\n beforeUpdateMany: `BeforeUpdateManyHookArgs<Prisma.${modelName.pascal}Delegate>`,\n afterUpdateMany: `AfterUpdateManyHookArgs<Prisma.${modelName.pascal}Delegate>`,\n beforeDeleteOne: `BeforeDeleteOneHookArgs<Prisma.${modelName.pascal}Delegate>`,\n afterDeleteOne: `AfterDeleteOneHookArgs<Prisma.${modelName.pascal}Delegate>`,\n beforeDeleteMany: `BeforeDeleteManyHookArgs<Prisma.${modelName.pascal}Delegate>`,\n afterDeleteMany: `AfterDeleteManyHookArgs<Prisma.${modelName.pascal}Delegate>`,\n // Error hook types\n onCreateOneError: `OnCreateOneErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,\n onCreateManyError: `OnCreateManyErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,\n onCountError: `OnCountErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,\n onFindManyError: `OnFindManyErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,\n onFindByIdError: `OnFindByIdErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,\n onFindOneError: `OnFindOneErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,\n onUpdateOneError: `OnUpdateOneErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,\n onUpdateManyError: `OnUpdateManyErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,\n onDeleteOneError: `OnDeleteOneErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,\n onDeleteManyError: `OnDeleteManyErrorHookArgs<Prisma.${modelName.pascal}Delegate>`,\n };\n\n return typeMap[hookName];\n };\n\n const generateHookFunction = (hookName: string, params: string[]) => {\n const argsType = getHookArgsType(hookName);\n const args = isTypeScript\n ? `{ ${params.join(\", \")} }: ${argsType}`\n : `{ ${params.join(\", \")} }`;\n return `async function (${args}) {}`;\n };\n\n const hooks = `\n// export const beforeFindOne = [\n// ${generateHookFunction(\"beforeFindOne\", [\"context\", \"filters\", \"queryOptions\"])}\n// ];\n\n// export const afterFindOne = [\n// ${generateHookFunction(\"afterFindOne\", [\"context\", \"result\", \"filters\", \"queryOptions\"])}\n// ];\n\n// export const onFindOneError = [\n// ${generateHookFunction(\"onFindOneError\", [\"context\", \"error\", \"filters\", \"queryOptions\"])}\n// ];\n\n// export const beforeUpdateOne = [\n// ${generateHookFunction(\"beforeUpdateOne\", [\"context\", \"filters\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const afterUpdateOne = [\n// ${generateHookFunction(\"afterUpdateOne\", [\"context\", \"result\", \"filters\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const onUpdateOneError = [\n// ${generateHookFunction(\"onUpdateOneError\", [\"context\", \"error\", \"filters\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const beforeCreateOne = [\n// ${generateHookFunction(\"beforeCreateOne\", [\"context\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const afterCreateOne = [\n// ${generateHookFunction(\"afterCreateOne\", [\"context\", \"result\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const onCreateOneError = [\n// ${generateHookFunction(\"onCreateOneError\", [\"context\", \"error\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const beforeCreateMany = [\n// ${generateHookFunction(\"beforeCreateMany\", [\"context\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const afterCreateMany = [\n// ${generateHookFunction(\"afterCreateMany\", [\"context\", \"result\", \"queryOptions\"])}\n// ];\n\n// export const onCreateManyError = [\n// ${generateHookFunction(\"onCreateManyError\", [\"context\", \"error\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const beforeCount = [\n// ${generateHookFunction(\"beforeCount\", [\"context\", \"filters\"])}\n// ];\n\n// export const afterCount = [\n// ${generateHookFunction(\"afterCount\", [\"context\", \"result\", \"filters\"])}\n// ];\n\n// export const onCountError = [\n// ${generateHookFunction(\"onCountError\", [\"context\", \"error\", \"filters\"])}\n// ];\n\n// export const beforeFindMany = [\n// ${generateHookFunction(\"beforeFindMany\", [\"context\", \"filters\", \"queryOptions\"])}\n// ];\n\n// export const afterFindMany = [\n// ${generateHookFunction(\"afterFindMany\", [\"context\", \"result\", \"filters\", \"queryOptions\"])}\n// ];\n\n// export const onFindManyError = [\n// ${generateHookFunction(\"onFindManyError\", [\"context\", \"error\", \"filters\", \"queryOptions\"])}\n// ];\n\n// export const beforeUpdateMany = [\n// ${generateHookFunction(\"beforeUpdateMany\", [\"context\", \"filters\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const afterUpdateMany = [\n// ${generateHookFunction(\"afterUpdateMany\", [\"context\", \"result\", \"filters\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const onUpdateManyError = [\n// ${generateHookFunction(\"onUpdateManyError\", [\"context\", \"error\", \"filters\", \"data\", \"queryOptions\"])}\n// ];\n\n// export const beforeDeleteOne = [\n// ${generateHookFunction(\"beforeDeleteOne\", [\"context\", \"filters\"])}\n// ];\n\n// export const afterDeleteOne = [\n// ${generateHookFunction(\"afterDeleteOne\", [\"context\", \"result\", \"filters\"])}\n// ];\n\n// export const onDeleteOneError = [\n// ${generateHookFunction(\"onDeleteOneError\", [\"context\", \"error\", \"filters\"])}\n// ];\n\n// export const beforeDeleteMany = [\n// ${generateHookFunction(\"beforeDeleteMany\", [\"context\", \"filters\"])}\n// ];\n\n// export const afterDeleteMany = [\n// ${generateHookFunction(\"afterDeleteMany\", [\"context\", \"result\", \"filters\"])}\n// ];\n\n// export const onDeleteManyError = [\n// ${generateHookFunction(\"onDeleteManyError\", [\"context\", \"error\", \"filters\"])}\n// ];\n`;\n\n return `${baseImports}\n// import { Prisma } from \"@prisma/client\"\n// import ${modelName.camel}Service from ${serviceImport}\n\n${hooks}`;\n}\n"]}
|
|
@@ -106,8 +106,6 @@ export function generateMiddlewaresTemplate(options) {
|
|
|
106
106
|
// next();
|
|
107
107
|
// }]
|
|
108
108
|
|
|
109
|
-
// There is not afterFindFile: because the main handler is handleded by express.static()
|
|
110
|
-
|
|
111
109
|
// export const onFindFileError =
|
|
112
110
|
// [async (${errorFunctionParams}) => {
|
|
113
111
|
// next();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middlewares-template.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/middlewares-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAGtE,MAAM,UAAU,2BAA2B,CAAC,OAAwB;IAClE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC9B,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;IACnC,MAAM,YAAY,GAAG,GAAG,KAAK,IAAI,CAAC;IAElC,IAAI,CAAC,SAAS;QACZ,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IAErE,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,KAAK,MAAM,CAAC;IAC1C,MAAM,YAAY,GAChB,SAAS,CAAC,KAAK,KAAK,YAAY,IAAI,SAAS,CAAC,KAAK,KAAK,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"middlewares-template.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/middlewares-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAGtE,MAAM,UAAU,2BAA2B,CAAC,OAAwB;IAClE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC9B,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;IACnC,MAAM,YAAY,GAAG,GAAG,KAAK,IAAI,CAAC;IAElC,IAAI,CAAC,SAAS;QACZ,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IAErE,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,KAAK,MAAM,CAAC;IAC1C,MAAM,YAAY,GAChB,SAAS,CAAC,KAAK,KAAK,YAAY,IAAI,SAAS,CAAC,KAAK,KAAK,aAAa,CAAC;IAExE,MAAM,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1D,MAAM,YAAY,GAAG,YAAY,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,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cAAc;;;;;eAKd,mBAAmB;;;;;eAKnB,cAAc;;;;;eAKd,cAAc;;;;;eAKd,mBAAmB;;;;;eAKnB,cAAc;;;;;eAKd,cAAc;;;;;eAKd,mBAAmB;;;;;eAKnB,cAAc;;;;;eAKd,cAAc;;;;;eAKd,mBAAmB;;;;;eAKnB,cAAc;;;;;eAKd,cAAc;;;;;eAKd,mBAAmB;;;;;eAKnB,cAAc;;;;;eAKd,cAAc;;;;;eAKd,mBAAmB;;;CAGjC,CAAC;AACF,CAAC","sourcesContent":["import { getUserFileExtension } from \"../../../../helpers/fs.helpers\";\nimport { TemplateOptions } from \"../../template-generators\";\n\nexport function generateMiddlewaresTemplate(options: TemplateOptions): string {\n const { modelName } = options;\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n\n if (!modelName)\n throw new Error(\"Module name is required for middleware template\");\n\n const isAuth = modelName.camel === \"auth\";\n const isFileUpload =\n modelName.camel === \"fileUpload\" || modelName.camel === \"file-upload\";\n\n const requestType = isTypeScript ? \"ArkosRequest\" : \"req\";\n const responseType = isTypeScript ? \"ArkosResponse\" : \"res\";\n const nextType = isTypeScript ? \"ArkosNextFunction\" : \"next\";\n\n const baseImports = isTypeScript\n ? `import { ArkosRequest, ArkosResponse, ArkosNextFunction } from \"arkos\";`\n : ``;\n\n const functionParams = isTypeScript\n ? `req: ${requestType}, res: ${responseType}, next: ${nextType}`\n : `req, res, next`;\n\n const errorFunctionParams = isTypeScript\n ? `err: any, req: ${requestType}, res: ${responseType}, next: ${nextType}`\n : `err, req, res, next`;\n\n if (isAuth) {\n return `${baseImports}\n\n// export const beforeGetMe = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const afterGetMe = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onGetMeError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n\n// export const beforeLogin = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const afterLogin = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onLoginError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n\n// export const beforeLogout = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const afterLogout = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onLogoutError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n\n// export const beforeSignup = \n// [async (${functionParams}) => {\n// }]\n\n// export const afterSignup = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onSignupError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n\n// export const beforeUpdatePassword = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const afterUpdatePassword = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onUpdatePasswordError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n`;\n }\n\n if (isFileUpload) {\n return `${baseImports}\n\n\n// export const beforeFindF]ile = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onFindFileError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n\n// export const beforeUploadFile = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const afterUploadFile = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onUploadFileError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n\n// export const beforeUpdateFile = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const afterUpdateFile = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onUpdateFileError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n\n// export const beforeDeleteFile = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const afterDeleteFile = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onDeleteFileError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n`;\n }\n\n // Regular model interceptors\n return `${baseImports}\n\n// export const beforeCreateOne = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const afterCreateOne = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onCreateOneError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n\n// export const beforeFindOne = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const afterFindOne = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onFindOneError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n\n// export const beforeFindMany = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const afterFindMany = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onFindManyError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n\n// export const beforeUpdateOne = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const afterUpdateOne = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onUpdateOneError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n\n// export const beforeDeleteOne = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const afterDeleteOne = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onDeleteOneError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n\n// export const beforeCreateMany = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const afterCreateMany = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onCreateManyError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n\n// export const beforeUpdateMany = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const afterUpdateMany = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onUpdateManyError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n\n// export const beforeDeleteMany = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const afterDeleteMany = \n// [async (${functionParams}) => {\n// next();\n// }]\n\n// export const onDeleteManyError =\n// [async (${errorFunctionParams}) => {\n// next();\n// }]\n`;\n}\n"]}
|
|
@@ -5,7 +5,7 @@ export function generateQueryOptionsTemplate(options) {
|
|
|
5
5
|
const ext = getUserFileExtension();
|
|
6
6
|
const isTypeScript = ext === "ts";
|
|
7
7
|
if (!modelName)
|
|
8
|
-
throw new Error("
|
|
8
|
+
throw new Error("Module name is required for query config template");
|
|
9
9
|
const imports = isAuth
|
|
10
10
|
? `import { AuthPrismaQueryOptions } from 'arkos/prisma'`
|
|
11
11
|
: `import { PrismaQueryOptions } from 'arkos/prisma'`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-options-template.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/query-options-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAGtE,MAAM,UAAU,4BAA4B,CAAC,OAAwB;IACnE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC9B,MAAM,MAAM,GAAG,SAAS,EAAE,KAAK,KAAK,MAAM,CAAC;IAC3C,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;IACnC,MAAM,YAAY,GAAG,GAAG,KAAK,IAAI,CAAC;IAElC,IAAI,CAAC,SAAS;QACZ,MAAM,IAAI,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"query-options-template.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/query-options-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAGtE,MAAM,UAAU,4BAA4B,CAAC,OAAwB;IACnE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC9B,MAAM,MAAM,GAAG,SAAS,EAAE,KAAK,KAAK,MAAM,CAAC;IAC3C,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;IACnC,MAAM,YAAY,GAAG,GAAG,KAAK,IAAI,CAAC;IAElC,IAAI,CAAC,SAAS;QACZ,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IAEvE,MAAM,OAAO,GAAG,MAAM;QACpB,CAAC,CAAC,uDAAuD;QACzD,CAAC,CAAC,mDAAmD,CAAC;IAExD,MAAM,cAAc,GAAG,YAAY;QACjC,CAAC,CAAC,MAAM;YACN,CAAC,CAAC,0CAA0C,SAAS,CAAC,KAAK,GAAG;YAC9D,CAAC,CAAC,sCAAsC,SAAS,CAAC,KAAK,GAAG;QAC5D,CAAC,CAAC,EAAE,CAAC;IAEP,MAAM,YAAY,GAAG,YAAY;QAC/B,CAAC,CAAC,4CAA4C;QAC9C,CAAC,CAAC,EAAE,CAAC;IAEP,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,GAAG,YAAY,GAAG,OAAO;;QAE5B,SAAS,CAAC,KAAK,eAAe,cAAc;;;;;;;;;iBASnC,SAAS,CAAC,KAAK;CAC/B,CAAC;IACA,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,YAAY,GAAG,OAAO;;QAE5B,SAAS,CAAC,KAAK,eAAe,cAAc;;;;;;;;;;;;;;;;;;;iBAmBnC,SAAS,CAAC,KAAK;CAC/B,CAAC;IACA,CAAC;AACH,CAAC","sourcesContent":["import { getUserFileExtension } from \"../../../../helpers/fs.helpers\";\nimport { TemplateOptions } from \"../../template-generators\";\n\nexport function generateQueryOptionsTemplate(options: TemplateOptions): string {\n const { modelName } = options;\n const isAuth = modelName?.camel === \"auth\";\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n\n if (!modelName)\n throw new Error(\"Module name is required for query config template\");\n\n const imports = isAuth\n ? `import { AuthPrismaQueryOptions } from 'arkos/prisma'`\n : `import { PrismaQueryOptions } from 'arkos/prisma'`;\n\n const typeAnnotation = isTypeScript\n ? isAuth\n ? `: AuthPrismaQueryOptions<typeof prisma.${modelName.camel}>`\n : `: PrismaQueryOptions<typeof prisma.${modelName.camel}>`\n : \"\";\n\n const prismaImport = isTypeScript\n ? `import prisma from \"../../utils/prisma\";\\n`\n : \"\";\n\n if (isAuth) {\n return `${prismaImport}${imports};\n\nconst ${modelName.camel}QueryOptions${typeAnnotation} = {\n getMe: {},\n updateMe: {},\n deleteMe: {},\n login: {},\n signup: {},\n updatePassword: {},\n}\n\nexport default ${modelName.camel}QueryOptions;\n`;\n } else {\n return `${prismaImport}${imports};\n\nconst ${modelName.camel}QueryOptions${typeAnnotation} = {\n global: {},\n find: {},\n findOne: {},\n findMany: {},\n update: {},\n updateMany: {},\n updateOne: {},\n create: {},\n createMany: {},\n createOne: {},\n save: {},\n saveMany: {},\n saveOne: {},\n delete: {},\n deleteMany: {},\n deleteOne: {},\n}\n\nexport default ${modelName.camel}QueryOptions;\n`;\n }\n}\n"]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import pluralize from "pluralize";
|
|
2
1
|
import { checkFileExists, getUserFileExtension, } from "../../../../helpers/fs.helpers.js";
|
|
3
2
|
export function generateRouterTemplate(options) {
|
|
4
3
|
const { modelName, imports } = options;
|
|
@@ -12,13 +11,14 @@ export function generateRouterTemplate(options) {
|
|
|
12
11
|
const controllerImportLine = controllerExists
|
|
13
12
|
? `import ${modelName.camel}Controller from "${imports?.controller ||
|
|
14
13
|
`./${modelName.kebab}.controller${ext === "js" ? "." + "js" : ""}`}"`
|
|
15
|
-
:
|
|
14
|
+
: `import ${modelName.camel}Controller from "${imports?.controller ||
|
|
16
15
|
`./${modelName.kebab}.controller${ext === "js" ? "." + "js" : ""}`}"`;
|
|
17
16
|
const controllerHandlerLine = controllerExists
|
|
18
|
-
?
|
|
19
|
-
:
|
|
17
|
+
? `${modelName.camel}Controller.someHandler`
|
|
18
|
+
: `${modelName.camel}Controller.someHandler`;
|
|
20
19
|
return `import { Router } from 'express'
|
|
21
20
|
import { authService } from 'arkos/services'
|
|
21
|
+
import { catchAsync } from 'arkos/error-handler'
|
|
22
22
|
${controllerImportLine}
|
|
23
23
|
${routerConfigTsTypeImport}
|
|
24
24
|
|
|
@@ -26,11 +26,11 @@ export const config${routerConfigTsType} = { }
|
|
|
26
26
|
|
|
27
27
|
const ${modelName.camel}Router = Router()
|
|
28
28
|
|
|
29
|
-
${modelName.camel}Router.
|
|
30
|
-
'/custom-endpoint',
|
|
29
|
+
${modelName.camel}Router.get(
|
|
30
|
+
'/custom-endpoint',
|
|
31
31
|
authService.authenticate,
|
|
32
32
|
authService.handleAccessControl('CustomAction', '${modelName.kebab}'),
|
|
33
|
-
${controllerHandlerLine}
|
|
33
|
+
catchAsync(${controllerHandlerLine})
|
|
34
34
|
)
|
|
35
35
|
|
|
36
36
|
export default ${modelName.camel}Router
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-template.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/router-template.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"router-template.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/router-template.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,oBAAoB,GACrB,MAAM,gCAAgC,CAAC;AAGxC,MAAM,UAAU,sBAAsB,CAAC,OAAwB;IAC7D,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAEvC,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAG9E,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;IACnC,MAAM,cAAc,GAClB,OAAO,EAAE,UAAU,IAAI,KAAK,SAAS,CAAC,KAAK,eAAe,GAAG,EAAE,CAAC;IAElE,MAAM,kBAAkB,GAAG,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;IAChE,MAAM,wBAAwB,GAC5B,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,sCAAsC,CAAC,CAAC,CAAC,EAAE,CAAC;IAE7D,MAAM,gBAAgB,GAAG,eAAe,CAAC,cAAc,CAAC,CAAC;IAEzD,MAAM,oBAAoB,GAAG,gBAAgB;QAC3C,CAAC,CAAC,UAAU,SAAS,CAAC,KAAK,oBACvB,OAAO,EAAE,UAAU;YACnB,KAAK,SAAS,CAAC,KAAK,cAAc,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,EAClE,GAAG;QACL,CAAC,CAAC,UAAU,SAAS,CAAC,KAAK,oBACvB,OAAO,EAAE,UAAU;YACnB,KAAK,SAAS,CAAC,KAAK,cAAc,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,EAClE,GAAG,CAAC;IAER,MAAM,qBAAqB,GAAG,gBAAgB;QAC5C,CAAC,CAAC,GAAG,SAAS,CAAC,KAAK,wBAAwB;QAC5C,CAAC,CAAC,GAAG,SAAS,CAAC,KAAK,wBAAwB,CAAC;IAE/C,OAAO;;;EAGP,oBAAoB;EACpB,wBAAwB;;qBAEL,kBAAkB;;QAE/B,SAAS,CAAC,KAAK;;EAErB,SAAS,CAAC,KAAK;;;qDAGoC,SAAS,CAAC,KAAK;eACrD,qBAAqB;;;iBAGnB,SAAS,CAAC,KAAK;CAC/B,CAAC;AACF,CAAC","sourcesContent":["import {\n checkFileExists,\n getUserFileExtension,\n} from \"../../../../helpers/fs.helpers\";\nimport { TemplateOptions } from \"../../template-generators\";\n\nexport function generateRouterTemplate(options: TemplateOptions): string {\n const { modelName, imports } = options;\n\n if (!modelName) throw new Error(\"Model name is required for router template\");\n\n // Check if controller file exists\n const ext = getUserFileExtension();\n const controllerPath =\n imports?.controller || `./${modelName.kebab}.controller.${ext}`;\n\n const routerConfigTsType = ext === \"ts\" ? \": RouterConfig\" : \"\";\n const routerConfigTsTypeImport =\n ext === \"ts\" ? \"import { RouterConfig } from 'arkos'\" : \"\";\n\n const controllerExists = checkFileExists(controllerPath);\n\n const controllerImportLine = controllerExists\n ? `import ${modelName.camel}Controller from \"${\n imports?.controller ||\n `./${modelName.kebab}.controller${ext === \"js\" ? \".\" + \"js\" : \"\"}`\n }\"`\n : `import ${modelName.camel}Controller from \"${\n imports?.controller ||\n `./${modelName.kebab}.controller${ext === \"js\" ? \".\" + \"js\" : \"\"}`\n }\"`;\n\n const controllerHandlerLine = controllerExists\n ? `${modelName.camel}Controller.someHandler`\n : `${modelName.camel}Controller.someHandler`;\n\n return `import { Router } from 'express'\nimport { authService } from 'arkos/services'\nimport { catchAsync } from 'arkos/error-handler'\n${controllerImportLine}\n${routerConfigTsTypeImport}\n\nexport const config${routerConfigTsType} = { }\n\nconst ${modelName.camel}Router = Router()\n\n${modelName.camel}Router.get(\n '/custom-endpoint',\n authService.authenticate,\n authService.handleAccessControl('CustomAction', '${modelName.kebab}'),\n catchAsync(${controllerHandlerLine})\n)\n\nexport default ${modelName.camel}Router\n`;\n}\n"]}
|
|
@@ -7,6 +7,7 @@ import { kebabCase, pascalCase } from "./helpers/change-case.helpers.js";
|
|
|
7
7
|
import { crd, getUserFileExtension } from "./helpers/fs.helpers.js";
|
|
8
8
|
import { importModule } from "./helpers/global.helpers.js";
|
|
9
9
|
import prismaSchemaParser from "./prisma/prisma-schema-parser.js";
|
|
10
|
+
import debuggerService from "../modules/debugger/debugger.service.js";
|
|
10
11
|
let prismaModelsModules = {};
|
|
11
12
|
export function setModuleComponents(modelName, modules) {
|
|
12
13
|
prismaModelsModules[pascalCase(modelName)] = modules;
|
|
@@ -237,9 +238,9 @@ export async function importModuleComponents(modelName, arkosConfig, moduleDirEx
|
|
|
237
238
|
};
|
|
238
239
|
}
|
|
239
240
|
export const appModules = Array.from(new Set([
|
|
240
|
-
...prismaSchemaParser.getModelsAsArrayOfStrings(),
|
|
241
241
|
"auth",
|
|
242
242
|
"file-upload",
|
|
243
|
+
...prismaSchemaParser.getModelsAsArrayOfStrings(),
|
|
243
244
|
]));
|
|
244
245
|
export async function loadAllModuleComponents(arkosConfig) {
|
|
245
246
|
const moduleDirExists = [];
|
|
@@ -249,6 +250,14 @@ export async function loadAllModuleComponents(arkosConfig) {
|
|
|
249
250
|
moduleDirExists.push(appModule);
|
|
250
251
|
}));
|
|
251
252
|
const modulesComponentsImportPromises = appModules.map(async (appModule) => await importModuleComponents(appModule, arkosConfig, moduleDirExists.includes(appModule)));
|
|
252
|
-
await Promise.all(modulesComponentsImportPromises);
|
|
253
|
+
const modulesComponents = await Promise.all(modulesComponentsImportPromises);
|
|
254
|
+
debuggerService.logDynamicLoadedModulesComponents(modulesComponents.map((components, i) => {
|
|
255
|
+
const moduleDir = path.resolve(crd(), "src", "modules", kebabCase(appModules[i]));
|
|
256
|
+
return {
|
|
257
|
+
moduleName: kebabCase(appModules[i]),
|
|
258
|
+
moduleDir,
|
|
259
|
+
components,
|
|
260
|
+
};
|
|
261
|
+
}));
|
|
253
262
|
}
|
|
254
263
|
//# sourceMappingURL=dynamic-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-loader.js","sourceRoot":"","sources":["../../../src/utils/dynamic-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAc,MAAM,KAAK,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,EACL,uBAAuB,EACvB,UAAU,GACX,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,GAAG,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,kBAAkB,MAAM,+BAA+B,CAAC;AAI/D,IAAI,mBAAmB,GAAuC,EAAE,CAAC;AAGjE,MAAM,UAAU,mBAAmB,CACjC,SAAiB,EACjB,OAA2B;IAE3B,mBAAmB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,GAAG,OAAO,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,S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AK,EACL,SAAS,EACT,SAAS,CAAC,SAAS,CAAC,CACrB,CAAC;QACF,IAAI,MAAM,UAAU,CAAC,SAAS,CAAC;YAAE,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACnE,CAAC,CAAC,CACH,CAAC;IAEF,MAAM,+BAA+B,GAAG,UAAU,CAAC,GAAG,CACpD,KAAK,EAAE,SAAS,EAAE,EAAE,CAClB,MAAM,sBAAsB,CAC1B,SAAS,EACT,WAAW,EACX,eAAe,CAAC,QAAQ,CAAC,SAAS,CAAC,CACpC,CACJ,CAAC;IAEF,MAAM,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import { z, ZodTypeAny } from \"zod\";\nimport path from \"path\";\nimport { AuthConfigs } from \"../types/auth\";\nimport { killServerChildProcess } from \"./cli/utils/cli.helpers\";\nimport { ArkosConfig } from \"../exports\";\nimport sheu from \"./sheu\";\nimport {\n applyStrictRoutingRules,\n pathExists,\n} from \"./helpers/dynamic-loader.helpers\";\nimport { kebabCase, pascalCase } from \"./helpers/change-case.helpers\";\nimport { crd, getUserFileExtension } from \"./helpers/fs.helpers\";\nimport { importModule } from \"./helpers/global.helpers\";\nimport prismaSchemaParser from \"./prisma/prisma-schema-parser\";\n\ntype AppModuleComponent = Awaited<ReturnType<typeof importModuleComponents>>;\n\nlet prismaModelsModules: Record<string, AppModuleComponent> = {};\n\n/** This was a workaround when testing and also when cjs was generated while `prismaModelsModules` was exported there where some problems */\nexport function setModuleComponents(\n modelName: string,\n modules: AppModuleComponent\n): any {\n prismaModelsModules[pascalCase(modelName)] = modules;\n}\n\nexport function getModuleComponents(modelName: string) {\n return prismaModelsModules[pascalCase(modelName)];\n}\n\n/**\n * To be reused on other part of code for correct typing\n *\n * @param key\n * @param fileName\n * @param result\n */\nexport type ValidationFileMappingKey = keyof ReturnType<\n typeof getFileModuleComponentsFileStructure\n>[\"dtos\"];\n\nexport function getFileModuleComponentsFileStructure(modelName: string) {\n const kebabModelName = kebabCase(modelName).toLowerCase();\n const isAuthModule = modelName.toLowerCase() === \"auth\";\n const ext = getUserFileExtension();\n\n return {\n core: {\n hooks: `${kebabModelName}.hooks.${ext}`,\n interceptors: `${kebabModelName}.middlewares.${ext}`,\n authConfigs: `${kebabModelName}.auth-configs.${ext}`,\n authConfigsNew: `${kebabModelName}.auth.${ext}`,\n prismaQueryOptions: `${kebabModelName}.prisma-query-options.${ext}`,\n prismaQueryOptionsNew: `${kebabModelName}.query.${ext}`,\n router: `${kebabModelName}.router.${ext}`,\n },\n dtos: isAuthModule\n ? {\n login: `login.dto.${ext}`,\n signup: `signup.dto.${ext}`,\n getMe: `get-me.dto.${ext}`,\n updateMe: `update-me.dto.${ext}`,\n updatePassword: `update-password.dto.${ext}`,\n }\n : {\n model: `${kebabModelName}.dto.${ext}`,\n create: `create-${kebabModelName}.dto.${ext}`,\n createOne: `create-${kebabModelName}.dto.${ext}`, // just for sake of completion and reusability around other parts of code\n createMany: ``,\n update: `update-${kebabModelName}.dto.${ext}`,\n updateOne: `update-${kebabModelName}.dto.${ext}`, // same as createOne\n updateMany: ``,\n query: `query-${kebabModelName}.dto.${ext}`,\n // looking for some better naming convetion\n findOne: ``,\n findMany: ``,\n },\n schemas: isAuthModule\n ? {\n login: `login.schema.${ext}`,\n signup: `signup.schema.${ext}`,\n getMe: `get-me.schema.${ext}`,\n updateMe: `update-me.schema.${ext}`,\n updatePassword: `update-password.schema.${ext}`,\n }\n : {\n model: `${kebabModelName}.schema.${ext}`,\n create: `create-${kebabModelName}.schema.${ext}`,\n createOne: `create-${kebabModelName}.schema.${ext}`,\n createMany: ``, // just for sake of completion and reusability around other parts of code\n update: `update-${kebabModelName}.schema.${ext}`,\n updateOne: `update-${kebabModelName}.schema.${ext}`, // same as createOne\n updateMany: ``,\n query: `query-${kebabModelName}.schema.${ext}`,\n // looking for some better naming convetion\n findOne: ``,\n findMany: ``,\n },\n };\n}\n\nexport function isClass(value: any): boolean {\n return (\n typeof value === \"function\" &&\n /^class\\s/.test(Function.prototype.toString.call(value))\n );\n}\n\nexport function isZodSchema(value: any): value is ZodTypeAny {\n return value instanceof z.ZodType;\n}\n\nexport async function processSubdir(\n modelName: string,\n type: \"dtos\" | \"schemas\"\n) {\n const moduleDir = path.resolve(crd(), \"src\", \"modules\", kebabCase(modelName));\n\n const subdir = path.join(moduleDir, type);\n const fileStructure = getFileModuleComponentsFileStructure(modelName);\n const result: Record<string, any> = {};\n\n if (!(await pathExists(subdir))) return result;\n\n try {\n await Promise.all(\n Object.entries(fileStructure[type]).map(async ([key, fileName]) => {\n const filePath = path.join(subdir, fileName);\n if (!fileName || !(await pathExists(filePath))) return;\n\n try {\n const module = await importModule(filePath).catch(\n async (err: any) => {\n if (await pathExists(filePath)) {\n sheu.error(`Failed to import ${fileName}: `);\n console.error(err);\n killServerChildProcess();\n process.exit(1);\n }\n }\n );\n\n const cleanFilePath = `src/modules/${kebabCase(modelName)}/${fileName}`;\n if (type === \"dtos\" && !isClass(module?.default))\n throw Error(\n `ValidationError: Please export as default a valid class under ${cleanFilePath}, in order to use as Dto.`\n );\n else if (type === \"schemas\" && !isZodSchema(module?.default))\n throw Error(\n `ValidationError: Please export as default a valid zod schema under ${cleanFilePath}, in order to use as Schema`\n );\n\n if (module && module?.default) result[key] = module.default;\n } catch (err: any) {\n if (err?.message?.includes(\"ValidationError\")) throw err;\n console.error(err);\n }\n })\n );\n } catch (err: any) {\n if (err?.message?.includes(\"ValidationError\")) throw err;\n console.error(err);\n }\n\n return result;\n}\n\ntype importModuleComponentsReturnType = {\n hooks?: any;\n interceptors?: any;\n authConfigs?: AuthConfigs;\n authConfigsNew?: AuthConfigs;\n prismaQueryOptions?: any;\n prismaQueryOptionsNew?: any;\n router?: any;\n dtos?: Record<string, any>;\n schemas?: Record<string, any>;\n};\n\n/**\n * Validates naming convention conflicts for prismaQueryOptions and authConfigs\n * @param {string} key - The current file key being processed\n * @param {string} fileName - The filename being imported\n * @param {importModuleComponentsReturnType} result - The current result object\n * @throws {Error} When conflicting naming conventions are detected\n */\nexport function validateNamingConventions(\n key: string,\n fileName: string,\n result: importModuleComponentsReturnType\n): void {\n if (key === \"prismaQueryOptions\") {\n sheu.warn(\n `Found ${fileName} which will be deprecated from 1.4.0-beta, consider switching to ${fileName.replace(\"prisma-query-options\", \"query\")}.`\n );\n if (result.prismaQueryOptions) {\n killServerChildProcess();\n throw new Error(\n `\\n Cannot use both ${fileName} and ${fileName.replace(\n \"prisma-query-options\",\n \"query\"\n )} at once, please choose only one name convention. \\n`\n );\n }\n } else if (key === \"prismaQueryOptionsNew\") {\n if (result.prismaQueryOptions) {\n killServerChildProcess();\n throw new Error(\n `\\n Cannot use both ${fileName} and ${fileName.replace(\n \"query\",\n \"prisma-query-options\"\n )} at once, please choose only one name convention. \\n`\n );\n }\n } else if (key === \"authConfigs\") {\n sheu.warn(\n `Found ${fileName} which will be deprecated from 1.4.0-beta, consider switching to ${fileName.replace(\"auth-configs\", \"auth\")}.`\n );\n if (result.authConfigs) {\n killServerChildProcess();\n throw new Error(\n `\\n Cannot use both ${fileName} and ${fileName.replace(\n \"auth-configs\",\n \"auth\"\n )} at once, please choose only one name convention. \\n`\n );\n }\n } else if (key === \"authConfigsNew\") {\n if (result.authConfigs) {\n killServerChildProcess();\n throw new Error(\n `\\n Cannot use both ${fileName} and ${fileName.replace(\n \"auth\",\n \"auth-configs\"\n )} at once, please choose only one name convention. \\n`\n );\n }\n }\n}\n\n/**\n * Processes and assigns module to the result object based on the key\n * @param {string} key - The file key being processed\n * @param {any} module - The imported module\n * @param {importModuleComponentsReturnType} result - The result object to modify\n */\nexport function assignModuleToResult(\n appModule: string,\n key: string,\n module: any,\n result: importModuleComponentsReturnType,\n arkosConfig: ArkosConfig\n): void {\n if (key === \"prismaQueryOptions\" || key === \"prismaQueryOptionsNew\") {\n result.prismaQueryOptions = module.default || module;\n } else if (key === \"authConfigs\" || key === \"authConfigsNew\") {\n result.authConfigs = module.default || module;\n } else if (key === \"interceptors\") {\n result[key] = module;\n } else if (key === \"router\") {\n result[key] = {\n ...module,\n config: applyStrictRoutingRules(\n appModule,\n arkosConfig,\n module?.config || {}\n ),\n };\n } else {\n result[key as keyof typeof result] = module.default || module;\n }\n}\n\n/**\n * Dynamically imports model-specific modules for a given model with optimized file handling.\n * Includes special handling for the Auth module.\n *\n * @param {string} modelName - The name of the model (e.g., \"User\", \"Post\", \"Auth\").\n * @returns {Promise<Object>} An object containing the imported modules\n */\nexport async function importModuleComponents(\n modelName: string,\n arkosConfig: ArkosConfig,\n moduleDirExists?: boolean\n): Promise<importModuleComponentsReturnType> {\n const result: importModuleComponentsReturnType = {\n dtos: {},\n schemas: {},\n };\n const usingStrictRouting = arkosConfig.routers?.strict;\n\n if (!moduleDirExists && !usingStrictRouting) return result;\n\n if (getModuleComponents(modelName)) return getModuleComponents(modelName);\n\n const moduleDir = path.resolve(crd(), \"src\", \"modules\", kebabCase(modelName));\n const fileStructure = getFileModuleComponentsFileStructure(modelName);\n\n const validationSubdir = arkosConfig.validation?.resolver\n ? arkosConfig.validation.resolver === \"zod\"\n ? \"schemas\"\n : \"dtos\"\n : null;\n\n // Batch process core files\n const [_, validators] = await Promise.all([\n Object.entries(fileStructure.core).map(async ([key, fileName]) => {\n if (\n [\"createMany\", \"findMany\", \"findOne\", \"updateMany\"].includes(key) ||\n !fileName\n )\n return;\n\n const filePath = path.join(moduleDir, fileName);\n\n if (\n key === \"router\" &&\n !usingStrictRouting &&\n !(await pathExists(filePath))\n )\n return;\n else if (\n key !== \"router\" &&\n usingStrictRouting &&\n !(await pathExists(filePath))\n )\n return;\n\n try {\n let module = await importModule(filePath).catch(async (err) => {\n try {\n if (await pathExists(filePath)) {\n sheu.error(`Failed to import ${fileName}`);\n console.error(err);\n killServerChildProcess();\n process.exit(1);\n }\n } catch (err) {}\n });\n\n if (!module && key === \"router\" && usingStrictRouting) module = {};\n\n if (module) {\n // Validate naming conventions before assignment\n validateNamingConventions(key, fileName, result);\n\n // Assign module to result\n assignModuleToResult(modelName, key, module, result, arkosConfig);\n }\n } catch (err: any) {\n if (err.message?.includes(\"Cannot use both\")) throw err;\n console.error(err);\n killServerChildProcess();\n }\n }),\n validationSubdir && processSubdir(modelName, validationSubdir),\n ]);\n\n prismaModelsModules[pascalCase(modelName)] = {\n ...result,\n ...(validationSubdir && { [validationSubdir]: validators }),\n };\n\n return {\n ...result,\n ...(validationSubdir && { [validationSubdir]: validators }),\n };\n}\n\nexport const appModules = Array.from(\n new Set([\n ...prismaSchemaParser.getModelsAsArrayOfStrings(),\n \"auth\",\n \"file-upload\",\n ])\n);\n\n/**\n * Allows to asynchronously load all app modules components at once to speed up app start time.\n */\nexport async function loadAllModuleComponents(arkosConfig: ArkosConfig) {\n const moduleDirExists: string[] = [];\n await Promise.all(\n appModules.map(async (appModule) => {\n const moduleDir = path.resolve(\n crd(),\n \"src\",\n \"modules\",\n kebabCase(appModule)\n );\n if (await pathExists(moduleDir)) moduleDirExists.push(appModule);\n })\n );\n\n const modulesComponentsImportPromises = appModules.map(\n async (appModule) =>\n await importModuleComponents(\n appModule,\n arkosConfig,\n moduleDirExists.includes(appModule)\n )\n );\n\n await Promise.all(modulesComponentsImportPromises);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dynamic-loader.js","sourceRoot":"","sources":["../../../src/utils/dynamic-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAc,MAAM,KAAK,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,EACL,uBAAuB,EACvB,UAAU,GACX,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,GAAG,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,YA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;IACN,aAAa;IACb,GAAG,kBAAkB,CAAC,yBAAyB,EAAE;CAClD,CAAC,CACH,CAAC;AAKF,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,WAAwB;IACpE,MAAM,eAAe,GAAa,EAAE,CAAC;IACrC,MAAM,OAAO,CAAC,GAAG,CACf,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACjC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAC5B,GAAG,EAAE,EACL,KAAK,EACL,SAAS,EACT,SAAS,CAAC,SAAS,CAAC,CACrB,CAAC;QACF,IAAI,MAAM,UAAU,CAAC,SAAS,CAAC;YAAE,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACnE,CAAC,CAAC,CACH,CAAC;IAEF,MAAM,+BAA+B,GAAG,UAAU,CAAC,GAAG,CACpD,KAAK,EAAE,SAAS,EAAE,EAAE,CAClB,MAAM,sBAAsB,CAC1B,SAAS,EACT,WAAW,EACX,eAAe,CAAC,QAAQ,CAAC,SAAS,CAAC,CACpC,CACJ,CAAC;IAEF,MAAM,iBAAiB,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAC7E,eAAe,CAAC,iCAAiC,CAC/C,iBAAiB,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE;QACtC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAC5B,GAAG,EAAE,EACL,KAAK,EACL,SAAS,EACT,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CACzB,CAAC;QAEF,OAAO;YACL,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YACpC,SAAS;YACT,UAAU;SACX,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { z, ZodTypeAny } from \"zod\";\nimport path from \"path\";\nimport { AuthConfigs } from \"../types/auth\";\nimport { killServerChildProcess } from \"./cli/utils/cli.helpers\";\nimport { ArkosConfig, RouterConfig } from \"../exports\";\nimport sheu from \"./sheu\";\nimport {\n applyStrictRoutingRules,\n pathExists,\n} from \"./helpers/dynamic-loader.helpers\";\nimport { kebabCase, pascalCase } from \"./helpers/change-case.helpers\";\nimport { crd, getUserFileExtension } from \"./helpers/fs.helpers\";\nimport { importModule } from \"./helpers/global.helpers\";\nimport prismaSchemaParser from \"./prisma/prisma-schema-parser\";\nimport debuggerService from \"../modules/debugger/debugger.service\";\nimport { PrismaQueryOptions } from \"../types\";\nimport { ServiceHook } from \"../modules/base/utils/service-hooks-manager\";\n\ntype AppModuleComponent = Awaited<ReturnType<typeof importModuleComponents>>;\n\nlet prismaModelsModules: Record<string, AppModuleComponent> = {};\n\n/** This was a workaround when testing and also when cjs was generated while `prismaModelsModules` was exported there where some problems */\nexport function setModuleComponents(\n modelName: string,\n modules: AppModuleComponent\n): any {\n prismaModelsModules[pascalCase(modelName)] = modules;\n}\n\nexport function getModuleComponents(modelName: string) {\n return prismaModelsModules[pascalCase(modelName)];\n}\n\n/**\n * To be reused on other part of code for correct typing\n *\n * @param key\n * @param fileName\n * @param result\n */\nexport type ValidationFileMappingKey = keyof ReturnType<\n typeof getFileModuleComponentsFileStructure\n>[\"dtos\"];\n\nexport function getFileModuleComponentsFileStructure(modelName: string) {\n const kebabModelName = kebabCase(modelName).toLowerCase();\n const isAuthModule = modelName.toLowerCase() === \"auth\";\n const ext = getUserFileExtension();\n\n return {\n core: {\n hooks: `${kebabModelName}.hooks.${ext}`,\n interceptors: `${kebabModelName}.middlewares.${ext}`,\n authConfigs: `${kebabModelName}.auth-configs.${ext}`,\n authConfigsNew: `${kebabModelName}.auth.${ext}`,\n prismaQueryOptions: `${kebabModelName}.prisma-query-options.${ext}`,\n prismaQueryOptionsNew: `${kebabModelName}.query.${ext}`,\n router: `${kebabModelName}.router.${ext}`,\n },\n dtos: isAuthModule\n ? {\n login: `login.dto.${ext}`,\n signup: `signup.dto.${ext}`,\n getMe: `get-me.dto.${ext}`,\n updateMe: `update-me.dto.${ext}`,\n updatePassword: `update-password.dto.${ext}`,\n }\n : {\n model: `${kebabModelName}.dto.${ext}`,\n create: `create-${kebabModelName}.dto.${ext}`,\n createOne: `create-${kebabModelName}.dto.${ext}`, // just for sake of completion and reusability around other parts of code\n createMany: ``,\n update: `update-${kebabModelName}.dto.${ext}`,\n updateOne: `update-${kebabModelName}.dto.${ext}`, // same as createOne\n updateMany: ``,\n query: `query-${kebabModelName}.dto.${ext}`,\n // looking for some better naming convetion\n findOne: ``,\n findMany: ``,\n },\n schemas: isAuthModule\n ? {\n login: `login.schema.${ext}`,\n signup: `signup.schema.${ext}`,\n getMe: `get-me.schema.${ext}`,\n updateMe: `update-me.schema.${ext}`,\n updatePassword: `update-password.schema.${ext}`,\n }\n : {\n model: `${kebabModelName}.schema.${ext}`,\n create: `create-${kebabModelName}.schema.${ext}`,\n createOne: `create-${kebabModelName}.schema.${ext}`,\n createMany: ``, // just for sake of completion and reusability around other parts of code\n update: `update-${kebabModelName}.schema.${ext}`,\n updateOne: `update-${kebabModelName}.schema.${ext}`, // same as createOne\n updateMany: ``,\n query: `query-${kebabModelName}.schema.${ext}`,\n // looking for some better naming convetion\n findOne: ``,\n findMany: ``,\n },\n };\n}\n\nexport function isClass(value: any): boolean {\n return (\n typeof value === \"function\" &&\n /^class\\s/.test(Function.prototype.toString.call(value))\n );\n}\n\nexport function isZodSchema(value: any): value is ZodTypeAny {\n return value instanceof z.ZodType;\n}\n\nexport async function processSubdir(\n modelName: string,\n type: \"dtos\" | \"schemas\"\n) {\n const moduleDir = path.resolve(crd(), \"src\", \"modules\", kebabCase(modelName));\n\n const subdir = path.join(moduleDir, type);\n const fileStructure = getFileModuleComponentsFileStructure(modelName);\n const result: Record<string, any> = {};\n\n if (!(await pathExists(subdir))) return result;\n\n try {\n await Promise.all(\n Object.entries(fileStructure[type]).map(async ([key, fileName]) => {\n const filePath = path.join(subdir, fileName);\n if (!fileName || !(await pathExists(filePath))) return;\n\n try {\n const module = await importModule(filePath).catch(\n async (err: any) => {\n if (await pathExists(filePath)) {\n sheu.error(`Failed to import ${fileName}: `);\n console.error(err);\n killServerChildProcess();\n process.exit(1);\n }\n }\n );\n\n const cleanFilePath = `src/modules/${kebabCase(modelName)}/${fileName}`;\n if (type === \"dtos\" && !isClass(module?.default))\n throw Error(\n `ValidationError: Please export as default a valid class under ${cleanFilePath}, in order to use as Dto.`\n );\n else if (type === \"schemas\" && !isZodSchema(module?.default))\n throw Error(\n `ValidationError: Please export as default a valid zod schema under ${cleanFilePath}, in order to use as Schema`\n );\n\n if (module && module?.default) result[key] = module.default;\n } catch (err: any) {\n if (err?.message?.includes(\"ValidationError\")) throw err;\n console.error(err);\n }\n })\n );\n } catch (err: any) {\n if (err?.message?.includes(\"ValidationError\")) throw err;\n console.error(err);\n }\n\n return result;\n}\n\nexport type ModuleComponents = Omit<\n ImportModuleComponentsReturnType,\n \"authConfigsNew\" | \"prismaQueryOptionsNew\"\n>;\n\ntype ImportModuleComponentsReturnType = {\n hooks?: Record<string, ServiceHook | ServiceHook[]>;\n interceptors?: Record<string, Function | Function[]>;\n authConfigs?: AuthConfigs;\n authConfigsNew?: AuthConfigs;\n prismaQueryOptions?: PrismaQueryOptions<any>;\n prismaQueryOptionsNew?: PrismaQueryOptions<any>;\n router?: { config?: RouterConfig<any>; default: RouterConfig };\n dtos?: {\n create?: any;\n update?: any;\n signup?: any;\n login?: any;\n updatePassword?: any;\n updateMe?: any;\n };\n schemas?: {\n create?: any;\n update?: any;\n signup?: any;\n login?: any;\n updatePassword?: any;\n updateMe?: any;\n };\n};\n\n/**\n * Validates naming convention conflicts for prismaQueryOptions and authConfigs\n * @param {string} key - The current file key being processed\n * @param {string} fileName - The filename being imported\n * @param {ImportModuleComponentsReturnType} result - The current result object\n * @throws {Error} When conflicting naming conventions are detected\n */\nexport function validateNamingConventions(\n key: string,\n fileName: string,\n result: ImportModuleComponentsReturnType\n): void {\n if (key === \"prismaQueryOptions\") {\n sheu.warn(\n `Found ${fileName} which will be deprecated from 1.4.0-beta, consider switching to ${fileName.replace(\"prisma-query-options\", \"query\")}.`\n );\n if (result.prismaQueryOptions) {\n killServerChildProcess();\n throw new Error(\n `\\n Cannot use both ${fileName} and ${fileName.replace(\n \"prisma-query-options\",\n \"query\"\n )} at once, please choose only one name convention. \\n`\n );\n }\n } else if (key === \"prismaQueryOptionsNew\") {\n if (result.prismaQueryOptions) {\n killServerChildProcess();\n throw new Error(\n `\\n Cannot use both ${fileName} and ${fileName.replace(\n \"query\",\n \"prisma-query-options\"\n )} at once, please choose only one name convention. \\n`\n );\n }\n } else if (key === \"authConfigs\") {\n sheu.warn(\n `Found ${fileName} which will be deprecated from 1.4.0-beta, consider switching to ${fileName.replace(\"auth-configs\", \"auth\")}.`\n );\n if (result.authConfigs) {\n killServerChildProcess();\n throw new Error(\n `\\n Cannot use both ${fileName} and ${fileName.replace(\n \"auth-configs\",\n \"auth\"\n )} at once, please choose only one name convention. \\n`\n );\n }\n } else if (key === \"authConfigsNew\") {\n if (result.authConfigs) {\n killServerChildProcess();\n throw new Error(\n `\\n Cannot use both ${fileName} and ${fileName.replace(\n \"auth\",\n \"auth-configs\"\n )} at once, please choose only one name convention. \\n`\n );\n }\n }\n}\n\n/**\n * Processes and assigns module to the result object based on the key\n * @param {string} key - The file key being processed\n * @param {any} module - The imported module\n * @param {ImportModuleComponentsReturnType} result - The result object to modify\n */\nexport function assignModuleToResult(\n appModule: string,\n key: string,\n module: any,\n result: ImportModuleComponentsReturnType,\n arkosConfig: ArkosConfig\n): void {\n if (key === \"prismaQueryOptions\" || key === \"prismaQueryOptionsNew\") {\n result.prismaQueryOptions = module.default || module;\n } else if (key === \"authConfigs\" || key === \"authConfigsNew\") {\n result.authConfigs = module.default || module;\n } else if (key === \"interceptors\") {\n result[key] = module;\n } else if (key === \"router\") {\n result[key] = {\n ...module,\n config: applyStrictRoutingRules(\n appModule,\n arkosConfig,\n module?.config || {}\n ),\n };\n } else {\n result[key as keyof typeof result] = module.default || module;\n }\n}\n\n/**\n * Dynamically imports model-specific modules for a given model with optimized file handling.\n * Includes special handling for the Auth module.\n *\n * @param {string} modelName - The name of the model (e.g., \"User\", \"Post\", \"Auth\").\n * @returns {Promise<Object>} An object containing the imported modules\n */\nexport async function importModuleComponents(\n modelName: string,\n arkosConfig: ArkosConfig,\n moduleDirExists?: boolean\n): Promise<ImportModuleComponentsReturnType> {\n const result: ImportModuleComponentsReturnType = {\n dtos: {},\n schemas: {},\n };\n const usingStrictRouting = arkosConfig.routers?.strict;\n\n if (!moduleDirExists && !usingStrictRouting) return result;\n\n if (getModuleComponents(modelName)) return getModuleComponents(modelName);\n\n const moduleDir = path.resolve(crd(), \"src\", \"modules\", kebabCase(modelName));\n const fileStructure = getFileModuleComponentsFileStructure(modelName);\n\n const validationSubdir = arkosConfig.validation?.resolver\n ? arkosConfig.validation.resolver === \"zod\"\n ? \"schemas\"\n : \"dtos\"\n : null;\n\n // Batch process core files\n const [_, validators] = await Promise.all([\n Object.entries(fileStructure.core).map(async ([key, fileName]) => {\n if (\n [\"createMany\", \"findMany\", \"findOne\", \"updateMany\"].includes(key) ||\n !fileName\n )\n return;\n\n const filePath = path.join(moduleDir, fileName);\n\n if (\n key === \"router\" &&\n !usingStrictRouting &&\n !(await pathExists(filePath))\n )\n return;\n else if (\n key !== \"router\" &&\n usingStrictRouting &&\n !(await pathExists(filePath))\n )\n return;\n\n try {\n let module = await importModule(filePath).catch(async (err) => {\n try {\n if (await pathExists(filePath)) {\n sheu.error(`Failed to import ${fileName}`);\n console.error(err);\n killServerChildProcess();\n process.exit(1);\n }\n } catch (err) {}\n });\n\n if (!module && key === \"router\" && usingStrictRouting) module = {};\n\n if (module) {\n // Validate naming conventions before assignment\n validateNamingConventions(key, fileName, result);\n\n // Assign module to result\n assignModuleToResult(modelName, key, module, result, arkosConfig);\n }\n } catch (err: any) {\n if (err.message?.includes(\"Cannot use both\")) throw err;\n console.error(err);\n killServerChildProcess();\n }\n }),\n validationSubdir && processSubdir(modelName, validationSubdir),\n ]);\n\n prismaModelsModules[pascalCase(modelName)] = {\n ...result,\n ...(validationSubdir && { [validationSubdir]: validators }),\n };\n\n return {\n ...result,\n ...(validationSubdir && { [validationSubdir]: validators }),\n };\n}\n\nexport const appModules = Array.from(\n new Set([\n \"auth\",\n \"file-upload\",\n ...prismaSchemaParser.getModelsAsArrayOfStrings(),\n ])\n);\n\n/**\n * Allows to asynchronously load all app modules components at once to speed up app start time.\n */\nexport async function loadAllModuleComponents(arkosConfig: ArkosConfig) {\n const moduleDirExists: string[] = [];\n await Promise.all(\n appModules.map(async (appModule) => {\n const moduleDir = path.resolve(\n crd(),\n \"src\",\n \"modules\",\n kebabCase(appModule)\n );\n if (await pathExists(moduleDir)) moduleDirExists.push(appModule);\n })\n );\n\n const modulesComponentsImportPromises = appModules.map(\n async (appModule) =>\n await importModuleComponents(\n appModule,\n arkosConfig,\n moduleDirExists.includes(appModule)\n )\n );\n\n const modulesComponents = await Promise.all(modulesComponentsImportPromises);\n debuggerService.logDynamicLoadedModulesComponents(\n modulesComponents.map((components, i) => {\n const moduleDir = path.resolve(\n crd(),\n \"src\",\n \"modules\",\n kebabCase(appModules[i])\n );\n\n return {\n moduleName: kebabCase(appModules[i]),\n moduleDir,\n components,\n };\n })\n );\n}\n"]}
|