@via-profit/ability 3.6.1 → 3.6.2
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/index.d.ts +4 -1
- package/dist/index.js +60 -27
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -218,14 +218,16 @@ type AbilityExplainConfig = {
|
|
|
218
218
|
readonly type: AbilityExplainType;
|
|
219
219
|
readonly name: string;
|
|
220
220
|
readonly match: AbilityMatchType;
|
|
221
|
+
readonly debugInfo?: boolean;
|
|
221
222
|
};
|
|
222
223
|
declare class AbilityExplain {
|
|
223
224
|
readonly type: AbilityExplainType;
|
|
224
225
|
readonly children: AbilityExplain[];
|
|
225
226
|
readonly name: string;
|
|
226
227
|
readonly match: AbilityMatchType;
|
|
228
|
+
readonly debugInfo?: boolean;
|
|
227
229
|
constructor(config: AbilityExplainConfig, children?: AbilityExplain[]);
|
|
228
|
-
toString(
|
|
230
|
+
toString(indentPrefix?: string, isLast?: boolean): string;
|
|
229
231
|
}
|
|
230
232
|
declare class AbilityExplainRule extends AbilityExplain {
|
|
231
233
|
constructor(rule: AbilityRule);
|
|
@@ -551,6 +553,7 @@ declare class AbilityDSLParser<R extends ResourceObject = Record<string, unknown
|
|
|
551
553
|
private takeAnnotations;
|
|
552
554
|
private isStartOfPolicy;
|
|
553
555
|
private isStartOfGroup;
|
|
556
|
+
private isStartOfRule;
|
|
554
557
|
private isStartOfExcept;
|
|
555
558
|
private isStartOfAlias;
|
|
556
559
|
}
|
package/dist/index.js
CHANGED
|
@@ -126,27 +126,49 @@ const AbilityMatch = {
|
|
|
126
126
|
disabled: brand$2('disabled'),
|
|
127
127
|
};
|
|
128
128
|
|
|
129
|
+
const colors = {
|
|
130
|
+
reset: '\x1b[0m',
|
|
131
|
+
green: '\x1b[32m',
|
|
132
|
+
red: '\x1b[31m',
|
|
133
|
+
blue: '\x1b[34m',
|
|
134
|
+
yellow: '\x1b[33m',
|
|
135
|
+
white: '\x1b[37m',
|
|
136
|
+
gray: '\x1b[90m',
|
|
137
|
+
};
|
|
129
138
|
class AbilityExplain {
|
|
130
139
|
type;
|
|
131
140
|
children;
|
|
132
141
|
name;
|
|
133
142
|
match;
|
|
143
|
+
debugInfo;
|
|
134
144
|
constructor(config, children = []) {
|
|
135
145
|
this.type = config.type;
|
|
136
146
|
this.children = children;
|
|
137
147
|
this.name = config.name;
|
|
138
148
|
this.match = config.match;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
149
|
+
this.debugInfo = config.debugInfo;
|
|
150
|
+
}
|
|
151
|
+
toString(indentPrefix = '', isLast = true) {
|
|
152
|
+
const isMatch = this.match === AbilityMatch.match;
|
|
153
|
+
const mark = isMatch ? `${colors.green}✓${colors.reset}` : `${colors.red}✗${colors.reset}`;
|
|
154
|
+
const label = this.type === 'policy'
|
|
155
|
+
? `${colors.blue}POLICY${colors.reset}`
|
|
156
|
+
: this.type === 'ruleSet'
|
|
157
|
+
? `${colors.yellow}RULESET${colors.reset}`
|
|
158
|
+
: `${colors.white}RULE${colors.reset}`;
|
|
159
|
+
const branch = indentPrefix.length === 0
|
|
160
|
+
? ''
|
|
161
|
+
: isLast
|
|
162
|
+
? `${colors.gray}└─${colors.reset} `
|
|
163
|
+
: `${colors.gray}├─${colors.reset} `;
|
|
164
|
+
let out = `${indentPrefix}${branch}${label} ${this.name} — ${mark}`;
|
|
165
|
+
if (this.debugInfo) {
|
|
166
|
+
out += ` ${colors.gray}(${this.debugInfo})${colors.reset}`;
|
|
167
|
+
}
|
|
168
|
+
const nextIndent = indentPrefix + (isLast ? ' ' : `${colors.gray}│ ${colors.reset}`);
|
|
169
|
+
this.children.forEach((child, index) => {
|
|
170
|
+
const last = index === this.children.length - 1;
|
|
171
|
+
out += '\n' + child.toString(nextIndent, last);
|
|
150
172
|
});
|
|
151
173
|
return out;
|
|
152
174
|
}
|
|
@@ -1500,32 +1522,32 @@ class AbilityJSONParser {
|
|
|
1500
1522
|
return {
|
|
1501
1523
|
id: rule.id,
|
|
1502
1524
|
name: rule.name,
|
|
1525
|
+
disabled: rule.disabled,
|
|
1503
1526
|
subject: rule.subject,
|
|
1504
1527
|
resource: rule.resource,
|
|
1505
1528
|
condition: rule.condition,
|
|
1506
|
-
disabled: rule.disabled,
|
|
1507
1529
|
};
|
|
1508
1530
|
}
|
|
1509
1531
|
static ruleSetToJSON(ruleSet) {
|
|
1510
1532
|
return {
|
|
1511
1533
|
id: ruleSet.id.toString(),
|
|
1512
1534
|
name: ruleSet.name.toString(),
|
|
1535
|
+
disabled: ruleSet.disabled,
|
|
1513
1536
|
compareMethod: ruleSet.compareMethod,
|
|
1514
1537
|
rules: ruleSet.rules.map(rule => AbilityJSONParser.ruleToJSON(rule)),
|
|
1515
|
-
disabled: ruleSet.disabled,
|
|
1516
1538
|
};
|
|
1517
1539
|
}
|
|
1518
1540
|
static policyToJSON(policy) {
|
|
1519
1541
|
return {
|
|
1520
1542
|
id: policy.id.toString(),
|
|
1521
1543
|
name: policy.name.toString(),
|
|
1522
|
-
|
|
1523
|
-
|
|
1544
|
+
disabled: policy.disabled,
|
|
1545
|
+
priority: policy.priority,
|
|
1524
1546
|
permission: policy.permission,
|
|
1525
1547
|
effect: policy.effect,
|
|
1526
|
-
|
|
1527
|
-
disabled: policy.disabled,
|
|
1548
|
+
compareMethod: policy.compareMethod,
|
|
1528
1549
|
tags: policy.tags,
|
|
1550
|
+
ruleSet: policy.ruleSet.map(ruleSet => AbilityJSONParser.ruleSetToJSON(ruleSet)),
|
|
1529
1551
|
};
|
|
1530
1552
|
}
|
|
1531
1553
|
static toJSON(policies) {
|
|
@@ -2313,28 +2335,34 @@ class AbilityDSLParser {
|
|
|
2313
2335
|
*/
|
|
2314
2336
|
parseRuleSets(policyCompareMethod) {
|
|
2315
2337
|
const sets = [];
|
|
2338
|
+
this.consumeLeadingComments();
|
|
2339
|
+
this.consumeLeadingAnnotations();
|
|
2316
2340
|
while (!this.stream.eof() && !this.isStartOfPolicy()) {
|
|
2317
|
-
|
|
2318
|
-
this.consumeLeadingAnnotations();
|
|
2319
|
-
// Если начинается новая except группа — парсим её
|
|
2341
|
+
// maybe except ruleSet
|
|
2320
2342
|
if (this.isStartOfExcept()) {
|
|
2321
2343
|
sets.push(this.parseExceptGroup(policyCompareMethod));
|
|
2322
2344
|
continue;
|
|
2323
2345
|
}
|
|
2324
|
-
//
|
|
2346
|
+
// maybe ruleSet
|
|
2325
2347
|
if (this.isStartOfGroup()) {
|
|
2326
2348
|
sets.push(this.parseGroup());
|
|
2327
2349
|
continue;
|
|
2328
2350
|
}
|
|
2329
|
-
|
|
2351
|
+
// implicit ruleSet
|
|
2352
|
+
// if (!this.isStartOfRule()) {
|
|
2353
|
+
// this.consumeLeadingComments();
|
|
2354
|
+
// this.consumeLeadingAnnotations();
|
|
2355
|
+
// }
|
|
2356
|
+
// is implicit group
|
|
2357
|
+
// const annotation = this.takeAnnotations('ruleSet');
|
|
2330
2358
|
const group = new AbilityRuleSet({
|
|
2331
|
-
id: annotation.id?.value || null,
|
|
2359
|
+
// id: annotation.id?.value || null,
|
|
2332
2360
|
compareMethod: policyCompareMethod,
|
|
2333
|
-
name: annotation.name?.value ?? null,
|
|
2334
|
-
description: annotation.description?.value || null,
|
|
2335
|
-
disabled: annotation.disabled?.value ?? undefined,
|
|
2361
|
+
// name: annotation.name?.value ?? null,
|
|
2362
|
+
// description: annotation.description?.value || null,
|
|
2363
|
+
// disabled: annotation.disabled?.value ?? undefined,
|
|
2336
2364
|
});
|
|
2337
|
-
//
|
|
2365
|
+
// Read rules of implicit-группы
|
|
2338
2366
|
while (!this.stream.eof()) {
|
|
2339
2367
|
this.consumeLeadingComments();
|
|
2340
2368
|
this.consumeLeadingAnnotations();
|
|
@@ -2935,6 +2963,11 @@ class AbilityDSLParser {
|
|
|
2935
2963
|
isStartOfGroup() {
|
|
2936
2964
|
return this.stream.check(TokenTypes.ALL) || this.stream.check(TokenTypes.ANY);
|
|
2937
2965
|
}
|
|
2966
|
+
isStartOfRule() {
|
|
2967
|
+
return (this.stream.check(TokenTypes.IDENTIFIER) ||
|
|
2968
|
+
this.stream.check(TokenTypes.ALWAYS) ||
|
|
2969
|
+
this.stream.check(TokenTypes.NEVER));
|
|
2970
|
+
}
|
|
2938
2971
|
isStartOfExcept() {
|
|
2939
2972
|
return this.stream.check(TokenTypes.EXCEPT);
|
|
2940
2973
|
}
|