@via-profit/ability 3.4.0 → 3.5.0

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/package.json CHANGED
@@ -1,73 +1,74 @@
1
- {
2
- "name": "@via-profit/ability",
3
- "support": "https://via-profit.ru",
4
- "version": "3.4.0",
5
- "description": "Via-Profit Ability service",
6
- "keywords": [
7
- "ability",
8
- "access",
9
- "via-profit"
10
- ],
11
- "main": "./dist/index.js",
12
- "engines": {
13
- "node": ">= 17.0.0",
14
- "npm": ">= 8.19.3"
15
- },
16
- "files": [
17
- "dist",
18
- "README.md",
19
- "LICENSE",
20
- "CHANGELOG.md",
21
- "CONTRIBUTING.md",
22
- "SECURITY.md"
23
- ],
24
- "scripts": {
25
- "build": "rollup -c",
26
- "build:dev": "cross-env NODE_ENV=development rollup -c -w",
27
- "bench": "npm run build && node ./bench/benchmark.js",
28
- "test": "jest",
29
- "lint": "tsc --noEmit && eslint --fix .",
30
- "pretty": "prettier --write ./src"
31
- },
32
- "repository": {
33
- "type": "git",
34
- "url": "https://github.com/via-profit/ability.git"
35
- },
36
- "author": {
37
- "name": "Via Profit",
38
- "url": "https://dev.via-profit.ru"
39
- },
40
- "contributors": [
41
- "Vasily Novosad <delhsmail@gmail.com>",
42
- "Pavel Natalin <trubonru@gmail.com>"
43
- ],
44
- "license": "MIT",
45
- "devDependencies": {
46
- "@eslint/js": "^9.13.0",
47
- "@jagi/jest-transform-graphql": "^1.0.2",
48
- "@jest/types": "^29.6.3",
49
- "@rollup/plugin-alias": "^6.0.0",
50
- "@rollup/plugin-commonjs": "^29.0.2",
51
- "@rollup/plugin-node-resolve": "^16.0.3",
52
- "@rollup/plugin-typescript": "^12.3.0",
53
- "@types/jest": "^29.5.13",
54
- "@types/node": "^22.7.7",
55
- "@types/nodemon": "^1.19.6",
56
- "concurrently": "^9.0.1",
57
- "cross-env": "^7.0.3",
58
- "eslint": "^9.13.0",
59
- "globals": "^15.11.0",
60
- "jest": "^29.7.0",
61
- "jest-transform-graphql": "^2.1.0",
62
- "nodemon": "^3.1.7",
63
- "prettier": "^3.3.3",
64
- "rollup": "^4.60.0",
65
- "rollup-plugin-copy": "^3.5.0",
66
- "tinybench": "^6.0.0",
67
- "ts-jest": "^29.2.5",
68
- "ts-loader": "^9.5.1",
69
- "ts-node": "^10.9.2",
70
- "typescript": "^5.6.3",
71
- "typescript-eslint": "^8.10.0"
72
- }
73
- }
1
+ {
2
+ "name": "@via-profit/ability",
3
+ "support": "https://via-profit.ru",
4
+ "version": "3.5.0",
5
+ "description": "Via-Profit Ability service",
6
+ "keywords": [
7
+ "ability",
8
+ "access",
9
+ "via-profit"
10
+ ],
11
+ "main": "./dist/index.js",
12
+ "engines": {
13
+ "node": ">= 17.0.0",
14
+ "npm": ">= 8.19.3"
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "LICENSE",
20
+ "CHANGELOG.md",
21
+ "CONTRIBUTING.md",
22
+ "SECURITY.md"
23
+ ],
24
+ "scripts": {
25
+ "build": "rollup -c",
26
+ "build:dev": "cross-env NODE_ENV=development rollup -c -w",
27
+ "bench": "npm run build && node ./bench/benchmark.js",
28
+ "test": "jest",
29
+ "lint": "tsc --noEmit && eslint --fix .",
30
+ "pretty": "prettier --write ./src"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/via-profit/ability.git"
35
+ },
36
+ "author": {
37
+ "name": "Via Profit",
38
+ "url": "https://dev.via-profit.ru"
39
+ },
40
+ "contributors": [
41
+ "Vasily Novosad <delhsmail@gmail.com>",
42
+ "Pavel Natalin <trubonru@gmail.com>"
43
+ ],
44
+ "license": "MIT",
45
+ "devDependencies": {
46
+ "@eslint/js": "^10.0.1",
47
+ "@jagi/jest-transform-graphql": "^1.0.2",
48
+ "@jest/types": "^30.3.0",
49
+ "@rollup/plugin-alias": "^6.0.0",
50
+ "@rollup/plugin-commonjs": "^29.0.2",
51
+ "@rollup/plugin-node-resolve": "^16.0.3",
52
+ "@rollup/plugin-typescript": "^12.3.0",
53
+ "@types/jest": "^30.0.0",
54
+ "@types/node": "^25.5.0",
55
+ "concurrently": "^9.2.1",
56
+ "cross-env": "^10.1.0",
57
+ "eslint": "^10.1.0",
58
+ "eslint-plugin-jest": "^29.15.1",
59
+ "globals": "^17.4.0",
60
+ "jest": "^30.3.0",
61
+ "jest-transform-graphql": "^2.1.0",
62
+ "nodemon": "^3.1.14",
63
+ "prettier": "^3.8.1",
64
+ "rollup": "^4.60.1",
65
+ "rollup-plugin-copy": "^3.5.0",
66
+ "rollup-plugin-dts": "^6.4.1",
67
+ "tinybench": "^6.0.0",
68
+ "ts-jest": "^29.4.9",
69
+ "ts-loader": "^9.5.4",
70
+ "ts-node": "^10.9.2",
71
+ "typescript": "^6.0.2",
72
+ "typescript-eslint": "^8.58.0"
73
+ }
74
+ }
@@ -1,8 +0,0 @@
1
- export interface AbilityCacheAdapter {
2
- get<T = unknown>(key: string): Promise<T | undefined>;
3
- set<T = unknown>(key: string, value: T, ttlSeconds?: number): Promise<void>;
4
- serialize<T = unknown>(input: T): string;
5
- delete(key: string): Promise<void>;
6
- clear(): Promise<void>;
7
- deleteByPrefix(prefix: string): Promise<void>;
8
- }
@@ -1,12 +0,0 @@
1
- import { AbilityCacheAdapter } from '../cache/AbilityCacheAdapter';
2
- export declare class AbilityInMemoryCache implements AbilityCacheAdapter {
3
- private store;
4
- get<T>(key: string): Promise<T | undefined>;
5
- set<T>(key: string, value: T, ttlSeconds?: number): Promise<void>;
6
- serialize(input: unknown): string;
7
- delete(key: string): Promise<void>;
8
- clear(): Promise<void>;
9
- deleteByPrefix(prefix: string): Promise<void>;
10
- private fastHash;
11
- private stableStringify;
12
- }
@@ -1,8 +0,0 @@
1
- export declare class AbilityCode<Code extends string | number> {
2
- _code: Code;
3
- constructor(code: Code);
4
- get code(): Code;
5
- isEqual(compareWith: AbilityCode<Code> | null): boolean;
6
- isNotEqual(compareWith: AbilityCode<Code> | null): boolean;
7
- }
8
- export default AbilityCode;
@@ -1,7 +0,0 @@
1
- import AbilityCode from './AbilityCode';
2
- export type AbilityCompareCodeType = 'and' | 'or';
3
- export declare class AbilityCompare extends AbilityCode<AbilityCompareCodeType> {
4
- static and: AbilityCompare;
5
- static or: AbilityCompare;
6
- }
7
- export default AbilityCompare;
@@ -1,23 +0,0 @@
1
- import AbilityCode from './AbilityCode';
2
- export type AbilityConditionCodeType = '=' | '<>' | '>' | '<' | '>=' | '<=' | 'in' | 'not in' | 'contains' | 'not contains' | 'length greater than' | 'length less than' | 'length equals' | 'always' | 'never';
3
- export type AbilityConditionLiteralType = 'equals' | 'not_equals' | 'contains' | 'no_contains' | 'in' | 'not_in' | 'greater_than' | 'less_than' | 'less_or_equal' | 'greater_or_equal' | 'length_greater_than' | 'length_less_than' | 'length_equals' | 'always' | 'never';
4
- export declare class AbilityCondition extends AbilityCode<AbilityConditionCodeType> {
5
- static equals: AbilityCondition;
6
- static not_equals: AbilityCondition;
7
- static greater_than: AbilityCondition;
8
- static less_than: AbilityCondition;
9
- static less_or_equal: AbilityCondition;
10
- static greater_or_equal: AbilityCondition;
11
- static in: AbilityCondition;
12
- static not_in: AbilityCondition;
13
- static contains: AbilityCondition;
14
- static not_contains: AbilityCondition;
15
- static length_greater_than: AbilityCondition;
16
- static length_less_than: AbilityCondition;
17
- static length_equals: AbilityCondition;
18
- static always: AbilityCondition;
19
- static never: AbilityCondition;
20
- static fromLiteral(literal: AbilityConditionLiteralType): AbilityCondition;
21
- get literal(): AbilityConditionLiteralType;
22
- }
23
- export default AbilityCondition;
@@ -1,6 +0,0 @@
1
- export declare class AbilityError extends Error {
2
- constructor(message: string);
3
- }
4
- export declare class AbilityParserError extends Error {
5
- constructor(message: string);
6
- }
@@ -1,27 +0,0 @@
1
- import AbilityRule from './AbilityRule';
2
- import AbilityRuleSet from '../core/AbilityRuleSet';
3
- import AbilityPolicy from '../core/AbilityPolicy';
4
- import AbilityMatch from '../core/AbilityMatch';
5
- export type AbilityExplainConfig = {
6
- readonly type: AbilityExplainType;
7
- readonly name: string;
8
- readonly match: AbilityMatch;
9
- };
10
- export declare class AbilityExplain {
11
- readonly type: AbilityExplainType;
12
- readonly children: AbilityExplain[];
13
- readonly name: string;
14
- readonly match: AbilityMatch;
15
- constructor(config: AbilityExplainConfig, children?: AbilityExplain[]);
16
- toString(indent?: number): string;
17
- }
18
- export declare class AbilityExplainRule extends AbilityExplain {
19
- constructor(rule: AbilityRule);
20
- }
21
- export declare class AbilityExplainRuleSet extends AbilityExplain {
22
- constructor(ruleSet: AbilityRuleSet);
23
- }
24
- export declare class AbilityExplainPolicy extends AbilityExplain {
25
- constructor(policy: AbilityPolicy);
26
- }
27
- export type AbilityExplainType = 'policy' | 'rule' | 'ruleSet';
@@ -1,8 +0,0 @@
1
- import AbilityCode from './AbilityCode';
2
- export type AbilityMatchCodeType = 'pending' | 'match' | 'mismatch';
3
- export declare class AbilityMatch extends AbilityCode<AbilityMatchCodeType> {
4
- static pending: AbilityMatch;
5
- static match: AbilityMatch;
6
- static mismatch: AbilityMatch;
7
- }
8
- export default AbilityMatch;
@@ -1,61 +0,0 @@
1
- import AbilityPolicy from './AbilityPolicy';
2
- export type Primitive = string | number | boolean | null | undefined;
3
- export type NestedDict<T = Primitive> = {
4
- [key: string]: NestedDict<T> | T;
5
- };
6
- export type ResourceObject = Record<string, unknown>;
7
- export type ResourcesMap = Record<string, ResourceObject>;
8
- export declare class AbilityParser {
9
- /**
10
- * Sets a value in a nested object structure based on a dot/bracket notation path.
11
- * @param object - The target object to modify.
12
- * @param path - The path to the property in dot/bracket notation.
13
- * @param value - The value to set at the specified path.
14
- */
15
- static setValueDotValue<T extends Primitive>(object: NestedDict<T>, path: string, value: T): void;
16
- /**
17
- * Generates TypeScript type definitions based on the provided policies.
18
- * @param policies - An array of AbilityPolicy instances.
19
- * @returns A generated type definitions.
20
- */
21
- static generateTypeDefs(policies: readonly AbilityPolicy[]): string;
22
- /**
23
- * Determines TypeScript type based on the rule
24
- * @param rule - The rule to analyze
25
- * @returns TypeScript type as string
26
- */
27
- private static determineTypeFromRule;
28
- /**
29
- * Gets TypeScript type for array values
30
- * @param resource - The resource value to analyze
31
- * @returns TypeScript array type as string
32
- */
33
- private static getArrayType;
34
- /**
35
- * Gets primitive TypeScript type for a value
36
- * @param value - The value to analyze
37
- * @returns TypeScript primitive type as string
38
- */
39
- private static getPrimitiveType;
40
- /**
41
- * Builds nested structure from flat paths
42
- * Example: 'user.profile.name' -> { user: { profile: { name: 'string' } } }
43
- * @param flatStructure - Flat structure with dot notation paths
44
- * @returns Nested object structure
45
- */
46
- private static buildNestedStructure;
47
- /**
48
- * Formats type structure into a string
49
- * @param structure - Nested type structure
50
- * @returns Formatted TypeScript type definition string
51
- */
52
- private static formatTypeDefinitions;
53
- /**
54
- * Recursively formats nested object
55
- * @param obj - Object to format
56
- * @param indent - Current indentation level
57
- * @returns Formatted string
58
- */
59
- private static formatNestedObject;
60
- }
61
- export default AbilityParser;
@@ -1,79 +0,0 @@
1
- import AbilityRuleSet, { AbilityRuleSetConfig } from './AbilityRuleSet';
2
- import AbilityMatch from './AbilityMatch';
3
- import AbilityCompare, { AbilityCompareCodeType } from './AbilityCompare';
4
- import AbilityPolicyEffect, { AbilityPolicyEffectCodeType } from './AbilityPolicyEffect';
5
- import { AbilityExplain } from './AbilityExplain';
6
- import { ResourceObject } from './AbilityTypeGenerator';
7
- export type AbilityPolicyConfig = {
8
- readonly permission: string;
9
- readonly effect: AbilityPolicyEffectCodeType;
10
- readonly compareMethod: AbilityCompareCodeType;
11
- readonly ruleSet: readonly AbilityRuleSetConfig[];
12
- readonly id: string;
13
- readonly name: string;
14
- };
15
- export type AbilityPolicyConstructorProps = {
16
- id: string;
17
- name: string;
18
- permission: string;
19
- effect: AbilityPolicyEffect;
20
- compareMethod?: AbilityCompare;
21
- };
22
- export declare class AbilityPolicy<Resource extends ResourceObject = Record<string, unknown>, Environment = unknown> {
23
- matchState: AbilityMatch;
24
- /**
25
- * List of rules
26
- */
27
- ruleSet: AbilityRuleSet<Resource, Environment>[];
28
- /**
29
- * Policy effect
30
- */
31
- effect: AbilityPolicyEffect;
32
- /**
33
- * Rules compare method.\
34
- * For the «and» method the rule will be permitted if all\
35
- * rules will be returns «permit» status and for the «or» - if\
36
- * one of the rules returns as «permit»
37
- */
38
- compareMethod: AbilityCompare;
39
- /**
40
- * Policy name
41
- */
42
- name: string;
43
- /**
44
- * Policy ID
45
- */
46
- id: string;
47
- /**
48
- * Running the `enforce` or `resolve` method
49
- * will select only those from all passed policies that fall under the specified permission key.
50
- */
51
- permission: string;
52
- constructor(params: AbilityPolicyConstructorProps);
53
- /**
54
- * Add rule set to the policy
55
- * @param ruleSet - The rule set to add
56
- */
57
- addRuleSet(ruleSet: AbilityRuleSet<Resource, Environment>): this;
58
- /**
59
- * Add rule set to the policy
60
- * @param ruleSets - The array of rule set to add
61
- */
62
- addRuleSets(ruleSets: readonly AbilityRuleSet<Resource, Environment>[]): this;
63
- /**
64
- * Check if the policy is matched
65
- * @param resource - The resource to check
66
- * @param environment - The user environment object
67
- */
68
- check(resource: Resource, environment?: Environment): Promise<AbilityMatch>;
69
- explain(): AbilityExplain;
70
- copyWith(props: Partial<{
71
- id: string;
72
- name: string;
73
- permission: string;
74
- effect: AbilityPolicyEffect;
75
- compareMethod: AbilityCompare;
76
- ruleSet: AbilityRuleSet<Resource, Environment>[];
77
- }>): AbilityPolicy<Resource, Environment>;
78
- }
79
- export default AbilityPolicy;
@@ -1,7 +0,0 @@
1
- import AbilityCode from './AbilityCode';
2
- export type AbilityPolicyEffectCodeType = 'deny' | 'permit';
3
- export declare class AbilityPolicyEffect extends AbilityCode<AbilityPolicyEffectCodeType> {
4
- static deny: AbilityPolicyEffect;
5
- static permit: AbilityPolicyEffect;
6
- }
7
- export default AbilityPolicyEffect;
@@ -1,35 +0,0 @@
1
- import AbilityPolicy from './AbilityPolicy';
2
- import { AbilityResult } from './AbilityResult';
3
- import { ResourcesMap } from './AbilityTypeGenerator';
4
- import { AbilityCacheAdapter } from '../cache/AbilityCacheAdapter';
5
- export type AbilityResolverOptions = {
6
- readonly cache?: AbilityCacheAdapter | null;
7
- };
8
- export declare class AbilityResolver<Resources extends ResourcesMap, Environment = unknown> {
9
- private policies;
10
- private readonly cache?;
11
- constructor(
12
- /**
13
- * `Important!` The incorrect Resources type was intentionally passed to AbilityPolicy so that TypeScript could suggest the name of the permission and the structure of its resource in the parse method.
14
- */
15
- policyOrListOfPolicies: readonly AbilityPolicy<Resources>[] | AbilityPolicy<Resources>, options?: AbilityResolverOptions);
16
- /**
17
- * Resolve policy for the resource and permission key
18
- *
19
- * @param permission - Permission key
20
- * @param resource - Resource
21
- * @param environment
22
- */
23
- resolve<Permission extends keyof Resources>(permission: Permission, resource: Resources[Permission], environment?: Environment): Promise<AbilityResult<Resources[Permission]>>;
24
- enforce<Permission extends keyof Resources>(permission: Permission, resource: Resources[Permission], environment?: Environment): Promise<void | never>;
25
- /**
26
- * Check if the permission key is contained in another permission key
27
- * @param permissionA - The first permission to check
28
- * @param permissionB - The second permission to check
29
- */
30
- static isInPermissionContain(permissionA: string, permissionB: string): boolean;
31
- private makeCacheKey;
32
- invalidatePolicy(policyId: string): Promise<void>;
33
- invalidateCache(): Promise<void>;
34
- }
35
- export default AbilityResolver;
@@ -1,27 +0,0 @@
1
- import { AbilityExplain } from './AbilityExplain';
2
- import { ResourceObject } from './AbilityTypeGenerator';
3
- import AbilityPolicy from './AbilityPolicy';
4
- import AbilityPolicyEffect from './AbilityPolicyEffect';
5
- export declare class AbilityResult<Resource extends ResourceObject = Record<string, unknown>> {
6
- /**
7
- * Already checked policies (after call the policy.check())
8
- */
9
- readonly policies: readonly AbilityPolicy<Resource>[];
10
- constructor(policies: readonly AbilityPolicy<Resource>[]);
11
- /**
12
- * Returns a list of explanations for each policy involved in the ability evaluation.
13
- * Each item describes how a specific policy contributed to the final permission result.
14
- *
15
- * Useful for debugging, logging, or building UI tools that visualize permission logic.
16
- */
17
- explain(): readonly AbilityExplain[];
18
- getLastMatchedPolicy(): AbilityPolicy<Resource> | null;
19
- isAllowed(): boolean;
20
- isDenied(): boolean;
21
- /**
22
- * Get the last effect of the policy
23
- *
24
- * @returns {AbilityPolicyEffect | null}
25
- */
26
- getLastEffectOfMatchedPolicy(): AbilityPolicyEffect | null;
27
- }
@@ -1,83 +0,0 @@
1
- import AbilityMatch from './AbilityMatch';
2
- import AbilityCondition, { AbilityConditionCodeType } from './AbilityCondition';
3
- export type AbilityRuleConfig = {
4
- readonly id?: string | null;
5
- readonly name?: string | null;
6
- /**
7
- * Subject key path like a 'user.name'
8
- */
9
- readonly subject: string;
10
- /**
11
- * Resource key path like a 'user.name' or value
12
- */
13
- readonly resource: string | number | boolean | null | (string | number | boolean | null)[];
14
- readonly condition: AbilityConditionCodeType;
15
- };
16
- export type AbilityRuleConstructorProps = Omit<AbilityRuleConfig, 'condition'> & {
17
- readonly condition: AbilityCondition;
18
- };
19
- /**
20
- * Represents a rule that defines a condition to be checked against a subject and resource.
21
- */
22
- export declare class AbilityRule<Resources extends object = object, Environment = unknown> {
23
- /**
24
- * Subject key path like a 'user.name'
25
- */
26
- subject: string;
27
- /**
28
- * Resource key path like a 'user.name' or value
29
- */
30
- resource: AbilityRuleConfig['resource'];
31
- condition: AbilityCondition;
32
- name: string;
33
- id: string;
34
- state: AbilityMatch;
35
- /**
36
- * Creates an instance of AbilityRule.
37
- * @param {string} params.id - The unique identifier of the rule.
38
- * @param {string} params.name - The name of the rule.
39
- * @param {AbilityCondition} params.condition - The condition to evaluate.
40
- * @param {string} params.subject - The subject of the rule.
41
- * @param {string} params.resource - The resource to compare against.
42
- * @param params
43
- */
44
- constructor(params: AbilityRuleConstructorProps);
45
- /**
46
- * Check if the rule is matched
47
- * @param resource - The resource to check
48
- * @param environment
49
- */
50
- check(resource: Resources | null, environment?: Environment): Promise<AbilityMatch>;
51
- /**
52
- * Extract values from the resourceData
53
- * @param resourceData - The resourceData to extract values from
54
- * @param environment - Environment data
55
- */
56
- extractValues(resourceData: Resources | null, environment?: Environment | null): [AbilityRuleConfig['resource'] | undefined, AbilityRuleConfig['resource'] | undefined];
57
- /**
58
- * Get the value of the object by dot notation
59
- * @param resource - The object to get the value from
60
- * @param desc - The dot notation string
61
- */
62
- getDotNotationValue<T = unknown>(resource: unknown, desc: string): T | undefined;
63
- toString(): string;
64
- copyWith(props: Partial<{
65
- id: string | null;
66
- name: string | null;
67
- subject: string;
68
- resource: AbilityRuleConfig['resource'];
69
- condition: AbilityCondition;
70
- }>): AbilityRule<Resources, Environment>;
71
- static equals<Resources extends object = object, Environment = unknown>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
72
- static notEquals<Resources extends object = object, Environment = unknown>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
73
- static contains<Resources extends object = object, Environment = unknown>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
74
- static notContains<Resources extends object = object, Environment = unknown>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
75
- static notIn<Resources extends object = object, Environment = unknown>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
76
- static in<Resources extends object = object, Environment = unknown>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
77
- static notEqual<Resources extends object = object, Environment = unknown>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
78
- static lessThan<Resources extends object = object, Environment = unknown>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
79
- static lessOrEqual<Resources extends object = object, Environment = unknown>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
80
- static moreThan<Resources extends object = object, Environment = unknown>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
81
- static moreOrEqual<Resources extends object = object, Environment = unknown>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
82
- }
83
- export default AbilityRule;
@@ -1,51 +0,0 @@
1
- import AbilityRule, { AbilityRuleConfig } from './AbilityRule';
2
- import AbilityCompare, { AbilityCompareCodeType } from './AbilityCompare';
3
- import AbilityMatch from './AbilityMatch';
4
- import { ResourceObject } from './AbilityTypeGenerator';
5
- export type AbilityRuleSetConfig = {
6
- readonly id?: string | null;
7
- readonly name?: string | null;
8
- readonly compareMethod: AbilityCompareCodeType;
9
- readonly rules: readonly AbilityRuleConfig[];
10
- };
11
- export type AbilityRuleSetConstructorProps = {
12
- readonly id?: string | null;
13
- readonly name?: string | null;
14
- readonly compareMethod: AbilityCompare;
15
- };
16
- export declare class AbilityRuleSet<Resources extends ResourceObject = Record<string, unknown>, Environment = unknown> {
17
- state: AbilityMatch;
18
- /**
19
- * List of rules
20
- */
21
- rules: AbilityRule<Resources, Environment>[];
22
- /**
23
- * Rules compare method.\
24
- * For the «and» method the rule will be permitted if all\
25
- * rules will be returns «permit» status and for the «or» - if\
26
- * one of the rules returns as «permit»
27
- */
28
- compareMethod: AbilityCompare;
29
- /**
30
- * Group name
31
- */
32
- name: string;
33
- /**
34
- * Group ID
35
- */
36
- id: string;
37
- constructor(params: AbilityRuleSetConstructorProps);
38
- addRule(rule: AbilityRule<Resources, Environment>): this;
39
- addRules(rules: AbilityRule<Resources, Environment>[]): this;
40
- check(resources: Resources | null, environment?: Environment): Promise<AbilityMatch>;
41
- toString(): string;
42
- copyWith(props: Partial<{
43
- id: string | null;
44
- name: string | null;
45
- compareMethod: AbilityCompare;
46
- rules: AbilityRule<Resources, Environment>[];
47
- }>): AbilityRuleSet<Resources, Environment>;
48
- static and(rules: AbilityRule[]): AbilityRuleSet<Record<string, unknown>, unknown>;
49
- static or(rules: AbilityRule[]): AbilityRuleSet<Record<string, unknown>, unknown>;
50
- }
51
- export default AbilityRuleSet;