arkos 1.1.91-test → 1.1.93-test
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/modules/auth/auth.controller.js +1 -1
- package/dist/cjs/modules/auth/auth.controller.js.map +1 -1
- package/dist/cjs/modules/base/base.middlewares.js.map +1 -1
- package/dist/cjs/modules/base/base.service.js +7 -5
- package/dist/cjs/modules/base/base.service.js.map +1 -1
- package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js +6 -5
- package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js.map +1 -1
- package/dist/cjs/utils/cli/build.js +1 -1
- package/dist/cjs/utils/cli/build.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js +36 -0
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js.map +1 -0
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-controller-template.js +21 -0
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-controller-template.js.map +1 -0
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-middlewares.js +268 -0
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-middlewares.js.map +1 -0
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js +58 -0
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js.map +1 -0
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-router-template.js +38 -0
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-router-template.js.map +1 -0
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-service-template.js +35 -0
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-service-template.js.map +1 -0
- package/dist/cjs/utils/cli/utils/template-generators.js +12 -434
- package/dist/cjs/utils/cli/utils/template-generators.js.map +1 -1
- package/dist/cjs/utils/helpers/fs.helpers.js +7 -0
- package/dist/cjs/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/es2020/modules/auth/auth.controller.js +1 -1
- package/dist/es2020/modules/auth/auth.controller.js.map +1 -1
- package/dist/es2020/modules/base/base.middlewares.js.map +1 -1
- package/dist/es2020/modules/base/base.service.js +7 -5
- package/dist/es2020/modules/base/base.service.js.map +1 -1
- package/dist/es2020/modules/file-upload/utils/helpers/file-upload.helpers.js +6 -5
- package/dist/es2020/modules/file-upload/utils/helpers/file-upload.helpers.js.map +1 -1
- package/dist/es2020/utils/cli/build.js +1 -1
- package/dist/es2020/utils/cli/build.js.map +1 -1
- package/dist/es2020/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js +33 -0
- package/dist/es2020/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js.map +1 -0
- package/dist/es2020/utils/cli/utils/template-generator/templates/generate-controller-template.js +18 -0
- package/dist/es2020/utils/cli/utils/template-generator/templates/generate-controller-template.js.map +1 -0
- package/dist/es2020/utils/cli/utils/template-generator/templates/generate-middlewares.js +265 -0
- package/dist/es2020/utils/cli/utils/template-generator/templates/generate-middlewares.js.map +1 -0
- package/dist/es2020/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js +55 -0
- package/dist/es2020/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js.map +1 -0
- package/dist/es2020/utils/cli/utils/template-generator/templates/generate-router-template.js +32 -0
- package/dist/es2020/utils/cli/utils/template-generator/templates/generate-router-template.js.map +1 -0
- package/dist/es2020/utils/cli/utils/template-generator/templates/generate-service-template.js +32 -0
- package/dist/es2020/utils/cli/utils/template-generator/templates/generate-service-template.js.map +1 -0
- package/dist/es2020/utils/cli/utils/template-generators.js +6 -425
- package/dist/es2020/utils/cli/utils/template-generators.js.map +1 -1
- package/dist/es2020/utils/helpers/fs.helpers.js +6 -0
- package/dist/es2020/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/types/modules/base/base.service.d.ts +31 -31
- package/dist/types/modules/file-upload/utils/helpers/file-upload.helpers.d.ts +3 -3
- package/dist/types/utils/cli/utils/template-generator/templates/generate-auth-configs-template.d.ts +2 -0
- package/dist/types/utils/cli/utils/template-generator/templates/generate-controller-template.d.ts +2 -0
- package/dist/types/utils/cli/utils/template-generator/templates/generate-middlewares.d.ts +2 -0
- package/dist/types/utils/cli/utils/template-generator/templates/generate-prisma-query-options.d.ts +2 -0
- package/dist/types/utils/cli/utils/template-generator/templates/generate-router-template.d.ts +2 -0
- package/dist/types/utils/cli/utils/template-generator/templates/generate-service-template.d.ts +2 -0
- package/dist/types/utils/cli/utils/template-generators.d.ts +1 -1
- package/dist/types/utils/helpers/fs.helpers.d.ts +1 -0
- package/package.json +10 -30
|
@@ -1,450 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.generateTemplate = generateTemplate;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
4
|
+
const generate_controller_template_1 = require("./template-generator/templates/generate-controller-template");
|
|
5
|
+
const generate_auth_configs_template_1 = require("./template-generator/templates/generate-auth-configs-template");
|
|
6
|
+
const generate_middlewares_1 = require("./template-generator/templates/generate-middlewares");
|
|
7
|
+
const generate_prisma_query_options_1 = require("./template-generator/templates/generate-prisma-query-options");
|
|
8
|
+
const generate_router_template_1 = require("./template-generator/templates/generate-router-template");
|
|
9
|
+
const generate_service_template_1 = require("./template-generator/templates/generate-service-template");
|
|
9
10
|
function generateTemplate(type, options = {}) {
|
|
10
11
|
switch (type) {
|
|
11
12
|
case "controller":
|
|
12
|
-
return generateControllerTemplate(options);
|
|
13
|
+
return (0, generate_controller_template_1.generateControllerTemplate)(options);
|
|
13
14
|
case "service":
|
|
14
|
-
return generateServiceTemplate(options);
|
|
15
|
+
return (0, generate_service_template_1.generateServiceTemplate)(options);
|
|
15
16
|
case "router":
|
|
16
|
-
return generateRouterTemplate(options);
|
|
17
|
+
return (0, generate_router_template_1.generateRouterTemplate)(options);
|
|
17
18
|
case "auth-configs":
|
|
18
|
-
return generateAuthConfigsTemplate(options);
|
|
19
|
+
return (0, generate_auth_configs_template_1.generateAuthConfigsTemplate)(options);
|
|
19
20
|
case "query-options":
|
|
20
|
-
return generateQueryOptionsTemplate(options);
|
|
21
|
+
return (0, generate_prisma_query_options_1.generateQueryOptionsTemplate)(options);
|
|
21
22
|
case "middlewares":
|
|
22
|
-
return generateMiddlewaresTemplate(options);
|
|
23
|
+
return (0, generate_middlewares_1.generateMiddlewaresTemplate)(options);
|
|
23
24
|
default:
|
|
24
25
|
throw new Error(`\n Unknown template type: ${type}`);
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
|
-
function generateControllerTemplate(options) {
|
|
28
|
-
const { modelName, imports } = options;
|
|
29
|
-
if (!modelName)
|
|
30
|
-
throw new Error("Model name is required for controller template");
|
|
31
|
-
return `import { BaseController } from "${imports?.baseController || "arkos/controllers"}";
|
|
32
|
-
|
|
33
|
-
class ${modelName.pascal}Controller extends BaseController {
|
|
34
|
-
constructor() {
|
|
35
|
-
super("${modelName.kebab}");
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const ${modelName.camel}Controller = new ${modelName.pascal}Controller();
|
|
40
|
-
|
|
41
|
-
export default ${modelName.camel}Controller;
|
|
42
|
-
`;
|
|
43
|
-
}
|
|
44
|
-
function generateServiceTemplate(options) {
|
|
45
|
-
const { modelName, imports } = options;
|
|
46
|
-
const ext = (0, fs_helpers_1.getUserFileExtension)();
|
|
47
|
-
const isTypeScript = ext === "ts";
|
|
48
|
-
if (!modelName)
|
|
49
|
-
throw new Error("Model name is required for service template");
|
|
50
|
-
const prismaImport = isTypeScript
|
|
51
|
-
? `import { prisma } from "../../utils/prisma";\n`
|
|
52
|
-
: "";
|
|
53
|
-
const baseServiceImport = isTypeScript
|
|
54
|
-
? `import { BaseService } from "${imports?.baseService || "arkos/services"}";`
|
|
55
|
-
: `import { BaseService } from "${imports?.baseService || "arkos/services"}";`;
|
|
56
|
-
const typeParameter = isTypeScript
|
|
57
|
-
? `<typeof prisma.${modelName.camel}>`
|
|
58
|
-
: "";
|
|
59
|
-
return `${prismaImport}${baseServiceImport}
|
|
60
|
-
|
|
61
|
-
class ${modelName.pascal}Service extends BaseService${typeParameter} {
|
|
62
|
-
constructor() {
|
|
63
|
-
super("${modelName.kebab}");
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Add your custom service methods here
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const ${modelName.camel}Service = new ${modelName.pascal}Service();
|
|
70
|
-
|
|
71
|
-
export default ${modelName.camel}Service;
|
|
72
|
-
`;
|
|
73
|
-
}
|
|
74
|
-
function generateRouterTemplate(options) {
|
|
75
|
-
const { modelName, imports } = options;
|
|
76
|
-
if (!modelName)
|
|
77
|
-
throw new Error("Model name is required for router template");
|
|
78
|
-
const ext = (0, fs_helpers_1.getUserFileExtension)();
|
|
79
|
-
const controllerPath = imports?.controller || `./${modelName.kebab}.controller.${ext}`;
|
|
80
|
-
const controllerExists = (0, fs_helpers_1.checkFileExists)(controllerPath);
|
|
81
|
-
const controllerImportLine = controllerExists
|
|
82
|
-
? `import ${modelName.camel}Controller from "${imports?.controller || `./${modelName.kebab}.controller`}"`
|
|
83
|
-
: `// import ${modelName.camel}Controller from "${imports?.controller || `./${modelName.kebab}.controller`}"`;
|
|
84
|
-
const controllerHandlerLine = controllerExists
|
|
85
|
-
? ` ${modelName.camel}Controller.someHandler`
|
|
86
|
-
: ` // ${modelName.camel}Controller.someHandler`;
|
|
87
|
-
return `import { Router } from 'express'
|
|
88
|
-
import { authService } from 'arkos/services'
|
|
89
|
-
${controllerImportLine}
|
|
90
|
-
|
|
91
|
-
const ${modelName.camel}Router = Router()
|
|
92
|
-
|
|
93
|
-
${modelName.camel}Router.post(
|
|
94
|
-
'/custom-endpoint', // resolves to /api/${(0, pluralize_1.default)(modelName.kebab)}/custom-endpoint
|
|
95
|
-
authService.authenticate,
|
|
96
|
-
authService.handleAccessControl('CustomAction', '${modelName.kebab}'),
|
|
97
|
-
${controllerHandlerLine}
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
export default ${modelName.camel}Router
|
|
101
|
-
`;
|
|
102
|
-
}
|
|
103
|
-
function generateAuthConfigsTemplate(options) {
|
|
104
|
-
const { modelName } = options;
|
|
105
|
-
const ext = (0, fs_helpers_1.getUserFileExtension)();
|
|
106
|
-
const isTypeScript = ext === "ts";
|
|
107
|
-
if (!modelName)
|
|
108
|
-
throw new Error("Model name is required for auth config template");
|
|
109
|
-
const imports = isTypeScript
|
|
110
|
-
? `import { AuthConfigs } from 'arkos/prisma';\n`
|
|
111
|
-
: "";
|
|
112
|
-
const typeAnnotation = isTypeScript ? `: AuthConfigs` : "";
|
|
113
|
-
return `${imports}
|
|
114
|
-
const ${modelName.camel}AuthConfigs${typeAnnotation} = {
|
|
115
|
-
authenticationControl: {
|
|
116
|
-
// Create: true,
|
|
117
|
-
// Update: true,
|
|
118
|
-
// Delete: true,
|
|
119
|
-
// View: false,
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
// Only when using Static RBAC
|
|
123
|
-
accessControl: {
|
|
124
|
-
// Create: ["Admin"],
|
|
125
|
-
// Update: ["Admin", "Manager"],
|
|
126
|
-
// Delete: ["Admin"],
|
|
127
|
-
// View: ["User", "Admin", "Guest"],
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
export default ${modelName.camel}AuthConfigs;
|
|
132
|
-
`;
|
|
133
|
-
}
|
|
134
|
-
function generateQueryOptionsTemplate(options) {
|
|
135
|
-
const { modelName } = options;
|
|
136
|
-
const isAuth = modelName?.camel === "auth";
|
|
137
|
-
const ext = (0, fs_helpers_1.getUserFileExtension)();
|
|
138
|
-
const isTypeScript = ext === "ts";
|
|
139
|
-
if (!modelName)
|
|
140
|
-
throw new Error("Model name is required for query config template");
|
|
141
|
-
const imports = isAuth
|
|
142
|
-
? `import { AuthPrismaQueryOptions } from 'arkos/prisma'`
|
|
143
|
-
: `import { PrismaQueryOptions } from 'arkos/prisma'`;
|
|
144
|
-
const typeAnnotation = isTypeScript
|
|
145
|
-
? isAuth
|
|
146
|
-
? `: AuthPrismaQueryOptions<typeof prisma.${modelName.camel}>`
|
|
147
|
-
: `: PrismaQueryOptions<typeof prisma.${modelName.camel}>`
|
|
148
|
-
: "";
|
|
149
|
-
const prismaImport = isTypeScript
|
|
150
|
-
? `import { prisma } from "../../utils/prisma";\n`
|
|
151
|
-
: "";
|
|
152
|
-
if (isAuth) {
|
|
153
|
-
return `${prismaImport}${imports};
|
|
154
|
-
|
|
155
|
-
const ${modelName.camel}QueryOptions${typeAnnotation} = {
|
|
156
|
-
getMe: {},
|
|
157
|
-
updateMe: {},
|
|
158
|
-
deleteMe: {},
|
|
159
|
-
login: {},
|
|
160
|
-
signup: {},
|
|
161
|
-
updatePassword: {},
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export default ${modelName.camel}QueryOptions;
|
|
165
|
-
`;
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
return `${prismaImport}${imports};
|
|
169
|
-
|
|
170
|
-
const ${modelName.camel}QueryOptions${typeAnnotation} = {
|
|
171
|
-
// for all queries
|
|
172
|
-
queryOptions: {},
|
|
173
|
-
findOne: {},
|
|
174
|
-
findMany: {},
|
|
175
|
-
deleteMany: {},
|
|
176
|
-
updateMany: {},
|
|
177
|
-
createMany: {},
|
|
178
|
-
createOne: {},
|
|
179
|
-
updateOne: {},
|
|
180
|
-
deleteOne: {},
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export default ${modelName.camel}QueryOptions;
|
|
184
|
-
`;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
function generateMiddlewaresTemplate(options) {
|
|
188
|
-
const { modelName } = options;
|
|
189
|
-
const ext = (0, fs_helpers_1.getUserFileExtension)();
|
|
190
|
-
const isTypeScript = ext === "ts";
|
|
191
|
-
if (!modelName)
|
|
192
|
-
throw new Error("Model name is required for middleware template");
|
|
193
|
-
const isAuth = modelName.camel === "auth";
|
|
194
|
-
const isFileUpload = modelName.camel === "fileUpload" || modelName.camel === "file-upload";
|
|
195
|
-
const requestType = isTypeScript ? "ArkosRequest" : "req";
|
|
196
|
-
const responseType = isTypeScript ? "ArkosResponse" : "res";
|
|
197
|
-
const nextType = isTypeScript ? "ArkosNextFunction" : "next";
|
|
198
|
-
const baseImports = isTypeScript
|
|
199
|
-
? `import { ArkosRequest, ArkosResponse, ArkosNextFunction } from "arkos";
|
|
200
|
-
import { catchAsync } from "arkos/error-handler";`
|
|
201
|
-
: `import { catchAsync } from "arkos/error-handler";`;
|
|
202
|
-
const functionParams = isTypeScript
|
|
203
|
-
? `req: ${requestType}, res: ${responseType}, next: ${nextType}`
|
|
204
|
-
: `req, res, next`;
|
|
205
|
-
if (isAuth) {
|
|
206
|
-
return `${baseImports}
|
|
207
|
-
|
|
208
|
-
// export const beforeGetMe = catchAsync(
|
|
209
|
-
// async (${functionParams}) => {
|
|
210
|
-
// // Your logic here
|
|
211
|
-
// next();
|
|
212
|
-
// }
|
|
213
|
-
// );
|
|
214
|
-
|
|
215
|
-
// export const afterGetMe = catchAsync(
|
|
216
|
-
// async (${functionParams}) => {
|
|
217
|
-
// // Your logic here
|
|
218
|
-
// next();
|
|
219
|
-
// }
|
|
220
|
-
// );
|
|
221
|
-
|
|
222
|
-
// export const beforeLogin = catchAsync(
|
|
223
|
-
// async (${functionParams}) => {
|
|
224
|
-
// // Your logic here
|
|
225
|
-
// next();
|
|
226
|
-
// }
|
|
227
|
-
// );
|
|
228
|
-
|
|
229
|
-
// export const afterLogin = catchAsync(
|
|
230
|
-
// async (${functionParams}) => {
|
|
231
|
-
// // Your logic here
|
|
232
|
-
// next();
|
|
233
|
-
// }
|
|
234
|
-
// );
|
|
235
|
-
|
|
236
|
-
// export const beforeLogout = catchAsync(
|
|
237
|
-
// async (${functionParams}) => {
|
|
238
|
-
// // Your logic here
|
|
239
|
-
// next();
|
|
240
|
-
// }
|
|
241
|
-
// );
|
|
242
|
-
|
|
243
|
-
// export const afterLogout = catchAsync(
|
|
244
|
-
// async (${functionParams}) => {
|
|
245
|
-
// // Your logic here
|
|
246
|
-
// next();
|
|
247
|
-
// }
|
|
248
|
-
// );
|
|
249
|
-
|
|
250
|
-
// export const beforeSignup = catchAsync(
|
|
251
|
-
// async (${functionParams}) => {
|
|
252
|
-
// // Your logic here
|
|
253
|
-
// next();
|
|
254
|
-
// }
|
|
255
|
-
// );
|
|
256
|
-
|
|
257
|
-
// export const afterSignup = catchAsync(
|
|
258
|
-
// async (${functionParams}) => {
|
|
259
|
-
// // Your logic here
|
|
260
|
-
// next();
|
|
261
|
-
// }
|
|
262
|
-
// );
|
|
263
|
-
|
|
264
|
-
// export const beforeUpdatePassword = catchAsync(
|
|
265
|
-
// async (${functionParams}) => {
|
|
266
|
-
// // Your logic here
|
|
267
|
-
// next();
|
|
268
|
-
// }
|
|
269
|
-
// );
|
|
270
|
-
|
|
271
|
-
// export const afterUpdatePassword = catchAsync(
|
|
272
|
-
// async (${functionParams}) => {
|
|
273
|
-
// // Your logic here
|
|
274
|
-
// next();
|
|
275
|
-
// }
|
|
276
|
-
// );
|
|
277
|
-
`;
|
|
278
|
-
}
|
|
279
|
-
if (isFileUpload) {
|
|
280
|
-
return `${baseImports}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
// export const beforeFindFile = catchAsync(
|
|
284
|
-
// async (${functionParams}) => {
|
|
285
|
-
// // Your logic here
|
|
286
|
-
// next();
|
|
287
|
-
// }
|
|
288
|
-
// );
|
|
289
|
-
|
|
290
|
-
// There is not afterFindFile: because the main handler is handleded by express.static()
|
|
291
|
-
|
|
292
|
-
// export const beforeUploadFile = catchAsync(
|
|
293
|
-
// async (${functionParams}) => {
|
|
294
|
-
// // Your logic here
|
|
295
|
-
// next();
|
|
296
|
-
// }
|
|
297
|
-
// );
|
|
298
|
-
|
|
299
|
-
// export const afterUploadFile = catchAsync(
|
|
300
|
-
// async (${functionParams}) => {
|
|
301
|
-
// // Your logic here
|
|
302
|
-
// next();
|
|
303
|
-
// }
|
|
304
|
-
// );
|
|
305
|
-
|
|
306
|
-
// export const beforeUpdateFile = catchAsync(
|
|
307
|
-
// async (${functionParams}) => {
|
|
308
|
-
// // Your logic here
|
|
309
|
-
// next();
|
|
310
|
-
// }
|
|
311
|
-
// );
|
|
312
|
-
|
|
313
|
-
// export const afterUpdateFile = catchAsync(
|
|
314
|
-
// async (${functionParams}) => {
|
|
315
|
-
// // Your logic here
|
|
316
|
-
// next();
|
|
317
|
-
// }
|
|
318
|
-
// );
|
|
319
|
-
|
|
320
|
-
// export const beforeDeleteFile = catchAsync(
|
|
321
|
-
// async (${functionParams}) => {
|
|
322
|
-
// // Your logic here
|
|
323
|
-
// next();
|
|
324
|
-
// }
|
|
325
|
-
// );
|
|
326
|
-
|
|
327
|
-
// export const afterDeleteFile = catchAsync(
|
|
328
|
-
// async (${functionParams}) => {
|
|
329
|
-
// // Your logic here
|
|
330
|
-
// next();
|
|
331
|
-
// }
|
|
332
|
-
// );
|
|
333
|
-
`;
|
|
334
|
-
}
|
|
335
|
-
return `${baseImports}
|
|
336
|
-
|
|
337
|
-
// export const beforeCreateOne = catchAsync(
|
|
338
|
-
// async (${functionParams}) => {
|
|
339
|
-
// // Your logic here
|
|
340
|
-
// next();
|
|
341
|
-
// }
|
|
342
|
-
// );
|
|
343
|
-
|
|
344
|
-
// export const afterCreateOne = catchAsync(
|
|
345
|
-
// async (${functionParams}) => {
|
|
346
|
-
// // Your logic here
|
|
347
|
-
// next();
|
|
348
|
-
// }
|
|
349
|
-
// );
|
|
350
|
-
|
|
351
|
-
// export const beforeFindOne = catchAsync(
|
|
352
|
-
// async (${functionParams}) => {
|
|
353
|
-
// // Your logic here
|
|
354
|
-
// next();
|
|
355
|
-
// }
|
|
356
|
-
// );
|
|
357
|
-
|
|
358
|
-
// export const afterFindOne = catchAsync(
|
|
359
|
-
// async (${functionParams}) => {
|
|
360
|
-
// // Your logic here
|
|
361
|
-
// next();
|
|
362
|
-
// }
|
|
363
|
-
// );
|
|
364
|
-
|
|
365
|
-
// export const beforeFindMany = catchAsync(
|
|
366
|
-
// async (${functionParams}) => {
|
|
367
|
-
// // Your logic here
|
|
368
|
-
// next();
|
|
369
|
-
// }
|
|
370
|
-
// );
|
|
371
|
-
|
|
372
|
-
// export const afterFindMany = catchAsync(
|
|
373
|
-
// async (${functionParams}) => {
|
|
374
|
-
// // Your logic here
|
|
375
|
-
// next();
|
|
376
|
-
// }
|
|
377
|
-
// );
|
|
378
|
-
|
|
379
|
-
// export const beforeUpdateOne = catchAsync(
|
|
380
|
-
// async (${functionParams}) => {
|
|
381
|
-
// // Your logic here
|
|
382
|
-
// next();
|
|
383
|
-
// }
|
|
384
|
-
// );
|
|
385
|
-
|
|
386
|
-
// export const afterUpdateOne = catchAsync(
|
|
387
|
-
// async (${functionParams}) => {
|
|
388
|
-
// // Your logic here
|
|
389
|
-
// next();
|
|
390
|
-
// }
|
|
391
|
-
// );
|
|
392
|
-
|
|
393
|
-
// export const beforeDeleteOne = catchAsync(
|
|
394
|
-
// async (${functionParams}) => {
|
|
395
|
-
// // Your logic here
|
|
396
|
-
// next();
|
|
397
|
-
// }
|
|
398
|
-
// );
|
|
399
|
-
|
|
400
|
-
// export const afterDeleteOne = catchAsync(
|
|
401
|
-
// async (${functionParams}) => {
|
|
402
|
-
// // Your logic here
|
|
403
|
-
// next();
|
|
404
|
-
// }
|
|
405
|
-
// );
|
|
406
|
-
|
|
407
|
-
// export const beforeCreateMany = catchAsync(
|
|
408
|
-
// async (${functionParams}) => {
|
|
409
|
-
// // Your logic here
|
|
410
|
-
// next();
|
|
411
|
-
// }
|
|
412
|
-
// );
|
|
413
|
-
|
|
414
|
-
// export const afterCreateMany = catchAsync(
|
|
415
|
-
// async (${functionParams}) => {
|
|
416
|
-
// // Your logic here
|
|
417
|
-
// next();
|
|
418
|
-
// }
|
|
419
|
-
// );
|
|
420
|
-
|
|
421
|
-
// export const beforeUpdateMany = catchAsync(
|
|
422
|
-
// async (${functionParams}) => {
|
|
423
|
-
// // Your logic here
|
|
424
|
-
// next();
|
|
425
|
-
// }
|
|
426
|
-
// );
|
|
427
|
-
|
|
428
|
-
// export const afterUpdateMany = catchAsync(
|
|
429
|
-
// async (${functionParams}) => {
|
|
430
|
-
// // Your logic here
|
|
431
|
-
// next();
|
|
432
|
-
// }
|
|
433
|
-
// );
|
|
434
|
-
|
|
435
|
-
// export const beforeDeleteMany = catchAsync(
|
|
436
|
-
// async (${functionParams}) => {
|
|
437
|
-
// // Your logic here
|
|
438
|
-
// next();
|
|
439
|
-
// }
|
|
440
|
-
// );
|
|
441
|
-
|
|
442
|
-
// export const afterDeleteMany = catchAsync(
|
|
443
|
-
// async (${functionParams}) => {
|
|
444
|
-
// // Your logic here
|
|
445
|
-
// next();
|
|
446
|
-
// }
|
|
447
|
-
// );
|
|
448
|
-
`;
|
|
449
|
-
}
|
|
450
28
|
//# sourceMappingURL=template-generators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-generators.js","sourceRoot":"","sources":["../../../../../src/utils/cli/utils/template-generators.ts"],"names":[],"mappings":";;;;;AAwBA,4CAoBC;AA5CD,0DAAkC;AAClC,yDAGkC;AAoBlC,SAAgB,gBAAgB,CAC9B,IAAY,EACZ,UAA2B,EAAE;IAE7B,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,YAAY;YACf,OAAO,0BAA0B,CAAC,OAAO,CAAC,CAAC;QAC7C,KAAK,SAAS;YACZ,OAAO,uBAAuB,CAAC,OAAO,CAAC,CAAC;QAC1C,KAAK,QAAQ;YACX,OAAO,sBAAsB,CAAC,OAAO,CAAC,CAAC;QACzC,KAAK,cAAc;YACjB,OAAO,2BAA2B,CAAC,OAAO,CAAC,CAAC;QAC9C,KAAK,eAAe;YAClB,OAAO,4BAA4B,CAAC,OAAO,CAAC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c;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;CAK3B,CAAC;IACA,CAAC;IAED,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,GAAG,WAAW;;;;cAIX,cAAc;;;;;;;;;cASd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;CAK3B,CAAC;IACA,CAAC;IAGD,OAAO,GAAG,WAAW;;;cAGT,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;;;cAOd,cAAc;;;;;CAK3B,CAAC;AACF,CAAC","sourcesContent":["import pluralize from \"pluralize\";\nimport {\n checkFileExists,\n getUserFileExtension,\n} from \"../../helpers/fs.helpers\";\n\ninterface ModelName {\n pascal: string;\n camel: string;\n kebab: string;\n}\n\ninterface MiddlewareName {\n pascal: string;\n camel: string;\n kebab: string;\n}\n\ninterface TemplateOptions {\n modelName?: ModelName;\n middlewareName?: MiddlewareName;\n imports?: Record<string, string>;\n}\n\nexport function generateTemplate(\n type: string,\n options: TemplateOptions = {}\n): string {\n switch (type) {\n case \"controller\":\n return generateControllerTemplate(options);\n case \"service\":\n return generateServiceTemplate(options);\n case \"router\":\n return generateRouterTemplate(options);\n case \"auth-configs\":\n return generateAuthConfigsTemplate(options);\n case \"query-options\":\n return generateQueryOptionsTemplate(options);\n case \"middlewares\":\n return generateMiddlewaresTemplate(options);\n default:\n throw new Error(`\\n Unknown template type: ${type}`);\n }\n}\n\nfunction 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 \n class ${modelName.pascal}Controller extends BaseController {\n constructor() {\n super(\"${modelName.kebab}\");\n }\n }\n \n const ${modelName.camel}Controller = new ${modelName.pascal}Controller();\n \n export default ${modelName.camel}Controller;\n `;\n}\n\nfunction generateServiceTemplate(options: TemplateOptions): string {\n const { modelName, imports } = options;\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n\n if (!modelName)\n throw new Error(\"Model name is required for service template\");\n\n // Generate imports\n const prismaImport = isTypeScript\n ? `import { prisma } from \"../../utils/prisma\";\\n`\n : \"\";\n\n const baseServiceImport = isTypeScript\n ? `import { BaseService } from \"${\n imports?.baseService || \"arkos/services\"\n }\";`\n : `import { BaseService } from \"${\n imports?.baseService || \"arkos/services\"\n }\";`;\n\n // Generate type parameter for TypeScript\n const typeParameter = isTypeScript\n ? `<typeof prisma.${modelName.camel}>`\n : \"\";\n\n return `${prismaImport}${baseServiceImport}\n \nclass ${modelName.pascal}Service extends BaseService${typeParameter} {\n constructor() {\n super(\"${modelName.kebab}\");\n }\n\n // Add your custom service methods here\n}\n\nconst ${modelName.camel}Service = new ${modelName.pascal}Service();\n\nexport default ${modelName.camel}Service;\n`;\n}\n\nfunction 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 controllerExists = checkFileExists(controllerPath);\n\n const controllerImportLine = controllerExists\n ? `import ${modelName.camel}Controller from \"${\n imports?.controller || `./${modelName.kebab}.controller`\n }\"`\n : `// import ${modelName.camel}Controller from \"${\n imports?.controller || `./${modelName.kebab}.controller`\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'\n${controllerImportLine}\n\nconst ${modelName.camel}Router = Router()\n\n${modelName.camel}Router.post(\n '/custom-endpoint', // resolves to /api/${pluralize(\n modelName.kebab\n )}/custom-endpoint\n authService.authenticate,\n authService.handleAccessControl('CustomAction', '${modelName.kebab}'),\n${controllerHandlerLine}\n)\n\nexport default ${modelName.camel}Router\n`;\n}\n\nfunction 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/prisma';\\n`\n : \"\";\n\n // Generate type annotation for TypeScript\n const typeAnnotation = isTypeScript ? `: AuthConfigs` : \"\";\n\n return `${imports}\nconst ${modelName.camel}AuthConfigs${typeAnnotation} = {\n authenticationControl: {\n // Create: true,\n // Update: true,\n // Delete: true,\n // View: false,\n },\n \n // Only when using Static RBAC\n accessControl: {\n // Create: [\"Admin\"],\n // Update: [\"Admin\", \"Manager\"],\n // Delete: [\"Admin\"],\n // View: [\"User\", \"Admin\", \"Guest\"],\n },\n};\n\nexport default ${modelName.camel}AuthConfigs;\n`;\n}\n\nfunction 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(\"Model name is required for query config template\");\n\n // Generate imports\n const imports = isAuth\n ? `import { AuthPrismaQueryOptions } from 'arkos/prisma'`\n : `import { PrismaQueryOptions } from 'arkos/prisma'`;\n\n // Generate type annotation for TypeScript\n const typeAnnotation = isTypeScript\n ? isAuth\n ? `: AuthPrismaQueryOptions<typeof prisma.${modelName.camel}>`\n : `: PrismaQueryOptions<typeof prisma.${modelName.camel}>`\n : \"\";\n\n // Generate prisma import if TypeScript\n const prismaImport = isTypeScript\n ? `import { prisma } from \"../../utils/prisma\";\\n`\n : \"\";\n\n if (isAuth) {\n // Auth template\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 // Regular template\n return `${prismaImport}${imports};\n\nconst ${modelName.camel}QueryOptions${typeAnnotation} = {\n // for all queries\n queryOptions: {},\n findOne: {},\n findMany: {},\n deleteMany: {},\n updateMany: {},\n createMany: {},\n createOne: {},\n updateOne: {},\n deleteOne: {},\n}\n\nexport default ${modelName.camel}QueryOptions;\n`;\n }\n}\n\nfunction 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(\"Model 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 // Generate imports based on TypeScript/JavaScript\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\";\nimport { catchAsync } from \"arkos/error-handler\";`\n : `import { catchAsync } from \"arkos/error-handler\";`;\n\n const functionParams = isTypeScript\n ? `req: ${requestType}, res: ${responseType}, next: ${nextType}`\n : `req, res, next`;\n\n if (isAuth) {\n return `${baseImports}\n\n// export const beforeGetMe = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterGetMe = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeLogin = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterLogin = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeLogout = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterLogout = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeSignup = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterSignup = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeUpdatePassword = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterUpdatePassword = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n`;\n }\n\n if (isFileUpload) {\n return `${baseImports}\n\n\n// export const beforeFindFile = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// There is not afterFindFile: because the main handler is handleded by express.static()\n\n// export const beforeUploadFile = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterUploadFile = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeUpdateFile = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterUpdateFile = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeDeleteFile = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterDeleteFile = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n`;\n }\n\n // Regular model middlewares\n return `${baseImports}\n\n// export const beforeCreateOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterCreateOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeFindOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterFindOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeFindMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterFindMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeUpdateOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterUpdateOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeDeleteOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterDeleteOne = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeCreateMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterCreateMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeUpdateMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterUpdateMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const beforeDeleteMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n\n// export const afterDeleteMany = catchAsync(\n// async (${functionParams}) => {\n// // Your logic here\n// next();\n// }\n// );\n`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"template-generators.js","sourceRoot":"","sources":["../../../../../src/utils/cli/utils/template-generators.ts"],"names":[],"mappings":";;AAyBA,4CAoBC;AA7CD,8GAAyG;AACzG,kHAA4G;AAC5G,8FAAkG;AAClG,gHAA4G;AAC5G,sGAAiG;AACjG,wGAAmG;AAoBnG,SAAgB,gBAAgB,CAC9B,IAAY,EACZ,UAA2B,EAAE;IAE7B,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,YAAY;YACf,OAAO,IAAA,yDAA0B,EAAC,OAAO,CAAC,CAAC;QAC7C,KAAK,SAAS;YACZ,OAAO,IAAA,mDAAuB,EAAC,OAAO,CAAC,CAAC;QAC1C,KAAK,QAAQ;YACX,OAAO,IAAA,iDAAsB,EAAC,OAAO,CAAC,CAAC;QACzC,KAAK,cAAc;YACjB,OAAO,IAAA,4DAA2B,EAAC,OAAO,CAAC,CAAC;QAC9C,KAAK,eAAe;YAClB,OAAO,IAAA,4DAA4B,EAAC,OAAO,CAAC,CAAC;QAC/C,KAAK,aAAa;YAChB,OAAO,IAAA,kDAA2B,EAAC,OAAO,CAAC,CAAC;QAC9C;YACE,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;AACH,CAAC","sourcesContent":["import { generateControllerTemplate } from \"./template-generator/templates/generate-controller-template\";\nimport { generateAuthConfigsTemplate } from \"./template-generator/templates/generate-auth-configs-template\";\nimport { generateMiddlewaresTemplate } from \"./template-generator/templates/generate-middlewares\";\nimport { generateQueryOptionsTemplate } from \"./template-generator/templates/generate-prisma-query-options\";\nimport { generateRouterTemplate } from \"./template-generator/templates/generate-router-template\";\nimport { generateServiceTemplate } from \"./template-generator/templates/generate-service-template\";\n\ninterface ModelName {\n pascal: string;\n camel: string;\n kebab: string;\n}\n\ninterface MiddlewareName {\n pascal: string;\n camel: string;\n kebab: string;\n}\n\nexport interface TemplateOptions {\n modelName?: ModelName;\n middlewareName?: MiddlewareName;\n imports?: Record<string, string>;\n}\n\nexport function generateTemplate(\n type: string,\n options: TemplateOptions = {}\n): string {\n switch (type) {\n case \"controller\":\n return generateControllerTemplate(options);\n case \"service\":\n return generateServiceTemplate(options);\n case \"router\":\n return generateRouterTemplate(options);\n case \"auth-configs\":\n return generateAuthConfigsTemplate(options);\n case \"query-options\":\n return generateQueryOptionsTemplate(options);\n case \"middlewares\":\n return generateMiddlewaresTemplate(options);\n default:\n throw new Error(`\\n Unknown template type: ${type}`);\n }\n}\n"]}
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getUserFileExtension = exports.userFileExtension = exports.crd = exports.mkdirAsync = exports.accessAsync = exports.statAsync = void 0;
|
|
7
|
+
exports.fullCleanCwd = fullCleanCwd;
|
|
7
8
|
exports.checkFileExists = checkFileExists;
|
|
8
9
|
const util_1 = require("util");
|
|
9
10
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -15,6 +16,12 @@ const crd = () => process.env.ARKOS_BUILD === "true"
|
|
|
15
16
|
? process.cwd() + "/.build/"
|
|
16
17
|
: process.cwd();
|
|
17
18
|
exports.crd = crd;
|
|
19
|
+
function fullCleanCwd(path) {
|
|
20
|
+
if (typeof path !== "string")
|
|
21
|
+
throw new Error("Path must be a string");
|
|
22
|
+
const cwd = process.cwd().replace(/\/+$/, "");
|
|
23
|
+
return path.replace(new RegExp(`^${cwd}/?`), "");
|
|
24
|
+
}
|
|
18
25
|
const getUserFileExtension = () => {
|
|
19
26
|
if (exports.userFileExtension)
|
|
20
27
|
return exports.userFileExtension;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/fs.helpers.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"fs.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/fs.helpers.ts"],"names":[],"mappings":";;;;;;AAoBA,oCAKC;AAkDD,0CAMC;AAjFD,+BAAiC;AACjC,4CAAoB;AACpB,gDAAwB;AAEX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I,CAAC;QAC3B,CAAC;QAED,OAAO,yBAAiB,CAAC;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QAEX,yBAAiB,GAAG,IAAI,CAAC;QACzB,OAAO,yBAAiB,CAAC;IAC3B,CAAC;AACH,CAAC,CAAC;AAzBW,QAAA,oBAAoB,wBAyB/B;AAgBF,SAAgB,eAAe,CAAC,QAAgB;IAC9C,IAAI,CAAC;QACH,OAAO,YAAE,CAAC,UAAU,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["import { promisify } from \"util\";\nimport fs from \"fs\";\nimport path from \"path\";\n\nexport const statAsync = promisify(fs.stat);\nexport const accessAsync = promisify(fs.access);\nexport const mkdirAsync = promisify(fs.mkdir);\n\nexport const crd = () =>\n process.env.ARKOS_BUILD === \"true\"\n ? process.cwd() + \"/.build/\"\n : process.cwd();\n\n/**\n * Removes the current working directory prefix from the given path.\n * Handles cases with or without a trailing slash in cwd.\n *\n * @param path - The path to clean\n * @returns The path without the cwd prefix\n */\nexport function fullCleanCwd(path: string): string {\n if (typeof path !== \"string\") throw new Error(\"Path must be a string\");\n\n const cwd = process.cwd().replace(/\\/+$/, \"\"); // remove trailing slashes\n return path.replace(new RegExp(`^${cwd}/?`), \"\"); // remove cwd + optional slash\n}\n\nexport let userFileExtension: \"ts\" | \"js\" | undefined;\n\n/**\n * Detects the file extension that should be used in the current execution context\n * Returns 'ts' when TypeScript config exists and not in build mode, otherwise 'js'\n * @returns 'ts' | 'js'\n */\nexport const getUserFileExtension = (): \"ts\" | \"js\" => {\n if (userFileExtension) return userFileExtension;\n\n try {\n const currentDir = process.cwd();\n\n // Check for tsconfig.json in current directory\n const hasTsConfig = fs.existsSync(path.join(currentDir, \"tsconfig.json\"));\n\n // Check environment variable for build mode\n const isBuildMode = process.env.ARKOS_BUILD === \"true\";\n\n // If tsconfig exists and not in build mode, use TypeScript\n if (hasTsConfig && !isBuildMode) {\n userFileExtension = \"ts\";\n } else {\n userFileExtension = \"js\";\n }\n\n return userFileExtension;\n } catch (e) {\n // Default to js if anything goes wrong\n userFileExtension = \"js\";\n return userFileExtension;\n }\n};\n\n/**\n * Checks if a file exists at the specified file path.\n *\n * @param filePath - The path to the file to check\n * @returns {boolean} True if the file exists, false otherwise or if there's an error\n *\n * @example\n * ```ts\n * const exists = checkFileExists('./path/to/file.txt');\n * if (exists) {\n * console.log('File exists!');\n * }\n * ```\n */\nexport function checkFileExists(filePath: string): boolean {\n try {\n return fs.existsSync(path.resolve(filePath));\n } catch (error) {\n return false;\n }\n}\n"]}
|
|
@@ -31,7 +31,7 @@ export const authControllerFactory = async (middlewares = {}) => {
|
|
|
31
31
|
}),
|
|
32
32
|
updateMe: catchAsync(async (req, res, next) => {
|
|
33
33
|
if ("password" in req.body)
|
|
34
|
-
throw new AppError("In order to update password use the update-password endpoint.", 400, {}, "
|
|
34
|
+
throw new AppError("In order to update password use the update-password endpoint.", 400, {}, "InvalidFieldPassword");
|
|
35
35
|
const user = (await userService.updateOne({ id: req.user.id }, req.body, req.prismaQueryOptions || {}));
|
|
36
36
|
Object.keys(defaultExcludedUserFields).forEach((key) => {
|
|
37
37
|
if (user)
|