aws-service-stack 0.18.396 → 0.18.398
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/model/filter.model.d.ts +13 -2
- package/dist/model/filter.model.js +11 -0
- package/dist/model/filter.model.js.map +1 -1
- package/dist/model/role.model.d.ts +0 -6
- package/dist/model/role.model.js +0 -9
- package/dist/model/role.model.js.map +1 -1
- package/dist/service/permission.service.js +1 -1
- package/dist/service/permission.service.js.map +1 -1
- package/dist/utils/opensearch/opensearch.parser.query.map.js +25 -0
- package/dist/utils/opensearch/opensearch.parser.query.map.js.map +1 -1
- package/package.json +1 -1
|
@@ -45,12 +45,23 @@ export declare enum BoolQueryTypeOS {
|
|
|
45
45
|
nin = "nin",
|
|
46
46
|
gte = "gte",
|
|
47
47
|
lte = "lte",
|
|
48
|
+
gt = "gt",
|
|
49
|
+
lt = "lt",
|
|
48
50
|
exists = "exists",
|
|
49
|
-
regex = "regex"
|
|
51
|
+
regex = "regex",
|
|
52
|
+
prefix = "prefix",
|
|
53
|
+
not_prefix = "not_prefix",
|
|
54
|
+
contains = "contains",
|
|
55
|
+
not_contains = "not_contains",
|
|
56
|
+
wildcard = "wildcard",
|
|
57
|
+
not_wildcard = "not_wildcard",
|
|
58
|
+
fuzzy = "fuzzy"
|
|
50
59
|
}
|
|
51
60
|
export declare enum RangeTypeOS {
|
|
52
61
|
lte = "lte",
|
|
53
|
-
gte = "gte"
|
|
62
|
+
gte = "gte",
|
|
63
|
+
lt = "lt",
|
|
64
|
+
gt = "gt"
|
|
54
65
|
}
|
|
55
66
|
export declare enum SearchOperatorOS {
|
|
56
67
|
AND = "and",
|
|
@@ -9,13 +9,24 @@ var BoolQueryTypeOS;
|
|
|
9
9
|
BoolQueryTypeOS["nin"] = "nin";
|
|
10
10
|
BoolQueryTypeOS["gte"] = "gte";
|
|
11
11
|
BoolQueryTypeOS["lte"] = "lte";
|
|
12
|
+
BoolQueryTypeOS["gt"] = "gt";
|
|
13
|
+
BoolQueryTypeOS["lt"] = "lt";
|
|
12
14
|
BoolQueryTypeOS["exists"] = "exists";
|
|
13
15
|
BoolQueryTypeOS["regex"] = "regex";
|
|
16
|
+
BoolQueryTypeOS["prefix"] = "prefix";
|
|
17
|
+
BoolQueryTypeOS["not_prefix"] = "not_prefix";
|
|
18
|
+
BoolQueryTypeOS["contains"] = "contains";
|
|
19
|
+
BoolQueryTypeOS["not_contains"] = "not_contains";
|
|
20
|
+
BoolQueryTypeOS["wildcard"] = "wildcard";
|
|
21
|
+
BoolQueryTypeOS["not_wildcard"] = "not_wildcard";
|
|
22
|
+
BoolQueryTypeOS["fuzzy"] = "fuzzy";
|
|
14
23
|
})(BoolQueryTypeOS || (exports.BoolQueryTypeOS = BoolQueryTypeOS = {}));
|
|
15
24
|
var RangeTypeOS;
|
|
16
25
|
(function (RangeTypeOS) {
|
|
17
26
|
RangeTypeOS["lte"] = "lte";
|
|
18
27
|
RangeTypeOS["gte"] = "gte";
|
|
28
|
+
RangeTypeOS["lt"] = "lt";
|
|
29
|
+
RangeTypeOS["gt"] = "gt";
|
|
19
30
|
})(RangeTypeOS || (exports.RangeTypeOS = RangeTypeOS = {}));
|
|
20
31
|
var SearchOperatorOS;
|
|
21
32
|
(function (SearchOperatorOS) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.model.js","sourceRoot":"","sources":["../../src/model/filter.model.ts"],"names":[],"mappings":";;;AA8CA,IAAY,
|
|
1
|
+
{"version":3,"file":"filter.model.js","sourceRoot":"","sources":["../../src/model/filter.model.ts"],"names":[],"mappings":";;;AA8CA,IAAY,eAkBX;AAlBD,WAAY,eAAe;IACzB,4BAAS,CAAA;IACT,4BAAS,CAAA;IACT,4BAAS,CAAA;IACT,8BAAW,CAAA;IACX,8BAAW,CAAA;IACX,8BAAW,CAAA;IACX,4BAAS,CAAA;IACT,4BAAS,CAAA;IACT,oCAAiB,CAAA;IACjB,kCAAe,CAAA;IACf,oCAAiB,CAAA;IACjB,4CAAyB,CAAA;IACzB,wCAAqB,CAAA;IACrB,gDAA6B,CAAA;IAC7B,wCAAqB,CAAA;IACrB,gDAA6B,CAAA;IAC7B,kCAAe,CAAA;AACjB,CAAC,EAlBW,eAAe,+BAAf,eAAe,QAkB1B;AAED,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,0BAAW,CAAA;IACX,0BAAW,CAAA;IACX,wBAAS,CAAA;IACT,wBAAS,CAAA;AACX,CAAC,EALW,WAAW,2BAAX,WAAW,QAKtB;AAED,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,+BAAW,CAAA;IACX,6BAAS,CAAA;AACX,CAAC,EAHW,gBAAgB,gCAAhB,gBAAgB,QAG3B;AAED,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,wBAAW,CAAA;IACX,wBAAW,CAAA;IACX,wBAAW,CAAA;IACX,wBAAW,CAAA;IACX,0BAAa,CAAA;AACf,CAAC,EAPW,SAAS,yBAAT,SAAS,QAOpB","sourcesContent":["import { SortOrder } from \"@chinggis/core\";\n\nexport interface Filter extends Record<string, any> {\n page?: number; // The page number for pagination\n size?: number; // The size of items per page\n sortBy?: string; // The field to sort by\n sort?: SortOrder; // Sorting order, either ascending or descending\n searchBy?: string[]; // The field to search in\n searchKeyword?: string; // The keyword to search for\n rangeFilters?: RangeFilter[]; // The field to apply range filtering on\n lastKey?: string;\n indexName?: string;\n indexValue?: string;\n indexSortName?: string;\n indexSortValue?: string;\n fieldsInclude?: string[];\n fieldsExclude?: string[];\n urlRaw?: string;\n}\n\nexport type RangeFilter = {\n fieldName: string;\n minValue?: number | Date;\n maxValue?: number | Date;\n minExclude?: boolean;\n maxExclude?: boolean;\n};\n\nexport type NumberRange = {\n gte?: number;\n lte?: number;\n};\n\nexport type DateRange = {\n gte?: string;\n lte?: string;\n};\n\nexport interface BoolQueryOS {\n must: Array<any>;\n must_not: Array<any>;\n filter: Array<any>;\n should: Array<any>;\n minimum_should_match?: number;\n}\n\nexport enum BoolQueryTypeOS {\n eq = \"eq\",\n ne = \"ne\",\n in = \"in\",\n nin = \"nin\",\n gte = \"gte\",\n lte = \"lte\",\n gt = \"gt\",\n lt = \"lt\",\n exists = \"exists\",\n regex = \"regex\",\n prefix = \"prefix\",\n not_prefix = \"not_prefix\",\n contains = \"contains\",\n not_contains = \"not_contains\",\n wildcard = \"wildcard\",\n not_wildcard = \"not_wildcard\",\n fuzzy = \"fuzzy\",\n}\n\nexport enum RangeTypeOS {\n lte = \"lte\",\n gte = \"gte\",\n lt = \"lt\",\n gt = \"gt\",\n}\n\nexport enum SearchOperatorOS {\n AND = \"and\",\n OR = \"or\",\n}\n\nexport enum AggTypeOS {\n TERMS = \"terms\",\n SUM = \"sum\",\n AVG = \"avg\",\n MAX = \"max\",\n MIN = \"min\",\n TREE = \"tree\",\n}\n"]}
|
|
@@ -12,9 +12,3 @@ export interface Permission extends BaseEntity {
|
|
|
12
12
|
};
|
|
13
13
|
permissionKey: string;
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Build a fully-qualified permission key.
|
|
17
|
-
* Format: `${role}.${resource}.${scope}.${method}`
|
|
18
|
-
* Example: `OwnerRole.PropertyTable.BranchScope.GET`
|
|
19
|
-
*/
|
|
20
|
-
export declare function buildPermissionKey(role: string, resource: string, scope: string, method: string): string;
|
package/dist/model/role.model.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildPermissionKey = buildPermissionKey;
|
|
4
|
-
/**
|
|
5
|
-
* Build a fully-qualified permission key.
|
|
6
|
-
* Format: `${role}.${resource}.${scope}.${method}`
|
|
7
|
-
* Example: `OwnerRole.PropertyTable.BranchScope.GET`
|
|
8
|
-
*/
|
|
9
|
-
function buildPermissionKey(role, resource, scope, method) {
|
|
10
|
-
return `${role}.${resource}.${scope}.${method}`;
|
|
11
|
-
}
|
|
12
3
|
//# sourceMappingURL=role.model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role.model.js","sourceRoot":"","sources":["../../src/model/role.model.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"role.model.js","sourceRoot":"","sources":["../../src/model/role.model.ts"],"names":[],"mappings":"","sourcesContent":["import { BaseEntity } from \"./base.model\";\n\nexport interface Permission extends BaseEntity {\n role: string; // DB Index: Manager | User etc\n resource: string; // DB Index: Property | Profile etc\n scope: string; // DB Index: Organization | Branch | Agent\n method: {\n get?: boolean;\n post?: boolean;\n patch?: boolean;\n put?: boolean;\n delete?: boolean;\n };\n permissionKey: string; // DB Index: role#resourse#scope Manager#Property#Branch\n}\n"]}
|
|
@@ -50,7 +50,7 @@ class PermissionService {
|
|
|
50
50
|
async hasPermission(role, resource, scope, method) {
|
|
51
51
|
if (!role || !resource || !scope || !method)
|
|
52
52
|
return false;
|
|
53
|
-
const permissionKey = `${role}
|
|
53
|
+
const permissionKey = `${role}#${resource}#${scope}`;
|
|
54
54
|
const permission = await this.getPermissionByKey(permissionKey);
|
|
55
55
|
if (!permission?.method)
|
|
56
56
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission.service.js","sourceRoot":"","sources":["../../src/service/permission.service.ts"],"names":[],"mappings":";;;AACA,4CAAyC;AACzC,yDAAqD;AACrD,uDAAmD;AAGnD;;;;;;;;;GASG;AACH,MAAa,iBAAiB;IACX,IAAI,CAAiB;IACrB,KAAK,CAAkB;IAExC,YAAY,SAAiB,EAAE,UAAmB;QAChD,IAAI,CAAC,IAAI,GAAG,IAAI,gCAAc,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,kCAAe,CAAC,UAAU,CAAC,CAAC;IAC/C,CAAC;IAED,8EAA8E;IAC9E,cAAc;IACd,8EAA8E;IAE9E,oFAAoF;IACpF,KAAK,CAAC,kBAAkB,CAAC,aAAqB;QAC5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AAM,CAAC;IAChB,CAAC;IAED,8EAA8E;IAC9E,cAAc;IACd,8EAA8E;IAE9E,KAAK,CAAC,eAAe,CAAC,MAAe;QACnC,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,8EAA8E;IAC9E,8BAA8B;IAC9B,8EAA8E;IAE9E,UAAU;QACR,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF;AAhKD,8CAgKC","sourcesContent":["import { Permission } from \"../model/role.model\";\nimport { ErrorHttp } from \"../exception\";\nimport { PermissionCache } from \"./permission.cache\";\nimport { PermissionRepo } from \"./permission.repo\";\nimport { Filter, List } from \"@chinggis/types\";\n\n/**\n * PermissionService — cache + orchestration layer for Permission entities.\n *\n * Design decisions:\n * - Read-through cache via PermissionCache (in-flight dedup, TTL).\n * - Repository handles only DB I/O.\n * - Cache invalidation on every mutation.\n * - ~100 roles total, read-heavy → caching makes sense.\n * - Cache keyed by `perm:{permissionKey}` for deterministic, namespaced lookup.\n */\nexport class PermissionService {\n private readonly repo: PermissionRepo;\n private readonly cache: PermissionCache;\n\n constructor(tableName: string, cacheTtlMs?: number) {\n this.repo = new PermissionRepo(tableName);\n this.cache = new PermissionCache(cacheTtlMs);\n }\n\n // ---------------------------------------------------------------------------\n // Core lookup\n // ---------------------------------------------------------------------------\n\n /** Fetch Permission by composite key (role#resource#scope). Read-through cached. */\n async getPermissionByKey(permissionKey: string): Promise<Permission | null> {\n if (!permissionKey) return null;\n\n return this.cache.getOrFetch(`perm:${permissionKey}`, () => this.repo.findByPermissionKey(permissionKey));\n }\n\n /** Fetch Permission by id. Read-through cached. */\n async getPermissionById(id: string): Promise<Permission | null> {\n if (!id) return null;\n\n return this.cache.getOrFetch(`id:${id}`, () => this.repo.findById(id));\n }\n\n // ---------------------------------------------------------------------------\n // Permission check\n // ---------------------------------------------------------------------------\n\n /**\n * Check if the given role+resource+scope has a specific HTTP method allowed.\n *\n * Builds the permissionKey `role#resource#scope`, fetches the Permission,\n * and checks the method map.\n *\n * @returns `true` if allowed, `false` otherwise.\n */\n async hasPermission(role: string, resource: string, scope: string, method: string): Promise<boolean> {\n if (!role || !resource || !scope || !method) return false;\n\n const permissionKey = `${role}.${resource}.${scope}.${method}`;\n const permission = await this.getPermissionByKey(permissionKey);\n if (!permission?.method) return false;\n\n const methodLower = method.toUpperCase() as keyof Permission[\"method\"];\n\n return permission.method[methodLower] === true;\n }\n\n // ---------------------------------------------------------------------------\n // CRUD — create\n // ---------------------------------------------------------------------------\n\n async createPermission(input: {\n role: string;\n resource: string;\n scope: string;\n method: Permission[\"method\"];\n }): Promise<Permission> {\n if (!input.role?.trim()) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Role is required\");\n }\n if (!input.resource?.trim()) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Resource is required\");\n }\n if (!input.scope?.trim()) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Scope is required\");\n }\n\n // Duplicate check\n const permissionKey = `${input.role}#${input.resource}#${input.scope}`;\n const existing = await this.repo.findByPermissionKey(permissionKey);\n if (existing) {\n throw new ErrorHttp({ code: 409, error: \"Conflict\" }, `Permission \"${permissionKey}\" already exists`);\n }\n\n const saved = await this.repo.save({\n role: input.role.trim(),\n resource: input.resource.trim(),\n scope: input.scope.trim(),\n method: input.method ?? {},\n permissionKey,\n });\n\n this.cache.clear();\n return saved;\n }\n\n // ---------------------------------------------------------------------------\n // CRUD — update\n // ---------------------------------------------------------------------------\n\n async updatePermission(\n id: string,\n updates: Partial<Pick<Permission, \"role\" | \"resource\" | \"scope\" | \"method\">>,\n ): Promise<Permission> {\n if (!id) throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Permission id is required\");\n\n const existing = await this.repo.findById(id);\n if (!existing) throw new ErrorHttp({ code: 404, error: \"NotFound\" }, `Permission \"${id}\" not found`);\n\n const data: Partial<Permission> = { id };\n if (updates.role !== undefined) data.role = updates.role.trim();\n if (updates.resource !== undefined) data.resource = updates.resource.trim();\n if (updates.scope !== undefined) data.scope = updates.scope.trim();\n if (updates.method !== undefined) data.method = updates.method;\n\n // Rebuild key if any key component changed\n const role = data.role ?? existing.role;\n const resource = data.resource ?? existing.resource;\n const scope = data.scope ?? existing.scope;\n data.permissionKey = `${role}#${resource}#${scope}`;\n\n // Check for duplicate key if components changed\n if (data.permissionKey !== existing.permissionKey) {\n const conflict = await this.repo.findByPermissionKey(data.permissionKey);\n if (conflict) {\n throw new ErrorHttp({ code: 409, error: \"Conflict\" }, `Permission \"${data.permissionKey}\" already exists`);\n }\n }\n\n const updated = await this.repo.update(data);\n\n this.cache.clear();\n return updated;\n }\n\n // ---------------------------------------------------------------------------\n // CRUD — delete\n // ---------------------------------------------------------------------------\n\n async deletePermission(id: string): Promise<boolean> {\n if (!id) throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Permission id is required\");\n\n const existing = await this.repo.findById(id);\n if (!existing) throw new ErrorHttp({ code: 404, error: \"NotFound\" }, `Permission \"${id}\" not found`);\n\n const result = await this.repo.delete(id);\n\n this.cache.clear();\n return result;\n }\n\n // ---------------------------------------------------------------------------\n // CRUD — list\n // ---------------------------------------------------------------------------\n\n async listPermissions(filter?: Filter): Promise<List<Partial<Permission>>> {\n return this.repo.findByIndex(filter);\n }\n\n // ---------------------------------------------------------------------------\n // Cache control (for testing)\n // ---------------------------------------------------------------------------\n\n clearCache(): void {\n this.cache.clear();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"permission.service.js","sourceRoot":"","sources":["../../src/service/permission.service.ts"],"names":[],"mappings":";;;AACA,4CAAyC;AACzC,yDAAqD;AACrD,uDAAmD;AAGnD;;;;;;;;;GASG;AACH,MAAa,iBAAiB;IACX,IAAI,CAAiB;IACrB,KAAK,CAAkB;IAExC,YAAY,SAAiB,EAAE,UAAmB;QAChD,IAAI,CAAC,IAAI,GAAG,IAAI,gCAAc,CAAC,SAAS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AAE,eAAe,EAAE,aAAa,CAAC,CAAC;QAErG,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAE1C,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,8EAA8E;IAC9E,cAAc;IACd,8EAA8E;IAE9E,KAAK,CAAC,eAAe,CAAC,MAAe;QACnC,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,8EAA8E;IAC9E,8BAA8B;IAC9B,8EAA8E;IAE9E,UAAU;QACR,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF;AAhKD,8CAgKC","sourcesContent":["import { Permission } from \"../model/role.model\";\nimport { ErrorHttp } from \"../exception\";\nimport { PermissionCache } from \"./permission.cache\";\nimport { PermissionRepo } from \"./permission.repo\";\nimport { Filter, List } from \"@chinggis/types\";\n\n/**\n * PermissionService — cache + orchestration layer for Permission entities.\n *\n * Design decisions:\n * - Read-through cache via PermissionCache (in-flight dedup, TTL).\n * - Repository handles only DB I/O.\n * - Cache invalidation on every mutation.\n * - ~100 roles total, read-heavy → caching makes sense.\n * - Cache keyed by `perm:{permissionKey}` for deterministic, namespaced lookup.\n */\nexport class PermissionService {\n private readonly repo: PermissionRepo;\n private readonly cache: PermissionCache;\n\n constructor(tableName: string, cacheTtlMs?: number) {\n this.repo = new PermissionRepo(tableName);\n this.cache = new PermissionCache(cacheTtlMs);\n }\n\n // ---------------------------------------------------------------------------\n // Core lookup\n // ---------------------------------------------------------------------------\n\n /** Fetch Permission by composite key (role#resource#scope). Read-through cached. */\n async getPermissionByKey(permissionKey: string): Promise<Permission | null> {\n if (!permissionKey) return null;\n\n return this.cache.getOrFetch(`perm:${permissionKey}`, () => this.repo.findByPermissionKey(permissionKey));\n }\n\n /** Fetch Permission by id. Read-through cached. */\n async getPermissionById(id: string): Promise<Permission | null> {\n if (!id) return null;\n\n return this.cache.getOrFetch(`id:${id}`, () => this.repo.findById(id));\n }\n\n // ---------------------------------------------------------------------------\n // Permission check\n // ---------------------------------------------------------------------------\n\n /**\n * Check if the given role+resource+scope has a specific HTTP method allowed.\n *\n * Builds the permissionKey `role#resource#scope`, fetches the Permission,\n * and checks the method map.\n *\n * @returns `true` if allowed, `false` otherwise.\n */\n async hasPermission(role: string, resource: string, scope: string, method: string): Promise<boolean> {\n if (!role || !resource || !scope || !method) return false;\n\n const permissionKey = `${role}#${resource}#${scope}`;\n const permission = await this.getPermissionByKey(permissionKey);\n if (!permission?.method) return false;\n\n const methodLower = method.toUpperCase() as keyof Permission[\"method\"];\n\n return permission.method[methodLower] === true;\n }\n\n // ---------------------------------------------------------------------------\n // CRUD — create\n // ---------------------------------------------------------------------------\n\n async createPermission(input: {\n role: string;\n resource: string;\n scope: string;\n method: Permission[\"method\"];\n }): Promise<Permission> {\n if (!input.role?.trim()) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Role is required\");\n }\n if (!input.resource?.trim()) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Resource is required\");\n }\n if (!input.scope?.trim()) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Scope is required\");\n }\n\n // Duplicate check\n const permissionKey = `${input.role}#${input.resource}#${input.scope}`;\n const existing = await this.repo.findByPermissionKey(permissionKey);\n if (existing) {\n throw new ErrorHttp({ code: 409, error: \"Conflict\" }, `Permission \"${permissionKey}\" already exists`);\n }\n\n const saved = await this.repo.save({\n role: input.role.trim(),\n resource: input.resource.trim(),\n scope: input.scope.trim(),\n method: input.method ?? {},\n permissionKey,\n });\n\n this.cache.clear();\n return saved;\n }\n\n // ---------------------------------------------------------------------------\n // CRUD — update\n // ---------------------------------------------------------------------------\n\n async updatePermission(\n id: string,\n updates: Partial<Pick<Permission, \"role\" | \"resource\" | \"scope\" | \"method\">>,\n ): Promise<Permission> {\n if (!id) throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Permission id is required\");\n\n const existing = await this.repo.findById(id);\n if (!existing) throw new ErrorHttp({ code: 404, error: \"NotFound\" }, `Permission \"${id}\" not found`);\n\n const data: Partial<Permission> = { id };\n if (updates.role !== undefined) data.role = updates.role.trim();\n if (updates.resource !== undefined) data.resource = updates.resource.trim();\n if (updates.scope !== undefined) data.scope = updates.scope.trim();\n if (updates.method !== undefined) data.method = updates.method;\n\n // Rebuild key if any key component changed\n const role = data.role ?? existing.role;\n const resource = data.resource ?? existing.resource;\n const scope = data.scope ?? existing.scope;\n data.permissionKey = `${role}#${resource}#${scope}`;\n\n // Check for duplicate key if components changed\n if (data.permissionKey !== existing.permissionKey) {\n const conflict = await this.repo.findByPermissionKey(data.permissionKey);\n if (conflict) {\n throw new ErrorHttp({ code: 409, error: \"Conflict\" }, `Permission \"${data.permissionKey}\" already exists`);\n }\n }\n\n const updated = await this.repo.update(data);\n\n this.cache.clear();\n return updated;\n }\n\n // ---------------------------------------------------------------------------\n // CRUD — delete\n // ---------------------------------------------------------------------------\n\n async deletePermission(id: string): Promise<boolean> {\n if (!id) throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Permission id is required\");\n\n const existing = await this.repo.findById(id);\n if (!existing) throw new ErrorHttp({ code: 404, error: \"NotFound\" }, `Permission \"${id}\" not found`);\n\n const result = await this.repo.delete(id);\n\n this.cache.clear();\n return result;\n }\n\n // ---------------------------------------------------------------------------\n // CRUD — list\n // ---------------------------------------------------------------------------\n\n async listPermissions(filter?: Filter): Promise<List<Partial<Permission>>> {\n return this.repo.findByIndex(filter);\n }\n\n // ---------------------------------------------------------------------------\n // Cache control (for testing)\n // ---------------------------------------------------------------------------\n\n clearCache(): void {\n this.cache.clear();\n }\n}\n"]}
|
|
@@ -10,8 +10,17 @@ exports.boolQueryMap = {
|
|
|
10
10
|
nin: (field, value) => ({ query: buildTermsFilter(field, value), negation: true }),
|
|
11
11
|
gte: (field, value, existing) => buildRangeFilter(field, value, types_1.RangeTypeOS.gte, existing),
|
|
12
12
|
lte: (field, value, existing) => buildRangeFilter(field, value, types_1.RangeTypeOS.lte, existing),
|
|
13
|
+
gt: (field, value, existing) => buildRangeFilter(field, value, types_1.RangeTypeOS.gt, existing),
|
|
14
|
+
lt: (field, value, existing) => buildRangeFilter(field, value, types_1.RangeTypeOS.lt, existing),
|
|
13
15
|
exists: (field, value) => buildExistsFilter(field, value),
|
|
14
16
|
regex: (field, value) => buildRegexpFilter(field, value),
|
|
17
|
+
prefix: (field, value) => buildPrefixFilter(field, value),
|
|
18
|
+
not_prefix: (field, value) => ({ query: buildPrefixFilter(field, value), negation: true }),
|
|
19
|
+
contains: (field, value) => buildContainsFilter(field, value),
|
|
20
|
+
not_contains: (field, value) => ({ query: buildContainsFilter(field, value), negation: true }),
|
|
21
|
+
wildcard: (field, value) => buildWildcardFilter(field, value),
|
|
22
|
+
not_wildcard: (field, value) => ({ query: buildWildcardFilter(field, value), negation: true }),
|
|
23
|
+
fuzzy: (field, value) => buildFuzzyFilter(field, value),
|
|
15
24
|
};
|
|
16
25
|
// ---------------- Operator Functions ----------------
|
|
17
26
|
function buildTermFilter(field, value) {
|
|
@@ -37,4 +46,20 @@ function buildExistsFilter(field, value) {
|
|
|
37
46
|
function buildRegexpFilter(field, value) {
|
|
38
47
|
return { regexp: { [field]: value } };
|
|
39
48
|
}
|
|
49
|
+
// Prefix: startsWith — used for tree path hierarchy (categoryPaths__prefix)
|
|
50
|
+
function buildPrefixFilter(field, value) {
|
|
51
|
+
return { prefix: { [`${field}.keyword`]: value } };
|
|
52
|
+
}
|
|
53
|
+
// Contains: substring match anywhere in the value (categoryPaths__contains)
|
|
54
|
+
function buildContainsFilter(field, value) {
|
|
55
|
+
return { wildcard: { [`${field}.keyword`]: { value: `*${value}*`, case_insensitive: true } } };
|
|
56
|
+
}
|
|
57
|
+
// Wildcard: user-supplied pattern with * and ? (field__wildcard: "ном*уран?охиол")
|
|
58
|
+
function buildWildcardFilter(field, value) {
|
|
59
|
+
return { wildcard: { [`${field}.keyword`]: { value, case_insensitive: true } } };
|
|
60
|
+
}
|
|
61
|
+
// Fuzzy: approximate/typo-tolerant match (field__fuzzy: "ураnзохиол")
|
|
62
|
+
function buildFuzzyFilter(field, value) {
|
|
63
|
+
return { fuzzy: { [field]: { value, fuzziness: "AUTO", prefix_length: 1 } } };
|
|
64
|
+
}
|
|
40
65
|
//# sourceMappingURL=opensearch.parser.query.map.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opensearch.parser.query.map.js","sourceRoot":"","sources":["../../../src/utils/opensearch/opensearch.parser.query.map.ts"],"names":[],"mappings":";;;AAAA,2CAA+D;AAE/D,mDAAmD;AACtC,QAAA,YAAY,GAGrB;IACF,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC;IACnD,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAChF,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC;IACpD,GAAG,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAClF,GAAG,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,mBAAW,CAAC,GAAG,EAAE,QAAQ,CAAC;IAC1F,GAAG,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,gBAA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E,CAAC;AACxC,CAAC;AAED,4EAA4E;AAC5E,SAAS,iBAAiB,CAAC,KAAa,EAAE,KAAa;IACrD,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,KAAK,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;AACrD,CAAC;AAED,4EAA4E;AAC5E,SAAS,mBAAmB,CAAC,KAAa,EAAE,KAAa;IACvD,OAAO,EAAE,QAAQ,EAAE,EAAE,CAAC,GAAG,KAAK,UAAU,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,KAAK,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AACjG,CAAC;AAED,mFAAmF;AACnF,SAAS,mBAAmB,CAAC,KAAa,EAAE,KAAa;IACvD,OAAO,EAAE,QAAQ,EAAE,EAAE,CAAC,GAAG,KAAK,UAAU,CAAC,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AACnF,CAAC;AAED,sEAAsE;AACtE,SAAS,gBAAgB,CAAC,KAAa,EAAE,KAAa;IACpD,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;AAChF,CAAC","sourcesContent":["import { BoolQueryTypeOS, RangeTypeOS } from \"@chinggis/types\";\n\n// ---------------- Bool Query Map ----------------\nexport const boolQueryMap: Record<\n BoolQueryTypeOS,\n (field: string, value: string, existing?: Record<string, any>) => { query: any; negation?: boolean } | any\n> = {\n eq: (field, value) => buildTermFilter(field, value),\n ne: (field, value) => ({ query: buildTermFilter(field, value), negation: true }),\n in: (field, value) => buildTermsFilter(field, value),\n nin: (field, value) => ({ query: buildTermsFilter(field, value), negation: true }),\n gte: (field, value, existing) => buildRangeFilter(field, value, RangeTypeOS.gte, existing),\n lte: (field, value, existing) => buildRangeFilter(field, value, RangeTypeOS.lte, existing),\n gt: (field, value, existing) => buildRangeFilter(field, value, RangeTypeOS.gt, existing),\n lt: (field, value, existing) => buildRangeFilter(field, value, RangeTypeOS.lt, existing),\n exists: (field, value) => buildExistsFilter(field, value),\n regex: (field, value) => buildRegexpFilter(field, value),\n prefix: (field, value) => buildPrefixFilter(field, value),\n not_prefix: (field, value) => ({ query: buildPrefixFilter(field, value), negation: true }),\n contains: (field, value) => buildContainsFilter(field, value),\n not_contains: (field, value) => ({ query: buildContainsFilter(field, value), negation: true }),\n wildcard: (field, value) => buildWildcardFilter(field, value),\n not_wildcard: (field, value) => ({ query: buildWildcardFilter(field, value), negation: true }),\n fuzzy: (field, value) => buildFuzzyFilter(field, value),\n};\n\n// ---------------- Operator Functions ----------------\nfunction buildTermFilter(field: string, value: string) {\n return { term: { [field]: value } };\n}\n\nfunction buildTermsFilter(field: string, value: string) {\n return { terms: { [field]: value.split(\",\") } };\n}\n\nfunction buildRangeFilter(field: string, value: string, operator: RangeTypeOS, existing?: Record<string, any>) {\n const val = isNaN(Number(value)) ? value : Number(value);\n return {\n range: {\n [field]: {\n ...(existing?.[field] || {}),\n [operator]: val,\n },\n },\n };\n}\n\nfunction buildExistsFilter(field: string, value: string | boolean) {\n return { query: { exists: { field } }, negation: value === \"false\" || value === false };\n}\n\nfunction buildRegexpFilter(field: string, value: string) {\n return { regexp: { [field]: value } };\n}\n\n// Prefix: startsWith — used for tree path hierarchy (categoryPaths__prefix)\nfunction buildPrefixFilter(field: string, value: string) {\n return { prefix: { [`${field}.keyword`]: value } };\n}\n\n// Contains: substring match anywhere in the value (categoryPaths__contains)\nfunction buildContainsFilter(field: string, value: string) {\n return { wildcard: { [`${field}.keyword`]: { value: `*${value}*`, case_insensitive: true } } };\n}\n\n// Wildcard: user-supplied pattern with * and ? (field__wildcard: \"ном*уран?охиол\")\nfunction buildWildcardFilter(field: string, value: string) {\n return { wildcard: { [`${field}.keyword`]: { value, case_insensitive: true } } };\n}\n\n// Fuzzy: approximate/typo-tolerant match (field__fuzzy: \"ураnзохиол\")\nfunction buildFuzzyFilter(field: string, value: string) {\n return { fuzzy: { [field]: { value, fuzziness: \"AUTO\", prefix_length: 1 } } };\n}\n"]}
|