aws-service-stack 0.18.379 → 0.18.381
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.
|
@@ -4,10 +4,14 @@ exports.PermissionRepo = void 0;
|
|
|
4
4
|
const base_db_repo_1 = require("../repositories/base-db.repo");
|
|
5
5
|
const dynamodb_model_1 = require("../model/dynamodb.model");
|
|
6
6
|
const dynamodb_utils_1 = require("../utils/dynamodb.utils");
|
|
7
|
+
const reflection_util_1 = require("../utils/reflection.util");
|
|
7
8
|
function createPermissionIndexMap() {
|
|
8
9
|
const map = new dynamodb_model_1.DynamoIndexMap();
|
|
9
10
|
map.partitionKey = "id";
|
|
10
11
|
map.set("byPermissionKey", { field: "permissionKey", rFields: ["role", "resource", "scope"], fieldSeparator: "#" });
|
|
12
|
+
map.set("byRole", { field: "role", rFields: ["role"] });
|
|
13
|
+
map.set("byResource", { field: "resource", rFields: ["resource"] });
|
|
14
|
+
map.set("byScope", { field: "scope", rFields: ["scope"] });
|
|
11
15
|
map.mapFields = ["method"];
|
|
12
16
|
return map;
|
|
13
17
|
}
|
|
@@ -32,7 +36,8 @@ class PermissionRepo {
|
|
|
32
36
|
});
|
|
33
37
|
}
|
|
34
38
|
async findByIndex(filter) {
|
|
35
|
-
|
|
39
|
+
const parsedFilter = (0, reflection_util_1.parseIndexFilter)(filter, this.db.getIndexMap());
|
|
40
|
+
return this.db.find({ indexName: parsedFilter.indexName, indexValue: parsedFilter.indexValue });
|
|
36
41
|
}
|
|
37
42
|
async save(permission) {
|
|
38
43
|
if (!permission.id)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission.repo.js","sourceRoot":"","sources":["../../src/service/permission.repo.ts"],"names":[],"mappings":";;;AAAA,+DAA8D;AAC9D,4DAAyD;AAEzD,4DAAuD;
|
|
1
|
+
{"version":3,"file":"permission.repo.js","sourceRoot":"","sources":["../../src/service/permission.repo.ts"],"names":[],"mappings":";;;AAAA,+DAA8D;A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AAK,EAAE,CAAC;YAC/D,UAAU,CAAC,aAAa,GAAG,GAAG,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;QAC7F,CAAC;QAED,OAAO,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,OAAO,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;CACF;AA1DD,wCA0DC","sourcesContent":["import { BaseRepoDBImpl } from \"../repositories/base-db.repo\";\nimport { DynamoIndexMap } from \"../model/dynamodb.model\";\nimport { Permission } from \"../model/role.model\";\nimport { generateUUID } from \"../utils/dynamodb.utils\";\nimport { List } from \"../model/base.model\";\nimport { Filter } from \"@chinggis/types\";\nimport { parseIndexFilter } from \"../utils/reflection.util\";\n\nfunction createPermissionIndexMap(): DynamoIndexMap {\n const map = new DynamoIndexMap();\n map.partitionKey = \"id\";\n map.set(\"byPermissionKey\", { field: \"permissionKey\", rFields: [\"role\", \"resource\", \"scope\"], fieldSeparator: \"#\" });\n map.set(\"byRole\", { field: \"role\", rFields: [\"role\"] });\n map.set(\"byResource\", { field: \"resource\", rFields: [\"resource\"] });\n map.set(\"byScope\", { field: \"scope\", rFields: [\"scope\"] });\n\n map.mapFields = [\"method\"];\n return map;\n}\n\n/**\n * Repository layer for Permission table.\n * Pure DB operations — no caching, no business logic.\n */\nexport class PermissionRepo {\n private readonly db: BaseRepoDBImpl<Permission>;\n\n constructor(tableName: string) {\n this.db = new BaseRepoDBImpl<Permission>();\n this.db.setTable(tableName);\n this.db.setIndexMap(createPermissionIndexMap());\n }\n\n async findById(id: string): Promise<Permission | null> {\n return this.db.findById(id);\n }\n\n async findByPermissionKey(permissionKey: string): Promise<Permission | null> {\n return this.db.findOne({\n indexName: \"byPermissionKey\",\n indexValue: permissionKey,\n });\n }\n\n async findByIndex(filter?: Filter): Promise<List<Partial<Permission>>> {\n const parsedFilter = parseIndexFilter(filter, this.db.getIndexMap());\n return this.db.find({ indexName: parsedFilter.indexName, indexValue: parsedFilter.indexValue });\n }\n\n async save(permission: Partial<Permission>): Promise<Permission> {\n if (!permission.id) permission.id = generateUUID();\n\n const now = new Date().toISOString();\n if (!permission.createdAt) permission.createdAt = now;\n permission.updatedAt = now;\n\n // Build composite key: role#resource#scope\n if (permission.role && permission.resource && permission.scope) {\n permission.permissionKey = `${permission.role}#${permission.resource}#${permission.scope}`;\n }\n\n return this.db.save(permission);\n }\n\n async update(permission: Partial<Permission>): Promise<Permission> {\n permission.updatedAt = new Date().toISOString();\n\n // Rebuild composite key if components changed\n if (permission.role && permission.resource && permission.scope) {\n permission.permissionKey = `${permission.role}#${permission.resource}#${permission.scope}`;\n }\n\n return this.db.update(permission);\n }\n\n async delete(id: string): Promise<boolean> {\n return this.db.delete(id);\n }\n\n async scan(): Promise<List<Partial<Permission>>> {\n return this.db.scan({});\n }\n}\n"]}
|