arkos 1.0.16 → 1.0.18-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,63 +10,102 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import path from "path";
11
11
  import fs from "fs";
12
12
  import { camelCase, kebabCase, pascalCase, } from "../../utils/helpers/change-case.helpers";
13
- import arkosEnv from "../arkos-env";
14
13
  import { userFileExtension } from "./fs.helpers";
14
+ import { importModule } from "./global.helpers";
15
15
  export let prismaModelsModules = {};
16
16
  export function getModelModules(modelName) {
17
17
  return prismaModelsModules[kebabCase(modelName)];
18
18
  }
19
- export function importPrismaModelModules(modelName) {
19
+ export function getFileModelModulesFileStructure(modelName) {
20
+ const kebabModelName = kebabCase(modelName).toLowerCase();
21
+ const lowerModelName = kebabModelName.toLowerCase();
22
+ const isAuthModule = modelName.toLowerCase() === "auth";
23
+ return {
24
+ core: {
25
+ service: `${kebabModelName}.service.${userFileExtension}`,
26
+ controller: `${kebabModelName}.controller.${userFileExtension}`,
27
+ middlewares: `${kebabModelName}.middlewares.${userFileExtension}`,
28
+ authConfigs: `${kebabModelName}.auth-configs.${userFileExtension}`,
29
+ prismaQueryOptions: `${kebabModelName}.prisma-query-options.${userFileExtension}`,
30
+ router: `${kebabModelName}.router.${userFileExtension}`,
31
+ },
32
+ dtos: isAuthModule
33
+ ? {
34
+ login: `login.dto.${userFileExtension}`,
35
+ signup: `signup.dto.${userFileExtension}`,
36
+ updateMe: `update-me.dto.${userFileExtension}`,
37
+ updatePassword: `update-password.dto.${userFileExtension}`,
38
+ }
39
+ : {
40
+ model: `${lowerModelName}.dto.${userFileExtension}`,
41
+ create: `create-${lowerModelName}.dto.${userFileExtension}`,
42
+ update: `update-${lowerModelName}.dto.${userFileExtension}`,
43
+ query: `query-${lowerModelName}.dto.${userFileExtension}`,
44
+ },
45
+ schemas: isAuthModule
46
+ ? {
47
+ login: `login.schema.${userFileExtension}`,
48
+ signup: `signup.schema.${userFileExtension}`,
49
+ updateMe: `update-me.schema.${userFileExtension}`,
50
+ updatePassword: `update-password.schema.${userFileExtension}`,
51
+ }
52
+ : {
53
+ model: `${lowerModelName}.schema.${userFileExtension}`,
54
+ create: `create-${lowerModelName}.schema.${userFileExtension}`,
55
+ update: `update-${lowerModelName}.schema.${userFileExtension}`,
56
+ query: `query-${lowerModelName}.schema.${userFileExtension}`,
57
+ },
58
+ };
59
+ }
60
+ export function processSubdir(modelName, type, result) {
20
61
  return __awaiter(this, void 0, void 0, function* () {
21
- const kebabModelName = kebabCase(modelName).toLowerCase();
22
- const lowerModelName = kebabModelName.toLowerCase();
62
+ const moduleDir = path.resolve(process.cwd(), "src", "modules", kebabCase(modelName));
63
+ const subdir = path.join(moduleDir, type);
23
64
  const pascalModelName = pascalCase(modelName);
24
- const moduleDir = path.resolve(process.cwd(), "src", "modules", modelName);
65
+ const fileStructure = getFileModelModulesFileStructure(modelName);
25
66
  const isAuthModule = modelName.toLowerCase() === "auth";
26
- const fileStructure = {
27
- core: {
28
- service: `${kebabModelName}.service.${userFileExtension}`,
29
- controller: `${kebabModelName}.controller.${userFileExtension}`,
30
- middlewares: `${kebabModelName}.middlewares.${userFileExtension}`,
31
- authConfigs: `${kebabModelName}.auth-configs.${userFileExtension}`,
32
- prismaQueryOptions: `${kebabModelName}.prisma-query-options.${userFileExtension}`,
33
- router: `${kebabModelName}.router.${userFileExtension}`,
34
- },
35
- dtos: isAuthModule
36
- ? {
37
- login: `login.dto.${userFileExtension}`,
38
- signup: `signup.dto.${userFileExtension}`,
39
- updateMe: `update-me.dto.${userFileExtension}`,
40
- updatePassword: `update-password.dto.${userFileExtension}`,
67
+ try {
68
+ yield fs.promises.access(subdir).catch(() => {
69
+ return;
70
+ });
71
+ yield Promise.all(Object.entries(fileStructure[type]).map((_a) => __awaiter(this, [_a], void 0, function* ([key, fileName]) {
72
+ const filePath = path.join(subdir, fileName);
73
+ try {
74
+ const module = yield import(filePath).catch(() => null);
75
+ if (module) {
76
+ if (isAuthModule) {
77
+ const pascalKey = key.charAt(0).toUpperCase() + key.slice(1);
78
+ const expectedName = `${pascalKey}${type === "dtos" ? "Dto" : "Schema"}`;
79
+ result[type][key] = module.default;
80
+ }
81
+ else {
82
+ const expectedName = key === "model"
83
+ ? `${pascalModelName}${type === "dtos" ? "Dto" : "Schema"}`
84
+ : `${key.charAt(0).toUpperCase() + key.slice(1)}${pascalModelName}${type === "dtos" ? "Dto" : "Schema"}`;
85
+ result[type][key] = module.default;
86
+ }
87
+ }
41
88
  }
42
- : {
43
- model: `${lowerModelName}.dto.${userFileExtension}`,
44
- create: `create-${lowerModelName}.dto.${userFileExtension}`,
45
- update: `update-${lowerModelName}.dto.${userFileExtension}`,
46
- query: `query-${lowerModelName}.dto.${userFileExtension}`,
47
- },
48
- schemas: isAuthModule
49
- ? {
50
- login: `login.schema.${userFileExtension}`,
51
- signup: `signup.schema.${userFileExtension}`,
52
- updateMe: `update-me.schema.${userFileExtension}`,
53
- updatePassword: `update-password.schema.${userFileExtension}`,
89
+ catch (error) {
54
90
  }
55
- : {
56
- model: `${lowerModelName}.schema.${userFileExtension}`,
57
- create: `create-${lowerModelName}.schema.${userFileExtension}`,
58
- update: `update-${lowerModelName}.schema.${userFileExtension}`,
59
- query: `query-${lowerModelName}.schema.${userFileExtension}`,
60
- },
61
- };
91
+ })));
92
+ }
93
+ catch (error) {
94
+ }
95
+ });
96
+ }
97
+ export function importPrismaModelModules(modelName) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ const moduleDir = path.resolve(process.cwd(), "src", "modules", modelName);
62
100
  const result = {
63
101
  dtos: {},
64
102
  schemas: {},
65
103
  };
104
+ const fileStructure = getFileModelModulesFileStructure(modelName);
66
105
  yield Promise.all(Object.entries(fileStructure.core).map((_a) => __awaiter(this, [_a], void 0, function* ([key, fileName]) {
67
106
  const filePath = path.join(moduleDir, fileName);
68
107
  try {
69
- const module = yield import(filePath).catch(() => null);
108
+ const module = yield importModule(filePath).catch(() => null);
70
109
  if (module) {
71
110
  if (key === "middlewares")
72
111
  result[key] = module;
@@ -74,48 +113,17 @@ export function importPrismaModelModules(modelName) {
74
113
  result[key] = module.default || module;
75
114
  }
76
115
  }
77
- catch (error) {
78
- }
116
+ catch (_b) { }
79
117
  })));
80
- const processSubdir = (type) => __awaiter(this, void 0, void 0, function* () {
81
- const subdir = path.join(moduleDir, type);
82
- try {
83
- yield fs.promises.access(subdir).catch(() => {
84
- return;
85
- });
86
- yield Promise.all(Object.entries(fileStructure[type]).map((_a) => __awaiter(this, [_a], void 0, function* ([key, fileName]) {
87
- const filePath = path.join(subdir, fileName);
88
- try {
89
- const module = yield import(filePath).catch(() => null);
90
- if (module) {
91
- if (isAuthModule) {
92
- const pascalKey = key.charAt(0).toUpperCase() + key.slice(1);
93
- const expectedName = `${pascalKey}${type === "dtos" ? "Dto" : "Schema"}`;
94
- result[type][key] = module.default;
95
- }
96
- else {
97
- const expectedName = key === "model"
98
- ? `${pascalModelName}${type === "dtos" ? "Dto" : "Schema"}`
99
- : `${key.charAt(0).toUpperCase() + key.slice(1)}${pascalModelName}${type === "dtos" ? "Dto" : "Schema"}`;
100
- result[type][key] = module.default;
101
- }
102
- }
103
- }
104
- catch (error) {
105
- }
106
- })));
107
- }
108
- catch (error) {
109
- }
110
- });
111
- yield Promise.all([processSubdir("dtos"), processSubdir("schemas")]);
118
+ yield Promise.all([
119
+ processSubdir(modelName, "dtos", result),
120
+ processSubdir(modelName, "schemas", result),
121
+ ]);
112
122
  prismaModelsModules[modelName] = result;
113
123
  return result;
114
124
  });
115
125
  }
116
- const schemaFolderPath = process.env.PRISMA_SCHEMA_PATH || arkosEnv.PRISMA_SCHEMA_PATH;
117
- const prismaModelRelationFields = {};
118
- const prismaContent = [];
126
+ export const prismaModelRelationFields = {};
119
127
  export function getAllPrismaFiles(dirPath, fileList = []) {
120
128
  const files = fs.readdirSync(dirPath);
121
129
  files === null || files === void 0 ? void 0 : files.forEach((file) => {
@@ -130,93 +138,90 @@ export function getAllPrismaFiles(dirPath, fileList = []) {
130
138
  });
131
139
  return fileList;
132
140
  }
133
- const files = getAllPrismaFiles("./prisma");
134
- for (const file of files) {
135
- const content = fs.readFileSync(file, "utf-8");
136
- prismaContent.push(content);
137
- }
138
141
  const modelRegex = /model\s+(\w+)\s*{/g;
139
- const models = [];
142
+ export const models = [];
140
143
  export const prismaModelsUniqueFields = [];
141
- prismaContent.join("\n").replace(modelRegex, (_, modelName) => {
142
- if (!models.includes(modelName))
143
- models.push(camelCase(modelName.trim()));
144
- return modelName;
145
- });
146
- for (const model of models) {
147
- const modelName = pascalCase(model);
148
- let modelFile;
144
+ export function initializePrismaModels(testName) {
145
+ const prismaContent = [];
146
+ const files = getAllPrismaFiles("./prisma");
149
147
  for (const file of files) {
150
- const filePath = path.join(file);
151
- const stats = fs.statSync(filePath);
152
- if (stats.isFile()) {
153
- const content = fs.readFileSync(filePath, "utf-8");
148
+ const content = fs.readFileSync(file, "utf-8");
149
+ if (!prismaContent.includes(content))
154
150
  prismaContent.push(content);
155
- if (content.includes(`model ${modelName} {`)) {
156
- modelFile = file;
157
- break;
158
- }
159
- }
160
151
  }
161
- if (!modelFile) {
162
- throw new Error(`Model ${modelName} not found`);
163
- }
164
- const content = fs.readFileSync(path.join(modelFile), "utf-8");
165
- const modelStart = content.indexOf(`model ${modelName} {`);
166
- const modelEnd = content.indexOf("}", modelStart);
167
- const modelDefinition = content.slice(modelStart, modelEnd);
168
- const relations = {
169
- singular: [],
170
- list: [],
171
- };
172
- const lines = modelDefinition.split("\n");
173
- for (const line of lines) {
174
- const trimmedLine = line.trim();
175
- if (!trimmedLine ||
176
- trimmedLine.startsWith("model") ||
177
- trimmedLine.startsWith("//"))
178
- continue;
179
- const [fieldName, type] = trimmedLine.split(/\s+/);
180
- const isUnique = trimmedLine.includes("@unique");
181
- if (isUnique)
182
- prismaModelsUniqueFields[model] = [
183
- ...(prismaModelsUniqueFields[model] || []),
184
- { name: fieldName, type, isUnique },
185
- ];
186
- const cleanType = type === null || type === void 0 ? void 0 : type.replace("[]", "").replace("?", "");
187
- if (trimmedLine.includes("@relation") ||
188
- trimmedLine.match(/\s+\w+(\[\])?(\s+@|$)/) ||
189
- models.includes(camelCase(cleanType || ""))) {
190
- const modelStart = content.indexOf(`enum ${cleanType} {`);
191
- if (!cleanType ||
192
- modelStart >= 0 ||
193
- cleanType === "String" ||
194
- cleanType === "Int" ||
195
- cleanType === "Float" ||
196
- cleanType === "Boolean" ||
197
- cleanType === "DateTime" ||
198
- cleanType === "Bytes" ||
199
- cleanType === "Decimal" ||
200
- cleanType === "BigInt" ||
201
- cleanType === "Json") {
152
+ const content = prismaContent
153
+ .join("\n")
154
+ .replace(modelRegex, (_, modelName) => {
155
+ if (!models.includes(modelName))
156
+ models.push(camelCase(modelName.trim()));
157
+ return `model ${modelName} {`;
158
+ });
159
+ for (const model of models) {
160
+ const modelName = pascalCase(model);
161
+ const modelStart = content.indexOf(`model ${modelName} {`);
162
+ const modelEnd = content.indexOf("}", modelStart);
163
+ const modelDefinition = content.slice(modelStart, modelEnd);
164
+ const relations = {
165
+ singular: [],
166
+ list: [],
167
+ };
168
+ const lines = modelDefinition.split("\n");
169
+ for (const line of lines) {
170
+ const trimmedLine = line.trim();
171
+ if (!trimmedLine ||
172
+ trimmedLine.startsWith("model") ||
173
+ trimmedLine.startsWith("//"))
202
174
  continue;
175
+ const [fieldName, type] = trimmedLine.split(/\s+/);
176
+ const isUnique = trimmedLine.includes("@unique");
177
+ if (isUnique) {
178
+ const existingFields = prismaModelsUniqueFields[model] || [];
179
+ const alreadyExists = existingFields.some((field) => field.name === fieldName &&
180
+ field.type === type &&
181
+ field.isUnique === isUnique);
182
+ if (!alreadyExists) {
183
+ prismaModelsUniqueFields[model] = [
184
+ ...existingFields,
185
+ { name: fieldName, type, isUnique },
186
+ ];
187
+ }
203
188
  }
204
- if (!(type === null || type === void 0 ? void 0 : type.includes("[]"))) {
205
- relations.singular.push({
206
- name: fieldName,
207
- type: cleanType,
208
- });
209
- }
210
- else {
211
- relations.list.push({
212
- name: fieldName,
213
- type: cleanType,
214
- });
189
+ const cleanType = type === null || type === void 0 ? void 0 : type.replace("[]", "").replace("?", "");
190
+ if (trimmedLine.includes("@relation") ||
191
+ trimmedLine.match(/\s+\w+(\[\])?(\s+@|$)/) ||
192
+ models.includes(camelCase(cleanType || ""))) {
193
+ const modelStart = content.indexOf(`enum ${cleanType} {`);
194
+ if (!cleanType ||
195
+ modelStart >= 0 ||
196
+ cleanType === "String" ||
197
+ cleanType === "Int" ||
198
+ cleanType === "Float" ||
199
+ cleanType === "Boolean" ||
200
+ cleanType === "DateTime" ||
201
+ cleanType === "Bytes" ||
202
+ cleanType === "Decimal" ||
203
+ cleanType === "BigInt" ||
204
+ cleanType === "Json") {
205
+ continue;
206
+ }
207
+ if (!(type === null || type === void 0 ? void 0 : type.includes("[]"))) {
208
+ relations.singular.push({
209
+ name: fieldName,
210
+ type: cleanType,
211
+ });
212
+ }
213
+ else {
214
+ relations.list.push({
215
+ name: fieldName,
216
+ type: cleanType,
217
+ });
218
+ }
215
219
  }
220
+ prismaModelRelationFields[modelName] = relations;
216
221
  }
217
- prismaModelRelationFields[modelName] = relations;
218
222
  }
219
223
  }
224
+ initializePrismaModels();
220
225
  export function getPrismaModelRelations(modelName) {
221
226
  modelName = pascalCase(modelName);
222
227
  if (!(modelName in prismaModelRelationFields))
@@ -229,5 +234,5 @@ function getModels() {
229
234
  function getModelUniqueFields(modelName) {
230
235
  return prismaModelsUniqueFields[modelName];
231
236
  }
232
- export { models, getModels, getModelUniqueFields, prismaModelRelationFields };
237
+ export { getModels, getModelUniqueFields };
233
238
  //# sourceMappingURL=models.helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"models.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/models.helpers.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,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gBACrB,SAAS,KAAK,SAAS;gBACvB,SAAS,KAAK,UAAU;gBACxB,SAAS,KAAK,OAAO;gBACrB,SAAS,KAAK,SAAS;gBACvB,SAAS,KAAK,QAAQ;gBACtB,SAAS,KAAK,MAAM,EACpB,CAAC;gBACD,SAAS;YACX,CAAC;YAED,IAAI,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,CAAC,IAAI,CAAC,CAAA,EAAE,CAAC;gBAC1B,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC;oBACtB,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,SAAS;iBAChB,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;oBAClB,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,SAAS;iBAChB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,yBAAyB,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IACnD,CAAC;AACH,CAAC;AAQD,MAAM,UAAU,uBAAuB,CAAC,SAAiB;IACvD,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IAElC,IAAI,CAAC,CAAC,SAAS,IAAI,yBAAyB,CAAC;QAAE,OAAO;IACtD,OAAO,yBAAyB,CAAC,SAAS,CAAC,CAAC;AAC9C,CAAC;AAOD,SAAS,SAAS;IAChB,OAAO,MAAM,CAAC;AAChB,CAAC;AAMD,SAAS,oBAAoB,CAAC,SAAiB;IAC7C,OAAO,wBAAwB,CAAC,SAAS,CAAC,CAAC;AAC7C,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,CAAC","sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport {\n camelCase,\n kebabCase,\n pascalCase,\n} from \"../../utils/helpers/change-case.helpers\";\nimport arkosEnv from \"../arkos-env\";\nimport { userFileExtension } from \"./fs.helpers\";\n\nexport let prismaModelsModules: Record<\n string,\n Awaited<ReturnType<typeof importPrismaModelModules>>\n> = {};\n\nexport function getModelModules(modelName: string) {\n return prismaModelsModules[kebabCase(modelName)];\n}\n\n// /**\n// * Dynamically imports model-specific modules like middlewares, auth configurations,\n// * prisma query options, and DTOs for a given model.\n// *\n// * @param {string} modelName - The name of the model (e.g., \"User\", \"Post\").\n// * @returns {Promise<Object>} An object containing the imported modules: `middlewares`, `authConfigs`, `prismaQueryOptions`, and `dtos`.\n// */\n// export async function importPrismaModelModules(modelName: string) {\n// const kebabModelName = kebabCase(modelName);\n// const lowerModelName = modelName.toLowerCase();\n\n// const moduleDir = path.resolve(process.cwd(), \"src\", \"modules\", modelName);\n// const dtosDir = path.join(moduleDir, \"dtos\");\n// const schemasDir = path.join(moduleDir, \"schemas\");\n\n// const middlewaresFile = path.join(\n// moduleDir,\n// `${kebabModelName}.middlewares.${userFileExtension}`\n// );\n// const authConfigsFile = path.join(\n// moduleDir,\n// `${kebabModelName}.auth-configs.${userFileExtension}`\n// );\n// const prismaQueryOptionsFile = path.join(\n// moduleDir,\n// `${kebabModelName}.prisma-query-options.${userFileExtension}`\n// );\n\n// // Define DTO file paths\n// const modelDtoFile = path.join(\n// dtosDir,\n// `${lowerModelName}.dto.${userFileExtension}`\n// );\n// const createDtoFile = path.join(\n// dtosDir,\n// `create-${lowerModelName}.dto.${userFileExtension}`\n// );\n// const updateDtoFile = path.join(\n// dtosDir,\n// `update-${lowerModelName}.dto.${userFileExtension}`\n// );\n// const queryDtoFile = path.join(\n// dtosDir,\n// `query-${lowerModelName}.dto.${userFileExtension}`\n// );\n\n// const modelSchemaFile = path.join(\n// schemasDir,\n// `${lowerModelName}.schema.${userFileExtension}`\n// );\n// const createSchemaFile = path.join(\n// schemasDir,\n// `create-${lowerModelName}.schema.${userFileExtension}`\n// );\n// const updateSchemaFile = path.join(\n// schemasDir,\n// `update-${lowerModelName}.schema.${userFileExtension}`\n// );\n// const querySchemaFile = path.join(\n// schemasDir,\n// `query-${lowerModelName}.schema.${userFileExtension}`\n// );\n\n// const result: {\n// middlewares?: any;\n// authConfigs?: any;\n// prismaQueryOptions?: any;\n// dtos: {\n// create?: any;\n// update?: any;\n// query?: any;\n// model?: any;\n// };\n// schemas: {\n// create?: any;\n// update?: any;\n// query?: any;\n// model?: any;\n// };\n// } = {\n// dtos: {},\n// schemas: {},\n// };\n\n// try {\n// if (fs.existsSync(middlewaresFile)) {\n// const middlewareModule = await import(middlewaresFile);\n// result.middlewares = middlewareModule;\n// }\n// } catch (error) {\n// console.error(\n// `Error importing middlewares for model \"${modelName}\":`,\n// error\n// );\n// }\n\n// try {\n// if (fs.existsSync(authConfigsFile)) {\n// const authConfigsModule = await import(authConfigsFile);\n// result.authConfigs = authConfigsModule.default || authConfigsModule;\n// }\n// } catch (error) {\n// console.error(\n// `Error importing auth configs for model \"${modelName}\":`,\n// error\n// );\n// }\n\n// try {\n// if (fs.existsSync(prismaQueryOptionsFile)) {\n// const prismaQueryOptionsModule = await import(prismaQueryOptionsFile);\n// result.prismaQueryOptions =\n// prismaQueryOptionsModule.default || prismaQueryOptionsModule;\n// }\n// } catch (error) {\n// console.error(\n// `Error importing prisma query options for model \"${modelName}\":`,\n// error\n// );\n// }\n\n// // Import DTOs\n// const pascalModelName = pascalCase(modelName);\n// try {\n// if (fs.existsSync(modelDtoFile)) {\n// const modelDtoModule = await import(modelDtoFile);\n// result.dtos.model =\n// modelDtoModule.default || modelDtoModule[`${pascalModelName}Dto`];\n// }\n// } catch (error) {\n// console.error(\n// `Error importing model main DTO for model \"${modelName} ${pascalModelName}\":`,\n// error\n// );\n// }\n\n// try {\n// if (fs.existsSync(createDtoFile)) {\n// const createDtoModule = await import(createDtoFile);\n// result.dtos.create =\n// createDtoModule.default ||\n// createDtoModule[`Create${pascalModelName}Dto`];\n// }\n// } catch (error) {\n// console.error(\n// `Error importing create DTO for model \"${modelName}\":`,\n// error\n// );\n// }\n\n// try {\n// if (fs.existsSync(updateDtoFile)) {\n// const updateDtoModule = await import(updateDtoFile);\n// result.dtos.update =\n// updateDtoModule.default ||\n// updateDtoModule[`Update${pascalModelName}Dto`];\n// }\n// } catch (error) {\n// console.error(\n// `Error importing update DTO for model \"${modelName}\":`,\n// error\n// );\n// }\n\n// try {\n// if (fs.existsSync(queryDtoFile)) {\n// const queryDtoModule = await import(queryDtoFile);\n// result.dtos.query =\n// queryDtoModule.default || queryDtoModule[`Query${pascalModelName}Dto`];\n// }\n// } catch (error) {\n// console.error(`Error importing query DTO for model \"${modelName}\":`, error);\n// }\n\n// try {\n// if (fs.existsSync(modelSchemaFile)) {\n// const modelSchemaModule = await import(modelSchemaFile);\n// result.dtos.model =\n// modelSchemaModule.default ||\n// modelSchemaModule[`${pascalModelName}Schema`];\n// }\n// } catch (error) {\n// console.error(\n// `Error importing create Schema for model \"${modelName}\":`,\n// error\n// );\n// }\n\n// try {\n// if (fs.existsSync(createSchemaFile)) {\n// const createSchemaModule = await import(createSchemaFile);\n// result.dtos.create =\n// createSchemaModule.default ||\n// createSchemaModule[`Create${pascalModelName}Schema`];\n// }\n// } catch (error) {\n// console.error(\n// `Error importing create Schema for model \"${modelName}\":`,\n// error\n// );\n// }\n\n// try {\n// if (fs.existsSync(updateSchemaFile)) {\n// const updateSchemaModule = await import(updateSchemaFile);\n// result.dtos.update =\n// updateSchemaModule.default ||\n// updateSchemaModule[`Update${pascalModelName}Schema`];\n// }\n// } catch (error) {\n// console.error(\n// `Error importing update Schema for model \"${modelName}\":`,\n// error\n// );\n// }\n\n// try {\n// if (fs.existsSync(querySchemaFile)) {\n// const querySchemaModule = await import(querySchemaFile);\n// result.dtos.query =\n// querySchemaModule.default ||\n// querySchemaModule[`Query${pascalModelName}Schema`];\n// }\n// } catch (error) {\n// console.error(\n// `Error importing query Schema for model \"${modelName}\":`,\n// error\n// );\n// }\n\n// prismaModelsModules[modelName] = result;\n\n// return result;\n// }\n\n/**\n * Dynamically imports model-specific modules for a given model with optimized file handling.\n * Includes special handling for the Auth module.\n *\n * @param {string} modelName - The name of the model (e.g., \"User\", \"Post\", \"Auth\").\n * @returns {Promise<Object>} An object containing the imported modules\n */\nexport async function importPrismaModelModules(modelName: string) {\n const kebabModelName = kebabCase(modelName).toLowerCase();\n const lowerModelName = kebabModelName.toLowerCase();\n const pascalModelName = pascalCase(modelName);\n\n const moduleDir = path.resolve(process.cwd(), \"src\", \"modules\", modelName);\n\n // Define special auth module structure if needed\n const isAuthModule = modelName.toLowerCase() === \"auth\";\n\n // Define the structure of files to import\n const fileStructure = {\n core: {\n service: `${kebabModelName}.service.${userFileExtension}`,\n controller: `${kebabModelName}.controller.${userFileExtension}`,\n middlewares: `${kebabModelName}.middlewares.${userFileExtension}`,\n authConfigs: `${kebabModelName}.auth-configs.${userFileExtension}`,\n prismaQueryOptions: `${kebabModelName}.prisma-query-options.${userFileExtension}`,\n router: `${kebabModelName}.router.${userFileExtension}`,\n },\n dtos: isAuthModule\n ? {\n login: `login.dto.${userFileExtension}`,\n signup: `signup.dto.${userFileExtension}`,\n updateMe: `update-me.dto.${userFileExtension}`,\n updatePassword: `update-password.dto.${userFileExtension}`,\n }\n : {\n model: `${lowerModelName}.dto.${userFileExtension}`,\n create: `create-${lowerModelName}.dto.${userFileExtension}`,\n update: `update-${lowerModelName}.dto.${userFileExtension}`,\n query: `query-${lowerModelName}.dto.${userFileExtension}`,\n },\n schemas: isAuthModule\n ? {\n login: `login.schema.${userFileExtension}`,\n signup: `signup.schema.${userFileExtension}`,\n updateMe: `update-me.schema.${userFileExtension}`,\n updatePassword: `update-password.schema.${userFileExtension}`,\n }\n : {\n model: `${lowerModelName}.schema.${userFileExtension}`,\n create: `create-${lowerModelName}.schema.${userFileExtension}`,\n update: `update-${lowerModelName}.schema.${userFileExtension}`,\n query: `query-${lowerModelName}.schema.${userFileExtension}`,\n },\n };\n\n // Initialize result object\n const result: {\n service?: any;\n controller?: any;\n middlewares?: any;\n authConfigs?: any;\n prismaQueryOptions?: any;\n router?: any;\n dtos: Record<string, any>;\n schemas: Record<string, any>;\n } = {\n dtos: {},\n schemas: {},\n };\n\n // Batch process core files\n await Promise.all(\n Object.entries(fileStructure.core).map(async ([key, fileName]) => {\n const filePath = path.join(moduleDir, fileName);\n try {\n const module = await import(filePath).catch(() => null);\n if (module) {\n // For middlewares, keep the entire module\n if (key === \"middlewares\") result[key] = module;\n // For all other core files, prefer default export\n else result[key as keyof typeof result] = module.default || module;\n }\n } catch (error) {\n // Silent fail - file might not exist\n }\n })\n );\n\n // Process DTOs and schemas in parallel\n const processSubdir = async (type: \"dtos\" | \"schemas\") => {\n const subdir = path.join(moduleDir, type);\n\n // Skip if directory doesn't exist\n try {\n await fs.promises.access(subdir).catch(() => {\n return; // Directory doesn't exist\n });\n\n await Promise.all(\n Object.entries(fileStructure[type]).map(async ([key, fileName]) => {\n const filePath = path.join(subdir, fileName);\n try {\n const module = await import(filePath).catch(() => null);\n if (module) {\n if (isAuthModule) {\n // Auth module uses different naming conventions\n const pascalKey = key.charAt(0).toUpperCase() + key.slice(1);\n const expectedName = `${pascalKey}${\n type === \"dtos\" ? \"Dto\" : \"Schema\"\n }`;\n result[type][key] = module.default;\n } else {\n // Standard modules\n const expectedName =\n key === \"model\"\n ? `${pascalModelName}${type === \"dtos\" ? \"Dto\" : \"Schema\"}`\n : `${\n key.charAt(0).toUpperCase() + key.slice(1)\n }${pascalModelName}${type === \"dtos\" ? \"Dto\" : \"Schema\"}`;\n\n result[type][key] = module.default;\n }\n }\n } catch (error) {\n // Silent fail - file might not exist\n }\n })\n );\n } catch (error) {\n // Directory doesn't exist, continue silently\n }\n };\n\n // Process both subdirectories in parallel\n await Promise.all([processSubdir(\"dtos\"), processSubdir(\"schemas\")]);\n\n // Cache the result\n prismaModelsModules[modelName] = result;\n\n return result;\n}\n\nexport type ModelFieldDefition = {\n name: string;\n type: string;\n isUnique: boolean;\n};\n\n/**\n * Represents the structure of relation fields for Prisma models.\n * It includes both singular (one-to-one) and list (one-to-many) relationships.\n *\n * @typedef {Object} RelationFields\n * @property {Array<{name: string, type: string}>} singular - List of singular relationships.\n * @property {Array<{name: string, type: string}>} list - List of list relationships.\n */\nexport type RelationFields = {\n singular: Omit<ModelFieldDefition, \"isUnique\">[];\n list: Omit<ModelFieldDefition, \"isUnique\">[];\n};\n\nconst schemaFolderPath =\n process.env.PRISMA_SCHEMA_PATH || arkosEnv.PRISMA_SCHEMA_PATH;\n\n/**\n * Reads the Prisma schema files and extracts all model definitions,\n * identifying their relations (one-to-one and one-to-many).\n */\nconst prismaModelRelationFields: Record<string, RelationFields> = {};\n\nconst prismaContent: string[] = [];\n\nexport function getAllPrismaFiles(dirPath: string, fileList: string[] = []) {\n const files = fs.readdirSync(dirPath);\n\n files?.forEach((file) => {\n const filePath = path.join(dirPath, file);\n const stat = fs.statSync(filePath);\n\n // Skip migrations folder\n if (stat.isDirectory() && file !== \"migrations\") {\n fileList = getAllPrismaFiles(filePath, fileList);\n } else if (stat.isFile() && file.endsWith(\".prisma\")) {\n fileList.push(filePath);\n }\n });\n\n return fileList;\n}\n\n// const prismaRootDir = \"\"; // Adjust this path if needed\nconst files = getAllPrismaFiles(\"./prisma\");\n\nfor (const file of files) {\n const content = fs.readFileSync(file, \"utf-8\");\n\n prismaContent.push(content);\n}\n\nconst modelRegex = /model\\s+(\\w+)\\s*{/g;\nconst models: string[] = [];\nexport const prismaModelsUniqueFields: Record<string, ModelFieldDefition[]> =\n [] as any;\n\nprismaContent.join(\"\\n\").replace(modelRegex, (_, modelName) => {\n if (!models.includes(modelName)) models.push(camelCase(modelName.trim()));\n return modelName;\n});\n\nfor (const model of models) {\n const modelName = pascalCase(model);\n\n let modelFile;\n for (const file of files) {\n const filePath = path.join(file);\n const stats = fs.statSync(filePath);\n\n if (stats.isFile()) {\n const content = fs.readFileSync(filePath, \"utf-8\");\n prismaContent.push(content);\n if (content.includes(`model ${modelName} {`)) {\n modelFile = file;\n break;\n }\n }\n }\n\n if (!modelFile) {\n throw new Error(`Model ${modelName} not found`);\n }\n\n const content = fs.readFileSync(path.join(modelFile), \"utf-8\");\n\n const modelStart = content.indexOf(`model ${modelName} {`);\n const modelEnd = content.indexOf(\"}\", modelStart);\n const modelDefinition = content.slice(modelStart, modelEnd);\n\n const relations: RelationFields = {\n singular: [],\n list: [],\n };\n const lines = modelDefinition.split(\"\\n\");\n\n for (const line of lines) {\n const trimmedLine = line.trim();\n\n if (\n !trimmedLine ||\n trimmedLine.startsWith(\"model\") ||\n trimmedLine.startsWith(\"//\")\n )\n continue;\n\n const [fieldName, type] = trimmedLine.split(/\\s+/);\n const isUnique = trimmedLine.includes(\"@unique\");\n\n if (isUnique)\n prismaModelsUniqueFields[model] = [\n ...(prismaModelsUniqueFields[model] || []),\n { name: fieldName, type, isUnique },\n ];\n\n const cleanType = type?.replace(\"[]\", \"\").replace(\"?\", \"\");\n\n if (\n trimmedLine.includes(\"@relation\") ||\n trimmedLine.match(/\\s+\\w+(\\[\\])?(\\s+@|$)/) ||\n models.includes(camelCase(cleanType || \"\"))\n ) {\n const modelStart = content.indexOf(`enum ${cleanType} {`);\n\n if (\n !cleanType ||\n modelStart >= 0 ||\n cleanType === \"String\" ||\n cleanType === \"Int\" ||\n cleanType === \"Float\" ||\n cleanType === \"Boolean\" ||\n cleanType === \"DateTime\" ||\n cleanType === \"Bytes\" ||\n cleanType === \"Decimal\" ||\n cleanType === \"BigInt\" ||\n cleanType === \"Json\"\n ) {\n continue;\n }\n\n if (!type?.includes(\"[]\")) {\n relations.singular.push({\n name: fieldName,\n type: cleanType,\n });\n } else {\n relations.list.push({\n name: fieldName,\n type: cleanType,\n });\n }\n }\n\n prismaModelRelationFields[modelName] = relations;\n }\n}\n\n/**\n * Retrieves the relations for a given Prisma model.\n *\n * @param {string} modelName - The name of the model (e.g., \"User\").\n * @returns {RelationFields|undefined} The relation fields for the model, or `undefined` if no relations are found.\n */\nexport function getPrismaModelRelations(modelName: string) {\n modelName = pascalCase(modelName);\n\n if (!(modelName in prismaModelRelationFields)) return;\n return prismaModelRelationFields[modelName];\n}\n\n/**\n * Retrieves all the model names from the Prisma schema.\n *\n * @returns {string[]} An array of model names (e.g., [\"User\", \"Post\"]).\n */\nfunction getModels() {\n return models;\n}\n\n/** Retuns a given model unique fields\n * @param {string} modelName - The name of model in PascalCase\n * @returns {string[]} An array of all unique fields,\n */\nfunction getModelUniqueFields(modelName: string) {\n return prismaModelsUniqueFields[modelName];\n}\n\nexport { models, getModels, getModelUniqueFields, prismaModelRelationFields };\n"]}
1
+ {"version":3,"file":"models.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/models.helpers.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EACL,SAAS,EACT,SAAS,EACT,UAAU,GACX,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,MAAM,CAAC,IAAI,mBAAmB,GAG1B,EAAE,CAAC;AAEP,MAAM,UAAU,eAAe,CAAC,SAAiB;IAC/C,OAAO,mBAAmB,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,gCAAgC,CAAC,SAAiB;IAChE,MAAM,cAAc,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;IAC1D,MAAM,cAAc,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;IACpD,MAAM,YAAY,GAAG,SAAS,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC;IAExD,OAAO;QACL,IAAI,EAAE;YACJ,OAAO,EAAE,GAAG,cAAc,YAAY,iBAAiB,EAAE;YACzD,UAAU,EAAE,GAAG,cAAc,eAAe,iBAAiB,EAAE;YAC/D,WAAW,EAAE,GAAG,cAAc,gBAAgB,iBAAiB,EAAE;YACjE,WAAW,EAAE,GAAG,cAAc,iBAA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yBAAyB,CAAC;QAAE,OAAO;IACtD,OAAO,yBAAyB,CAAC,SAAS,CAAC,CAAC;AAC9C,CAAC;AAOD,SAAS,SAAS;IAChB,OAAO,MAAM,CAAC;AAChB,CAAC;AAMD,SAAS,oBAAoB,CAAC,SAAiB;IAC7C,OAAO,wBAAwB,CAAC,SAAS,CAAC,CAAC;AAC7C,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport {\n camelCase,\n kebabCase,\n pascalCase,\n} from \"../../utils/helpers/change-case.helpers\";\nimport { userFileExtension } from \"./fs.helpers\";\nimport { importModule } from \"./global.helpers\";\n\nexport let prismaModelsModules: Record<\n string,\n Awaited<ReturnType<typeof importPrismaModelModules>>\n> = {};\n\nexport function getModelModules(modelName: string) {\n return prismaModelsModules[kebabCase(modelName)];\n}\n\nexport function getFileModelModulesFileStructure(modelName: string) {\n const kebabModelName = kebabCase(modelName).toLowerCase();\n const lowerModelName = kebabModelName.toLowerCase();\n const isAuthModule = modelName.toLowerCase() === \"auth\";\n\n return {\n core: {\n service: `${kebabModelName}.service.${userFileExtension}`,\n controller: `${kebabModelName}.controller.${userFileExtension}`,\n middlewares: `${kebabModelName}.middlewares.${userFileExtension}`,\n authConfigs: `${kebabModelName}.auth-configs.${userFileExtension}`,\n prismaQueryOptions: `${kebabModelName}.prisma-query-options.${userFileExtension}`,\n router: `${kebabModelName}.router.${userFileExtension}`,\n },\n dtos: isAuthModule\n ? {\n login: `login.dto.${userFileExtension}`,\n signup: `signup.dto.${userFileExtension}`,\n updateMe: `update-me.dto.${userFileExtension}`,\n updatePassword: `update-password.dto.${userFileExtension}`,\n }\n : {\n model: `${lowerModelName}.dto.${userFileExtension}`,\n create: `create-${lowerModelName}.dto.${userFileExtension}`,\n update: `update-${lowerModelName}.dto.${userFileExtension}`,\n query: `query-${lowerModelName}.dto.${userFileExtension}`,\n },\n schemas: isAuthModule\n ? {\n login: `login.schema.${userFileExtension}`,\n signup: `signup.schema.${userFileExtension}`,\n updateMe: `update-me.schema.${userFileExtension}`,\n updatePassword: `update-password.schema.${userFileExtension}`,\n }\n : {\n model: `${lowerModelName}.schema.${userFileExtension}`,\n create: `create-${lowerModelName}.schema.${userFileExtension}`,\n update: `update-${lowerModelName}.schema.${userFileExtension}`,\n query: `query-${lowerModelName}.schema.${userFileExtension}`,\n },\n };\n}\n\nexport async function processSubdir(\n modelName: string,\n type: \"dtos\" | \"schemas\",\n result: Record<string, any>\n) {\n const moduleDir = path.resolve(\n process.cwd(),\n \"src\",\n \"modules\",\n kebabCase(modelName)\n );\n\n const subdir = path.join(moduleDir, type);\n const pascalModelName = pascalCase(modelName);\n const fileStructure = getFileModelModulesFileStructure(modelName);\n const isAuthModule = modelName.toLowerCase() === \"auth\";\n\n // Skip if directory doesn't exist\n try {\n await fs.promises.access(subdir).catch(() => {\n return; // Directory doesn't exist\n });\n\n await Promise.all(\n Object.entries(fileStructure[type]).map(async ([key, fileName]) => {\n const filePath = path.join(subdir, fileName);\n try {\n const module = await import(filePath).catch(() => null);\n if (module) {\n if (isAuthModule) {\n // Auth module uses different naming conventions\n const pascalKey = key.charAt(0).toUpperCase() + key.slice(1);\n const expectedName = `${pascalKey}${\n type === \"dtos\" ? \"Dto\" : \"Schema\"\n }`;\n result[type][key] = module.default;\n } else {\n // Standard modules\n const expectedName =\n key === \"model\"\n ? `${pascalModelName}${type === \"dtos\" ? \"Dto\" : \"Schema\"}`\n : `${\n key.charAt(0).toUpperCase() + key.slice(1)\n }${pascalModelName}${type === \"dtos\" ? \"Dto\" : \"Schema\"}`;\n\n result[type][key] = module.default;\n }\n }\n } catch (error) {\n // Silent fail - file might not exist\n }\n })\n );\n } catch (error) {\n // Directory doesn't exist, continue silently\n }\n}\n\n/**\n * Dynamically imports model-specific modules for a given model with optimized file handling.\n * Includes special handling for the Auth module.\n *\n * @param {string} modelName - The name of the model (e.g., \"User\", \"Post\", \"Auth\").\n * @returns {Promise<Object>} An object containing the imported modules\n */\nexport async function importPrismaModelModules(\n modelName: string\n): Promise<Record<string, any>> {\n const moduleDir = path.resolve(process.cwd(), \"src\", \"modules\", modelName);\n\n const result: {\n service?: any;\n controller?: any;\n middlewares?: any;\n authConfigs?: any;\n prismaQueryOptions?: any;\n router?: any;\n dtos: Record<string, any>;\n schemas: Record<string, any>;\n } = {\n dtos: {},\n schemas: {},\n };\n\n const fileStructure = getFileModelModulesFileStructure(modelName);\n // Batch process core files\n await Promise.all(\n Object.entries(fileStructure.core).map(async ([key, fileName]) => {\n const filePath = path.join(moduleDir, fileName);\n try {\n const module = await importModule(filePath).catch(() => null);\n if (module) {\n if (key === \"middlewares\") result[key] = module;\n else result[key as keyof typeof result] = module.default || module;\n }\n } catch {}\n })\n );\n\n await Promise.all([\n processSubdir(modelName, \"dtos\", result),\n processSubdir(modelName, \"schemas\", result),\n ]);\n\n // Cache the result\n prismaModelsModules[modelName] = result;\n\n return result;\n}\n\nexport type ModelFieldDefition = {\n name: string;\n type: string;\n isUnique: boolean;\n};\n\n/**\n * Represents the structure of relation fields for Prisma models.\n * It includes both singular (one-to-one) and list (one-to-many) relationships.\n *\n * @typedef {Object} RelationFields\n * @property {Array<{name: string, type: string}>} singular - List of singular relationships.\n * @property {Array<{name: string, type: string}>} list - List of list relationships.\n */\nexport type RelationFields = {\n singular: Omit<ModelFieldDefition, \"isUnique\">[];\n list: Omit<ModelFieldDefition, \"isUnique\">[];\n};\n\n/**\n * Reads the Prisma schema files and extracts all model definitions,\n * identifying their relations (one-to-one and one-to-many).\n */\nexport const prismaModelRelationFields: Record<string, RelationFields> = {};\n\nexport function getAllPrismaFiles(dirPath: string, fileList: string[] = []) {\n const files = fs.readdirSync(dirPath);\n\n files?.forEach((file) => {\n const filePath = path.join(dirPath, file);\n const stat = fs.statSync(filePath);\n\n // Skip migrations folder\n if (stat.isDirectory() && file !== \"migrations\") {\n fileList = getAllPrismaFiles(filePath, fileList);\n } else if (stat.isFile() && file.endsWith(\".prisma\")) {\n fileList.push(filePath);\n }\n });\n\n return fileList;\n}\n\nconst modelRegex = /model\\s+(\\w+)\\s*{/g;\nexport const models: string[] = [];\nexport const prismaModelsUniqueFields: Record<string, ModelFieldDefition[]> =\n [] as any;\n\nexport function initializePrismaModels(testName?: string) {\n const prismaContent: string[] = [];\n\n const files = getAllPrismaFiles(\"./prisma\");\n\n for (const file of files) {\n const content = fs.readFileSync(file, \"utf-8\");\n\n if (!prismaContent.includes(content)) prismaContent.push(content);\n }\n\n const content = prismaContent\n .join(\"\\n\")\n .replace(modelRegex, (_, modelName) => {\n if (!models.includes(modelName)) models.push(camelCase(modelName.trim()));\n return `model ${modelName} {`;\n });\n\n for (const model of models) {\n const modelName = pascalCase(model);\n\n // let modelFile;\n // for (const file of files) {\n // const filePath = path.join(file);\n // const stats = fs.statSync(filePath);\n\n // if (stats.isFile()) {\n // const content = fs.readFileSync(filePath, \"utf-8\");\n // prismaContent.push(content);\n // if (content.includes(`model ${modelName} {`)) {\n // modelFile = file;\n // break;\n // }\n // }\n // }\n\n // if (!modelFile) {\n // return;\n // }\n\n // const content = fs.readFileSync(path.join(modelFile), \"utf-8\");\n const modelStart = content.indexOf(`model ${modelName} {`);\n const modelEnd = content.indexOf(\"}\", modelStart);\n const modelDefinition = content.slice(modelStart, modelEnd);\n\n const relations: RelationFields = {\n singular: [],\n list: [],\n };\n const lines = modelDefinition.split(\"\\n\");\n\n for (const line of lines) {\n const trimmedLine = line.trim();\n\n if (\n !trimmedLine ||\n trimmedLine.startsWith(\"model\") ||\n trimmedLine.startsWith(\"//\")\n )\n continue;\n\n const [fieldName, type] = trimmedLine.split(/\\s+/);\n const isUnique = trimmedLine.includes(\"@unique\");\n\n if (isUnique) {\n const existingFields = prismaModelsUniqueFields[model] || [];\n\n const alreadyExists = existingFields.some(\n (field) =>\n field.name === fieldName &&\n field.type === type &&\n field.isUnique === isUnique\n );\n\n if (!alreadyExists) {\n prismaModelsUniqueFields[model] = [\n ...existingFields,\n { name: fieldName, type, isUnique },\n ];\n }\n }\n\n const cleanType = type?.replace(\"[]\", \"\").replace(\"?\", \"\");\n\n if (\n trimmedLine.includes(\"@relation\") ||\n trimmedLine.match(/\\s+\\w+(\\[\\])?(\\s+@|$)/) ||\n models.includes(camelCase(cleanType || \"\"))\n ) {\n const modelStart = content.indexOf(`enum ${cleanType} {`);\n\n if (\n !cleanType ||\n modelStart >= 0 ||\n cleanType === \"String\" ||\n cleanType === \"Int\" ||\n cleanType === \"Float\" ||\n cleanType === \"Boolean\" ||\n cleanType === \"DateTime\" ||\n cleanType === \"Bytes\" ||\n cleanType === \"Decimal\" ||\n cleanType === \"BigInt\" ||\n cleanType === \"Json\"\n ) {\n continue;\n }\n\n if (!type?.includes(\"[]\")) {\n relations.singular.push({\n name: fieldName,\n type: cleanType,\n });\n } else {\n relations.list.push({\n name: fieldName,\n type: cleanType,\n });\n }\n }\n\n prismaModelRelationFields[modelName] = relations;\n }\n }\n}\n\ninitializePrismaModels();\n\n/**\n * Retrieves the relations for a given Prisma model.\n *\n * @param {string} modelName - The name of the model (e.g., \"User\").\n * @returns {RelationFields|undefined} The relation fields for the model, or `undefined` if no relations are found.\n */\nexport function getPrismaModelRelations(modelName: string) {\n modelName = pascalCase(modelName);\n\n if (!(modelName in prismaModelRelationFields)) return;\n return prismaModelRelationFields[modelName];\n}\n\n/**\n * Retrieves all the model names from the Prisma schema.\n *\n * @returns {string[]} An array of model names (e.g., [\"User\", \"Post\"]).\n */\nfunction getModels() {\n return models;\n}\n\n/** Retuns a given model unique fields\n * @param {string} modelName - The name of model in PascalCase\n * @returns {string[]} An array of all unique fields,\n */\nfunction getModelUniqueFields(modelName: string) {\n return prismaModelsUniqueFields[modelName];\n}\n\nexport { getModels, getModelUniqueFields };\n"]}
@@ -1,24 +1,55 @@
1
1
  export declare let prismaModelsModules: Record<string, Awaited<ReturnType<typeof importPrismaModelModules>>>;
2
- export declare function getModelModules(modelName: string): {
3
- service?: any;
4
- controller?: any;
5
- middlewares?: any;
6
- authConfigs?: any;
7
- prismaQueryOptions?: any;
8
- router?: any;
9
- dtos: Record<string, any>;
10
- schemas: Record<string, any>;
2
+ export declare function getModelModules(modelName: string): Record<string, any>;
3
+ export declare function getFileModelModulesFileStructure(modelName: string): {
4
+ core: {
5
+ service: string;
6
+ controller: string;
7
+ middlewares: string;
8
+ authConfigs: string;
9
+ prismaQueryOptions: string;
10
+ router: string;
11
+ };
12
+ dtos: {
13
+ login: string;
14
+ signup: string;
15
+ updateMe: string;
16
+ updatePassword: string;
17
+ model?: undefined;
18
+ create?: undefined;
19
+ update?: undefined;
20
+ query?: undefined;
21
+ } | {
22
+ model: string;
23
+ create: string;
24
+ update: string;
25
+ query: string;
26
+ login?: undefined;
27
+ signup?: undefined;
28
+ updateMe?: undefined;
29
+ updatePassword?: undefined;
30
+ };
31
+ schemas: {
32
+ login: string;
33
+ signup: string;
34
+ updateMe: string;
35
+ updatePassword: string;
36
+ model?: undefined;
37
+ create?: undefined;
38
+ update?: undefined;
39
+ query?: undefined;
40
+ } | {
41
+ model: string;
42
+ create: string;
43
+ update: string;
44
+ query: string;
45
+ login?: undefined;
46
+ signup?: undefined;
47
+ updateMe?: undefined;
48
+ updatePassword?: undefined;
49
+ };
11
50
  };
12
- export declare function importPrismaModelModules(modelName: string): Promise<{
13
- service?: any;
14
- controller?: any;
15
- middlewares?: any;
16
- authConfigs?: any;
17
- prismaQueryOptions?: any;
18
- router?: any;
19
- dtos: Record<string, any>;
20
- schemas: Record<string, any>;
21
- }>;
51
+ export declare function processSubdir(modelName: string, type: "dtos" | "schemas", result: Record<string, any>): Promise<void>;
52
+ export declare function importPrismaModelModules(modelName: string): Promise<Record<string, any>>;
22
53
  export type ModelFieldDefition = {
23
54
  name: string;
24
55
  type: string;
@@ -28,11 +59,12 @@ export type RelationFields = {
28
59
  singular: Omit<ModelFieldDefition, "isUnique">[];
29
60
  list: Omit<ModelFieldDefition, "isUnique">[];
30
61
  };
31
- declare const prismaModelRelationFields: Record<string, RelationFields>;
62
+ export declare const prismaModelRelationFields: Record<string, RelationFields>;
32
63
  export declare function getAllPrismaFiles(dirPath: string, fileList?: string[]): string[];
33
- declare const models: string[];
64
+ export declare const models: string[];
34
65
  export declare const prismaModelsUniqueFields: Record<string, ModelFieldDefition[]>;
66
+ export declare function initializePrismaModels(testName?: string): void;
35
67
  export declare function getPrismaModelRelations(modelName: string): RelationFields | undefined;
36
68
  declare function getModels(): string[];
37
69
  declare function getModelUniqueFields(modelName: string): ModelFieldDefition[];
38
- export { models, getModels, getModelUniqueFields, prismaModelRelationFields };
70
+ export { getModels, getModelUniqueFields };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkos",
3
- "version": "1.0.16",
3
+ "version": "1.0.18-beta",
4
4
  "description": "The Express & Prisma Framework For RESTful API",
5
5
  "main": "dist/cjs/exports/index.js",
6
6
  "module": "dist/es2020/exports/index.js",