@casl/angular 8.2.7 → 8.3.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/dist/es5m/index.js +58 -38
- package/dist/es5m/index.js.map +1 -1
- package/dist/es6m/index.mjs +47 -35
- package/dist/es6m/index.mjs.map +1 -1
- package/dist/types/AbilityServiceSignal.d.ts +15 -0
- package/dist/types/pipes.d.ts +8 -2
- package/dist/types/public.d.ts +1 -1
- package/dist/umd/index.js +57 -37
- package/dist/umd/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/types/AbilityModule.d.ts +0 -7
package/dist/es5m/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Pipe, Inject,
|
|
2
|
+
import { Pipe, Inject, Injectable, signal, inject } from '@angular/core';
|
|
3
3
|
import { PureAbility } from '@casl/ability';
|
|
4
4
|
import { Observable } from 'rxjs';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated use AbilityService instead
|
|
8
|
+
*/
|
|
6
9
|
var AblePipe = /** @class */ (function () {
|
|
7
10
|
function AblePipe(ability) {
|
|
8
11
|
this._ability = ability;
|
|
@@ -15,22 +18,24 @@ var AblePipe = /** @class */ (function () {
|
|
|
15
18
|
}
|
|
16
19
|
return (_a = this._ability).can.apply(_a, args);
|
|
17
20
|
};
|
|
18
|
-
AblePipe.ɵfac = function AblePipe_Factory(
|
|
19
|
-
AblePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "able", type: AblePipe, pure: false });
|
|
21
|
+
AblePipe.ɵfac = function AblePipe_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AblePipe)(i0.ɵɵdirectiveInject(PureAbility, 16)); };
|
|
22
|
+
AblePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "able", type: AblePipe, pure: false, standalone: true });
|
|
20
23
|
return AblePipe;
|
|
21
24
|
}());
|
|
22
25
|
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AblePipe, [{
|
|
23
26
|
type: Pipe,
|
|
24
|
-
args: [{ name: 'able', pure: false }]
|
|
27
|
+
args: [{ name: 'able', pure: false, standalone: true }]
|
|
25
28
|
}], function () { return [{ type: undefined, decorators: [{
|
|
26
29
|
type: Inject,
|
|
27
30
|
args: [PureAbility]
|
|
28
31
|
}] }]; }, null); })();
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated use AbilityService instead
|
|
34
|
+
*/
|
|
29
35
|
var AblePurePipe = /** @class */ (function () {
|
|
30
36
|
function AblePurePipe(ability) {
|
|
31
37
|
this._ability = ability;
|
|
32
38
|
}
|
|
33
|
-
// TODO: use computed signals https://github.com/angular/angular/issues/47553
|
|
34
39
|
AblePurePipe.prototype.transform = function () {
|
|
35
40
|
var _this = this;
|
|
36
41
|
var args = [];
|
|
@@ -46,61 +51,76 @@ var AblePurePipe = /** @class */ (function () {
|
|
|
46
51
|
return _this._ability.on('updated', emit);
|
|
47
52
|
});
|
|
48
53
|
};
|
|
49
|
-
AblePurePipe.ɵfac = function AblePurePipe_Factory(
|
|
50
|
-
AblePurePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "ablePure", type: AblePurePipe, pure: true });
|
|
54
|
+
AblePurePipe.ɵfac = function AblePurePipe_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AblePurePipe)(i0.ɵɵdirectiveInject(PureAbility, 16)); };
|
|
55
|
+
AblePurePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "ablePure", type: AblePurePipe, pure: true, standalone: true });
|
|
51
56
|
return AblePurePipe;
|
|
52
57
|
}());
|
|
53
58
|
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AblePurePipe, [{
|
|
54
59
|
type: Pipe,
|
|
55
|
-
args: [{ name: 'ablePure' }]
|
|
60
|
+
args: [{ name: 'ablePure', standalone: true }]
|
|
56
61
|
}], function () { return [{ type: undefined, decorators: [{
|
|
57
62
|
type: Inject,
|
|
58
63
|
args: [PureAbility]
|
|
59
64
|
}] }]; }, null); })();
|
|
60
65
|
|
|
61
|
-
var AbilityModule = /** @class */ (function () {
|
|
62
|
-
function AbilityModule() {
|
|
63
|
-
}
|
|
64
|
-
AbilityModule.ɵfac = function AbilityModule_Factory(t) { return new (t || AbilityModule)(); };
|
|
65
|
-
AbilityModule.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: AbilityModule });
|
|
66
|
-
AbilityModule.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({});
|
|
67
|
-
return AbilityModule;
|
|
68
|
-
}());
|
|
69
|
-
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AbilityModule, [{
|
|
70
|
-
type: NgModule,
|
|
71
|
-
args: [{
|
|
72
|
-
declarations: [
|
|
73
|
-
AblePipe,
|
|
74
|
-
AblePurePipe,
|
|
75
|
-
],
|
|
76
|
-
exports: [
|
|
77
|
-
AblePipe,
|
|
78
|
-
AblePurePipe,
|
|
79
|
-
],
|
|
80
|
-
}]
|
|
81
|
-
}], null, null); })();
|
|
82
|
-
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(AbilityModule, { declarations: [AblePipe,
|
|
83
|
-
AblePurePipe], exports: [AblePipe,
|
|
84
|
-
AblePurePipe] }); })();
|
|
85
|
-
|
|
86
66
|
var AbilityService = /** @class */ (function () {
|
|
87
67
|
function AbilityService(ability) {
|
|
88
|
-
// IGNORE: this comment. it's for release debugging
|
|
89
68
|
this.ability$ = new Observable(function (observer) {
|
|
90
69
|
observer.next(ability);
|
|
91
70
|
return ability.on('updated', function () { return observer.next(ability); });
|
|
92
71
|
});
|
|
93
72
|
}
|
|
94
|
-
AbilityService.ɵfac = function AbilityService_Factory(
|
|
95
|
-
AbilityService.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: AbilityService, factory: AbilityService.ɵfac });
|
|
73
|
+
AbilityService.ɵfac = function AbilityService_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AbilityService)(i0.ɵɵinject(PureAbility)); };
|
|
74
|
+
AbilityService.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: AbilityService, factory: AbilityService.ɵfac, providedIn: 'root' });
|
|
96
75
|
return AbilityService;
|
|
97
76
|
}());
|
|
98
77
|
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AbilityService, [{
|
|
99
|
-
type: Injectable
|
|
78
|
+
type: Injectable,
|
|
79
|
+
args: [{ providedIn: 'root' }]
|
|
100
80
|
}], function () { return [{ type: undefined, decorators: [{
|
|
101
81
|
type: Inject,
|
|
102
82
|
args: [PureAbility]
|
|
103
83
|
}] }]; }, null); })();
|
|
104
84
|
|
|
105
|
-
|
|
85
|
+
var AbilityServiceSignal = /** @class */ (function () {
|
|
86
|
+
function AbilityServiceSignal() {
|
|
87
|
+
var _this = this;
|
|
88
|
+
this._rules = signal([]);
|
|
89
|
+
this._ability = inject(PureAbility);
|
|
90
|
+
this.can = function () {
|
|
91
|
+
var _a;
|
|
92
|
+
var args = [];
|
|
93
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
94
|
+
args[_i] = arguments[_i];
|
|
95
|
+
}
|
|
96
|
+
_this._rules(); // generate side effect for angular to track changes in this signal
|
|
97
|
+
return (_a = _this._ability).can.apply(_a, args);
|
|
98
|
+
};
|
|
99
|
+
this.cannot = function () {
|
|
100
|
+
var args = [];
|
|
101
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
102
|
+
args[_i] = arguments[_i];
|
|
103
|
+
}
|
|
104
|
+
return !_this.can.apply(_this, args);
|
|
105
|
+
};
|
|
106
|
+
this._disposeAbilitySubscription = this._ability.on('updated', function (event) {
|
|
107
|
+
_this._rules.set(event.rules);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
AbilityServiceSignal.prototype.ngOnDestroy = function () {
|
|
111
|
+
this._disposeAbilitySubscription();
|
|
112
|
+
};
|
|
113
|
+
AbilityServiceSignal.prototype.update = function (rules) {
|
|
114
|
+
this._ability.update(rules);
|
|
115
|
+
};
|
|
116
|
+
AbilityServiceSignal.ɵfac = function AbilityServiceSignal_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AbilityServiceSignal)(); };
|
|
117
|
+
AbilityServiceSignal.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: AbilityServiceSignal, factory: AbilityServiceSignal.ɵfac, providedIn: 'root' });
|
|
118
|
+
return AbilityServiceSignal;
|
|
119
|
+
}());
|
|
120
|
+
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AbilityServiceSignal, [{
|
|
121
|
+
type: Injectable,
|
|
122
|
+
args: [{ providedIn: 'root' }]
|
|
123
|
+
}], function () { return []; }, null); })();
|
|
124
|
+
|
|
125
|
+
export { AbilityService, AbilityServiceSignal, AblePipe, AblePurePipe };
|
|
106
126
|
//# sourceMappingURL=index.js.map
|
package/dist/es5m/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/pipes.ts","../../src/
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/pipes.ts","../../src/AbilityService.ts","../../src/AbilityServiceSignal.ts"],"sourcesContent":["import { Pipe, Inject, PipeTransform } from '@angular/core';\nimport { PureAbility, AnyAbility } from '@casl/ability';\nimport { Observable } from 'rxjs';\n\n/**\n * @deprecated use AbilityService instead\n */\n@Pipe({ name: 'able', pure: false, standalone: true })\nexport class AblePipe<T extends AnyAbility> implements PipeTransform {\n private _ability: T;\n\n constructor(@Inject(PureAbility) ability: T) {\n this._ability = ability;\n }\n\n transform(...args: Parameters<T['can']>): boolean {\n return this._ability.can(...args);\n }\n}\n\n/**\n * @deprecated use AbilityService instead\n */\n@Pipe({ name: 'ablePure', standalone: true })\nexport class AblePurePipe<T extends AnyAbility> implements PipeTransform {\n private _ability: T;\n\n constructor(@Inject(PureAbility) ability: T) {\n this._ability = ability;\n }\n\n transform(...args: Parameters<T['can']>): Observable<boolean> {\n return new Observable((s) => {\n const emit = () => s.next(this._ability.can(...args));\n emit();\n return this._ability.on('updated', emit);\n });\n }\n}\n","import { Inject, Injectable } from '@angular/core';\nimport { AnyAbility, PureAbility } from '@casl/ability';\nimport { Observable } from 'rxjs';\n\n@Injectable({ providedIn: 'root' })\nexport class AbilityService<T extends AnyAbility> {\n readonly ability$: Observable<T>;\n\n constructor(@Inject(PureAbility) ability: T) {\n this.ability$ = new Observable((observer) => {\n observer.next(ability);\n return ability.on('updated', () => observer.next(ability));\n });\n }\n}\n","import { inject, Injectable, OnDestroy, signal } from \"@angular/core\";\nimport { AnyAbility, PureAbility, RawRuleOf } from \"@casl/ability\";\n\n@Injectable({ providedIn: 'root' })\nexport class AbilityServiceSignal<T extends AnyAbility> implements OnDestroy {\n private readonly _rules = signal<RawRuleOf<T>[]>([]);\n private readonly _ability = inject(PureAbility) as unknown as T;\n private readonly _disposeAbilitySubscription: () => void;\n\n constructor() {\n this._disposeAbilitySubscription = this._ability.on('updated', (event) => {\n this._rules.set(event.rules as any);\n });\n }\n\n ngOnDestroy(): void {\n this._disposeAbilitySubscription();\n }\n\n can = (...args: Parameters<T['can']>): boolean => {\n this._rules(); // generate side effect for angular to track changes in this signal\n return this._ability.can(...args);\n };\n\n cannot = (...args: Parameters<T['can']>): boolean => {\n return !this.can(...args);\n };\n\n update(rules: T['rules']): void {\n this._ability.update(rules);\n }\n}"],"names":[],"mappings":";;;;;AAIA;;AAEG;AACH,IAAA,QAAA,kBAAA,YAAA;AAIE,IAAA,SAAA,QAAA,CAAiC,OAAU,EAAA;AACzC,QAAA,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;KACzB;AAED,IAAA,QAAA,CAAA,SAAA,CAAA,SAAS,GAAT,YAAA;;QAAU,IAA6B,I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A7B,IAA6B,CAAA,EAAA,CAAA,GAAA,SAAA,CAAA,EAAA,CAAA,CAAA;;YACrC,OAAO,CAAC,KAAI,CAAC,GAAG,OAAR,KAAI,EAAQ,IAAI,CAAC,CAAC;AAC5B,SAAC,CAAC;AAhBA,QAAA,IAAI,CAAC,2BAA2B,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,UAAC,KAAK,EAAA;YACnE,KAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAY,CAAC,CAAC;AACtC,SAAC,CAAC,CAAC;KACJ;AAED,IAAA,oBAAA,CAAA,SAAA,CAAA,WAAW,GAAX,YAAA;QACE,IAAI,CAAC,2BAA2B,EAAE,CAAC;KACpC,CAAA;IAWD,oBAAM,CAAA,SAAA,CAAA,MAAA,GAAN,UAAO,KAAiB,EAAA;AACtB,QAAA,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;KAC7B,CAAA;4HA1BU,oBAAoB,GAAA,CAAA,EAAA,CAAA;8EAApB,oBAAoB,EAAA,OAAA,EAApB,oBAAoB,CAAA,IAAA,EAAA,UAAA,EADP,MAAM,EAAA,CAAA,CAAA;AAHhC,IAAA,OAAA,oBAAA,CAAA;AA+BC,CA5BD,EA4BC,EAAA;uFA3BY,oBAAoB,EAAA,CAAA;cADhC,UAAU;eAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;;;;;"}
|
package/dist/es6m/index.mjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Pipe, Inject,
|
|
2
|
+
import { Pipe, Inject, Injectable, signal, inject } from '@angular/core';
|
|
3
3
|
import { PureAbility } from '@casl/ability';
|
|
4
4
|
import { Observable } from 'rxjs';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated use AbilityService instead
|
|
8
|
+
*/
|
|
6
9
|
class AblePipe {
|
|
7
10
|
constructor(ability) {
|
|
8
11
|
this._ability = ability;
|
|
@@ -11,20 +14,22 @@ class AblePipe {
|
|
|
11
14
|
return this._ability.can(...args);
|
|
12
15
|
}
|
|
13
16
|
}
|
|
14
|
-
AblePipe.ɵfac = function AblePipe_Factory(
|
|
15
|
-
AblePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "able", type: AblePipe, pure: false });
|
|
17
|
+
AblePipe.ɵfac = function AblePipe_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AblePipe)(i0.ɵɵdirectiveInject(PureAbility, 16)); };
|
|
18
|
+
AblePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "able", type: AblePipe, pure: false, standalone: true });
|
|
16
19
|
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AblePipe, [{
|
|
17
20
|
type: Pipe,
|
|
18
|
-
args: [{ name: 'able', pure: false }]
|
|
21
|
+
args: [{ name: 'able', pure: false, standalone: true }]
|
|
19
22
|
}], () => [{ type: undefined, decorators: [{
|
|
20
23
|
type: Inject,
|
|
21
24
|
args: [PureAbility]
|
|
22
25
|
}] }], null); })();
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated use AbilityService instead
|
|
28
|
+
*/
|
|
23
29
|
class AblePurePipe {
|
|
24
30
|
constructor(ability) {
|
|
25
31
|
this._ability = ability;
|
|
26
32
|
}
|
|
27
|
-
// TODO: use computed signals https://github.com/angular/angular/issues/47553
|
|
28
33
|
transform(...args) {
|
|
29
34
|
return new Observable((s) => {
|
|
30
35
|
const emit = () => s.next(this._ability.can(...args));
|
|
@@ -33,55 +38,62 @@ class AblePurePipe {
|
|
|
33
38
|
});
|
|
34
39
|
}
|
|
35
40
|
}
|
|
36
|
-
AblePurePipe.ɵfac = function AblePurePipe_Factory(
|
|
37
|
-
AblePurePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "ablePure", type: AblePurePipe, pure: true });
|
|
41
|
+
AblePurePipe.ɵfac = function AblePurePipe_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AblePurePipe)(i0.ɵɵdirectiveInject(PureAbility, 16)); };
|
|
42
|
+
AblePurePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "ablePure", type: AblePurePipe, pure: true, standalone: true });
|
|
38
43
|
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AblePurePipe, [{
|
|
39
44
|
type: Pipe,
|
|
40
|
-
args: [{ name: 'ablePure' }]
|
|
45
|
+
args: [{ name: 'ablePure', standalone: true }]
|
|
41
46
|
}], () => [{ type: undefined, decorators: [{
|
|
42
47
|
type: Inject,
|
|
43
48
|
args: [PureAbility]
|
|
44
49
|
}] }], null); })();
|
|
45
50
|
|
|
46
|
-
class AbilityModule {
|
|
47
|
-
}
|
|
48
|
-
AbilityModule.ɵfac = function AbilityModule_Factory(t) { return new (t || AbilityModule)(); };
|
|
49
|
-
AbilityModule.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: AbilityModule });
|
|
50
|
-
AbilityModule.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({});
|
|
51
|
-
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AbilityModule, [{
|
|
52
|
-
type: NgModule,
|
|
53
|
-
args: [{
|
|
54
|
-
declarations: [
|
|
55
|
-
AblePipe,
|
|
56
|
-
AblePurePipe,
|
|
57
|
-
],
|
|
58
|
-
exports: [
|
|
59
|
-
AblePipe,
|
|
60
|
-
AblePurePipe,
|
|
61
|
-
],
|
|
62
|
-
}]
|
|
63
|
-
}], null, null); })();
|
|
64
|
-
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(AbilityModule, { declarations: [AblePipe,
|
|
65
|
-
AblePurePipe], exports: [AblePipe,
|
|
66
|
-
AblePurePipe] }); })();
|
|
67
|
-
|
|
68
51
|
class AbilityService {
|
|
69
52
|
constructor(ability) {
|
|
70
|
-
// IGNORE: this comment. it's for release debugging
|
|
71
53
|
this.ability$ = new Observable((observer) => {
|
|
72
54
|
observer.next(ability);
|
|
73
55
|
return ability.on('updated', () => observer.next(ability));
|
|
74
56
|
});
|
|
75
57
|
}
|
|
76
58
|
}
|
|
77
|
-
AbilityService.ɵfac = function AbilityService_Factory(
|
|
78
|
-
AbilityService.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: AbilityService, factory: AbilityService.ɵfac });
|
|
59
|
+
AbilityService.ɵfac = function AbilityService_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AbilityService)(i0.ɵɵinject(PureAbility)); };
|
|
60
|
+
AbilityService.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: AbilityService, factory: AbilityService.ɵfac, providedIn: 'root' });
|
|
79
61
|
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AbilityService, [{
|
|
80
|
-
type: Injectable
|
|
62
|
+
type: Injectable,
|
|
63
|
+
args: [{ providedIn: 'root' }]
|
|
81
64
|
}], () => [{ type: undefined, decorators: [{
|
|
82
65
|
type: Inject,
|
|
83
66
|
args: [PureAbility]
|
|
84
67
|
}] }], null); })();
|
|
85
68
|
|
|
86
|
-
|
|
69
|
+
class AbilityServiceSignal {
|
|
70
|
+
constructor() {
|
|
71
|
+
this._rules = signal([]);
|
|
72
|
+
this._ability = inject(PureAbility);
|
|
73
|
+
this.can = (...args) => {
|
|
74
|
+
this._rules(); // generate side effect for angular to track changes in this signal
|
|
75
|
+
return this._ability.can(...args);
|
|
76
|
+
};
|
|
77
|
+
this.cannot = (...args) => {
|
|
78
|
+
return !this.can(...args);
|
|
79
|
+
};
|
|
80
|
+
this._disposeAbilitySubscription = this._ability.on('updated', (event) => {
|
|
81
|
+
this._rules.set(event.rules);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
ngOnDestroy() {
|
|
85
|
+
this._disposeAbilitySubscription();
|
|
86
|
+
}
|
|
87
|
+
update(rules) {
|
|
88
|
+
this._ability.update(rules);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
AbilityServiceSignal.ɵfac = function AbilityServiceSignal_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AbilityServiceSignal)(); };
|
|
92
|
+
AbilityServiceSignal.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: AbilityServiceSignal, factory: AbilityServiceSignal.ɵfac, providedIn: 'root' });
|
|
93
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AbilityServiceSignal, [{
|
|
94
|
+
type: Injectable,
|
|
95
|
+
args: [{ providedIn: 'root' }]
|
|
96
|
+
}], () => [], null); })();
|
|
97
|
+
|
|
98
|
+
export { AbilityService, AbilityServiceSignal, AblePipe, AblePurePipe };
|
|
87
99
|
//# sourceMappingURL=index.mjs.map
|
package/dist/es6m/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/pipes.ts","../../src/
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/pipes.ts","../../src/AbilityService.ts","../../src/AbilityServiceSignal.ts"],"sourcesContent":["import { Pipe, Inject, PipeTransform } from '@angular/core';\nimport { PureAbility, AnyAbility } from '@casl/ability';\nimport { Observable } from 'rxjs';\n\n/**\n * @deprecated use AbilityService instead\n */\n@Pipe({ name: 'able', pure: false, standalone: true })\nexport class AblePipe<T extends AnyAbility> implements PipeTransform {\n private _ability: T;\n\n constructor(@Inject(PureAbility) ability: T) {\n this._ability = ability;\n }\n\n transform(...args: Parameters<T['can']>): boolean {\n return this._ability.can(...args);\n }\n}\n\n/**\n * @deprecated use AbilityService instead\n */\n@Pipe({ name: 'ablePure', standalone: true })\nexport class AblePurePipe<T extends AnyAbility> implements PipeTransform {\n private _ability: T;\n\n constructor(@Inject(PureAbility) ability: T) {\n this._ability = ability;\n }\n\n transform(...args: Parameters<T['can']>): Observable<boolean> {\n return new Observable((s) => {\n const emit = () => s.next(this._ability.can(...args));\n emit();\n return this._ability.on('updated', emit);\n });\n }\n}\n","import { Inject, Injectable } from '@angular/core';\nimport { AnyAbility, PureAbility } from '@casl/ability';\nimport { Observable } from 'rxjs';\n\n@Injectable({ providedIn: 'root' })\nexport class AbilityService<T extends AnyAbility> {\n readonly ability$: Observable<T>;\n\n constructor(@Inject(PureAbility) ability: T) {\n this.ability$ = new Observable((observer) => {\n observer.next(ability);\n return ability.on('updated', () => observer.next(ability));\n });\n }\n}\n","import { inject, Injectable, OnDestroy, signal } from \"@angular/core\";\nimport { AnyAbility, PureAbility, RawRuleOf } from \"@casl/ability\";\n\n@Injectable({ providedIn: 'root' })\nexport class AbilityServiceSignal<T extends AnyAbility> implements OnDestroy {\n private readonly _rules = signal<RawRuleOf<T>[]>([]);\n private readonly _ability = inject(PureAbility) as unknown as T;\n private readonly _disposeAbilitySubscription: () => void;\n\n constructor() {\n this._disposeAbilitySubscription = this._ability.on('updated', (event) => {\n this._rules.set(event.rules as any);\n });\n }\n\n ngOnDestroy(): void {\n this._disposeAbilitySubscription();\n }\n\n can = (...args: Parameters<T['can']>): boolean => {\n this._rules(); // generate side effect for angular to track changes in this signal\n return this._ability.can(...args);\n };\n\n cannot = (...args: Parameters<T['can']>): boolean => {\n return !this.can(...args);\n };\n\n update(rules: T['rules']): void {\n this._ability.update(rules);\n }\n}"],"names":[],"mappings":";;;;;AAIA;;AAEG;MAEU,QAAQ,CAAA;AAGnB,IAAA,WAAA,CAAiC,OAAU,EAAA;AACzC,QAAA,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;KACzB;IAED,SAAS,CAAC,GAAG,IAA0B,EAAA;QACrC,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;KACnC;;AATU,QAAA,CAAA,IAAA,GAAA,SAAA,gBAAA,CAAA,iBAAA,EAAA,EAAA,OAAA,KAAA,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Q,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,KAAI;YACvE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAY,CAAC,CAAC;AACtC,SAAC,CAAC,CAAC;KACJ;IAED,WAAW,GAAA;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;KACpC;AAWD,IAAA,MAAM,CAAC,KAAiB,EAAA;AACtB,QAAA,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;KAC7B;;wHA1BU,oBAAoB,GAAA,CAAA,EAAA,CAAA;0EAApB,oBAAoB,EAAA,OAAA,EAApB,oBAAoB,CAAA,IAAA,EAAA,UAAA,EADP,MAAM,EAAA,CAAA,CAAA;iFACnB,oBAAoB,EAAA,CAAA;cADhC,UAAU;eAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { OnDestroy } from "@angular/core";
|
|
2
|
+
import { AnyAbility } from "@casl/ability";
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
export declare class AbilityServiceSignal<T extends AnyAbility> implements OnDestroy {
|
|
5
|
+
private readonly _rules;
|
|
6
|
+
private readonly _ability;
|
|
7
|
+
private readonly _disposeAbilitySubscription;
|
|
8
|
+
constructor();
|
|
9
|
+
ngOnDestroy(): void;
|
|
10
|
+
can: (...args: Parameters<T["can"]>) => boolean;
|
|
11
|
+
cannot: (...args: Parameters<T["can"]>) => boolean;
|
|
12
|
+
update(rules: T['rules']): void;
|
|
13
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<AbilityServiceSignal<any>, never>;
|
|
14
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<AbilityServiceSignal<any>>;
|
|
15
|
+
}
|
package/dist/types/pipes.d.ts
CHANGED
|
@@ -2,17 +2,23 @@ import { PipeTransform } from '@angular/core';
|
|
|
2
2
|
import { AnyAbility } from '@casl/ability';
|
|
3
3
|
import { Observable } from 'rxjs';
|
|
4
4
|
import * as i0 from "@angular/core";
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated use AbilityService instead
|
|
7
|
+
*/
|
|
5
8
|
export declare class AblePipe<T extends AnyAbility> implements PipeTransform {
|
|
6
9
|
private _ability;
|
|
7
10
|
constructor(ability: T);
|
|
8
11
|
transform(...args: Parameters<T['can']>): boolean;
|
|
9
12
|
static ɵfac: i0.ɵɵFactoryDeclaration<AblePipe<any>, never>;
|
|
10
|
-
static ɵpipe: i0.ɵɵPipeDeclaration<AblePipe<any>, "able",
|
|
13
|
+
static ɵpipe: i0.ɵɵPipeDeclaration<AblePipe<any>, "able", true>;
|
|
11
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated use AbilityService instead
|
|
17
|
+
*/
|
|
12
18
|
export declare class AblePurePipe<T extends AnyAbility> implements PipeTransform {
|
|
13
19
|
private _ability;
|
|
14
20
|
constructor(ability: T);
|
|
15
21
|
transform(...args: Parameters<T['can']>): Observable<boolean>;
|
|
16
22
|
static ɵfac: i0.ɵɵFactoryDeclaration<AblePurePipe<any>, never>;
|
|
17
|
-
static ɵpipe: i0.ɵɵPipeDeclaration<AblePurePipe<any>, "ablePure",
|
|
23
|
+
static ɵpipe: i0.ɵɵPipeDeclaration<AblePurePipe<any>, "ablePure", true>;
|
|
18
24
|
}
|
package/dist/types/public.d.ts
CHANGED
package/dist/umd/index.js
CHANGED
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
|
|
24
24
|
var i0__namespace = /*#__PURE__*/_interopNamespaceDefault(i0);
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated use AbilityService instead
|
|
28
|
+
*/
|
|
26
29
|
var AblePipe = /** @class */ (function () {
|
|
27
30
|
function AblePipe(ability) {
|
|
28
31
|
this._ability = ability;
|
|
@@ -35,22 +38,24 @@
|
|
|
35
38
|
}
|
|
36
39
|
return (_a = this._ability).can.apply(_a, args);
|
|
37
40
|
};
|
|
38
|
-
AblePipe.ɵfac = function AblePipe_Factory(
|
|
39
|
-
AblePipe.ɵpipe = /*@__PURE__*/ i0__namespace.ɵɵdefinePipe({ name: "able", type: AblePipe, pure: false });
|
|
41
|
+
AblePipe.ɵfac = function AblePipe_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AblePipe)(i0__namespace.ɵɵdirectiveInject(ability.PureAbility, 16)); };
|
|
42
|
+
AblePipe.ɵpipe = /*@__PURE__*/ i0__namespace.ɵɵdefinePipe({ name: "able", type: AblePipe, pure: false, standalone: true });
|
|
40
43
|
return AblePipe;
|
|
41
44
|
}());
|
|
42
45
|
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(AblePipe, [{
|
|
43
46
|
type: i0.Pipe,
|
|
44
|
-
args: [{ name: 'able', pure: false }]
|
|
47
|
+
args: [{ name: 'able', pure: false, standalone: true }]
|
|
45
48
|
}], function () { return [{ type: undefined, decorators: [{
|
|
46
49
|
type: i0.Inject,
|
|
47
50
|
args: [ability.PureAbility]
|
|
48
51
|
}] }]; }, null); })();
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated use AbilityService instead
|
|
54
|
+
*/
|
|
49
55
|
var AblePurePipe = /** @class */ (function () {
|
|
50
56
|
function AblePurePipe(ability) {
|
|
51
57
|
this._ability = ability;
|
|
52
58
|
}
|
|
53
|
-
// TODO: use computed signals https://github.com/angular/angular/issues/47553
|
|
54
59
|
AblePurePipe.prototype.transform = function () {
|
|
55
60
|
var _this = this;
|
|
56
61
|
var args = [];
|
|
@@ -66,64 +71,79 @@
|
|
|
66
71
|
return _this._ability.on('updated', emit);
|
|
67
72
|
});
|
|
68
73
|
};
|
|
69
|
-
AblePurePipe.ɵfac = function AblePurePipe_Factory(
|
|
70
|
-
AblePurePipe.ɵpipe = /*@__PURE__*/ i0__namespace.ɵɵdefinePipe({ name: "ablePure", type: AblePurePipe, pure: true });
|
|
74
|
+
AblePurePipe.ɵfac = function AblePurePipe_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AblePurePipe)(i0__namespace.ɵɵdirectiveInject(ability.PureAbility, 16)); };
|
|
75
|
+
AblePurePipe.ɵpipe = /*@__PURE__*/ i0__namespace.ɵɵdefinePipe({ name: "ablePure", type: AblePurePipe, pure: true, standalone: true });
|
|
71
76
|
return AblePurePipe;
|
|
72
77
|
}());
|
|
73
78
|
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(AblePurePipe, [{
|
|
74
79
|
type: i0.Pipe,
|
|
75
|
-
args: [{ name: 'ablePure' }]
|
|
80
|
+
args: [{ name: 'ablePure', standalone: true }]
|
|
76
81
|
}], function () { return [{ type: undefined, decorators: [{
|
|
77
82
|
type: i0.Inject,
|
|
78
83
|
args: [ability.PureAbility]
|
|
79
84
|
}] }]; }, null); })();
|
|
80
85
|
|
|
81
|
-
var AbilityModule = /** @class */ (function () {
|
|
82
|
-
function AbilityModule() {
|
|
83
|
-
}
|
|
84
|
-
AbilityModule.ɵfac = function AbilityModule_Factory(t) { return new (t || AbilityModule)(); };
|
|
85
|
-
AbilityModule.ɵmod = /*@__PURE__*/ i0__namespace.ɵɵdefineNgModule({ type: AbilityModule });
|
|
86
|
-
AbilityModule.ɵinj = /*@__PURE__*/ i0__namespace.ɵɵdefineInjector({});
|
|
87
|
-
return AbilityModule;
|
|
88
|
-
}());
|
|
89
|
-
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(AbilityModule, [{
|
|
90
|
-
type: i0.NgModule,
|
|
91
|
-
args: [{
|
|
92
|
-
declarations: [
|
|
93
|
-
AblePipe,
|
|
94
|
-
AblePurePipe,
|
|
95
|
-
],
|
|
96
|
-
exports: [
|
|
97
|
-
AblePipe,
|
|
98
|
-
AblePurePipe,
|
|
99
|
-
],
|
|
100
|
-
}]
|
|
101
|
-
}], null, null); })();
|
|
102
|
-
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0__namespace.ɵɵsetNgModuleScope(AbilityModule, { declarations: [AblePipe,
|
|
103
|
-
AblePurePipe], exports: [AblePipe,
|
|
104
|
-
AblePurePipe] }); })();
|
|
105
|
-
|
|
106
86
|
var AbilityService = /** @class */ (function () {
|
|
107
87
|
function AbilityService(ability) {
|
|
108
|
-
// IGNORE: this comment. it's for release debugging
|
|
109
88
|
this.ability$ = new rxjs.Observable(function (observer) {
|
|
110
89
|
observer.next(ability);
|
|
111
90
|
return ability.on('updated', function () { return observer.next(ability); });
|
|
112
91
|
});
|
|
113
92
|
}
|
|
114
|
-
AbilityService.ɵfac = function AbilityService_Factory(
|
|
115
|
-
AbilityService.ɵprov = /*@__PURE__*/ i0__namespace.ɵɵdefineInjectable({ token: AbilityService, factory: AbilityService.ɵfac });
|
|
93
|
+
AbilityService.ɵfac = function AbilityService_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AbilityService)(i0__namespace.ɵɵinject(ability.PureAbility)); };
|
|
94
|
+
AbilityService.ɵprov = /*@__PURE__*/ i0__namespace.ɵɵdefineInjectable({ token: AbilityService, factory: AbilityService.ɵfac, providedIn: 'root' });
|
|
116
95
|
return AbilityService;
|
|
117
96
|
}());
|
|
118
97
|
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(AbilityService, [{
|
|
119
|
-
type: i0.Injectable
|
|
98
|
+
type: i0.Injectable,
|
|
99
|
+
args: [{ providedIn: 'root' }]
|
|
120
100
|
}], function () { return [{ type: undefined, decorators: [{
|
|
121
101
|
type: i0.Inject,
|
|
122
102
|
args: [ability.PureAbility]
|
|
123
103
|
}] }]; }, null); })();
|
|
124
104
|
|
|
125
|
-
|
|
105
|
+
var AbilityServiceSignal = /** @class */ (function () {
|
|
106
|
+
function AbilityServiceSignal() {
|
|
107
|
+
var _this = this;
|
|
108
|
+
this._rules = i0.signal([]);
|
|
109
|
+
this._ability = i0.inject(ability.PureAbility);
|
|
110
|
+
this.can = function () {
|
|
111
|
+
var _a;
|
|
112
|
+
var args = [];
|
|
113
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
114
|
+
args[_i] = arguments[_i];
|
|
115
|
+
}
|
|
116
|
+
_this._rules(); // generate side effect for angular to track changes in this signal
|
|
117
|
+
return (_a = _this._ability).can.apply(_a, args);
|
|
118
|
+
};
|
|
119
|
+
this.cannot = function () {
|
|
120
|
+
var args = [];
|
|
121
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
122
|
+
args[_i] = arguments[_i];
|
|
123
|
+
}
|
|
124
|
+
return !_this.can.apply(_this, args);
|
|
125
|
+
};
|
|
126
|
+
this._disposeAbilitySubscription = this._ability.on('updated', function (event) {
|
|
127
|
+
_this._rules.set(event.rules);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
AbilityServiceSignal.prototype.ngOnDestroy = function () {
|
|
131
|
+
this._disposeAbilitySubscription();
|
|
132
|
+
};
|
|
133
|
+
AbilityServiceSignal.prototype.update = function (rules) {
|
|
134
|
+
this._ability.update(rules);
|
|
135
|
+
};
|
|
136
|
+
AbilityServiceSignal.ɵfac = function AbilityServiceSignal_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AbilityServiceSignal)(); };
|
|
137
|
+
AbilityServiceSignal.ɵprov = /*@__PURE__*/ i0__namespace.ɵɵdefineInjectable({ token: AbilityServiceSignal, factory: AbilityServiceSignal.ɵfac, providedIn: 'root' });
|
|
138
|
+
return AbilityServiceSignal;
|
|
139
|
+
}());
|
|
140
|
+
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(AbilityServiceSignal, [{
|
|
141
|
+
type: i0.Injectable,
|
|
142
|
+
args: [{ providedIn: 'root' }]
|
|
143
|
+
}], function () { return []; }, null); })();
|
|
144
|
+
|
|
126
145
|
exports.AbilityService = AbilityService;
|
|
146
|
+
exports.AbilityServiceSignal = AbilityServiceSignal;
|
|
127
147
|
exports.AblePipe = AblePipe;
|
|
128
148
|
exports.AblePurePipe = AblePurePipe;
|
|
129
149
|
|
package/dist/umd/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/pipes.ts","../../src/
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/pipes.ts","../../src/AbilityService.ts","../../src/AbilityServiceSignal.ts"],"sourcesContent":["import { Pipe, Inject, PipeTransform } from '@angular/core';\nimport { PureAbility, AnyAbility } from '@casl/ability';\nimport { Observable } from 'rxjs';\n\n/**\n * @deprecated use AbilityService instead\n */\n@Pipe({ name: 'able', pure: false, standalone: true })\nexport class AblePipe<T extends AnyAbility> implements PipeTransform {\n private _ability: T;\n\n constructor(@Inject(PureAbility) ability: T) {\n this._ability = ability;\n }\n\n transform(...args: Parameters<T['can']>): boolean {\n return this._ability.can(...args);\n }\n}\n\n/**\n * @deprecated use AbilityService instead\n */\n@Pipe({ name: 'ablePure', standalone: true })\nexport class AblePurePipe<T extends AnyAbility> implements PipeTransform {\n private _ability: T;\n\n constructor(@Inject(PureAbility) ability: T) {\n this._ability = ability;\n }\n\n transform(...args: Parameters<T['can']>): Observable<boolean> {\n return new Observable((s) => {\n const emit = () => s.next(this._ability.can(...args));\n emit();\n return this._ability.on('updated', emit);\n });\n }\n}\n","import { Inject, Injectable } from '@angular/core';\nimport { AnyAbility, PureAbility } from '@casl/ability';\nimport { Observable } from 'rxjs';\n\n@Injectable({ providedIn: 'root' })\nexport class AbilityService<T extends AnyAbility> {\n readonly ability$: Observable<T>;\n\n constructor(@Inject(PureAbility) ability: T) {\n this.ability$ = new Observable((observer) => {\n observer.next(ability);\n return ability.on('updated', () => observer.next(ability));\n });\n }\n}\n","import { inject, Injectable, OnDestroy, signal } from \"@angular/core\";\nimport { AnyAbility, PureAbility, RawRuleOf } from \"@casl/ability\";\n\n@Injectable({ providedIn: 'root' })\nexport class AbilityServiceSignal<T extends AnyAbility> implements OnDestroy {\n private readonly _rules = signal<RawRuleOf<T>[]>([]);\n private readonly _ability = inject(PureAbility) as unknown as T;\n private readonly _disposeAbilitySubscription: () => void;\n\n constructor() {\n this._disposeAbilitySubscription = this._ability.on('updated', (event) => {\n this._rules.set(event.rules as any);\n });\n }\n\n ngOnDestroy(): void {\n this._disposeAbilitySubscription();\n }\n\n can = (...args: Parameters<T['can']>): boolean => {\n this._rules(); // generate side effect for angular to track changes in this signal\n return this._ability.can(...args);\n };\n\n cannot = (...args: Parameters<T['can']>): boolean => {\n return !this.can(...args);\n };\n\n update(rules: T['rules']): void {\n this._ability.update(rules);\n }\n}"],"names":["PureAbility","Pipe","Inject","Observable","Injectable","signal","inject"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;IAIA;;IAEG;AACH,QAAA,QAAA,kBAAA,YAAA;IAIE,IAAA,SAAA,QAAA,CAAiC,OAAU,EAAA;IACzC,QAAA,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;SACzB;IAED,IAAA,QAAA,CAAA,SAAA,CAAA,SAAS,GAAT,YAAA;;YAAU,IAA6B,IAAA,GAAA,EAAA,CAAA;iBAA7B,IAA6B,EAAA,GAAA,CAAA,EAA7B,EAA6B,GAAA,SAAA,CAAA,MAAA,EAA7B,EAA6B,EAAA,EAAA;gBAA7B,IAA6B,CAAA,EAAA,CAAA,GAAA,SAAA,CAAA,EAAA,CAAA,CAAA;;YACrC,OAAO,CAAA,EAAA,GAAA,IAAI,CAAC,QAAQ,EAAC,GAAG,CAAI,KAAA,CAAA,EAAA,EAAA,IAAI,CAAE,CAAA;SACnC,CAAA;IATU,IAAA,QAAA,CAAA,IAAA,GAAA,SAAA,gBAAA,CAAA,iBAAA,EAAA,EAAA,OAAA,KAAA,iBAAA,IAAA,QAAQ,kCAGCA,mBAAW,EAAA,EAAA,CAAA,CAAA,CAAA,EAAA,CAAA;wFAHpB,QAAQ,EAAA,IAAA,EAAA,KAAA,EAAA,UAAA,EAAA,IAAA,EAAA,CAAA,CAAA;IARrB,IAAA,OAAA,QAAA,CAAA;IAkBC,CAXD,EAWC,EAAA;sGAVY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,CAAC,KAAK,CAAC,CAAC;SAC7B,CAAA;gIA1BU,oBAAoB,GAAA,CAAA,EAAA,CAAA;6FAApB,oBAAoB,EAAA,OAAA,EAApB,oBAAoB,CAAA,IAAA,EAAA,UAAA,EADP,MAAM,EAAA,CAAA,CAAA;IAHhC,IAAA,OAAA,oBAAA,CAAA;IA+BC,CA5BD,EA4BC,EAAA;sGA3BY,oBAAoB,EAAA,CAAA;kBADhCI,aAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@casl/angular",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.3.0",
|
|
4
4
|
"description": "Angular module for CASL which makes it easy to add permissions in any Angular app",
|
|
5
5
|
"main": "dist/umd/index.js",
|
|
6
6
|
"module": "dist/es5m/index.js",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"author": "Sergii Stotskyi <sergiy.stotskiy@gmail.com>",
|
|
48
48
|
"license": "MIT",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@angular/core": "^
|
|
51
|
-
"@casl/ability": "^
|
|
50
|
+
"@angular/core": "^16.0.0 || ^17.0.0 || ^18.0.0",
|
|
51
|
+
"@casl/ability": "^4.0.0 || ^5.1.0 || ^6.0.0",
|
|
52
52
|
"rxjs": "^7.5.5",
|
|
53
53
|
"tslib": "^2.0.0"
|
|
54
54
|
},
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"rxjs": "^7.5.5",
|
|
69
69
|
"tslib": "^2.0.0",
|
|
70
70
|
"typescript": "~5.5.0",
|
|
71
|
-
"zone.js": "~0.
|
|
71
|
+
"zone.js": "~0.15.0"
|
|
72
72
|
},
|
|
73
73
|
"files": [
|
|
74
74
|
"dist",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as i0 from "@angular/core";
|
|
2
|
-
import * as i1 from "./pipes";
|
|
3
|
-
export declare class AbilityModule {
|
|
4
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<AbilityModule, never>;
|
|
5
|
-
static ɵmod: i0.ɵɵNgModuleDeclaration<AbilityModule, [typeof i1.AblePipe, typeof i1.AblePurePipe], never, [typeof i1.AblePipe, typeof i1.AblePurePipe]>;
|
|
6
|
-
static ɵinj: i0.ɵɵInjectorDeclaration<AbilityModule>;
|
|
7
|
-
}
|