@autofleet/sadot 1.6.18-beta.19 → 1.6.18-beta.20
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/field-policies/index.cjs +1 -17
- package/dist/api/v1/field-policies/index.js +3 -19
- package/dist/api/v1/validator/index.cjs +4 -0
- package/dist/api/v1/validator/index.js +4 -0
- package/dist/repository/field-policy.cjs +22 -0
- package/dist/repository/field-policy.d.cts +2 -1
- package/dist/repository/field-policy.d.ts +2 -1
- package/dist/repository/field-policy.js +22 -1
- package/package.json +3 -3
|
@@ -2,7 +2,6 @@ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs
|
|
|
2
2
|
const require_index = require('../../../utils/logger/index.cjs');
|
|
3
3
|
const require_errors = require('../errors.cjs');
|
|
4
4
|
const require_mat_path_state = require('../../../mat-path-state.cjs');
|
|
5
|
-
const require_FieldPolicy = require('../../../models/FieldPolicy.cjs');
|
|
6
5
|
const require_field_policy = require('../../../repository/field-policy.cjs');
|
|
7
6
|
let sequelize = require("sequelize");
|
|
8
7
|
let _autofleet_node_common = require("@autofleet/node-common");
|
|
@@ -13,26 +12,11 @@ const router = (0, _autofleet_node_common.Router)({
|
|
|
13
12
|
mergeParams: true
|
|
14
13
|
});
|
|
15
14
|
router.get("/effective", async (req, res) => {
|
|
16
|
-
const tableName = require_FieldPolicy.default.getTableName();
|
|
17
|
-
const EFFECTIVE_POLICY_QUERY = `
|
|
18
|
-
SELECT fp.*
|
|
19
|
-
FROM "${tableName}" fp
|
|
20
|
-
LEFT JOIN context_entity_path cep ON cep.deleted_at IS NULL
|
|
21
|
-
AND cep.entity_id = fp.context_id
|
|
22
|
-
AND cep.entity_type = 'context'
|
|
23
|
-
AND cep.path @> ANY(current_setting('mat_path.paths', true)::ltree[])
|
|
24
|
-
WHERE fp.entity_type = $1
|
|
25
|
-
ORDER BY COALESCE(nlevel(cep.path), 0) DESC
|
|
26
|
-
LIMIT 1`;
|
|
27
15
|
const { withMatPath } = require_mat_path_state.matPathState;
|
|
28
16
|
if (!withMatPath) return res.status(501).json({ error: "Effective field policy resolution is not configured" });
|
|
29
17
|
const entityType = req.params.entityType;
|
|
30
18
|
try {
|
|
31
|
-
const [policy] = await
|
|
32
|
-
bind: [entityType],
|
|
33
|
-
type: sequelize.QueryTypes.SELECT,
|
|
34
|
-
transaction
|
|
35
|
-
}));
|
|
19
|
+
const [policy] = await require_field_policy.findEffectivePolicy(entityType);
|
|
36
20
|
return res.status(200).json(policy ?? null);
|
|
37
21
|
} catch (err) {
|
|
38
22
|
return require_errors.default(err, res, {
|
|
@@ -1,9 +1,8 @@
|
|
|
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
|
|
5
|
-
import {
|
|
6
|
-
import { QueryTypes, UniqueConstraintError } from "sequelize";
|
|
4
|
+
import { create, findAll, findEffectivePolicy, remove, update } from "../../../repository/field-policy.js";
|
|
5
|
+
import { UniqueConstraintError } from "sequelize";
|
|
7
6
|
import { Router } from "@autofleet/node-common";
|
|
8
7
|
|
|
9
8
|
//#region src/api/v1/field-policies/index.ts
|
|
@@ -12,26 +11,11 @@ const router = Router({
|
|
|
12
11
|
mergeParams: true
|
|
13
12
|
});
|
|
14
13
|
router.get("/effective", async (req, res) => {
|
|
15
|
-
const tableName = FieldPolicy_default.getTableName();
|
|
16
|
-
const EFFECTIVE_POLICY_QUERY = `
|
|
17
|
-
SELECT fp.*
|
|
18
|
-
FROM "${tableName}" fp
|
|
19
|
-
LEFT JOIN context_entity_path cep ON cep.deleted_at IS NULL
|
|
20
|
-
AND cep.entity_id = fp.context_id
|
|
21
|
-
AND cep.entity_type = 'context'
|
|
22
|
-
AND cep.path @> ANY(current_setting('mat_path.paths', true)::ltree[])
|
|
23
|
-
WHERE fp.entity_type = $1
|
|
24
|
-
ORDER BY COALESCE(nlevel(cep.path), 0) DESC
|
|
25
|
-
LIMIT 1`;
|
|
26
14
|
const { withMatPath } = matPathState;
|
|
27
15
|
if (!withMatPath) return res.status(501).json({ error: "Effective field policy resolution is not configured" });
|
|
28
16
|
const entityType = req.params.entityType;
|
|
29
17
|
try {
|
|
30
|
-
const [policy] = await
|
|
31
|
-
bind: [entityType],
|
|
32
|
-
type: QueryTypes.SELECT,
|
|
33
|
-
transaction
|
|
34
|
-
}));
|
|
18
|
+
const [policy] = await findEffectivePolicy(entityType);
|
|
35
19
|
return res.status(200).json(policy ?? null);
|
|
36
20
|
} catch (err) {
|
|
37
21
|
return errors_default(err, res, {
|
|
@@ -55,6 +55,10 @@ router.get("/", async (req, res) => {
|
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
/**
|
|
58
|
+
* Effective
|
|
59
|
+
*/
|
|
60
|
+
router.get("/effective", (_req, res) => res.status(http_status_codes.StatusCodes.OK).json({ ok: true }));
|
|
61
|
+
/**
|
|
58
62
|
* Get by id
|
|
59
63
|
*/
|
|
60
64
|
router.get("/:validatorId", async (req, res) => {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_mat_path_state = require('../mat-path-state.cjs');
|
|
2
3
|
const require_FieldPolicy = require('../models/FieldPolicy.cjs');
|
|
4
|
+
let sequelize = require("sequelize");
|
|
3
5
|
|
|
4
6
|
//#region src/repository/field-policy.ts
|
|
5
7
|
var field_policy_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
|
|
@@ -9,6 +11,7 @@ var field_policy_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
|
|
|
9
11
|
findAllByContextIds: () => findAllByContextIds,
|
|
10
12
|
findByContextAndName: () => findByContextAndName,
|
|
11
13
|
findById: () => findById,
|
|
14
|
+
findEffectivePolicy: () => findEffectivePolicy,
|
|
12
15
|
remove: () => remove,
|
|
13
16
|
update: () => update
|
|
14
17
|
});
|
|
@@ -33,6 +36,24 @@ const update = async (id, data) => {
|
|
|
33
36
|
return policy.update(data);
|
|
34
37
|
};
|
|
35
38
|
const remove = (id) => require_FieldPolicy.default.destroy({ where: { id } });
|
|
39
|
+
const findEffectivePolicy = (entityType) => {
|
|
40
|
+
const tableName = require_FieldPolicy.default.getTableName();
|
|
41
|
+
const EFFECTIVE_POLICY_QUERY = `
|
|
42
|
+
SELECT fp.*
|
|
43
|
+
FROM "${tableName}" fp
|
|
44
|
+
LEFT JOIN context_entity_path cep ON cep.deleted_at IS NULL
|
|
45
|
+
AND cep.entity_id = fp.context_id
|
|
46
|
+
AND cep.entity_type = 'context'
|
|
47
|
+
AND cep.path @> ANY(current_setting('mat_path.paths', true)::ltree[])
|
|
48
|
+
WHERE fp.entity_type = $1
|
|
49
|
+
ORDER BY COALESCE(nlevel(cep.path), 0) DESC
|
|
50
|
+
LIMIT 1`;
|
|
51
|
+
return require_mat_path_state.matPathState.withMatPath(tableName, (transaction) => require_FieldPolicy.default.sequelize.query(EFFECTIVE_POLICY_QUERY, {
|
|
52
|
+
bind: [entityType],
|
|
53
|
+
type: sequelize.QueryTypes.SELECT,
|
|
54
|
+
transaction
|
|
55
|
+
}));
|
|
56
|
+
};
|
|
36
57
|
|
|
37
58
|
//#endregion
|
|
38
59
|
exports.create = create;
|
|
@@ -43,5 +64,6 @@ Object.defineProperty(exports, 'field_policy_exports', {
|
|
|
43
64
|
}
|
|
44
65
|
});
|
|
45
66
|
exports.findAll = findAll;
|
|
67
|
+
exports.findEffectivePolicy = findEffectivePolicy;
|
|
46
68
|
exports.remove = remove;
|
|
47
69
|
exports.update = update;
|
|
@@ -2,7 +2,7 @@ import { EntityType, FieldPolicy, ModelInclusion } from "../models/FieldPolicy.c
|
|
|
2
2
|
|
|
3
3
|
//#region src/repository/field-policy.d.ts
|
|
4
4
|
declare namespace field_policy_d_exports {
|
|
5
|
-
export { CreateFieldPolicyData, UpdateFieldPolicyData, create, findAll, findAllByContext, findAllByContextIds, findByContextAndName, findById, remove, update };
|
|
5
|
+
export { CreateFieldPolicyData, UpdateFieldPolicyData, create, findAll, findAllByContext, findAllByContextIds, findByContextAndName, findById, findEffectivePolicy, remove, update };
|
|
6
6
|
}
|
|
7
7
|
interface CreateFieldPolicyData {
|
|
8
8
|
contextId: string;
|
|
@@ -30,5 +30,6 @@ declare const create: ({
|
|
|
30
30
|
}: CreateFieldPolicyData) => Promise<FieldPolicy>;
|
|
31
31
|
declare const update: (id: string, data: UpdateFieldPolicyData) => Promise<FieldPolicy | null>;
|
|
32
32
|
declare const remove: (id: string) => Promise<number>;
|
|
33
|
+
declare const findEffectivePolicy: (entityType: string) => Promise<Record<string, unknown>[]>;
|
|
33
34
|
//#endregion
|
|
34
35
|
export { field_policy_d_exports };
|
|
@@ -2,7 +2,7 @@ import { EntityType, FieldPolicy, ModelInclusion } from "../models/FieldPolicy.j
|
|
|
2
2
|
|
|
3
3
|
//#region src/repository/field-policy.d.ts
|
|
4
4
|
declare namespace field_policy_d_exports {
|
|
5
|
-
export { CreateFieldPolicyData, UpdateFieldPolicyData, create, findAll, findAllByContext, findAllByContextIds, findByContextAndName, findById, remove, update };
|
|
5
|
+
export { CreateFieldPolicyData, UpdateFieldPolicyData, create, findAll, findAllByContext, findAllByContextIds, findByContextAndName, findById, findEffectivePolicy, remove, update };
|
|
6
6
|
}
|
|
7
7
|
interface CreateFieldPolicyData {
|
|
8
8
|
contextId: string;
|
|
@@ -30,5 +30,6 @@ declare const create: ({
|
|
|
30
30
|
}: CreateFieldPolicyData) => Promise<FieldPolicy>;
|
|
31
31
|
declare const update: (id: string, data: UpdateFieldPolicyData) => Promise<FieldPolicy | null>;
|
|
32
32
|
declare const remove: (id: string) => Promise<number>;
|
|
33
|
+
declare const findEffectivePolicy: (entityType: string) => Promise<Record<string, unknown>[]>;
|
|
33
34
|
//#endregion
|
|
34
35
|
export { field_policy_d_exports };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { __export } from "../_virtual/rolldown_runtime.js";
|
|
2
|
+
import { matPathState } from "../mat-path-state.js";
|
|
2
3
|
import FieldPolicy_default from "../models/FieldPolicy.js";
|
|
4
|
+
import { QueryTypes } from "sequelize";
|
|
3
5
|
|
|
4
6
|
//#region src/repository/field-policy.ts
|
|
5
7
|
var field_policy_exports = /* @__PURE__ */ __export({
|
|
@@ -9,6 +11,7 @@ var field_policy_exports = /* @__PURE__ */ __export({
|
|
|
9
11
|
findAllByContextIds: () => findAllByContextIds,
|
|
10
12
|
findByContextAndName: () => findByContextAndName,
|
|
11
13
|
findById: () => findById,
|
|
14
|
+
findEffectivePolicy: () => findEffectivePolicy,
|
|
12
15
|
remove: () => remove,
|
|
13
16
|
update: () => update
|
|
14
17
|
});
|
|
@@ -33,6 +36,24 @@ const update = async (id, data) => {
|
|
|
33
36
|
return policy.update(data);
|
|
34
37
|
};
|
|
35
38
|
const remove = (id) => FieldPolicy_default.destroy({ where: { id } });
|
|
39
|
+
const findEffectivePolicy = (entityType) => {
|
|
40
|
+
const tableName = FieldPolicy_default.getTableName();
|
|
41
|
+
const EFFECTIVE_POLICY_QUERY = `
|
|
42
|
+
SELECT fp.*
|
|
43
|
+
FROM "${tableName}" fp
|
|
44
|
+
LEFT JOIN context_entity_path cep ON cep.deleted_at IS NULL
|
|
45
|
+
AND cep.entity_id = fp.context_id
|
|
46
|
+
AND cep.entity_type = 'context'
|
|
47
|
+
AND cep.path @> ANY(current_setting('mat_path.paths', true)::ltree[])
|
|
48
|
+
WHERE fp.entity_type = $1
|
|
49
|
+
ORDER BY COALESCE(nlevel(cep.path), 0) DESC
|
|
50
|
+
LIMIT 1`;
|
|
51
|
+
return matPathState.withMatPath(tableName, (transaction) => FieldPolicy_default.sequelize.query(EFFECTIVE_POLICY_QUERY, {
|
|
52
|
+
bind: [entityType],
|
|
53
|
+
type: QueryTypes.SELECT,
|
|
54
|
+
transaction
|
|
55
|
+
}));
|
|
56
|
+
};
|
|
36
57
|
|
|
37
58
|
//#endregion
|
|
38
|
-
export { create, field_policy_exports, findAll, remove, update };
|
|
59
|
+
export { create, field_policy_exports, findAll, findEffectivePolicy, remove, 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.20",
|
|
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",
|
|
58
57
|
"@autofleet/errors": "^3.3.7",
|
|
59
|
-
"@autofleet/zehut": "^4.13.4"
|
|
58
|
+
"@autofleet/zehut": "^4.13.4",
|
|
59
|
+
"@autofleet/logger": "^4.7.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@autofleet/errors": "^3",
|