@autofleet/sadot 1.6.18-beta.20 → 1.6.18-beta.21
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/api/v1/validator/index.cjs +14 -1
- package/dist/api/v1/validator/index.js +15 -2
- package/dist/models/index.d.ts +4 -0
- package/dist/models/tests/AssociatedTestModel.d.ts +2 -0
- package/dist/models/tests/TestModel.d.ts +2 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.d.ts +2 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.d.ts +1 -0
- package/dist/repository/validator.cjs +27 -0
- package/dist/repository/validator.js +25 -1
- package/package.json +3 -3
|
@@ -57,7 +57,20 @@ router.get("/", async (req, res) => {
|
|
|
57
57
|
/**
|
|
58
58
|
* Effective
|
|
59
59
|
*/
|
|
60
|
-
router.get("/effective", (
|
|
60
|
+
router.get("/effective", async (req, res) => {
|
|
61
|
+
const { withMatPath } = require_mat_path_state.matPathState;
|
|
62
|
+
if (!withMatPath) return res.status(http_status_codes.StatusCodes.NOT_IMPLEMENTED).json({ error: "Effective validator resolution is not configured" });
|
|
63
|
+
try {
|
|
64
|
+
const { modelName } = req.params;
|
|
65
|
+
const [validator] = await require_validator.findEffective(modelName);
|
|
66
|
+
return res.status(http_status_codes.StatusCodes.OK).json(validator ?? null);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
return require_errors.default(err, res, {
|
|
69
|
+
logger: require_index.default,
|
|
70
|
+
message: `Error resolving effective ${ENTITY}`
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
61
74
|
/**
|
|
62
75
|
* Get by id
|
|
63
76
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import logger_default from "../../../utils/logger/index.js";
|
|
2
2
|
import errors_default from "../errors.js";
|
|
3
3
|
import { matPathState } from "../../../mat-path-state.js";
|
|
4
|
-
import { create, disable, findAll, update } from "../../../repository/validator.js";
|
|
4
|
+
import { create, disable, findAll, findEffective, update } from "../../../repository/validator.js";
|
|
5
5
|
import validations_default from "./validations.js";
|
|
6
6
|
import { validateValidatorSchema } from "../../../utils/validations/schema/validator-schema.js";
|
|
7
7
|
import { ResourceNotFoundError } from "@autofleet/errors";
|
|
@@ -56,7 +56,20 @@ router.get("/", async (req, res) => {
|
|
|
56
56
|
/**
|
|
57
57
|
* Effective
|
|
58
58
|
*/
|
|
59
|
-
router.get("/effective", (
|
|
59
|
+
router.get("/effective", async (req, res) => {
|
|
60
|
+
const { withMatPath } = matPathState;
|
|
61
|
+
if (!withMatPath) return res.status(StatusCodes.NOT_IMPLEMENTED).json({ error: "Effective validator resolution is not configured" });
|
|
62
|
+
try {
|
|
63
|
+
const { modelName } = req.params;
|
|
64
|
+
const [validator] = await findEffective(modelName);
|
|
65
|
+
return res.status(StatusCodes.OK).json(validator ?? null);
|
|
66
|
+
} catch (err) {
|
|
67
|
+
return errors_default(err, res, {
|
|
68
|
+
logger: logger_default,
|
|
69
|
+
message: `Error resolving effective ${ENTITY}`
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
60
73
|
/**
|
|
61
74
|
* Get by id
|
|
62
75
|
*/
|
package/dist/models/index.d.ts
CHANGED
|
@@ -3,5 +3,9 @@ import { CustomFieldModelTypeMap } from "./CustomFieldModelTypeMap.js";
|
|
|
3
3
|
import { CustomFieldDefinition } from "./CustomFieldDefinition.js";
|
|
4
4
|
import { CustomValidator } from "./CustomValidator.js";
|
|
5
5
|
import "../types/index.js";
|
|
6
|
+
import "./tests/AssociatedTestModel.js";
|
|
7
|
+
import "./tests/TestModel.js";
|
|
8
|
+
import "./tests/contextAwareModels/ContextTestModel.js";
|
|
9
|
+
import "./tests/contextAwareModels/ContextAwareTestModel.js";
|
|
6
10
|
import { CustomFieldEntries } from "./CustomFieldEntries.js";
|
|
7
11
|
import { Sequelize } from "sequelize-typescript";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { Model } from "sequelize-typescript";
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
1
2
|
const require_index = require('../utils/logger/index.cjs');
|
|
2
3
|
const require_CustomValidator = require('../models/CustomValidator.cjs');
|
|
3
4
|
require('../models/index.cjs');
|
|
5
|
+
let sequelize_lib_sequelize = require("sequelize/lib/sequelize");
|
|
6
|
+
sequelize_lib_sequelize = require_rolldown_runtime.__toESM(sequelize_lib_sequelize);
|
|
4
7
|
|
|
5
8
|
//#region src/repository/validator.ts
|
|
6
9
|
const create = async (validatorAttributes, options = {}) => {
|
|
@@ -49,10 +52,34 @@ const disable = async (id, options) => {
|
|
|
49
52
|
require_index.default.debug("custom-validator - disable validator");
|
|
50
53
|
return update(id, { disabled: true }, options);
|
|
51
54
|
};
|
|
55
|
+
const findEffective = async (entityType = "Vehicle", requestPath) => {
|
|
56
|
+
const QUERY = `
|
|
57
|
+
SELECT DISTINCT ON (cv.model_type) cv.*, cep.path
|
|
58
|
+
FROM custom_validators cv
|
|
59
|
+
LEFT JOIN context_entity_path cep ON cep.deleted_at IS NULL
|
|
60
|
+
AND cep.entity_id = cv.entity_id
|
|
61
|
+
AND cep.entity_type = cv.entity_type
|
|
62
|
+
AND cep.path @> ANY(ARRAY['${requestPath}']::ltree[])
|
|
63
|
+
WHERE cv.model_type IN ($1) AND cv.disabled = false
|
|
64
|
+
ORDER BY cv.model_type, COALESCE(nlevel(cep.path), 0) DESC;`;
|
|
65
|
+
try {
|
|
66
|
+
await sequelize_lib_sequelize.default.query(QUERY, {
|
|
67
|
+
bind: [entityType],
|
|
68
|
+
type: sequelize_lib_sequelize.default.QueryTypes.SELECT
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
...result.schema.properties.after,
|
|
72
|
+
path: result.path
|
|
73
|
+
};
|
|
74
|
+
} catch (err) {
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
52
78
|
|
|
53
79
|
//#endregion
|
|
54
80
|
exports.create = create;
|
|
55
81
|
exports.disable = disable;
|
|
56
82
|
exports.findAll = findAll;
|
|
57
83
|
exports.findAllByModelType = findAllByModelType;
|
|
84
|
+
exports.findEffective = findEffective;
|
|
58
85
|
exports.update = update;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import logger_default from "../utils/logger/index.js";
|
|
2
2
|
import CustomValidator_default from "../models/CustomValidator.js";
|
|
3
3
|
import "../models/index.js";
|
|
4
|
+
import sequelize from "sequelize/lib/sequelize";
|
|
4
5
|
|
|
5
6
|
//#region src/repository/validator.ts
|
|
6
7
|
const create = async (validatorAttributes, options = {}) => {
|
|
@@ -49,6 +50,29 @@ const disable = async (id, options) => {
|
|
|
49
50
|
logger_default.debug("custom-validator - disable validator");
|
|
50
51
|
return update(id, { disabled: true }, options);
|
|
51
52
|
};
|
|
53
|
+
const findEffective = async (entityType = "Vehicle", requestPath) => {
|
|
54
|
+
const QUERY = `
|
|
55
|
+
SELECT DISTINCT ON (cv.model_type) cv.*, cep.path
|
|
56
|
+
FROM custom_validators cv
|
|
57
|
+
LEFT JOIN context_entity_path cep ON cep.deleted_at IS NULL
|
|
58
|
+
AND cep.entity_id = cv.entity_id
|
|
59
|
+
AND cep.entity_type = cv.entity_type
|
|
60
|
+
AND cep.path @> ANY(ARRAY['${requestPath}']::ltree[])
|
|
61
|
+
WHERE cv.model_type IN ($1) AND cv.disabled = false
|
|
62
|
+
ORDER BY cv.model_type, COALESCE(nlevel(cep.path), 0) DESC;`;
|
|
63
|
+
try {
|
|
64
|
+
await sequelize.query(QUERY, {
|
|
65
|
+
bind: [entityType],
|
|
66
|
+
type: sequelize.QueryTypes.SELECT
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
...result.schema.properties.after,
|
|
70
|
+
path: result.path
|
|
71
|
+
};
|
|
72
|
+
} catch (err) {
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
52
76
|
|
|
53
77
|
//#endregion
|
|
54
|
-
export { create, disable, findAll, findAllByModelType, update };
|
|
78
|
+
export { create, disable, findAll, findAllByModelType, findEffective, update };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/sadot",
|
|
3
|
-
"version": "1.6.18-beta.
|
|
3
|
+
"version": "1.6.18-beta.21",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"npm-watch": "^0.11.0",
|
|
55
55
|
"supertest": "^7.0.0",
|
|
56
56
|
"@autofleet/node-common": "^4.3.22",
|
|
57
|
+
"@autofleet/logger": "^4.7.0",
|
|
57
58
|
"@autofleet/errors": "^3.3.7",
|
|
58
|
-
"@autofleet/zehut": "^4.13.4"
|
|
59
|
-
"@autofleet/logger": "^4.7.0"
|
|
59
|
+
"@autofleet/zehut": "^4.13.4"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@autofleet/errors": "^3",
|