@currentjs/gen 0.3.2 → 0.5.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/CHANGELOG.md +18 -609
- package/README.md +623 -427
- package/dist/cli.js +2 -1
- package/dist/commands/commit.js +25 -42
- package/dist/commands/createApp.js +1 -0
- package/dist/commands/createModule.js +151 -45
- package/dist/commands/diff.js +27 -40
- package/dist/commands/generateAll.js +141 -291
- package/dist/commands/migrateCommit.js +6 -18
- package/dist/generators/controllerGenerator.d.ts +50 -19
- package/dist/generators/controllerGenerator.js +588 -331
- package/dist/generators/domainLayerGenerator.d.ts +21 -0
- package/dist/generators/domainLayerGenerator.js +286 -0
- package/dist/generators/dtoGenerator.d.ts +21 -0
- package/dist/generators/dtoGenerator.js +523 -0
- package/dist/generators/serviceGenerator.d.ts +22 -51
- package/dist/generators/serviceGenerator.js +345 -568
- package/dist/generators/storeGenerator.d.ts +39 -32
- package/dist/generators/storeGenerator.js +396 -236
- package/dist/generators/templateGenerator.d.ts +21 -21
- package/dist/generators/templateGenerator.js +393 -268
- package/dist/generators/templates/appTemplates.d.ts +3 -1
- package/dist/generators/templates/appTemplates.js +16 -11
- package/dist/generators/templates/data/appYamlTemplate +5 -2
- package/dist/generators/templates/data/cursorRulesTemplate +315 -221
- package/dist/generators/templates/data/frontendScriptTemplate +56 -15
- package/dist/generators/templates/data/mainViewTemplate +2 -1
- package/dist/generators/templates/data/systemTsTemplate +5 -0
- package/dist/generators/templates/index.d.ts +0 -3
- package/dist/generators/templates/index.js +0 -3
- package/dist/generators/templates/storeTemplates.d.ts +1 -5
- package/dist/generators/templates/storeTemplates.js +84 -224
- package/dist/generators/useCaseGenerator.d.ts +13 -0
- package/dist/generators/useCaseGenerator.js +191 -0
- package/dist/types/configTypes.d.ts +149 -0
- package/dist/types/configTypes.js +10 -0
- package/dist/utils/childEntityUtils.d.ts +18 -0
- package/dist/utils/childEntityUtils.js +78 -0
- package/dist/utils/commandUtils.d.ts +43 -0
- package/dist/utils/commandUtils.js +124 -0
- package/dist/utils/commitUtils.d.ts +4 -1
- package/dist/utils/constants.d.ts +10 -0
- package/dist/utils/constants.js +13 -1
- package/dist/utils/diResolver.d.ts +32 -0
- package/dist/utils/diResolver.js +204 -0
- package/dist/utils/typeUtils.d.ts +23 -0
- package/dist/utils/typeUtils.js +77 -0
- package/package.json +7 -3
- package/dist/generators/domainModelGenerator.d.ts +0 -41
- package/dist/generators/domainModelGenerator.js +0 -242
- package/dist/generators/templates/controllerTemplates.d.ts +0 -43
- package/dist/generators/templates/controllerTemplates.js +0 -82
- package/dist/generators/templates/serviceTemplates.d.ts +0 -16
- package/dist/generators/templates/serviceTemplates.js +0 -59
- package/dist/generators/templates/validationTemplates.d.ts +0 -25
- package/dist/generators/templates/validationTemplates.js +0 -66
- package/dist/generators/templates/viewTemplates.d.ts +0 -25
- package/dist/generators/templates/viewTemplates.js +0 -491
- package/dist/generators/validationGenerator.d.ts +0 -29
- package/dist/generators/validationGenerator.js +0 -250
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.controllerFileTemplate = exports.controllerTemplates = void 0;
|
|
4
|
-
exports.controllerTemplates = {
|
|
5
|
-
controllerClass: `@Controller('{{CONTROLLER_BASE}}', {})
|
|
6
|
-
export class {{CONTROLLER_NAME}} {
|
|
7
|
-
constructor(
|
|
8
|
-
private {{ENTITY_LOWER}}Service: {{ENTITY_NAME}}Service
|
|
9
|
-
) {}
|
|
10
|
-
|
|
11
|
-
{{CONTROLLER_METHODS}}
|
|
12
|
-
}`,
|
|
13
|
-
controllerMethod: ` @{{HTTP_DECORATOR}}("{{ENDPOINT_PATH}}"){{RENDER_DECORATOR}}
|
|
14
|
-
async {{METHOD_NAME}}(context: IContext): Promise<{{RETURN_TYPE}}> {
|
|
15
|
-
{{METHOD_IMPLEMENTATION}}
|
|
16
|
-
}`,
|
|
17
|
-
userExtraction: ` const user = context.request.user;
|
|
18
|
-
if (!user) {
|
|
19
|
-
throw new Error('User authentication required');
|
|
20
|
-
}`,
|
|
21
|
-
methodImplementations: {
|
|
22
|
-
list: `{{USER_EXTRACTION}}
|
|
23
|
-
// Extract pagination from URL parameters
|
|
24
|
-
const page = parseInt(context.request.parameters.page as string) || 1;
|
|
25
|
-
const limit = parseInt(context.request.parameters.limit as string) || 10;
|
|
26
|
-
|
|
27
|
-
const {{ENTITY_LOWER}}s = await this.{{ENTITY_LOWER}}Service.list(page, limit{{USER_PARAM}});
|
|
28
|
-
return {{ENTITY_LOWER}}s;`,
|
|
29
|
-
get: `{{USER_EXTRACTION}}
|
|
30
|
-
const id = parseInt(context.request.parameters.id as string);
|
|
31
|
-
if (isNaN(id)) {
|
|
32
|
-
throw new Error('Invalid ID parameter');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const {{ENTITY_LOWER}} = await this.{{ENTITY_LOWER}}Service.get(id{{USER_PARAM}});
|
|
36
|
-
return {{ENTITY_LOWER}};`,
|
|
37
|
-
create: `{{USER_EXTRACTION}}
|
|
38
|
-
const new{{ENTITY_NAME}} = await this.{{ENTITY_LOWER}}Service.create(context.request.body as {{ENTITY_NAME}}DTO{{USER_PARAM}});
|
|
39
|
-
return new{{ENTITY_NAME}};`,
|
|
40
|
-
update: `{{USER_EXTRACTION}}
|
|
41
|
-
const id = parseInt(context.request.parameters.id as string);
|
|
42
|
-
if (isNaN(id)) {
|
|
43
|
-
throw new Error('Invalid ID parameter');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const updated{{ENTITY_NAME}} = await this.{{ENTITY_LOWER}}Service.update(id, context.request.body as {{ENTITY_NAME}}DTO{{USER_PARAM}});
|
|
47
|
-
return updated{{ENTITY_NAME}};`,
|
|
48
|
-
delete: `{{USER_EXTRACTION}}
|
|
49
|
-
const id = parseInt(context.request.parameters.id as string);
|
|
50
|
-
if (isNaN(id)) {
|
|
51
|
-
throw new Error('Invalid ID parameter');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const result = await this.{{ENTITY_LOWER}}Service.delete(id{{USER_PARAM}});
|
|
55
|
-
return result;`,
|
|
56
|
-
empty: `{{USER_EXTRACTION}}
|
|
57
|
-
// Provide an empty/default {{ENTITY_NAME}} for create form rendering
|
|
58
|
-
// Note: actual create happens via API endpoint using custom form handling
|
|
59
|
-
return {} as any;`
|
|
60
|
-
},
|
|
61
|
-
responseFormats: {
|
|
62
|
-
list: `{ data: {{ENTITY_LOWER}}s, page, limit }`,
|
|
63
|
-
get: `{ data: {{ENTITY_LOWER}} }`,
|
|
64
|
-
create: `{ data: new{{ENTITY_NAME}}, message: '{{ENTITY_NAME}} created successfully' }`,
|
|
65
|
-
update: `{ data: updated{{ENTITY_NAME}}, message: '{{ENTITY_NAME}} updated successfully' }`,
|
|
66
|
-
delete: `result`
|
|
67
|
-
},
|
|
68
|
-
statusCodes: {
|
|
69
|
-
list: { success: 200, error: 500 },
|
|
70
|
-
get: { success: 200, error: 404 },
|
|
71
|
-
create: { success: 201, error: 400 },
|
|
72
|
-
update: { success: 200, error: 400 },
|
|
73
|
-
delete: { success: 200, error: 400 }
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
exports.controllerFileTemplate = `import { {{ENTITY_NAME}} } from '../../domain/entities/{{ENTITY_NAME}}';
|
|
77
|
-
import { {{ENTITY_NAME}}Service } from '../../application/services/{{ENTITY_NAME}}Service';
|
|
78
|
-
import { {{ENTITY_NAME}}DTO } from '../../application/validation/{{ENTITY_NAME}}Validation';{{JWT_IMPORT}}
|
|
79
|
-
import { Get, Post, Put, Patch, Delete, Controller, Render } from '@currentjs/router';
|
|
80
|
-
import type { IContext } from '@currentjs/router';
|
|
81
|
-
|
|
82
|
-
{{CONTROLLER_CLASS}}`;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export declare const serviceTemplates: {
|
|
2
|
-
serviceClass: string;
|
|
3
|
-
serviceMethod: string;
|
|
4
|
-
permissionCheck: string;
|
|
5
|
-
ownerPermissionCheck: string;
|
|
6
|
-
defaultImplementations: {
|
|
7
|
-
list: string;
|
|
8
|
-
get: string;
|
|
9
|
-
getById: string;
|
|
10
|
-
create: string;
|
|
11
|
-
update: string;
|
|
12
|
-
delete: string;
|
|
13
|
-
};
|
|
14
|
-
customActionImplementation: string;
|
|
15
|
-
};
|
|
16
|
-
export declare const serviceFileTemplate = "import { {{ENTITY_NAME}} } from '../../domain/entities/{{ENTITY_NAME}}';\nimport { {{ENTITY_NAME}}Store } from '../../infrastructure/stores/{{ENTITY_NAME}}Store';\nimport { {{ENTITY_NAME}}DTO, validateCreate{{ENTITY_NAME}}, validateUpdate{{ENTITY_NAME}} } from '../validation/{{ENTITY_NAME}}Validation';{{PERMISSIONS_IMPORT}}{{CUSTOM_IMPORTS}}\n\n{{SERVICE_CLASS}}";
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serviceFileTemplate = exports.serviceTemplates = void 0;
|
|
4
|
-
exports.serviceTemplates = {
|
|
5
|
-
serviceClass: `export class {{ENTITY_NAME}}Service {
|
|
6
|
-
constructor(
|
|
7
|
-
private {{ENTITY_LOWER}}Store: {{ENTITY_NAME}}Store{{AUTH_SERVICE_PARAM}}
|
|
8
|
-
) {}
|
|
9
|
-
|
|
10
|
-
{{SERVICE_METHODS}}
|
|
11
|
-
}`,
|
|
12
|
-
serviceMethod: ` async {{METHOD_NAME}}({{METHOD_PARAMS}}{{USER_PARAM}}): Promise<{{RETURN_TYPE}}> {
|
|
13
|
-
{{PERMISSION_CHECK}}
|
|
14
|
-
{{METHOD_IMPLEMENTATION}}
|
|
15
|
-
}`,
|
|
16
|
-
permissionCheck: ` // Role check: {{REQUIRED_ROLES}}
|
|
17
|
-
const allowedRoles = [{{ROLES_ARRAY}}];
|
|
18
|
-
if (allowedRoles.length > 0 && !allowedRoles.includes(user.role)) {
|
|
19
|
-
throw new Error('Insufficient permissions to perform this action');
|
|
20
|
-
}`,
|
|
21
|
-
ownerPermissionCheck: ``,
|
|
22
|
-
defaultImplementations: {
|
|
23
|
-
list: `const {{ENTITY_LOWER}}s = await this.{{ENTITY_LOWER}}Store.getAll(page, limit);
|
|
24
|
-
return {{ENTITY_LOWER}}s;`,
|
|
25
|
-
get: `const {{ENTITY_LOWER}} = await this.{{ENTITY_LOWER}}Store.getById(id);
|
|
26
|
-
if (!{{ENTITY_LOWER}}) {
|
|
27
|
-
throw new Error('{{ENTITY_NAME}} not found');
|
|
28
|
-
}
|
|
29
|
-
return {{ENTITY_LOWER}};`,
|
|
30
|
-
getById: `const {{ENTITY_LOWER}} = await this.{{ENTITY_LOWER}}Store.getById(id);
|
|
31
|
-
if (!{{ENTITY_LOWER}}) {
|
|
32
|
-
throw new Error('{{ENTITY_NAME}} not found');
|
|
33
|
-
}
|
|
34
|
-
return {{ENTITY_LOWER}};`,
|
|
35
|
-
create: `validateCreate{{ENTITY_NAME}}({{ENTITY_LOWER}}Data);
|
|
36
|
-
const {{ENTITY_LOWER}} = new {{ENTITY_NAME}}(0, {{CONSTRUCTOR_ARGS}});
|
|
37
|
-
return await this.{{ENTITY_LOWER}}Store.insert({{ENTITY_LOWER}});`,
|
|
38
|
-
update: `validateUpdate{{ENTITY_NAME}}({{ENTITY_LOWER}}Data);
|
|
39
|
-
const existing{{ENTITY_NAME}} = await this.{{ENTITY_LOWER}}Store.getById(id);
|
|
40
|
-
if (!existing{{ENTITY_NAME}}) {
|
|
41
|
-
throw new Error('{{ENTITY_NAME}} not found');
|
|
42
|
-
}
|
|
43
|
-
{{UPDATE_SETTER_CALLS}}
|
|
44
|
-
return await this.{{ENTITY_LOWER}}Store.update(id, existing{{ENTITY_NAME}});`,
|
|
45
|
-
delete: `const success = await this.{{ENTITY_LOWER}}Store.softDelete(id);
|
|
46
|
-
if (!success) {
|
|
47
|
-
throw new Error('{{ENTITY_NAME}} not found or could not be deleted');
|
|
48
|
-
}
|
|
49
|
-
return { success: true, message: '{{ENTITY_NAME}} deleted successfully' };`
|
|
50
|
-
},
|
|
51
|
-
customActionImplementation: `// Custom action implementation
|
|
52
|
-
const result = await {{CUSTOM_FUNCTION_CALL}};
|
|
53
|
-
return result;`
|
|
54
|
-
};
|
|
55
|
-
exports.serviceFileTemplate = `import { {{ENTITY_NAME}} } from '../../domain/entities/{{ENTITY_NAME}}';
|
|
56
|
-
import { {{ENTITY_NAME}}Store } from '../../infrastructure/stores/{{ENTITY_NAME}}Store';
|
|
57
|
-
import { {{ENTITY_NAME}}DTO, validateCreate{{ENTITY_NAME}}, validateUpdate{{ENTITY_NAME}} } from '../validation/{{ENTITY_NAME}}Validation';{{PERMISSIONS_IMPORT}}{{CUSTOM_IMPORTS}}
|
|
58
|
-
|
|
59
|
-
{{SERVICE_CLASS}}`;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export declare const validationTemplates: {
|
|
2
|
-
inputInterface: string;
|
|
3
|
-
validationFunction: string;
|
|
4
|
-
requiredStringValidation: string;
|
|
5
|
-
optionalStringValidation: string;
|
|
6
|
-
requiredNumberValidation: string;
|
|
7
|
-
optionalNumberValidation: string;
|
|
8
|
-
requiredBooleanValidation: string;
|
|
9
|
-
optionalBooleanValidation: string;
|
|
10
|
-
requiredDateValidation: string;
|
|
11
|
-
optionalDateValidation: string;
|
|
12
|
-
requiredComplexValidation: string;
|
|
13
|
-
optionalComplexValidation: string;
|
|
14
|
-
validationFileTemplate: string;
|
|
15
|
-
dtoInterface: string;
|
|
16
|
-
};
|
|
17
|
-
export declare const typeMapping: {
|
|
18
|
-
string: string;
|
|
19
|
-
number: string;
|
|
20
|
-
boolean: string;
|
|
21
|
-
datetime: string;
|
|
22
|
-
json: string;
|
|
23
|
-
object: string;
|
|
24
|
-
array: string;
|
|
25
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.typeMapping = exports.validationTemplates = void 0;
|
|
4
|
-
exports.validationTemplates = {
|
|
5
|
-
inputInterface: `export interface {{INTERFACE_NAME}} {
|
|
6
|
-
{{INTERFACE_FIELDS}}
|
|
7
|
-
}`,
|
|
8
|
-
validationFunction: `export function {{FUNCTION_NAME}}(data: any): boolean {
|
|
9
|
-
const errors: string[] = [];
|
|
10
|
-
|
|
11
|
-
{{VALIDATION_LOGIC}}
|
|
12
|
-
|
|
13
|
-
if (errors.length > 0) {
|
|
14
|
-
throw new Error(\`Validation failed: \${errors.join(', ')}\`);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return true;
|
|
18
|
-
}`,
|
|
19
|
-
requiredStringValidation: ` if (!data.{{FIELD_NAME}} || typeof data.{{FIELD_NAME}} !== 'string') {
|
|
20
|
-
errors.push('{{FIELD_NAME}} is required and must be a string');
|
|
21
|
-
}`,
|
|
22
|
-
optionalStringValidation: ` if (data.{{FIELD_NAME}} !== undefined && typeof data.{{FIELD_NAME}} !== 'string') {
|
|
23
|
-
errors.push('{{FIELD_NAME}} must be a string');
|
|
24
|
-
}`,
|
|
25
|
-
requiredNumberValidation: ` if (data.{{FIELD_NAME}} === undefined || data.{{FIELD_NAME}} === null || typeof data.{{FIELD_NAME}} !== 'number' || isNaN(data.{{FIELD_NAME}})) {
|
|
26
|
-
errors.push('{{FIELD_NAME}} is required and must be a number');
|
|
27
|
-
}`,
|
|
28
|
-
optionalNumberValidation: ` if (data.{{FIELD_NAME}} !== undefined && (typeof data.{{FIELD_NAME}} !== 'number' || isNaN(data.{{FIELD_NAME}}))) {
|
|
29
|
-
errors.push('{{FIELD_NAME}} must be a number');
|
|
30
|
-
}`,
|
|
31
|
-
requiredBooleanValidation: ` if (data.{{FIELD_NAME}} === undefined || data.{{FIELD_NAME}} === null || typeof data.{{FIELD_NAME}} !== 'boolean') {
|
|
32
|
-
errors.push('{{FIELD_NAME}} is required and must be a boolean');
|
|
33
|
-
}`,
|
|
34
|
-
optionalBooleanValidation: ` if (data.{{FIELD_NAME}} !== undefined && typeof data.{{FIELD_NAME}} !== 'boolean') {
|
|
35
|
-
errors.push('{{FIELD_NAME}} must be a boolean');
|
|
36
|
-
}`,
|
|
37
|
-
requiredDateValidation: ` if (!data.{{FIELD_NAME}} || !(data.{{FIELD_NAME}} instanceof Date) && isNaN(Date.parse(data.{{FIELD_NAME}}))) {
|
|
38
|
-
errors.push('{{FIELD_NAME}} is required and must be a valid date');
|
|
39
|
-
}`,
|
|
40
|
-
optionalDateValidation: ` if (data.{{FIELD_NAME}} !== undefined && !(data.{{FIELD_NAME}} instanceof Date) && isNaN(Date.parse(data.{{FIELD_NAME}}))) {
|
|
41
|
-
errors.push('{{FIELD_NAME}} must be a valid date');
|
|
42
|
-
}`,
|
|
43
|
-
// For complex types, just pass through for now
|
|
44
|
-
requiredComplexValidation: ` if (data.{{FIELD_NAME}} === undefined || data.{{FIELD_NAME}} === null) {
|
|
45
|
-
errors.push('{{FIELD_NAME}} is required');
|
|
46
|
-
}`,
|
|
47
|
-
optionalComplexValidation: ` // {{FIELD_NAME}} - complex type validation to be implemented later`,
|
|
48
|
-
validationFileTemplate: `// Generated validation for {{ENTITY_NAME}}
|
|
49
|
-
|
|
50
|
-
{{DTO_INTERFACES}}
|
|
51
|
-
|
|
52
|
-
{{VALIDATION_FUNCTIONS}}
|
|
53
|
-
`,
|
|
54
|
-
dtoInterface: `export interface {{DTO_NAME}} {
|
|
55
|
-
{{DTO_FIELDS}}
|
|
56
|
-
}`
|
|
57
|
-
};
|
|
58
|
-
exports.typeMapping = {
|
|
59
|
-
string: 'string',
|
|
60
|
-
number: 'number',
|
|
61
|
-
boolean: 'boolean',
|
|
62
|
-
datetime: 'Date',
|
|
63
|
-
json: 'any',
|
|
64
|
-
object: 'any',
|
|
65
|
-
array: 'any[]'
|
|
66
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
type FieldConfig = {
|
|
2
|
-
name: string;
|
|
3
|
-
type: string;
|
|
4
|
-
required?: boolean;
|
|
5
|
-
auto?: boolean;
|
|
6
|
-
unique?: boolean;
|
|
7
|
-
enum?: string[];
|
|
8
|
-
displayFields?: string[];
|
|
9
|
-
};
|
|
10
|
-
type RelationshipContext = {
|
|
11
|
-
routePaths: Map<string, string>;
|
|
12
|
-
apiPaths: Map<string, string>;
|
|
13
|
-
};
|
|
14
|
-
declare function setAvailableModels(models: string[]): void;
|
|
15
|
-
declare function setRelationshipContext(context: RelationshipContext): void;
|
|
16
|
-
declare function isRelationshipField(field: FieldConfig): boolean;
|
|
17
|
-
declare function getForeignKeyFieldName(field: FieldConfig): string;
|
|
18
|
-
export declare function toFileNameFromTemplateName(name: string): string;
|
|
19
|
-
export { setAvailableModels, setRelationshipContext, isRelationshipField, getForeignKeyFieldName };
|
|
20
|
-
export declare function renderListTemplate(entityName: string, templateName: string, basePath: string, fields: FieldConfig[], apiBase?: string): string;
|
|
21
|
-
export declare function renderDetailTemplate(entityName: string, templateName: string, fields: FieldConfig[]): string;
|
|
22
|
-
export declare function renderCreateTemplate(entityName: string, templateName: string, apiBase: string, fields: FieldConfig[], strategy?: string[], basePath?: string): string;
|
|
23
|
-
export declare function renderUpdateTemplate(entityName: string, templateName: string, apiBase: string, fields: FieldConfig[], strategy?: string[], basePath?: string): string;
|
|
24
|
-
export declare function renderDeleteTemplate(entityName: string, templateName: string, apiBase: string, strategy?: string[], basePath?: string): string;
|
|
25
|
-
export declare function renderLayoutTemplate(layoutName: string): string;
|