sigo-entities 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +76 -0
- package/dist/index.mjs +51 -0
- package/package.json +27 -0
package/README.md
ADDED
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
+
if (decorator = decorators[i])
|
|
23
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
+
if (kind && result) __defProp(target, key, result);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// src/index.ts
|
|
29
|
+
var src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
TrabajoENTITY: () => TrabajoENTITY,
|
|
32
|
+
validateAndFormatData: () => validateAndFormatData
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
|
|
36
|
+
// src/programados/trabajo/Alemania/index.ts
|
|
37
|
+
var import_class_transformer = require("class-transformer");
|
|
38
|
+
var import_class_validator = require("class-validator");
|
|
39
|
+
var TrabajoENTITY = class {
|
|
40
|
+
ID_Trabajo = 0;
|
|
41
|
+
};
|
|
42
|
+
__decorateClass([
|
|
43
|
+
(0, import_class_validator.IsNumber)({}, { message: "debe ser un numero" }),
|
|
44
|
+
(0, import_class_validator.IsNotEmpty)(),
|
|
45
|
+
(0, import_class_transformer.Expose)()
|
|
46
|
+
], TrabajoENTITY.prototype, "ID_Trabajo", 2);
|
|
47
|
+
|
|
48
|
+
// src/shared/utils/validarYFormatearDatos.ts
|
|
49
|
+
var import_class_transformer2 = require("class-transformer");
|
|
50
|
+
var import_class_validator2 = require("class-validator");
|
|
51
|
+
async function validateAndFormatData(data, dtoClass) {
|
|
52
|
+
const instance = (0, import_class_transformer2.plainToInstance)(dtoClass, data, { excludeExtraneousValues: true });
|
|
53
|
+
const errors = await (0, import_class_validator2.validate)(instance);
|
|
54
|
+
if (errors.length > 0) {
|
|
55
|
+
const formattedErrors = formatErrors(errors);
|
|
56
|
+
const errorMessage = `Response validation failed: ${formattedErrors[0]}`;
|
|
57
|
+
throw new Error(errorMessage);
|
|
58
|
+
}
|
|
59
|
+
return instance;
|
|
60
|
+
}
|
|
61
|
+
function formatErrors(errors, parentPath = "") {
|
|
62
|
+
return errors.flatMap((error) => {
|
|
63
|
+
const currentPath = parentPath ? `${parentPath}.${error.property}` : error.property;
|
|
64
|
+
if (error.constraints) {
|
|
65
|
+
return Object.values(error.constraints).map((constraint) => `${currentPath}: ${constraint}`);
|
|
66
|
+
} else if (error.children) {
|
|
67
|
+
return formatErrors(error.children, currentPath);
|
|
68
|
+
}
|
|
69
|
+
return ["Unknown validation error"];
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
TrabajoENTITY,
|
|
75
|
+
validateAndFormatData
|
|
76
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/programados/trabajo/Alemania/index.ts
|
|
13
|
+
import { Expose } from "class-transformer";
|
|
14
|
+
import { IsNotEmpty, IsNumber } from "class-validator";
|
|
15
|
+
var TrabajoENTITY = class {
|
|
16
|
+
ID_Trabajo = 0;
|
|
17
|
+
};
|
|
18
|
+
__decorateClass([
|
|
19
|
+
IsNumber({}, { message: "debe ser un numero" }),
|
|
20
|
+
IsNotEmpty(),
|
|
21
|
+
Expose()
|
|
22
|
+
], TrabajoENTITY.prototype, "ID_Trabajo", 2);
|
|
23
|
+
|
|
24
|
+
// src/shared/utils/validarYFormatearDatos.ts
|
|
25
|
+
import { plainToInstance } from "class-transformer";
|
|
26
|
+
import { validate } from "class-validator";
|
|
27
|
+
async function validateAndFormatData(data, dtoClass) {
|
|
28
|
+
const instance = plainToInstance(dtoClass, data, { excludeExtraneousValues: true });
|
|
29
|
+
const errors = await validate(instance);
|
|
30
|
+
if (errors.length > 0) {
|
|
31
|
+
const formattedErrors = formatErrors(errors);
|
|
32
|
+
const errorMessage = `Response validation failed: ${formattedErrors[0]}`;
|
|
33
|
+
throw new Error(errorMessage);
|
|
34
|
+
}
|
|
35
|
+
return instance;
|
|
36
|
+
}
|
|
37
|
+
function formatErrors(errors, parentPath = "") {
|
|
38
|
+
return errors.flatMap((error) => {
|
|
39
|
+
const currentPath = parentPath ? `${parentPath}.${error.property}` : error.property;
|
|
40
|
+
if (error.constraints) {
|
|
41
|
+
return Object.values(error.constraints).map((constraint) => `${currentPath}: ${constraint}`);
|
|
42
|
+
} else if (error.children) {
|
|
43
|
+
return formatErrors(error.children, currentPath);
|
|
44
|
+
}
|
|
45
|
+
return ["Unknown validation error"];
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
TrabajoENTITY,
|
|
50
|
+
validateAndFormatData
|
|
51
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sigo-entities",
|
|
3
|
+
"version": "0.0.1",
|
|
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",
|
|
10
|
+
"prepare": "npm run build"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git@github.com-trabajo:GRUPOCOBRA/sigo-entities.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"author": "usuario088",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"tsup": "^8.1.0",
|
|
21
|
+
"typescript": "^5.4.5"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"class-transformer": "^0.5.1",
|
|
25
|
+
"class-validator": "^0.14.1"
|
|
26
|
+
}
|
|
27
|
+
}
|