@via-profit/ability 3.6.5 → 3.7.3
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/README.md +42 -1286
- package/dist/index.cjs +1 -3380
- package/dist/index.d.ts +19 -6
- package/dist/index.js +1 -3344
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,13 +7,15 @@ declare const AbilityCompare: {
|
|
|
7
7
|
readonly and: AbilityCompareType;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
type AbilityConditionCode = '=' | '<>' | '>' | '<' | '>=' | '<=' | 'in' | 'not in' | 'contains' | 'not contains' | 'length greater than' | 'length less than' | 'length equals' | 'always' | 'never';
|
|
11
|
-
type AbilityConditionLiteral = 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'in' | 'not_in' | 'greater_than' | 'less_than' | 'less_or_equal' | 'greater_or_equal' | 'length_greater_than' | 'length_less_than' | 'length_equals' | 'always' | 'never';
|
|
10
|
+
type AbilityConditionCode = '=' | '<>' | '>' | '<' | '>=' | '<=' | 'in' | 'not in' | 'contains' | 'not contains' | 'length greater than' | 'length less than' | 'length equals' | 'always' | 'never' | 'defined' | 'not_defined';
|
|
11
|
+
type AbilityConditionLiteral = 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'in' | 'not_in' | 'greater_than' | 'less_than' | 'less_or_equal' | 'greater_or_equal' | 'length_greater_than' | 'length_less_than' | 'length_equals' | 'always' | 'never' | 'defined' | 'not_defined';
|
|
12
12
|
type AbilityConditionType = AbilityConditionCode & {
|
|
13
13
|
__brand: 'AbilityCondition';
|
|
14
14
|
};
|
|
15
15
|
declare const AbilityCondition: {
|
|
16
16
|
readonly equals: AbilityConditionType;
|
|
17
|
+
readonly defined: AbilityConditionType;
|
|
18
|
+
readonly not_defined: AbilityConditionType;
|
|
17
19
|
readonly not_equals: AbilityConditionType;
|
|
18
20
|
readonly greater_than: AbilityConditionType;
|
|
19
21
|
readonly less_than: AbilityConditionType;
|
|
@@ -438,7 +440,7 @@ declare abstract class AbilityStrategy<Resource extends ResourceObject = Record<
|
|
|
438
440
|
|
|
439
441
|
declare class AbilityResult<R extends ResourceObject = Record<string, unknown>, E extends EnvironmentObject = Record<string, unknown>> {
|
|
440
442
|
protected readonly effect: AbilityPolicyEffectType;
|
|
441
|
-
|
|
443
|
+
readonly strategy: AbilityStrategy<R, E>;
|
|
442
444
|
constructor(effect: AbilityPolicyEffectType, strategy: AbilityStrategy<R, E>);
|
|
443
445
|
/**
|
|
444
446
|
* Returns a list of explanations for each policy involved in the ability evaluation.
|
|
@@ -455,13 +457,23 @@ declare class AbilityResult<R extends ResourceObject = Record<string, unknown>,
|
|
|
455
457
|
|
|
456
458
|
interface AbilityResolverOptions<TTags extends string> {
|
|
457
459
|
tags?: readonly TTags[];
|
|
460
|
+
readonly onDeny?: EnforceOnDeny;
|
|
461
|
+
readonly onAllow?: EnforceOnAllow;
|
|
458
462
|
}
|
|
459
463
|
type ExtractResources<P> = P extends AbilityPolicy<infer R, any, any> ? R : never;
|
|
460
464
|
type ExtractEnvironment<P> = P extends AbilityPolicy<any, infer E, any> ? E : never;
|
|
461
465
|
type ExtractPermission<R> = R extends AbilityResolver<infer P, any, any> ? keyof ExtractResources<P> & string : never;
|
|
462
466
|
type ExtractResourceByPermission<P, Perm extends string> = P extends AbilityPolicy<infer R, any, any> ? (Perm extends keyof R ? R[Perm] : never) : never;
|
|
463
467
|
type ExtractEnvironmentByPermission<P, Perm extends string> = P extends AbilityPolicy<any, infer E, any> ? (Perm extends keyof E ? E[Perm] : never) : never;
|
|
468
|
+
type EnforceOptions<R extends ResourceObject = Record<string, unknown>, E extends EnvironmentObject = Record<string, unknown>> = {
|
|
469
|
+
readonly onDeny?: EnforceOnDeny<R, E>;
|
|
470
|
+
readonly onAllow?: EnforceOnDeny<R, E>;
|
|
471
|
+
};
|
|
472
|
+
type EnforceOnDeny<R extends ResourceObject = Record<string, unknown>, E extends EnvironmentObject = Record<string, unknown>> = (result: AbilityResult<R, E>) => void;
|
|
473
|
+
type EnforceOnAllow<R extends ResourceObject = Record<string, unknown>, E extends EnvironmentObject = Record<string, unknown>> = (result: AbilityResult<R, E>) => void;
|
|
464
474
|
declare class AbilityResolver<P extends AbilityPolicy<any, any, any>, S extends AbilityStrategy<P extends AbilityPolicy<infer R, infer E, any> ? R : never, P extends AbilityPolicy<any, infer E, any> ? E : never>, TTags extends string = P extends AbilityPolicy<any, any, infer T> ? T : never> {
|
|
475
|
+
private readonly onDeny?;
|
|
476
|
+
private readonly onAllow?;
|
|
465
477
|
private readonly StrategyClass;
|
|
466
478
|
private readonly policyEntries;
|
|
467
479
|
constructor(
|
|
@@ -477,7 +489,7 @@ declare class AbilityResolver<P extends AbilityPolicy<any, any, any>, S extends
|
|
|
477
489
|
* @param environment
|
|
478
490
|
*/
|
|
479
491
|
resolve<Permission extends keyof ExtractResources<P> & string>(permission: Permission, resource: ExtractResourceByPermission<P, Permission>, environment?: ExtractEnvironmentByPermission<P, Permission>): AbilityResult<ExtractResourceByPermission<P, Permission>, ExtractEnvironment<P>>;
|
|
480
|
-
enforce<Permission extends keyof ExtractResources<P> & string>(permission: Permission, resource: ExtractResourceByPermission<P, Permission>, environment?: ExtractEnvironmentByPermission<P, Permission
|
|
492
|
+
enforce<Permission extends keyof ExtractResources<P> & string>(permission: Permission, resource: ExtractResourceByPermission<P, Permission>, environment?: ExtractEnvironmentByPermission<P, Permission>, options?: EnforceOptions): void | never;
|
|
481
493
|
/**
|
|
482
494
|
* @deprecated - will be removed
|
|
483
495
|
*
|
|
@@ -590,7 +602,7 @@ declare class AbilityDSLParser<R extends ResourceObject = Record<string, unknown
|
|
|
590
602
|
private isStartOfAlias;
|
|
591
603
|
}
|
|
592
604
|
|
|
593
|
-
type TokenTypeCode = 'EFFECT' | 'IF' | 'PERMISSION' | 'IDENTIFIER' | 'COLON' | 'COMMA' | 'DOT' | 'LBRACKET' | 'RBRACKET' | 'ALL' | 'ANY' | 'OF' | 'EOF' | 'COMMENT' | 'EQ' | 'CONTAINS' | 'IN' | 'NOT_IN' | 'NOT_CONTAINS' | 'GT' | 'GTE' | 'LT' | 'LTE' | 'NULL' | 'EQ_NULL' | 'NOT_EQ_NULL' | 'NOT_EQ' | 'LEN_GT' | 'LEN_LT' | 'LEN_EQ' | 'ALWAYS' | 'NEVER' | 'EXCEPT' | 'ANNOTATION' | 'STRING' | 'NUMBER' | 'BOOLEAN' | 'SYMBOL' | 'KEYWORD' | 'ALIAS' | 'UNKNOWN';
|
|
605
|
+
type TokenTypeCode = 'EFFECT' | 'IF' | 'PERMISSION' | 'IDENTIFIER' | 'COLON' | 'COMMA' | 'DOT' | 'LBRACKET' | 'RBRACKET' | 'ALL' | 'ANY' | 'OF' | 'EOF' | 'COMMENT' | 'EQ' | 'CONTAINS' | 'IN' | 'NOT_IN' | 'NOT_CONTAINS' | 'GT' | 'GTE' | 'LT' | 'LTE' | 'NULL' | 'EQ_NULL' | 'NOT_EQ_NULL' | 'DEFINED' | 'NOT_EQ' | 'LEN_GT' | 'LEN_LT' | 'LEN_EQ' | 'ALWAYS' | 'NEVER' | 'EXCEPT' | 'ANNOTATION' | 'STRING' | 'NUMBER' | 'BOOLEAN' | 'SYMBOL' | 'KEYWORD' | 'ALIAS' | 'UNKNOWN';
|
|
594
606
|
type TokenType = TokenTypeCode & {
|
|
595
607
|
__brand: 'TokenType';
|
|
596
608
|
};
|
|
@@ -621,6 +633,7 @@ declare const TokenTypes: {
|
|
|
621
633
|
readonly NULL: TokenType;
|
|
622
634
|
readonly EQ_NULL: TokenType;
|
|
623
635
|
readonly NOT_EQ_NULL: TokenType;
|
|
636
|
+
readonly DEFINED: TokenType;
|
|
624
637
|
readonly NOT_EQ: TokenType;
|
|
625
638
|
readonly LEN_GT: TokenType;
|
|
626
639
|
readonly LEN_LT: TokenType;
|
|
@@ -858,4 +871,4 @@ declare class PriorityStrategy<R extends ResourceObject, E extends EnvironmentOb
|
|
|
858
871
|
}
|
|
859
872
|
|
|
860
873
|
export { AbilityCompare, AbilityCondition, AbilityDSLLexer, AbilityDSLParser, AbilityDSLToken, AbilityError, AbilityExplain, AbilityExplainPolicy, AbilityExplainRule, AbilityExplainRuleSet, AbilityJSONParser, AbilityMatch, AbilityParserError, AbilityPolicy, AbilityPolicyEffect, AbilityResolver, AbilityResult, AbilityRule, AbilityRuleSet, AbilityStrategy, AbilityTypeGenerator, AllMustPermitStrategy, AnyPermitStrategy, DenyOverridesStrategy, FirstMatchStrategy, OnlyOneApplicableStrategy, PermitOverridesStrategy, PriorityStrategy, SequentialLastMatchStrategy, TokenTypes, ability, fromLiteral, isConditionEqual, isConditionNotEqual, toLiteral };
|
|
861
|
-
export type { AbilityCompareType, AbilityConditionCode, AbilityConditionLiteral, AbilityConditionType, AbilityExplainConfig, AbilityExplainType, AbilityMatchType, AbilityPolicyConfig, AbilityPolicyConstructorProps, AbilityPolicyEffectType, AbilityResolverOptions, AbilityRuleConfig, AbilityRuleConstructorProps, AbilityRuleSetConfig, AbilityRuleSetConstructorProps, EnvironmentObject, ExtractEnvironment, ExtractEnvironmentByPermission, ExtractPermission, ExtractResourceByPermission, ExtractResources, NestedDict, Primitive, ResourceObject, ResourcesMap, TokenType, TokenTypeCode };
|
|
874
|
+
export type { AbilityCompareType, AbilityConditionCode, AbilityConditionLiteral, AbilityConditionType, AbilityExplainConfig, AbilityExplainType, AbilityMatchType, AbilityPolicyConfig, AbilityPolicyConstructorProps, AbilityPolicyEffectType, AbilityResolverOptions, AbilityRuleConfig, AbilityRuleConstructorProps, AbilityRuleSetConfig, AbilityRuleSetConstructorProps, EnforceOnAllow, EnforceOnDeny, EnforceOptions, EnvironmentObject, ExtractEnvironment, ExtractEnvironmentByPermission, ExtractPermission, ExtractResourceByPermission, ExtractResources, NestedDict, Primitive, ResourceObject, ResourcesMap, TokenType, TokenTypeCode };
|