@via-profit/ability 2.0.0-rc.2 → 2.0.0-rc.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/dist/AbilityPolicy.d.ts +8 -8
- package/dist/AbilityRule.d.ts +7 -4
- package/dist/AbilityRuleSet.d.ts +6 -6
- package/dist/index.js +18 -21
- package/package.json +1 -1
package/dist/AbilityPolicy.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import AbilityRule
|
|
1
|
+
import AbilityRule from './AbilityRule';
|
|
2
2
|
import AbilityRuleSet, { AbilityRuleSetConfig } from './AbilityRuleSet';
|
|
3
3
|
import AbilityMatch from './AbilityMatch';
|
|
4
4
|
import AbilityCompare from './AbilityCompare';
|
|
@@ -7,9 +7,9 @@ export type AbilityPolicyConfig = {
|
|
|
7
7
|
readonly action: string;
|
|
8
8
|
readonly effect: number;
|
|
9
9
|
readonly compareMethod: number;
|
|
10
|
-
readonly ruleSet:
|
|
11
|
-
readonly id
|
|
12
|
-
readonly name
|
|
10
|
+
readonly ruleSet: AbilityRuleSetConfig[];
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly name: string;
|
|
13
13
|
};
|
|
14
14
|
export declare class AbilityPolicy<Resources extends object = object> {
|
|
15
15
|
matchState: AbilityMatch;
|
|
@@ -31,20 +31,20 @@ export declare class AbilityPolicy<Resources extends object = object> {
|
|
|
31
31
|
/**
|
|
32
32
|
* Policy name
|
|
33
33
|
*/
|
|
34
|
-
name: string
|
|
34
|
+
name: string;
|
|
35
35
|
/**
|
|
36
36
|
* Policy ID
|
|
37
37
|
*/
|
|
38
|
-
id: string
|
|
38
|
+
id: string;
|
|
39
39
|
/**
|
|
40
40
|
* Soon
|
|
41
41
|
*/
|
|
42
42
|
action: string;
|
|
43
43
|
constructor(params: {
|
|
44
|
+
id: string;
|
|
45
|
+
name: string;
|
|
44
46
|
action: string;
|
|
45
47
|
effect: AbilityPolicyEffect;
|
|
46
|
-
name?: string | symbol;
|
|
47
|
-
id?: string | symbol;
|
|
48
48
|
});
|
|
49
49
|
/**
|
|
50
50
|
* Add rule set to the policy
|
package/dist/AbilityRule.d.ts
CHANGED
|
@@ -2,16 +2,19 @@ import AbilityMatch from './AbilityMatch';
|
|
|
2
2
|
import AbilityCondition from './AbilityCondition';
|
|
3
3
|
export type AbilityRuleMatches = [string, AbilityCondition, string | number | boolean];
|
|
4
4
|
export type AbilityRuleConfig = {
|
|
5
|
-
readonly
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly name: string;
|
|
6
7
|
readonly matches: [string, string, string | number | boolean];
|
|
7
8
|
};
|
|
8
9
|
export declare class AbilityRule<Resources extends object = object> {
|
|
9
10
|
matches: AbilityRuleMatches;
|
|
10
|
-
name: string
|
|
11
|
+
name: string;
|
|
12
|
+
id: string;
|
|
11
13
|
state: AbilityMatch;
|
|
12
14
|
constructor(params: {
|
|
13
|
-
|
|
14
|
-
name
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly matches: AbilityRuleMatches;
|
|
15
18
|
});
|
|
16
19
|
/**
|
|
17
20
|
* Check if the rule is matched
|
package/dist/AbilityRuleSet.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import AbilityRule, { AbilityRuleConfig } from './AbilityRule';
|
|
|
2
2
|
import AbilityCompare from './AbilityCompare';
|
|
3
3
|
import AbilityMatch from './AbilityMatch';
|
|
4
4
|
export type AbilityRuleSetConfig = {
|
|
5
|
-
readonly id
|
|
5
|
+
readonly id: string;
|
|
6
6
|
readonly name: string;
|
|
7
7
|
readonly compareMethod: number;
|
|
8
8
|
readonly rules: AbilityRuleConfig[];
|
|
@@ -23,14 +23,14 @@ export declare class AbilityRuleSet<Resources extends object = object> {
|
|
|
23
23
|
/**
|
|
24
24
|
* Group name
|
|
25
25
|
*/
|
|
26
|
-
name: string
|
|
26
|
+
name: string;
|
|
27
27
|
/**
|
|
28
28
|
* Group ID
|
|
29
29
|
*/
|
|
30
|
-
id: string
|
|
31
|
-
constructor(params
|
|
32
|
-
name
|
|
33
|
-
id
|
|
30
|
+
id: string;
|
|
31
|
+
constructor(params: {
|
|
32
|
+
name: string;
|
|
33
|
+
id: string;
|
|
34
34
|
});
|
|
35
35
|
addRule(rule: AbilityRule, compareMethod: AbilityCompare): this;
|
|
36
36
|
addRules(rules: AbilityRule[], compareMethod: AbilityCompare): this;
|
package/dist/index.js
CHANGED
|
@@ -259,7 +259,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
259
259
|
};
|
|
260
260
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
261
261
|
exports.AbilityPolicy = void 0;
|
|
262
|
-
const AbilityRule_1 = __importDefault(__webpack_require__(476));
|
|
263
262
|
const AbilityRuleSet_1 = __importDefault(__webpack_require__(402));
|
|
264
263
|
const AbilityMatch_1 = __importDefault(__webpack_require__(909));
|
|
265
264
|
const AbilityCompare_1 = __importDefault(__webpack_require__(923));
|
|
@@ -296,8 +295,8 @@ class AbilityPolicy {
|
|
|
296
295
|
action;
|
|
297
296
|
constructor(params) {
|
|
298
297
|
const { name, id, action, effect } = params;
|
|
299
|
-
this.name = name
|
|
300
|
-
this.id = id
|
|
298
|
+
this.name = name;
|
|
299
|
+
this.id = id;
|
|
301
300
|
this.action = action;
|
|
302
301
|
this.effect = effect;
|
|
303
302
|
}
|
|
@@ -315,6 +314,7 @@ class AbilityPolicy {
|
|
|
315
314
|
*/
|
|
316
315
|
addRule(rule) {
|
|
317
316
|
this.addRuleSet(new AbilityRuleSet_1.default({
|
|
317
|
+
id: rule.id,
|
|
318
318
|
name: rule.name,
|
|
319
319
|
}).addRule(rule, AbilityCompare_1.default.AND));
|
|
320
320
|
return this;
|
|
@@ -352,7 +352,7 @@ class AbilityPolicy {
|
|
|
352
352
|
*/
|
|
353
353
|
static parse(configOrJson) {
|
|
354
354
|
const config = AbilityParser_1.default.prepareAndValidateConfig(configOrJson, [
|
|
355
|
-
['id', 'string',
|
|
355
|
+
['id', 'string', true],
|
|
356
356
|
['name', 'string', true],
|
|
357
357
|
['action', 'string', true],
|
|
358
358
|
['effect', 'number', true],
|
|
@@ -368,15 +368,8 @@ class AbilityPolicy {
|
|
|
368
368
|
effect: new AbilityPolicyEffect_1.default(effect),
|
|
369
369
|
});
|
|
370
370
|
policy.compareMethod = new AbilityCompare_1.default(compareMethod);
|
|
371
|
-
ruleSet.forEach(
|
|
372
|
-
|
|
373
|
-
if ('rules' in ruleOrRuleSet) {
|
|
374
|
-
policy.addRuleSet(AbilityRuleSet_1.default.parse(ruleOrRuleSet));
|
|
375
|
-
}
|
|
376
|
-
// is simple rule
|
|
377
|
-
if (!('rules' in ruleOrRuleSet)) {
|
|
378
|
-
policy.addRule(AbilityRule_1.default.parse(ruleOrRuleSet));
|
|
379
|
-
}
|
|
371
|
+
ruleSet.forEach(ruleSetConfig => {
|
|
372
|
+
policy.addRuleSet(AbilityRuleSet_1.default.parse(ruleSetConfig));
|
|
380
373
|
});
|
|
381
374
|
return policy;
|
|
382
375
|
}
|
|
@@ -524,10 +517,12 @@ const AbilityParser_1 = __importDefault(__webpack_require__(189));
|
|
|
524
517
|
class AbilityRule {
|
|
525
518
|
matches;
|
|
526
519
|
name;
|
|
520
|
+
id;
|
|
527
521
|
state = AbilityMatch_1.default.PENDING;
|
|
528
522
|
constructor(params) {
|
|
529
|
-
const { name, matches } = params;
|
|
530
|
-
this.
|
|
523
|
+
const { id, name, matches } = params;
|
|
524
|
+
this.id = id;
|
|
525
|
+
this.name = name;
|
|
531
526
|
this.matches = matches;
|
|
532
527
|
}
|
|
533
528
|
/**
|
|
@@ -642,13 +637,14 @@ class AbilityRule {
|
|
|
642
637
|
}
|
|
643
638
|
static parse(configOrJson) {
|
|
644
639
|
const config = AbilityParser_1.default.prepareAndValidateConfig(configOrJson, [
|
|
645
|
-
['id', 'string',
|
|
640
|
+
['id', 'string', true],
|
|
646
641
|
['name', 'string', true],
|
|
647
642
|
['matches', 'array', true],
|
|
648
643
|
]);
|
|
649
|
-
const { name, matches } = config;
|
|
644
|
+
const { id, name, matches } = config;
|
|
650
645
|
const [leftField, condition, rightField] = matches;
|
|
651
646
|
return new AbilityRule({
|
|
647
|
+
id,
|
|
652
648
|
name,
|
|
653
649
|
matches: [leftField, new AbilityCondition_1.default(condition), rightField],
|
|
654
650
|
});
|
|
@@ -659,6 +655,7 @@ class AbilityRule {
|
|
|
659
655
|
export() {
|
|
660
656
|
const [leftField, condition, rightField] = this.matches;
|
|
661
657
|
return {
|
|
658
|
+
id: this.id,
|
|
662
659
|
name: this.name,
|
|
663
660
|
matches: [leftField, condition.code, rightField],
|
|
664
661
|
};
|
|
@@ -705,9 +702,9 @@ class AbilityRuleSet {
|
|
|
705
702
|
*/
|
|
706
703
|
id;
|
|
707
704
|
constructor(params) {
|
|
708
|
-
const { name, id } = params
|
|
709
|
-
this.name = name
|
|
710
|
-
this.id = id
|
|
705
|
+
const { name, id } = params;
|
|
706
|
+
this.name = name;
|
|
707
|
+
this.id = id;
|
|
711
708
|
}
|
|
712
709
|
addRule(rule, compareMethod) {
|
|
713
710
|
this.rules.push(rule);
|
|
@@ -743,7 +740,7 @@ class AbilityRuleSet {
|
|
|
743
740
|
*/
|
|
744
741
|
static parse(configOrJson) {
|
|
745
742
|
const config = AbilityParser_1.default.prepareAndValidateConfig(configOrJson, [
|
|
746
|
-
['id', 'string',
|
|
743
|
+
['id', 'string', true],
|
|
747
744
|
['name', 'string', true],
|
|
748
745
|
['compareMethod', 'number', true],
|
|
749
746
|
['rules', 'array', true],
|