sigo-entities 1.2.389 → 1.2.390
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/.ai_context.md +50 -0
- package/build.log +0 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/functionGenerateDto.ts +168 -168
- package/generateDtos.ts +32 -32
- package/package.json +38 -38
- package/test.ts +12 -12
package/.ai_context.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Contexto del Proyecto
|
|
2
|
+
|
|
3
|
+
**Nombre:** Ingeniero Brayan Valero
|
|
4
|
+
**Preferencias de idioma:** Español (Indispensable)
|
|
5
|
+
**Formato de Planes y Tareas:** Siempre en Español
|
|
6
|
+
**Contexto del proyecto:** Librería transversal para entidades compartidas (Front y Back)
|
|
7
|
+
**Nombre del Asistente:** Latas
|
|
8
|
+
|
|
9
|
+
**Tipo de Proyecto:** Shared Library
|
|
10
|
+
**Ubicación Raíz:** `d:\16_SIGO_ENTITYS\sigo-entities`
|
|
11
|
+
|
|
12
|
+
Este archivo contiene la visión general del proyecto `sigo-entities`.
|
|
13
|
+
|
|
14
|
+
## Descripción
|
|
15
|
+
`sigo-entities` es la librería donde se alojan las entidades compartidas por front y back. En ambos hay un archivo de contexto llamado `.ai_context.md`, donde almacenamos la configuración del proyecto, estructura del mismo y contexto de workflows para tareas futuras.
|
|
16
|
+
|
|
17
|
+
## Normas Generales
|
|
18
|
+
1. **Archivos de Contexto**: Mantener actualizados los `.ai_context.md` locales.
|
|
19
|
+
2. **Git Ignore**: Asegurarse de que `**/.ai_context.md` esté ignorado.
|
|
20
|
+
3. **sigo-entities**: Librería transversal para tipos compartidos.
|
|
21
|
+
|
|
22
|
+
## Guía de Desarrollo de Entidades y DTOs
|
|
23
|
+
|
|
24
|
+
### Estructura de Carpetas
|
|
25
|
+
- **DTOs compartidos**: `src/programados/procesos/[Entidad]/shared`
|
|
26
|
+
- **Request DTOs**: `src/programados/procesos/[Entidad]/shared/requestDto`
|
|
27
|
+
|
|
28
|
+
### Convenciones de Nombres
|
|
29
|
+
- **Archivos**: `kebab-case` con sufijo `-dto.ts` (ej. `job-macro-request-dto.ts`).
|
|
30
|
+
- **Clases**: `PascalCase` con sufijo `DTO` (ej. `JobMacroRequestDTO`).
|
|
31
|
+
|
|
32
|
+
### Reglas de Implementación
|
|
33
|
+
1. **Librerías**: Usar `class-transformer` (@Expose, @Type) y `class-validator` (IsString, IsNumber, etc.).
|
|
34
|
+
2. **Mensajes de Validación**: Deben ser en español (ej. "debe ser un texto", "es requerido").
|
|
35
|
+
3. **Inicialización**: Todas las propiedades deben tener valor inicial (ej. `string = ''`, `number = 0`).
|
|
36
|
+
4. **Exposición**: Decorar todas las propiedades con `@Expose()`.
|
|
37
|
+
|
|
38
|
+
## Proceso de Despliegue (sigo-entities)
|
|
39
|
+
|
|
40
|
+
1. **Validación**: Confirmar que la nueva entidad o DTO es correcto y cumple con las normas (preguntar al usuario).
|
|
41
|
+
- *Aprendizaje*: No incluir campos como `UsuarioEdicion` si el backend puede obtenerlos del token. Los DTOs de actualización deben ser lo más minimalistas posible (ID, nuevos valores, observaciones).
|
|
42
|
+
2. **Sincronización Inicial**: Bajar cambios (`git pull`) y subir cambios de la nueva entidad (`git push`).
|
|
43
|
+
3. **Versionamiento**: Incrementar la versión en el `package.json` (ej: `1.2.205` -> `1.2.206`).
|
|
44
|
+
4. **Sincronización de Versión**: Bajar y subir cambios nuevamente para asegurar la versión en el repositorio.
|
|
45
|
+
5. **Publicación**: Ejecutar `npm publish`.
|
|
46
|
+
6. **Actualización en Servicios**:
|
|
47
|
+
- Posicionarse en el servicio (Back/Front) objetivo mediante el comando `cd`.
|
|
48
|
+
- Ejecutar `npm i sigo-entities@latest`.
|
|
49
|
+
- Verificar importaciones.
|
|
50
|
+
- *Aprendizaje*: Los DTOs de procesos deben exportarse desde el `index.ts` principal de la entidad (ej. `obra/index.ts`) y no solo desde el `shared/index.ts`.
|
package/build.log
ADDED
|
Binary file
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -50392,6 +50392,7 @@ __decorateClass([
|
|
|
50392
50392
|
|
|
50393
50393
|
// src/v2/enums/CompanyType.ts
|
|
50394
50394
|
var CompanyType = /* @__PURE__ */ ((CompanyType2) => {
|
|
50395
|
+
CompanyType2["OPERATIVA"] = "Operativa";
|
|
50395
50396
|
CompanyType2["PROVEEDOR"] = "Proveedor";
|
|
50396
50397
|
return CompanyType2;
|
|
50397
50398
|
})(CompanyType || {});
|
package/dist/index.mjs
CHANGED
|
@@ -49910,6 +49910,7 @@ __decorateClass([
|
|
|
49910
49910
|
|
|
49911
49911
|
// src/v2/enums/CompanyType.ts
|
|
49912
49912
|
var CompanyType = /* @__PURE__ */ ((CompanyType2) => {
|
|
49913
|
+
CompanyType2["OPERATIVA"] = "Operativa";
|
|
49913
49914
|
CompanyType2["PROVEEDOR"] = "Proveedor";
|
|
49914
49915
|
return CompanyType2;
|
|
49915
49916
|
})(CompanyType || {});
|
package/functionGenerateDto.ts
CHANGED
|
@@ -1,169 +1,169 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import { ClassDeclaration, Project, PropertyDeclaration } from 'ts-morph'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Obtiene todas las propiedades de una clase, incluyendo las heredadas de otros archivos.
|
|
6
|
-
*/
|
|
7
|
-
function getAllProperties(entityClass: ClassDeclaration): { allProperties: PropertyDeclaration[], imports: string[] } {
|
|
8
|
-
let allProperties: PropertyDeclaration[] = [...entityClass.getProperties()];
|
|
9
|
-
let baseClass = entityClass.getBaseClass();
|
|
10
|
-
let imports: string[] = [];
|
|
11
|
-
const baseSourceFile = entityClass.getSourceFile();
|
|
12
|
-
baseSourceFile.getImportDeclarations().forEach(importDecl => {
|
|
13
|
-
imports.push(importDecl.getText())
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
while (baseClass) {
|
|
17
|
-
// Asegurarse de agregar las propiedades de la clase base
|
|
18
|
-
allProperties = [...baseClass.getProperties(), ...allProperties];
|
|
19
|
-
|
|
20
|
-
const baseClassSource = baseClass.getSourceFile();
|
|
21
|
-
|
|
22
|
-
const baseSourceFile = baseClass.getSourceFile();
|
|
23
|
-
baseSourceFile.getImportDeclarations().forEach(importDecl => {
|
|
24
|
-
imports.push(importDecl.getText())
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
if (!baseClassSource.wasForgotten()) {
|
|
28
|
-
baseClass = baseClass.getBaseClass();
|
|
29
|
-
} else {
|
|
30
|
-
break; // Si no puede seguir buscando, detenemos el proceso
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return { allProperties, imports };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function buildImports(imports: string[]) {
|
|
38
|
-
const mergedMap: Map<string, Map<string, boolean>> = imports.reduce((ac: Map<string, Map<string, boolean>>, el: string) => {
|
|
39
|
-
const normalizedImport: string = el.replace(/\s+/g, ' ').trim();
|
|
40
|
-
const matchModuleName = normalizedImport.match(/from\s+['"]([^'"]+)['"]/);
|
|
41
|
-
if (matchModuleName) {
|
|
42
|
-
const moduleName: string = matchModuleName[1];
|
|
43
|
-
const matchImports = normalizedImport.match(/import\s*{([^}]+)}/);
|
|
44
|
-
if (matchImports) {
|
|
45
|
-
const importsArray: string[] = matchImports[1]
|
|
46
|
-
.split(',')
|
|
47
|
-
.map((item: string) => item.trim())
|
|
48
|
-
.filter((item: string) => item.length > 0);
|
|
49
|
-
if (importsArray.length) {
|
|
50
|
-
if (!ac.has(moduleName)) {
|
|
51
|
-
ac.set(moduleName, new Map<string, boolean>());
|
|
52
|
-
}
|
|
53
|
-
const innerMap = ac.get(moduleName)!;
|
|
54
|
-
importsArray.forEach((symbol: string) => innerMap.set(symbol, true));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return ac;
|
|
59
|
-
}, new Map<string, Map<string, boolean>>());
|
|
60
|
-
|
|
61
|
-
const uniqueImportStatements: string = Array.from(mergedMap.entries())
|
|
62
|
-
.map(([moduleName, symbolsMap]: [string, Map<string, boolean>]) => {
|
|
63
|
-
const symbolsArray: string[] = Array.from(symbolsMap.keys());
|
|
64
|
-
return `import { ${symbolsArray.join(', ')} } from '${moduleName}';`;
|
|
65
|
-
})
|
|
66
|
-
.join('\n');
|
|
67
|
-
return uniqueImportStatements
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Genera un DTO parcial a partir de una entidad TypeScript, manteniendo validaciones y valores por defecto.
|
|
72
|
-
* @param entityFilePath Ruta del archivo que contiene la entidad (ej: './entities/UserENTITY.ts')
|
|
73
|
-
* @param entityClassName Nombre de la clase dentro del archivo (ej: 'UserENTITY')
|
|
74
|
-
* @param dtoName Nombre de la clase DTO a generar (ej: 'PartialUserDTO')
|
|
75
|
-
* @param fields Campos que deben incluirse en el DTO (ej: ['_id', 'email', 'identity'])
|
|
76
|
-
* @param outputDir Directorio donde se guardará el DTO (ej: './dtos')
|
|
77
|
-
*/
|
|
78
|
-
export function generateDTO<T>(
|
|
79
|
-
entityFilePath: string,
|
|
80
|
-
entityClassName: string,
|
|
81
|
-
dtoName: string,
|
|
82
|
-
fields: (keyof T)[],
|
|
83
|
-
outputDir: string = './src/v2/dtos',
|
|
84
|
-
entityAux?: { entityFilePath: string, entityClassName: string },
|
|
85
|
-
base: boolean = false
|
|
86
|
-
) {
|
|
87
|
-
// Inicializar ts-morph y cargar el archivo de la entidad
|
|
88
|
-
const project = new Project({
|
|
89
|
-
tsConfigFilePath: './tsconfig.json', // Asegura que se analicen correctamente las importaciones
|
|
90
|
-
});
|
|
91
|
-
const sourceFile = project.addSourceFileAtPath(entityFilePath);
|
|
92
|
-
|
|
93
|
-
// Obtener la clase de la entidad
|
|
94
|
-
const entityClass = sourceFile.getClass(entityClassName);
|
|
95
|
-
if (!entityClass) {
|
|
96
|
-
console.error(`❌ No se encontró la clase ${entityClassName} en ${entityFilePath}`);
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const dtoProperties: string[] = [];
|
|
101
|
-
|
|
102
|
-
const { allProperties, imports } = getAllProperties(entityClass)
|
|
103
|
-
|
|
104
|
-
allProperties.forEach(prop => {
|
|
105
|
-
const propName = prop.getName() as keyof T
|
|
106
|
-
if (!fields.includes(propName)) return
|
|
107
|
-
dtoProperties.push(prop.getFullText());
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
//#region EntityAux
|
|
111
|
-
if (entityAux) {
|
|
112
|
-
const sourceFile = project.addSourceFileAtPath(entityAux.entityFilePath);
|
|
113
|
-
|
|
114
|
-
// Obtener la clase de la entidad
|
|
115
|
-
const entityClass = sourceFile.getClass(entityAux.entityClassName);
|
|
116
|
-
if (!entityClass) {
|
|
117
|
-
console.error(`❌ No se encontró la clase auxiliar ${entityAux.entityClassName} en ${entityAux.entityFilePath}`);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const { allProperties, imports: _imports } = getAllProperties(entityClass)
|
|
122
|
-
|
|
123
|
-
allProperties.forEach(prop => {
|
|
124
|
-
dtoProperties.push(prop.getFullText());
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
imports.push(..._imports)
|
|
128
|
-
}
|
|
129
|
-
//#endregion
|
|
130
|
-
|
|
131
|
-
// Generar el código del DTO
|
|
132
|
-
const dtoCode = `
|
|
133
|
-
${buildImports(imports)}
|
|
134
|
-
|
|
135
|
-
export class ${dtoName}${base ? ` extends BaseEntity` : ''} {${dtoProperties.join('')}
|
|
136
|
-
}
|
|
137
|
-
`
|
|
138
|
-
|
|
139
|
-
// Crear el directorio si no existe
|
|
140
|
-
if (!fs.existsSync(outputDir)) {
|
|
141
|
-
fs.mkdirSync(outputDir);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Guardar el archivo DTO
|
|
145
|
-
const dtoFilePath = `${outputDir}/${dtoName.split('Dto')[0]}.ts`;
|
|
146
|
-
fs.writeFileSync(dtoFilePath, dtoCode);
|
|
147
|
-
|
|
148
|
-
console.log(`✅ Dto ${dtoName} generado en ${dtoFilePath}`);
|
|
149
|
-
|
|
150
|
-
// Actualizar index.ts
|
|
151
|
-
const indexPath = `${outputDir}/index.ts`
|
|
152
|
-
const exportLine = `export * from './${dtoName.split('Dto')[0]}'`
|
|
153
|
-
|
|
154
|
-
let indexContent = ''
|
|
155
|
-
|
|
156
|
-
if (fs.existsSync(indexPath)) {
|
|
157
|
-
indexContent = fs.readFileSync(indexPath, 'utf8')
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (!indexContent.includes(exportLine)) {
|
|
161
|
-
const newContent = indexContent
|
|
162
|
-
? `${indexContent.trimEnd()}\n${exportLine}\n`
|
|
163
|
-
: `${exportLine}\n`
|
|
164
|
-
|
|
165
|
-
fs.writeFileSync(indexPath, newContent)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
console.log(`✅ Export agregado en ${indexPath}`)
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import { ClassDeclaration, Project, PropertyDeclaration } from 'ts-morph'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Obtiene todas las propiedades de una clase, incluyendo las heredadas de otros archivos.
|
|
6
|
+
*/
|
|
7
|
+
function getAllProperties(entityClass: ClassDeclaration): { allProperties: PropertyDeclaration[], imports: string[] } {
|
|
8
|
+
let allProperties: PropertyDeclaration[] = [...entityClass.getProperties()];
|
|
9
|
+
let baseClass = entityClass.getBaseClass();
|
|
10
|
+
let imports: string[] = [];
|
|
11
|
+
const baseSourceFile = entityClass.getSourceFile();
|
|
12
|
+
baseSourceFile.getImportDeclarations().forEach(importDecl => {
|
|
13
|
+
imports.push(importDecl.getText())
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
while (baseClass) {
|
|
17
|
+
// Asegurarse de agregar las propiedades de la clase base
|
|
18
|
+
allProperties = [...baseClass.getProperties(), ...allProperties];
|
|
19
|
+
|
|
20
|
+
const baseClassSource = baseClass.getSourceFile();
|
|
21
|
+
|
|
22
|
+
const baseSourceFile = baseClass.getSourceFile();
|
|
23
|
+
baseSourceFile.getImportDeclarations().forEach(importDecl => {
|
|
24
|
+
imports.push(importDecl.getText())
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (!baseClassSource.wasForgotten()) {
|
|
28
|
+
baseClass = baseClass.getBaseClass();
|
|
29
|
+
} else {
|
|
30
|
+
break; // Si no puede seguir buscando, detenemos el proceso
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return { allProperties, imports };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function buildImports(imports: string[]) {
|
|
38
|
+
const mergedMap: Map<string, Map<string, boolean>> = imports.reduce((ac: Map<string, Map<string, boolean>>, el: string) => {
|
|
39
|
+
const normalizedImport: string = el.replace(/\s+/g, ' ').trim();
|
|
40
|
+
const matchModuleName = normalizedImport.match(/from\s+['"]([^'"]+)['"]/);
|
|
41
|
+
if (matchModuleName) {
|
|
42
|
+
const moduleName: string = matchModuleName[1];
|
|
43
|
+
const matchImports = normalizedImport.match(/import\s*{([^}]+)}/);
|
|
44
|
+
if (matchImports) {
|
|
45
|
+
const importsArray: string[] = matchImports[1]
|
|
46
|
+
.split(',')
|
|
47
|
+
.map((item: string) => item.trim())
|
|
48
|
+
.filter((item: string) => item.length > 0);
|
|
49
|
+
if (importsArray.length) {
|
|
50
|
+
if (!ac.has(moduleName)) {
|
|
51
|
+
ac.set(moduleName, new Map<string, boolean>());
|
|
52
|
+
}
|
|
53
|
+
const innerMap = ac.get(moduleName)!;
|
|
54
|
+
importsArray.forEach((symbol: string) => innerMap.set(symbol, true));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return ac;
|
|
59
|
+
}, new Map<string, Map<string, boolean>>());
|
|
60
|
+
|
|
61
|
+
const uniqueImportStatements: string = Array.from(mergedMap.entries())
|
|
62
|
+
.map(([moduleName, symbolsMap]: [string, Map<string, boolean>]) => {
|
|
63
|
+
const symbolsArray: string[] = Array.from(symbolsMap.keys());
|
|
64
|
+
return `import { ${symbolsArray.join(', ')} } from '${moduleName}';`;
|
|
65
|
+
})
|
|
66
|
+
.join('\n');
|
|
67
|
+
return uniqueImportStatements
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Genera un DTO parcial a partir de una entidad TypeScript, manteniendo validaciones y valores por defecto.
|
|
72
|
+
* @param entityFilePath Ruta del archivo que contiene la entidad (ej: './entities/UserENTITY.ts')
|
|
73
|
+
* @param entityClassName Nombre de la clase dentro del archivo (ej: 'UserENTITY')
|
|
74
|
+
* @param dtoName Nombre de la clase DTO a generar (ej: 'PartialUserDTO')
|
|
75
|
+
* @param fields Campos que deben incluirse en el DTO (ej: ['_id', 'email', 'identity'])
|
|
76
|
+
* @param outputDir Directorio donde se guardará el DTO (ej: './dtos')
|
|
77
|
+
*/
|
|
78
|
+
export function generateDTO<T>(
|
|
79
|
+
entityFilePath: string,
|
|
80
|
+
entityClassName: string,
|
|
81
|
+
dtoName: string,
|
|
82
|
+
fields: (keyof T)[],
|
|
83
|
+
outputDir: string = './src/v2/dtos',
|
|
84
|
+
entityAux?: { entityFilePath: string, entityClassName: string },
|
|
85
|
+
base: boolean = false
|
|
86
|
+
) {
|
|
87
|
+
// Inicializar ts-morph y cargar el archivo de la entidad
|
|
88
|
+
const project = new Project({
|
|
89
|
+
tsConfigFilePath: './tsconfig.json', // Asegura que se analicen correctamente las importaciones
|
|
90
|
+
});
|
|
91
|
+
const sourceFile = project.addSourceFileAtPath(entityFilePath);
|
|
92
|
+
|
|
93
|
+
// Obtener la clase de la entidad
|
|
94
|
+
const entityClass = sourceFile.getClass(entityClassName);
|
|
95
|
+
if (!entityClass) {
|
|
96
|
+
console.error(`❌ No se encontró la clase ${entityClassName} en ${entityFilePath}`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const dtoProperties: string[] = [];
|
|
101
|
+
|
|
102
|
+
const { allProperties, imports } = getAllProperties(entityClass)
|
|
103
|
+
|
|
104
|
+
allProperties.forEach(prop => {
|
|
105
|
+
const propName = prop.getName() as keyof T
|
|
106
|
+
if (!fields.includes(propName)) return
|
|
107
|
+
dtoProperties.push(prop.getFullText());
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
//#region EntityAux
|
|
111
|
+
if (entityAux) {
|
|
112
|
+
const sourceFile = project.addSourceFileAtPath(entityAux.entityFilePath);
|
|
113
|
+
|
|
114
|
+
// Obtener la clase de la entidad
|
|
115
|
+
const entityClass = sourceFile.getClass(entityAux.entityClassName);
|
|
116
|
+
if (!entityClass) {
|
|
117
|
+
console.error(`❌ No se encontró la clase auxiliar ${entityAux.entityClassName} en ${entityAux.entityFilePath}`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const { allProperties, imports: _imports } = getAllProperties(entityClass)
|
|
122
|
+
|
|
123
|
+
allProperties.forEach(prop => {
|
|
124
|
+
dtoProperties.push(prop.getFullText());
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
imports.push(..._imports)
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
|
|
131
|
+
// Generar el código del DTO
|
|
132
|
+
const dtoCode = `
|
|
133
|
+
${buildImports(imports)}
|
|
134
|
+
|
|
135
|
+
export class ${dtoName}${base ? ` extends BaseEntity` : ''} {${dtoProperties.join('')}
|
|
136
|
+
}
|
|
137
|
+
`
|
|
138
|
+
|
|
139
|
+
// Crear el directorio si no existe
|
|
140
|
+
if (!fs.existsSync(outputDir)) {
|
|
141
|
+
fs.mkdirSync(outputDir);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Guardar el archivo DTO
|
|
145
|
+
const dtoFilePath = `${outputDir}/${dtoName.split('Dto')[0]}.ts`;
|
|
146
|
+
fs.writeFileSync(dtoFilePath, dtoCode);
|
|
147
|
+
|
|
148
|
+
console.log(`✅ Dto ${dtoName} generado en ${dtoFilePath}`);
|
|
149
|
+
|
|
150
|
+
// Actualizar index.ts
|
|
151
|
+
const indexPath = `${outputDir}/index.ts`
|
|
152
|
+
const exportLine = `export * from './${dtoName.split('Dto')[0]}'`
|
|
153
|
+
|
|
154
|
+
let indexContent = ''
|
|
155
|
+
|
|
156
|
+
if (fs.existsSync(indexPath)) {
|
|
157
|
+
indexContent = fs.readFileSync(indexPath, 'utf8')
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (!indexContent.includes(exportLine)) {
|
|
161
|
+
const newContent = indexContent
|
|
162
|
+
? `${indexContent.trimEnd()}\n${exportLine}\n`
|
|
163
|
+
: `${exportLine}\n`
|
|
164
|
+
|
|
165
|
+
fs.writeFileSync(indexPath, newContent)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
console.log(`✅ Export agregado en ${indexPath}`)
|
|
169
169
|
}
|
package/generateDtos.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { generateDTO } from './functionGenerateDto'
|
|
2
|
-
import { ProfileEntity } from '@Entities/Profile'
|
|
3
|
-
import { UserEntity } from '@Entities/User'
|
|
4
|
-
const path = './src/v2/entities'
|
|
5
|
-
|
|
6
|
-
function Bootstrap() {
|
|
7
|
-
generateDTO<UserEntity>(
|
|
8
|
-
`${path}/User.ts`,
|
|
9
|
-
'UserEntity',
|
|
10
|
-
'AuthUserDto',
|
|
11
|
-
['profileId', 'email', 'firstNames', 'identification', 'maternalLastName', 'paternalLastName', 'root']
|
|
12
|
-
)
|
|
13
|
-
generateDTO<ProfileEntity>(
|
|
14
|
-
`${path}/Profile.ts`,
|
|
15
|
-
'ProfileEntity',
|
|
16
|
-
'CreateProfileDto',
|
|
17
|
-
['_id', 'name', 'description', 'systemOptions']
|
|
18
|
-
)
|
|
19
|
-
generateDTO<ProfileEntity>(
|
|
20
|
-
`${path}/Profile.ts`,
|
|
21
|
-
'ProfileEntity',
|
|
22
|
-
'UpdateProfileDto',
|
|
23
|
-
['name', 'description', 'systemOptions', 'active']
|
|
24
|
-
)
|
|
25
|
-
generateDTO<ProfileEntity>(
|
|
26
|
-
`${path}/Profile.ts`,
|
|
27
|
-
'ProfileEntity',
|
|
28
|
-
'ProfileDto',
|
|
29
|
-
['name', 'description']
|
|
30
|
-
)
|
|
31
|
-
}
|
|
32
|
-
|
|
1
|
+
import { generateDTO } from './functionGenerateDto'
|
|
2
|
+
import { ProfileEntity } from '@Entities/Profile'
|
|
3
|
+
import { UserEntity } from '@Entities/User'
|
|
4
|
+
const path = './src/v2/entities'
|
|
5
|
+
|
|
6
|
+
function Bootstrap() {
|
|
7
|
+
generateDTO<UserEntity>(
|
|
8
|
+
`${path}/User.ts`,
|
|
9
|
+
'UserEntity',
|
|
10
|
+
'AuthUserDto',
|
|
11
|
+
['profileId', 'email', 'firstNames', 'identification', 'maternalLastName', 'paternalLastName', 'root']
|
|
12
|
+
)
|
|
13
|
+
generateDTO<ProfileEntity>(
|
|
14
|
+
`${path}/Profile.ts`,
|
|
15
|
+
'ProfileEntity',
|
|
16
|
+
'CreateProfileDto',
|
|
17
|
+
['_id', 'name', 'description', 'systemOptions']
|
|
18
|
+
)
|
|
19
|
+
generateDTO<ProfileEntity>(
|
|
20
|
+
`${path}/Profile.ts`,
|
|
21
|
+
'ProfileEntity',
|
|
22
|
+
'UpdateProfileDto',
|
|
23
|
+
['name', 'description', 'systemOptions', 'active']
|
|
24
|
+
)
|
|
25
|
+
generateDTO<ProfileEntity>(
|
|
26
|
+
`${path}/Profile.ts`,
|
|
27
|
+
'ProfileEntity',
|
|
28
|
+
'ProfileDto',
|
|
29
|
+
['name', 'description']
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
33
|
Bootstrap()
|
package/package.json
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "sigo-entities",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"description": "Desarrollo de modelos de datos SIGO",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "tsup && tsc-alias",
|
|
10
|
-
"prepare": "npm run build",
|
|
11
|
-
"gen-dto": "ts-node ./generateDtos.ts"
|
|
12
|
-
},
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "git@github.com-trabajo:GRUPOCOBRA/sigo-entities.git"
|
|
16
|
-
},
|
|
17
|
-
"keywords": [],
|
|
18
|
-
"author": "usuario088",
|
|
19
|
-
"license": "ISC",
|
|
20
|
-
"devDependencies": {
|
|
21
|
-
"@types/express": "^5.0.1",
|
|
22
|
-
"sigo-package": "^1.2.132",
|
|
23
|
-
"ts-morph": "^28.0.0",
|
|
24
|
-
"tsc-alias": "^1.8.15",
|
|
25
|
-
"tsconfig-paths": "^4.2.0",
|
|
26
|
-
"tsup": "^8.1.0",
|
|
27
|
-
"typescript": "^5.4.5"
|
|
28
|
-
},
|
|
29
|
-
"dependencies": {
|
|
30
|
-
"class-transformer": "^0.5.1",
|
|
31
|
-
"class-validator": "^0.14.1"
|
|
32
|
-
},
|
|
33
|
-
"peerDependencies": {
|
|
34
|
-
"reflect-metadata": "^0.2.2"
|
|
35
|
-
},
|
|
36
|
-
"overrides": {
|
|
37
|
-
"esbuild": "^0.28.0"
|
|
38
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "sigo-entities",
|
|
3
|
+
"version": "1.2.390",
|
|
4
|
+
"description": "Desarrollo de modelos de datos SIGO",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsup && tsc-alias",
|
|
10
|
+
"prepare": "npm run build",
|
|
11
|
+
"gen-dto": "ts-node ./generateDtos.ts"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git@github.com-trabajo:GRUPOCOBRA/sigo-entities.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [],
|
|
18
|
+
"author": "usuario088",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/express": "^5.0.1",
|
|
22
|
+
"sigo-package": "^1.2.132",
|
|
23
|
+
"ts-morph": "^28.0.0",
|
|
24
|
+
"tsc-alias": "^1.8.15",
|
|
25
|
+
"tsconfig-paths": "^4.2.0",
|
|
26
|
+
"tsup": "^8.1.0",
|
|
27
|
+
"typescript": "^5.4.5"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"class-transformer": "^0.5.1",
|
|
31
|
+
"class-validator": "^0.14.1"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"reflect-metadata": "^0.2.2"
|
|
35
|
+
},
|
|
36
|
+
"overrides": {
|
|
37
|
+
"esbuild": "^0.28.0"
|
|
38
|
+
}
|
|
39
39
|
}
|
package/test.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { validateAndFormatData, CubicacionColombia9612ENTITY } from './src'
|
|
2
|
-
import { convertDates } from 'sigo-package'
|
|
3
|
-
import fs from 'fs'
|
|
4
|
-
|
|
5
|
-
// ts-node -r tsconfig-paths/register test.ts
|
|
6
|
-
|
|
7
|
-
async function test() {
|
|
8
|
-
const data = JSON.parse(fs.readFileSync('./body_testing.json', 'utf-8'))
|
|
9
|
-
convertDates(data)
|
|
10
|
-
console.log(await validateAndFormatData(data, CubicacionColombia9612ENTITY))
|
|
11
|
-
}
|
|
12
|
-
|
|
1
|
+
import { validateAndFormatData, CubicacionColombia9612ENTITY } from './src'
|
|
2
|
+
import { convertDates } from 'sigo-package'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
|
|
5
|
+
// ts-node -r tsconfig-paths/register test.ts
|
|
6
|
+
|
|
7
|
+
async function test() {
|
|
8
|
+
const data = JSON.parse(fs.readFileSync('./body_testing.json', 'utf-8'))
|
|
9
|
+
convertDates(data)
|
|
10
|
+
console.log(await validateAndFormatData(data, CubicacionColombia9612ENTITY))
|
|
11
|
+
}
|
|
12
|
+
|
|
13
13
|
test()
|