@casl/angular 5.1.3 → 7.0.1
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 +5 -13
- package/dist/es5m/index.js +43 -78
- package/dist/es5m/index.js.map +1 -1
- package/dist/es6m/index.mjs +69 -0
- package/dist/es6m/index.mjs.map +1 -0
- package/dist/types/AbilityModule.d.ts +5 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/pipes.d.ts +8 -18
- package/dist/umd/index.js +62 -77
- package/dist/umd/index.js.map +1 -1
- package/package.json +25 -19
- package/CHANGELOG.md +0 -408
- package/dist/es6m/index.js +0 -96
- package/dist/es6m/index.js.map +0 -1
- package/dist/types/index.metadata.json +0 -1
package/README.md
CHANGED
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/%40casl%2Fangular)
|
|
5
5
|
[](https://gitter.im/stalniy-casl/casl)
|
|
6
6
|
|
|
7
|
-
This package allows to integrate `@casl/ability` with [Angular] application. It provides `AblePipe` and
|
|
7
|
+
This package allows to integrate `@casl/ability` with [Angular] application. It provides `AblePipe` and `AblePurePipe` to Angular templates, so you can show or hide components, buttons, etc based on user ability to see them.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
+
The latest version of this package is compiled by Ivy, so **apps that do not use Ivy are no longer supported.**
|
|
12
|
+
|
|
11
13
|
```sh
|
|
12
14
|
npm install @casl/angular @casl/ability
|
|
13
15
|
# or
|
|
@@ -39,7 +41,7 @@ import { Ability, PureAbility } from '@casl/ability';
|
|
|
39
41
|
export class AppModule {}
|
|
40
42
|
```
|
|
41
43
|
|
|
42
|
-
The 2nd provider provides instance of `PureAbility`, so
|
|
44
|
+
The 2nd provider provides instance of `PureAbility`, so pipes can inject it later. This pipes inject `PureAbility` (not `Ability`) because this allows an application developer to decide how to configure actions, subjects and conditions. Also this is the only way to get maximum from tree shaking (e.g., if you don't need conditions you can use `PureAbility` and shrink @casl/ability size).
|
|
43
45
|
|
|
44
46
|
> Read [CASL and TypeScript](https://casl.js.org/v5/en/advanced/typescript) to get more details about `Ability` type configuration.
|
|
45
47
|
|
|
@@ -131,16 +133,6 @@ To check permissions in any template you can use `AblePipe`:
|
|
|
131
133
|
|
|
132
134
|
> You can read the expression in `ngIf` as "if creatable Post"
|
|
133
135
|
|
|
134
|
-
Or with **deprecated** `CanPipe`:
|
|
135
|
-
|
|
136
|
-
```html
|
|
137
|
-
<div *ngIf="'Post' | can: 'create'">
|
|
138
|
-
<a (click)="createPost()">Add Post</a>
|
|
139
|
-
</div>
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
`CanPipe` was deprecated because it is less readable and it was harder to integrate it with all type definitions supported by `Ability`'s `can` method. That's why `CanPipe` has weaker typings than `AblePipe`.
|
|
143
|
-
|
|
144
136
|
## Why pipe and not directive?
|
|
145
137
|
|
|
146
138
|
Directive cannot be used to pass values into inputs of other components. For example, we need to enable or disable a button based on user's ability to create a post. With directive we cannot do this but we can do this with pipe:
|
|
@@ -180,7 +172,7 @@ For apps that mutate application state, we need to use impure `able` pipe as it
|
|
|
180
172
|
|
|
181
173
|
## TypeScript support
|
|
182
174
|
|
|
183
|
-
|
|
175
|
+
This package is written in TypeScript, so it will warn you about wrong usage.
|
|
184
176
|
|
|
185
177
|
It may be a bit tedious to use application specific abilities in Angular app because everywhere you inject `Ability` instance you will need to import its generic parameters:
|
|
186
178
|
|
package/dist/es5m/index.js
CHANGED
|
@@ -1,53 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Pipe, Inject, NgModule } from '@angular/core';
|
|
2
3
|
import { PureAbility } from '@casl/ability';
|
|
3
4
|
import { Observable } from 'rxjs';
|
|
4
5
|
|
|
5
|
-
var AbilityPipe = /** @class */ (function () {
|
|
6
|
-
function AbilityPipe(ability, cd) {
|
|
7
|
-
this._ability = ability;
|
|
8
|
-
this._cd = cd;
|
|
9
|
-
}
|
|
10
|
-
AbilityPipe.prototype.transform = function () {
|
|
11
|
-
var _a;
|
|
12
|
-
var _this = this;
|
|
13
|
-
var args = [];
|
|
14
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
15
|
-
args[_i] = arguments[_i];
|
|
16
|
-
}
|
|
17
|
-
if (!this._unsubscribeFromAbility) {
|
|
18
|
-
this._unsubscribeFromAbility = this._ability.on('updated', function () { return _this._cd.markForCheck(); });
|
|
19
|
-
}
|
|
20
|
-
return (_a = this._ability).can.apply(_a, args);
|
|
21
|
-
};
|
|
22
|
-
AbilityPipe.prototype.ngOnDestroy = function () {
|
|
23
|
-
if (this._unsubscribeFromAbility) {
|
|
24
|
-
this._unsubscribeFromAbility();
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
return AbilityPipe;
|
|
28
|
-
}());
|
|
29
|
-
var CanPipe = /** @class */ (function () {
|
|
30
|
-
function CanPipe(ability, cd) {
|
|
31
|
-
this.pipe = new AbilityPipe(ability, cd);
|
|
32
|
-
}
|
|
33
|
-
CanPipe.prototype.transform = function (subject, action, field) {
|
|
34
|
-
return this.pipe.transform(action, subject, field);
|
|
35
|
-
};
|
|
36
|
-
CanPipe.prototype.ngOnDestroy = function () {
|
|
37
|
-
this.pipe.ngOnDestroy();
|
|
38
|
-
};
|
|
39
|
-
CanPipe.decorators = [
|
|
40
|
-
{ type: Pipe, args: [{ name: 'can', pure: false },] }
|
|
41
|
-
];
|
|
42
|
-
CanPipe.ctorParameters = function () { return [
|
|
43
|
-
{ type: undefined, decorators: [{ type: Inject, args: [PureAbility,] }] },
|
|
44
|
-
{ type: ChangeDetectorRef }
|
|
45
|
-
]; };
|
|
46
|
-
return CanPipe;
|
|
47
|
-
}());
|
|
48
6
|
var AblePipe = /** @class */ (function () {
|
|
49
|
-
function AblePipe(ability
|
|
50
|
-
this.
|
|
7
|
+
function AblePipe(ability) {
|
|
8
|
+
this._ability = ability;
|
|
51
9
|
}
|
|
52
10
|
AblePipe.prototype.transform = function () {
|
|
53
11
|
var _a;
|
|
@@ -55,20 +13,19 @@ var AblePipe = /** @class */ (function () {
|
|
|
55
13
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
56
14
|
args[_i] = arguments[_i];
|
|
57
15
|
}
|
|
58
|
-
return (_a = this.
|
|
59
|
-
};
|
|
60
|
-
AblePipe.prototype.ngOnDestroy = function () {
|
|
61
|
-
this.pipe.ngOnDestroy();
|
|
16
|
+
return (_a = this._ability).can.apply(_a, args);
|
|
62
17
|
};
|
|
63
|
-
AblePipe
|
|
64
|
-
|
|
65
|
-
];
|
|
66
|
-
AblePipe.ctorParameters = function () { return [
|
|
67
|
-
{ type: undefined, decorators: [{ type: Inject, args: [PureAbility,] }] },
|
|
68
|
-
{ type: ChangeDetectorRef }
|
|
69
|
-
]; };
|
|
18
|
+
AblePipe.ɵfac = function AblePipe_Factory(t) { return new (t || AblePipe)(i0.ɵɵdirectiveInject(PureAbility, 16)); };
|
|
19
|
+
AblePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "able", type: AblePipe, pure: false });
|
|
70
20
|
return AblePipe;
|
|
71
21
|
}());
|
|
22
|
+
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AblePipe, [{
|
|
23
|
+
type: Pipe,
|
|
24
|
+
args: [{ name: 'able', pure: false }]
|
|
25
|
+
}], function () { return [{ type: undefined, decorators: [{
|
|
26
|
+
type: Inject,
|
|
27
|
+
args: [PureAbility]
|
|
28
|
+
}] }]; }, null); })();
|
|
72
29
|
var AblePurePipe = /** @class */ (function () {
|
|
73
30
|
function AblePurePipe(ability) {
|
|
74
31
|
this._ability = ability;
|
|
@@ -89,34 +46,42 @@ var AblePurePipe = /** @class */ (function () {
|
|
|
89
46
|
return _this._ability.on('updated', emit);
|
|
90
47
|
});
|
|
91
48
|
};
|
|
92
|
-
AblePurePipe
|
|
93
|
-
|
|
94
|
-
];
|
|
95
|
-
AblePurePipe.ctorParameters = function () { return [
|
|
96
|
-
{ type: undefined, decorators: [{ type: Inject, args: [PureAbility,] }] }
|
|
97
|
-
]; };
|
|
49
|
+
AblePurePipe.ɵfac = function AblePurePipe_Factory(t) { return new (t || AblePurePipe)(i0.ɵɵdirectiveInject(PureAbility, 16)); };
|
|
50
|
+
AblePurePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "ablePure", type: AblePurePipe, pure: true });
|
|
98
51
|
return AblePurePipe;
|
|
99
52
|
}());
|
|
53
|
+
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AblePurePipe, [{
|
|
54
|
+
type: Pipe,
|
|
55
|
+
args: [{ name: 'ablePure' }]
|
|
56
|
+
}], function () { return [{ type: undefined, decorators: [{
|
|
57
|
+
type: Inject,
|
|
58
|
+
args: [PureAbility]
|
|
59
|
+
}] }]; }, null); })();
|
|
100
60
|
|
|
101
61
|
var AbilityModule = /** @class */ (function () {
|
|
102
62
|
function AbilityModule() {
|
|
103
63
|
}
|
|
104
|
-
AbilityModule
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
CanPipe,
|
|
108
|
-
AblePipe,
|
|
109
|
-
AblePurePipe,
|
|
110
|
-
],
|
|
111
|
-
exports: [
|
|
112
|
-
CanPipe,
|
|
113
|
-
AblePipe,
|
|
114
|
-
AblePurePipe,
|
|
115
|
-
],
|
|
116
|
-
},] }
|
|
117
|
-
];
|
|
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({});
|
|
118
67
|
return AbilityModule;
|
|
119
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] }); })();
|
|
120
85
|
|
|
121
|
-
export { AbilityModule, AblePipe, AblePurePipe
|
|
86
|
+
export { AbilityModule, AblePipe, AblePurePipe };
|
|
122
87
|
//# sourceMappingURL=index.js.map
|
package/dist/es5m/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/pipes.ts","../../src/AbilityModule.ts"],"sourcesContent":["import { Pipe,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/pipes.ts","../../src/AbilityModule.ts"],"sourcesContent":["import { Pipe, Inject, PipeTransform } from '@angular/core';\nimport { PureAbility, Unsubscribe, AnyAbility } from '@casl/ability';\nimport { Observable } from 'rxjs';\n\n@Pipe({ name: 'able', pure: false })\nexport class AblePipe<T extends AnyAbility> implements PipeTransform {\n protected _unsubscribeFromAbility?: Unsubscribe;\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@Pipe({ name: 'ablePure' })\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 // TODO: `Observable` can be removed after https://github.com/angular/angular/issues/15041\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 { NgModule } from '@angular/core';\nimport { AblePipe, AblePurePipe } from './pipes';\n\n@NgModule({\n declarations: [\n AblePipe,\n AblePurePipe,\n ],\n exports: [\n AblePipe,\n AblePurePipe,\n ],\n})\nexport class AbilityModule {\n}\n"],"names":[],"mappings":";;;;;;IASE,kBAAiC,OAAU;QACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;KACzB;IAED,4BAAS,GAAT;;QAAU,cAA6B;aAA7B,UAA6B,EAA7B,qBAA6B,EAA7B,IAA6B;YAA7B,yBAA6B;;QACrC,OAAO,CAAA,KAAA,IAAI,CAAC,QAAQ,EAAC,GAAG,WAAI,IAAI,EAAE;KACnC;oEAVU,QAAQ,uBAIC,WAAW;yEAJpB,QAAQ;mBALrB;CAIA,IAYC;uFAXY,QAAQ;cADpB,IAAI;eAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE;;sBAKpB,MAAM;uBAAC,WAAW;;;IAa/B,sBAAiC,OAAU;QACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;KACzB;;IAGD,gCAAS,GAAT;QAAA,iBAMC;QANS,cAA6B;aAA7B,UAA6B,EAA7B,qBAA6B,EAA7B,IAA6B;YAA7B,yBAA6B;;QACrC,OAAO,IAAI,UAAU,CAAC,UAAC,CAAC;YACtB,IAAM,IAAI,GAAG;;gBAAM,OAAA,CAAC,CAAC,IAAI,CAAC,CAAA,KAAA,KAAI,CAAC,QAAQ,EAAC,GAAG,WAAI,IAAI,EAAE;aAAA,CAAC;YACtD,IAAI,EAAE,CAAC;YACP,OAAO,KAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;SAC1C,CAAC,CAAC;KACJ;4EAdU,YAAY,uBAGH,WAAW;iFAHpB,YAAY;uBAnBzB;CAkBA,IAgBC;uFAfY,YAAY;cADxB,IAAI;eAAC,EAAE,IAAI,EAAE,UAAU,EAAE;;sBAIX,MAAM;uBAAC,WAAW;;;;ICnBjC;KAWC;8EADY,aAAa;mEAAb,aAAa;;wBAb1B;CAGA,IAWC;uFADY,aAAa;cAVzB,QAAQ;eAAC;gBACR,YAAY,EAAE;oBACZ,QAAQ;oBACR,YAAY;iBACb;gBACD,OAAO,EAAE;oBACP,QAAQ;oBACR,YAAY;iBACb;aACF;;wFACY,aAAa,mBARtB,QAAQ;QACR,YAAY,aAGZ,QAAQ;QACR,YAAY;;;;"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Pipe, Inject, NgModule } from '@angular/core';
|
|
3
|
+
import { PureAbility } from '@casl/ability';
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
|
+
|
|
6
|
+
class AblePipe {
|
|
7
|
+
constructor(ability) {
|
|
8
|
+
this._ability = ability;
|
|
9
|
+
}
|
|
10
|
+
transform(...args) {
|
|
11
|
+
return this._ability.can(...args);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
AblePipe.ɵfac = function AblePipe_Factory(t) { return new (t || AblePipe)(i0.ɵɵdirectiveInject(PureAbility, 16)); };
|
|
15
|
+
AblePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "able", type: AblePipe, pure: false });
|
|
16
|
+
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AblePipe, [{
|
|
17
|
+
type: Pipe,
|
|
18
|
+
args: [{ name: 'able', pure: false }]
|
|
19
|
+
}], function () { return [{ type: undefined, decorators: [{
|
|
20
|
+
type: Inject,
|
|
21
|
+
args: [PureAbility]
|
|
22
|
+
}] }]; }, null); })();
|
|
23
|
+
class AblePurePipe {
|
|
24
|
+
constructor(ability) {
|
|
25
|
+
this._ability = ability;
|
|
26
|
+
}
|
|
27
|
+
// TODO: `Observable` can be removed after https://github.com/angular/angular/issues/15041
|
|
28
|
+
transform(...args) {
|
|
29
|
+
return new Observable((s) => {
|
|
30
|
+
const emit = () => s.next(this._ability.can(...args));
|
|
31
|
+
emit();
|
|
32
|
+
return this._ability.on('updated', emit);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
AblePurePipe.ɵfac = function AblePurePipe_Factory(t) { return new (t || AblePurePipe)(i0.ɵɵdirectiveInject(PureAbility, 16)); };
|
|
37
|
+
AblePurePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "ablePure", type: AblePurePipe, pure: true });
|
|
38
|
+
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AblePurePipe, [{
|
|
39
|
+
type: Pipe,
|
|
40
|
+
args: [{ name: 'ablePure' }]
|
|
41
|
+
}], function () { return [{ type: undefined, decorators: [{
|
|
42
|
+
type: Inject,
|
|
43
|
+
args: [PureAbility]
|
|
44
|
+
}] }]; }, null); })();
|
|
45
|
+
|
|
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
|
+
(function () { (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
|
+
export { AbilityModule, AblePipe, AblePurePipe };
|
|
69
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/pipes.ts","../../src/AbilityModule.ts"],"sourcesContent":["import { Pipe, Inject, PipeTransform } from '@angular/core';\nimport { PureAbility, Unsubscribe, AnyAbility } from '@casl/ability';\nimport { Observable } from 'rxjs';\n\n@Pipe({ name: 'able', pure: false })\nexport class AblePipe<T extends AnyAbility> implements PipeTransform {\n protected _unsubscribeFromAbility?: Unsubscribe;\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@Pipe({ name: 'ablePure' })\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 // TODO: `Observable` can be removed after https://github.com/angular/angular/issues/15041\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 { NgModule } from '@angular/core';\nimport { AblePipe, AblePurePipe } from './pipes';\n\n@NgModule({\n declarations: [\n AblePipe,\n AblePurePipe,\n ],\n exports: [\n AblePipe,\n AblePurePipe,\n ],\n})\nexport class AbilityModule {\n}\n"],"names":[],"mappings":";;;;;MAKa,QAAQ;IAInB,YAAiC,OAAU;QACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;KACzB;IAED,SAAS,CAAC,GAAG,IAA0B;QACrC,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;KACnC;;gEAVU,QAAQ,uBAIC,WAAW;qEAJpB,QAAQ;uFAAR,QAAQ;cADpB,IAAI;eAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE;;sBAKpB,MAAM;uBAAC,WAAW;;MAUpB,YAAY;IAGvB,YAAiC,OAAU;QACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;KACzB;;IAGD,SAAS,CAAC,GAAG,IAA0B;QACrC,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC;YACtB,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;YACtD,IAAI,EAAE,CAAC;YACP,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;SAC1C,CAAC,CAAC;KACJ;;wEAdU,YAAY,uBAGH,WAAW;6EAHpB,YAAY;uFAAZ,YAAY;cADxB,IAAI;eAAC,EAAE,IAAI,EAAE,UAAU,EAAE;;sBAIX,MAAM;uBAAC,WAAW;;;MCTpB,aAAa;;0EAAb,aAAa;+DAAb,aAAa;;uFAAb,aAAa;cAVzB,QAAQ;eAAC;gBACR,YAAY,EAAE;oBACZ,QAAQ;oBACR,YAAY;iBACb;gBACD,OAAO,EAAE;oBACP,QAAQ;oBACR,YAAY;iBACb;aACF;;wFACY,aAAa,mBARtB,QAAQ;QACR,YAAY,aAGZ,QAAQ;QACR,YAAY;;;;"}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import * as i1 from "./pipes";
|
|
1
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>;
|
|
2
7
|
}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/pipes.d.ts
CHANGED
|
@@ -1,29 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PipeTransform } from '@angular/core';
|
|
2
2
|
import { Unsubscribe, AnyAbility } from '@casl/ability';
|
|
3
3
|
import { Observable } from 'rxjs';
|
|
4
|
-
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
export declare class AblePipe<T extends AnyAbility> implements PipeTransform {
|
|
5
6
|
protected _unsubscribeFromAbility?: Unsubscribe;
|
|
6
7
|
private _ability;
|
|
7
|
-
|
|
8
|
-
constructor(ability: T, cd: ChangeDetectorRef);
|
|
9
|
-
transform(...args: Parameters<T['can']>): boolean;
|
|
10
|
-
ngOnDestroy(): void;
|
|
11
|
-
}
|
|
12
|
-
export declare class CanPipe<T extends AnyAbility> implements PipeTransform {
|
|
13
|
-
protected pipe: AbilityPipe<T>;
|
|
14
|
-
constructor(ability: T, cd: ChangeDetectorRef);
|
|
15
|
-
transform(subject: Parameters<T['can']>[1], action: Parameters<T['can']>[0], field?: string): boolean;
|
|
16
|
-
ngOnDestroy(): void;
|
|
17
|
-
}
|
|
18
|
-
export declare class AblePipe<T extends AnyAbility> implements PipeTransform {
|
|
19
|
-
protected pipe: AbilityPipe<T>;
|
|
20
|
-
constructor(ability: T, cd: ChangeDetectorRef);
|
|
8
|
+
constructor(ability: T);
|
|
21
9
|
transform(...args: Parameters<T['can']>): boolean;
|
|
22
|
-
|
|
10
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<AblePipe<any>, never>;
|
|
11
|
+
static ɵpipe: i0.ɵɵPipeDeclaration<AblePipe<any>, "able">;
|
|
23
12
|
}
|
|
24
13
|
export declare class AblePurePipe<T extends AnyAbility> implements PipeTransform {
|
|
25
14
|
private _ability;
|
|
26
15
|
constructor(ability: T);
|
|
27
16
|
transform(...args: Parameters<T['can']>): Observable<boolean>;
|
|
17
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<AblePurePipe<any>, never>;
|
|
18
|
+
static ɵpipe: i0.ɵɵPipeDeclaration<AblePurePipe<any>, "ablePure">;
|
|
28
19
|
}
|
|
29
|
-
export {};
|
package/dist/umd/index.js
CHANGED
|
@@ -2,54 +2,33 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@casl/ability'), require('rxjs')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@casl/ability', 'rxjs'], factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.casl = global.casl || {}, global.casl.ng = {}), global.ng.core, global.casl, global.rxjs));
|
|
5
|
-
}(this, (function (exports,
|
|
5
|
+
}(this, (function (exports, i0, ability, rxjs) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
return (_a = this._ability).can.apply(_a, args);
|
|
23
|
-
};
|
|
24
|
-
AbilityPipe.prototype.ngOnDestroy = function () {
|
|
25
|
-
if (this._unsubscribeFromAbility) {
|
|
26
|
-
this._unsubscribeFromAbility();
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
return AbilityPipe;
|
|
30
|
-
}());
|
|
31
|
-
var CanPipe = /** @class */ (function () {
|
|
32
|
-
function CanPipe(ability, cd) {
|
|
33
|
-
this.pipe = new AbilityPipe(ability, cd);
|
|
7
|
+
function _interopNamespace(e) {
|
|
8
|
+
if (e && e.__esModule) return e;
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () {
|
|
17
|
+
return e[k];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
34
22
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
CanPipe.decorators = [
|
|
42
|
-
{ type: core.Pipe, args: [{ name: 'can', pure: false },] }
|
|
43
|
-
];
|
|
44
|
-
CanPipe.ctorParameters = function () { return [
|
|
45
|
-
{ type: undefined, decorators: [{ type: core.Inject, args: [ability.PureAbility,] }] },
|
|
46
|
-
{ type: core.ChangeDetectorRef }
|
|
47
|
-
]; };
|
|
48
|
-
return CanPipe;
|
|
49
|
-
}());
|
|
23
|
+
n['default'] = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
|
|
28
|
+
|
|
50
29
|
var AblePipe = /** @class */ (function () {
|
|
51
|
-
function AblePipe(ability
|
|
52
|
-
this.
|
|
30
|
+
function AblePipe(ability) {
|
|
31
|
+
this._ability = ability;
|
|
53
32
|
}
|
|
54
33
|
AblePipe.prototype.transform = function () {
|
|
55
34
|
var _a;
|
|
@@ -57,20 +36,19 @@
|
|
|
57
36
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
58
37
|
args[_i] = arguments[_i];
|
|
59
38
|
}
|
|
60
|
-
return (_a = this.
|
|
61
|
-
};
|
|
62
|
-
AblePipe.prototype.ngOnDestroy = function () {
|
|
63
|
-
this.pipe.ngOnDestroy();
|
|
39
|
+
return (_a = this._ability).can.apply(_a, args);
|
|
64
40
|
};
|
|
65
|
-
AblePipe
|
|
66
|
-
|
|
67
|
-
];
|
|
68
|
-
AblePipe.ctorParameters = function () { return [
|
|
69
|
-
{ type: undefined, decorators: [{ type: core.Inject, args: [ability.PureAbility,] }] },
|
|
70
|
-
{ type: core.ChangeDetectorRef }
|
|
71
|
-
]; };
|
|
41
|
+
AblePipe.ɵfac = function AblePipe_Factory(t) { return new (t || AblePipe)(i0__namespace.ɵɵdirectiveInject(ability.PureAbility, 16)); };
|
|
42
|
+
AblePipe.ɵpipe = /*@__PURE__*/ i0__namespace.ɵɵdefinePipe({ name: "able", type: AblePipe, pure: false });
|
|
72
43
|
return AblePipe;
|
|
73
44
|
}());
|
|
45
|
+
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(AblePipe, [{
|
|
46
|
+
type: i0.Pipe,
|
|
47
|
+
args: [{ name: 'able', pure: false }]
|
|
48
|
+
}], function () { return [{ type: undefined, decorators: [{
|
|
49
|
+
type: i0.Inject,
|
|
50
|
+
args: [ability.PureAbility]
|
|
51
|
+
}] }]; }, null); })();
|
|
74
52
|
var AblePurePipe = /** @class */ (function () {
|
|
75
53
|
function AblePurePipe(ability) {
|
|
76
54
|
this._ability = ability;
|
|
@@ -91,39 +69,46 @@
|
|
|
91
69
|
return _this._ability.on('updated', emit);
|
|
92
70
|
});
|
|
93
71
|
};
|
|
94
|
-
AblePurePipe
|
|
95
|
-
|
|
96
|
-
];
|
|
97
|
-
AblePurePipe.ctorParameters = function () { return [
|
|
98
|
-
{ type: undefined, decorators: [{ type: core.Inject, args: [ability.PureAbility,] }] }
|
|
99
|
-
]; };
|
|
72
|
+
AblePurePipe.ɵfac = function AblePurePipe_Factory(t) { return new (t || AblePurePipe)(i0__namespace.ɵɵdirectiveInject(ability.PureAbility, 16)); };
|
|
73
|
+
AblePurePipe.ɵpipe = /*@__PURE__*/ i0__namespace.ɵɵdefinePipe({ name: "ablePure", type: AblePurePipe, pure: true });
|
|
100
74
|
return AblePurePipe;
|
|
101
75
|
}());
|
|
76
|
+
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(AblePurePipe, [{
|
|
77
|
+
type: i0.Pipe,
|
|
78
|
+
args: [{ name: 'ablePure' }]
|
|
79
|
+
}], function () { return [{ type: undefined, decorators: [{
|
|
80
|
+
type: i0.Inject,
|
|
81
|
+
args: [ability.PureAbility]
|
|
82
|
+
}] }]; }, null); })();
|
|
102
83
|
|
|
103
84
|
var AbilityModule = /** @class */ (function () {
|
|
104
85
|
function AbilityModule() {
|
|
105
86
|
}
|
|
106
|
-
AbilityModule
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
CanPipe,
|
|
110
|
-
AblePipe,
|
|
111
|
-
AblePurePipe,
|
|
112
|
-
],
|
|
113
|
-
exports: [
|
|
114
|
-
CanPipe,
|
|
115
|
-
AblePipe,
|
|
116
|
-
AblePurePipe,
|
|
117
|
-
],
|
|
118
|
-
},] }
|
|
119
|
-
];
|
|
87
|
+
AbilityModule.ɵfac = function AbilityModule_Factory(t) { return new (t || AbilityModule)(); };
|
|
88
|
+
AbilityModule.ɵmod = /*@__PURE__*/ i0__namespace.ɵɵdefineNgModule({ type: AbilityModule });
|
|
89
|
+
AbilityModule.ɵinj = /*@__PURE__*/ i0__namespace.ɵɵdefineInjector({});
|
|
120
90
|
return AbilityModule;
|
|
121
91
|
}());
|
|
92
|
+
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(AbilityModule, [{
|
|
93
|
+
type: i0.NgModule,
|
|
94
|
+
args: [{
|
|
95
|
+
declarations: [
|
|
96
|
+
AblePipe,
|
|
97
|
+
AblePurePipe,
|
|
98
|
+
],
|
|
99
|
+
exports: [
|
|
100
|
+
AblePipe,
|
|
101
|
+
AblePurePipe,
|
|
102
|
+
],
|
|
103
|
+
}]
|
|
104
|
+
}], null, null); })();
|
|
105
|
+
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0__namespace.ɵɵsetNgModuleScope(AbilityModule, { declarations: [AblePipe,
|
|
106
|
+
AblePurePipe], exports: [AblePipe,
|
|
107
|
+
AblePurePipe] }); })();
|
|
122
108
|
|
|
123
109
|
exports.AbilityModule = AbilityModule;
|
|
124
110
|
exports.AblePipe = AblePipe;
|
|
125
111
|
exports.AblePurePipe = AblePurePipe;
|
|
126
|
-
exports.CanPipe = CanPipe;
|
|
127
112
|
|
|
128
113
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
129
114
|
|
package/dist/umd/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/pipes.ts","../../src/AbilityModule.ts"],"sourcesContent":["import { Pipe,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/pipes.ts","../../src/AbilityModule.ts"],"sourcesContent":["import { Pipe, Inject, PipeTransform } from '@angular/core';\nimport { PureAbility, Unsubscribe, AnyAbility } from '@casl/ability';\nimport { Observable } from 'rxjs';\n\n@Pipe({ name: 'able', pure: false })\nexport class AblePipe<T extends AnyAbility> implements PipeTransform {\n protected _unsubscribeFromAbility?: Unsubscribe;\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@Pipe({ name: 'ablePure' })\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 // TODO: `Observable` can be removed after https://github.com/angular/angular/issues/15041\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 { NgModule } from '@angular/core';\nimport { AblePipe, AblePurePipe } from './pipes';\n\n@NgModule({\n declarations: [\n AblePipe,\n AblePurePipe,\n ],\n exports: [\n AblePipe,\n AblePurePipe,\n ],\n})\nexport class AbilityModule {\n}\n"],"names":["PureAbility","Pipe","Inject","Observable","NgModule"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;QASE,kBAAiC,OAAU;YACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;SACzB;QAED,4BAAS,GAAT;;YAAU,cAA6B;iBAA7B,UAA6B,EAA7B,qBAA6B,EAA7B,IAA6B;gBAA7B,yBAA6B;;YACrC,OAAO,CAAA,KAAA,IAAI,CAAC,QAAQ,EAAC,GAAG,WAAI,IAAI,EAAE;SACnC;wEAVU,QAAQ,kCAICA,mBAAW;wFAJpB,QAAQ;uBALrB;KAIA,IAYC;sGAXY,QAAQ;kBADpBC,OAAI;mBAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE;;0BAKpBC,SAAM;2BAACF,mBAAW;;;QAa/B,sBAAiC,OAAU;YACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;SACzB;;QAGD,gCAAS,GAAT;YAAA,iBAMC;YANS,cAA6B;iBAA7B,UAA6B,EAA7B,qBAA6B,EAA7B,IAA6B;gBAA7B,yBAA6B;;YACrC,OAAO,IAAIG,eAAU,CAAC,UAAC,CAAC;gBACtB,IAAM,IAAI,GAAG;;oBAAM,OAAA,CAAC,CAAC,IAAI,CAAC,CAAA,KAAA,KAAI,CAAC,QAAQ,EAAC,GAAG,WAAI,IAAI,EAAE;iBAAA,CAAC;gBACtD,IAAI,EAAE,CAAC;gBACP,OAAO,KAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;aAC1C,CAAC,CAAC;SACJ;gFAdU,YAAY,kCAGHH,mBAAW;gGAHpB,YAAY;2BAnBzB;KAkBA,IAgBC;sGAfY,YAAY;kBADxBC,OAAI;mBAAC,EAAE,IAAI,EAAE,UAAU,EAAE;;0BAIXC,SAAM;2BAACF,mBAAW;;;;QCnBjC;SAWC;kFADY,aAAa;kFAAb,aAAa;;4BAb1B;KAGA,IAWC;sGADY,aAAa;kBAVzBI,WAAQ;mBAAC;oBACR,YAAY,EAAE;wBACZ,QAAQ;wBACR,YAAY;qBACb;oBACD,OAAO,EAAE;wBACP,QAAQ;wBACR,YAAY;qBACb;iBACF;;uGACY,aAAa,mBARtB,QAAQ;YACR,YAAY,aAGZ,QAAQ;YACR,YAAY;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@casl/angular",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
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",
|
|
7
|
-
"es2015": "dist/es6m/index.
|
|
7
|
+
"es2015": "dist/es6m/index.mjs",
|
|
8
8
|
"typings": "dist/types/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"import": "./dist/es6m/index.
|
|
11
|
+
"import": "./dist/es6m/index.mjs",
|
|
12
12
|
"require": "./dist/umd/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
|
-
"url": "https://github.com/stalniy/casl.git"
|
|
17
|
+
"url": "https://github.com/stalniy/casl.git",
|
|
18
|
+
"directory": "packages/casl-angular"
|
|
18
19
|
},
|
|
19
20
|
"homepage": "https://casl.js.org",
|
|
20
21
|
"publishConfig": {
|
|
@@ -26,9 +27,9 @@
|
|
|
26
27
|
"build.es5m": "TARGET=es5 BUILD=es5m npm run rollup",
|
|
27
28
|
"build.es6": "TARGET=es2015 BUILD=es6m npm run rollup",
|
|
28
29
|
"build.umd": "TARGET=es5 BUILD=umd npm run rollup",
|
|
29
|
-
"build.types": "ngc -p tsconfig.types.json",
|
|
30
|
+
"build.types": "ngc -p tsconfig.types.json && rm -rf dist/types/*.js",
|
|
30
31
|
"prerollup": "ngc -p tsconfig.build.json --target $TARGET --outDir dist/$BUILD/tmp",
|
|
31
|
-
"rollup": "IGNORE_SUBPATH=1 LIB_MINIFY=false BUILD_TYPES=$BUILD ES_TRANSFORM=false
|
|
32
|
+
"rollup": "IGNORE_SUBPATH=1 LIB_MINIFY=false BUILD_TYPES=$BUILD ES_TRANSFORM=false dx rollup -i dist/$BUILD/tmp/index.js -n casl.ng -g @angular/core:ng.core,@casl/ability:casl,tslib:tslib,rxjs:rxjs",
|
|
32
33
|
"postrollup": "rm -rf dist/$BUILD/tmp",
|
|
33
34
|
"test": "dx jest --config ./jest.config.js",
|
|
34
35
|
"lint": "dx eslint src/ spec/",
|
|
@@ -45,24 +46,29 @@
|
|
|
45
46
|
"author": "Sergii Stotskyi <sergiy.stotskiy@gmail.com>",
|
|
46
47
|
"license": "MIT",
|
|
47
48
|
"peerDependencies": {
|
|
48
|
-
"@angular/core": "^
|
|
49
|
-
"@casl/ability": "^3.0.0 || ^4.0.0 || ^5.1.0",
|
|
50
|
-
"rxjs": "^
|
|
49
|
+
"@angular/core": "^13.0.0",
|
|
50
|
+
"@casl/ability": "^3.0.0 || ^4.0.0 || ^5.1.0 || ^6.0.0",
|
|
51
|
+
"rxjs": "^7.5.5",
|
|
51
52
|
"tslib": "^2.0.0"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@abraham/reflection": "^0.
|
|
55
|
-
"@angular/common": "^
|
|
56
|
-
"@angular/compiler": "^
|
|
57
|
-
"@angular/compiler-cli": "^
|
|
58
|
-
"@angular/core": "^
|
|
59
|
-
"@angular/platform-browser": "^
|
|
60
|
-
"@angular/platform-browser-dynamic": "^
|
|
61
|
-
"@
|
|
55
|
+
"@abraham/reflection": "^0.8.0",
|
|
56
|
+
"@angular/common": "^13.0.0",
|
|
57
|
+
"@angular/compiler": "^13.0.0",
|
|
58
|
+
"@angular/compiler-cli": "^13.0.0",
|
|
59
|
+
"@angular/core": "^13.0.0",
|
|
60
|
+
"@angular/platform-browser": "^13.0.0",
|
|
61
|
+
"@angular/platform-browser-dynamic": "^13.0.0",
|
|
62
|
+
"@angular-devkit/build-angular": "^13.0.0",
|
|
63
|
+
"jest": "^27.0.0",
|
|
64
|
+
"@casl/ability": "^6.0.0",
|
|
62
65
|
"@casl/dx": "workspace:^1.0.0",
|
|
63
|
-
"
|
|
66
|
+
"@types/jest": "^27.4.7",
|
|
67
|
+
"jest-preset-angular": "^11.0.0",
|
|
68
|
+
"rxjs": "^7.5.5",
|
|
64
69
|
"tslib": "^2.0.0",
|
|
65
|
-
"
|
|
70
|
+
"typescript": "~4.4.4",
|
|
71
|
+
"zone.js": "~0.11.4"
|
|
66
72
|
},
|
|
67
73
|
"files": [
|
|
68
74
|
"dist",
|
package/CHANGELOG.md
DELETED
|
@@ -1,408 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
## [5.1.1](https://github.com/stalniy/casl/compare/@casl/angular@5.1.0...@casl/angular@5.1.1) (2021-05-12)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
* adjusts package tags to improve discoverability ([73e88b0](https://github.com/stalniy/casl/commit/73e88b0a256625b193b2cd9dc4a219f2e1193cbc))
|
|
11
|
-
|
|
12
|
-
# [5.1.0](https://github.com/stalniy/casl/compare/@casl/angular@5.0.2...@casl/angular@5.1.0) (2021-01-14)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
### Features
|
|
16
|
-
|
|
17
|
-
* **angular:** updates angular to v11 ([#421](https://github.com/stalniy/casl/issues/421)) ([ec16bf9](https://github.com/stalniy/casl/commit/ec16bf9e93536c4ec249d2520cf336c1497615a9))
|
|
18
|
-
|
|
19
|
-
## [5.0.2](https://github.com/stalniy/casl/compare/@casl/angular@5.0.1...@casl/angular@5.0.2) (2021-01-10)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
### Bug Fixes
|
|
23
|
-
|
|
24
|
-
* **angular:** changes ES6M distribution to use `.js` ext instead of `.mjs` ([06bd5be](https://github.com/stalniy/casl/commit/06bd5be0904b3194733c9f6fc3a3dd34cc069aba)), closes [#427](https://github.com/stalniy/casl/issues/427)
|
|
25
|
-
|
|
26
|
-
## [5.0.1](https://github.com/stalniy/casl/compare/@casl/angular@5.0.0...@casl/angular@5.0.1) (2020-12-28)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
### Bug Fixes
|
|
30
|
-
|
|
31
|
-
* **dist:** adds separate `tsconfig.build.json` to every completementary project ([87742ce](https://github.com/stalniy/casl/commit/87742cec518a8a68d5fc29be2bbc9561cbc7da6c)), closes [#419](https://github.com/stalniy/casl/issues/419)
|
|
32
|
-
|
|
33
|
-
# [5.0.0](https://github.com/stalniy/casl/compare/@casl/angular@4.1.6...@casl/angular@5.0.0) (2020-12-26)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
### Bug Fixes
|
|
37
|
-
|
|
38
|
-
* **package:** removes `engine` section that points to npm@6 ([eecd12a](https://github.com/stalniy/casl/commit/eecd12ac49f56d6a0f57d1a57fb37487335b5f03)), closes [#417](https://github.com/stalniy/casl/issues/417)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
### Code Refactoring
|
|
42
|
-
|
|
43
|
-
* **angular:** removes support for Angular < 9.x and casl < 3.x ([3530cdf](https://github.com/stalniy/casl/commit/3530cdf5b73d19b9a6da9be675f292f67e44db32))
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
### Features
|
|
47
|
-
|
|
48
|
-
* **builder:** improves typings for AbilityBuilder [skip release] ([ebd4d17](https://github.com/stalniy/casl/commit/ebd4d17a355a2646467033118a3d6efee4321d27)), closes [#379](https://github.com/stalniy/casl/issues/379)
|
|
49
|
-
* **esm:** adds ESM support for latest Node.js through `exports` prop in package.json ([cac2506](https://github.com/stalniy/casl/commit/cac2506a80c18f194210c2d89108d1d094751fa4)), closes [#331](https://github.com/stalniy/casl/issues/331)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
### BREAKING CHANGES
|
|
53
|
-
|
|
54
|
-
* **angular:** removes support for Angular < 9.x and casl < 3.x
|
|
55
|
-
* **builder:** changes main generic parameter to be a class instead of instance and makes `defineAbility` to accept options as the 2nd argument.
|
|
56
|
-
|
|
57
|
-
**Before**
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
import { AbilityBuilder, defineAbility, Ability } from '@casl/ability';
|
|
61
|
-
|
|
62
|
-
const resolveAction = (action: string) => {/* custom implementation */ };
|
|
63
|
-
const ability = defineAbility({ resolveAction }, (can) => can('read', 'Item'));
|
|
64
|
-
const builder = new AbilityBuilder<Ability>(Ability);
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
**After**
|
|
68
|
-
|
|
69
|
-
```ts
|
|
70
|
-
import { AbilityBuilder, defineAbility, Ability } from '@casl/ability';
|
|
71
|
-
|
|
72
|
-
const resolveAction = (action: string) => {/* custom implementation */ };
|
|
73
|
-
const ability = defineAbility((can) => can('read', 'Item'), { resolveAction });
|
|
74
|
-
const builder = new AbilityBuilder(Ability); // first argument is now mandatory!
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
The 1st parameter to `AbilityBuilder` is now madatory. This allows to infer generic parameters from it and makes AbilityType that is built to be explicit.
|
|
78
|
-
|
|
79
|
-
## [4.1.6](https://github.com/stalniy/casl/compare/@casl/angular@4.1.5...@casl/angular@4.1.6) (2020-10-21)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
### Bug Fixes
|
|
83
|
-
|
|
84
|
-
* **README:** adds semi-colon ([cad1daa](https://github.com/stalniy/casl/commit/cad1daaabf8a7ad45d5736394d3ba3dc42207614))
|
|
85
|
-
|
|
86
|
-
## [4.1.5](https://github.com/stalniy/casl/compare/@casl/angular@4.1.4...@casl/angular@4.1.5) (2020-09-03)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
### Bug Fixes
|
|
90
|
-
|
|
91
|
-
* **angular:** fixes sourcemap generation for the code built by ngc ([7715263](https://github.com/stalniy/casl/commit/771526379ff8203170a433d71b68644a48ff44eb)), closes [#387](https://github.com/stalniy/casl/issues/387) [#382](https://github.com/stalniy/casl/issues/382)
|
|
92
|
-
|
|
93
|
-
## [4.1.4](https://github.com/stalniy/casl/compare/@casl/angular@4.1.3...@casl/angular@4.1.4) (2020-06-09)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
### Bug Fixes
|
|
97
|
-
|
|
98
|
-
* **docs:** ensure README and docs for all packages are in sync ([8df3684](https://github.com/stalniy/casl/commit/8df3684b139de0af60c9c37f284a5028ffbf2224)), closes [#338](https://github.com/stalniy/casl/issues/338)
|
|
99
|
-
|
|
100
|
-
## [4.1.3](https://github.com/stalniy/casl/compare/@casl/angular@4.1.2...@casl/angular@4.1.3) (2020-06-08)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
### Bug Fixes
|
|
104
|
-
|
|
105
|
-
* **package:** makes sure the latest casl works with Angular 8.x ([91ee505](https://github.com/stalniy/casl/commit/91ee505f25b77c7ddf13a066d9d0c22f6d8d2f99)), closes [#337](https://github.com/stalniy/casl/issues/337)
|
|
106
|
-
|
|
107
|
-
## [4.1.2](https://github.com/stalniy/casl/compare/@casl/angular@4.1.1...@casl/angular@4.1.2) (2020-06-02)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
### Bug Fixes
|
|
111
|
-
|
|
112
|
-
* **angular:** widen peer dependency for @angular/core ([aa2c3c4](https://github.com/stalniy/casl/commit/aa2c3c4e5a1e3cf14cebc83125571d3ab15c1451))
|
|
113
|
-
|
|
114
|
-
## [4.1.1](https://github.com/stalniy/casl/compare/@casl/angular@4.1.0...@casl/angular@4.1.1) (2020-05-19)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
### Bug Fixes
|
|
118
|
-
|
|
119
|
-
* **angular:** updates README for the latest release ([1103dec](https://github.com/stalniy/casl/commit/1103dec36b331a67944a5a9b9554daaeabc2b5bf)), closes [#276](https://github.com/stalniy/casl/issues/276)
|
|
120
|
-
|
|
121
|
-
# [4.1.0](https://github.com/stalniy/casl/compare/@casl/angular@4.0.4...@casl/angular@4.1.0) (2020-05-19)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
### Features
|
|
125
|
-
|
|
126
|
-
* **pipe:** adds pure `ablePure` pipe in `@casl/angular` ([23c851c](https://github.com/stalniy/casl/commit/23c851cb0fc4a9cb523a651308f8ad65e137b379)), closes [#276](https://github.com/stalniy/casl/issues/276)
|
|
127
|
-
|
|
128
|
-
## [4.0.4](https://github.com/stalniy/casl/compare/@casl/angular@4.0.3...@casl/angular@4.0.4) (2020-04-14)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
### Bug Fixes
|
|
132
|
-
|
|
133
|
-
* **angular:** removes ngcc `publishOnly` hook ([6e5c570](https://github.com/stalniy/casl/commit/6e5c570b92150e23e4e5c463ed4b497a4860db03))
|
|
134
|
-
|
|
135
|
-
## [4.0.3](https://github.com/stalniy/casl/compare/@casl/angular@4.0.2...@casl/angular@4.0.3) (2020-04-14)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
### Bug Fixes
|
|
139
|
-
|
|
140
|
-
* **package:** allows to disable minification through `LIB_MINIFY` env var ([de70838](https://github.com/stalniy/casl/commit/de70838a7a6e52ee4af52635f6dd91f3b767bdca))
|
|
141
|
-
|
|
142
|
-
## [4.0.2](https://github.com/stalniy/casl/compare/@casl/angular@4.0.1...@casl/angular@4.0.2) (2020-04-10)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
### Bug Fixes
|
|
146
|
-
|
|
147
|
-
* **angular:** ensure that terser doesn't mangle reserved required props ([5371166](https://github.com/stalniy/casl/commit/53711660cfd306bd713a9c59abc0b95d5d1d13c1))
|
|
148
|
-
|
|
149
|
-
## [4.0.1](https://github.com/stalniy/casl/compare/@casl/angular@4.0.0...@casl/angular@4.0.1) (2020-04-09)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
### Bug Fixes
|
|
153
|
-
|
|
154
|
-
* **angular:** adds support for casl/ability@4 in package.json ([9d65071](https://github.com/stalniy/casl/commit/9d65071fb2cd14bfef34e2cff8f7e79c9d595bdb))
|
|
155
|
-
|
|
156
|
-
# [4.0.0](https://github.com/stalniy/casl/compare/@casl/angular@3.0.6...@casl/angular@4.0.0) (2020-04-09)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
### Features
|
|
160
|
-
|
|
161
|
-
* **ability:** improves typing for `GetSubjectName` and adds default values for generics ([c089293](https://github.com/stalniy/casl/commit/c08929301a1b06880c054cbb2f21cda3725028a4)), closes [#256](https://github.com/stalniy/casl/issues/256)
|
|
162
|
-
* **angular:** adds generics to `CanPipe` ([68bd287](https://github.com/stalniy/casl/commit/68bd287e7af165b82bbf8076ea88e83b51754a31)), closes [#256](https://github.com/stalniy/casl/issues/256)
|
|
163
|
-
* **angular:** adds support for action only checks ([0462edb](https://github.com/stalniy/casl/commit/0462edb854ba4094e735287744404ea2d378defb)), closes [#107](https://github.com/stalniy/casl/issues/107)
|
|
164
|
-
* **angular:** allows to use custom `Ability` instances and improves tree shaking support ([2e7a149](https://github.com/stalniy/casl/commit/2e7a1498c27d0c542e9f6507ba9b5195ae3a1da8)), closes [#249](https://github.com/stalniy/casl/issues/249)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
### BREAKING CHANGES
|
|
168
|
-
|
|
169
|
-
* **angular:** the module doesn't provide `Ability` instance anymore thus it doesn't need `forRoot` static method anymore
|
|
170
|
-
|
|
171
|
-
Before
|
|
172
|
-
|
|
173
|
-
```js
|
|
174
|
-
import { NgModule } from '@angular/core';
|
|
175
|
-
import { AbilityModule } from '@casl/angular';
|
|
176
|
-
|
|
177
|
-
@NgModule({
|
|
178
|
-
imports: [
|
|
179
|
-
// other modules
|
|
180
|
-
AbilityModule.forRoot()
|
|
181
|
-
],
|
|
182
|
-
// other properties
|
|
183
|
-
})
|
|
184
|
-
export class AppModule {}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
After
|
|
188
|
-
|
|
189
|
-
```js
|
|
190
|
-
import { NgModule } from '@angular/core';
|
|
191
|
-
import { AbilityModule } from '@casl/angular';
|
|
192
|
-
import { Ability, PureAbility } from '@casl/ability';
|
|
193
|
-
|
|
194
|
-
@NgModule({
|
|
195
|
-
imports: [
|
|
196
|
-
// other modules
|
|
197
|
-
AbilityModule
|
|
198
|
-
],
|
|
199
|
-
providers: [
|
|
200
|
-
{ provide: Ability, useValue: new Ability() },
|
|
201
|
-
{ provide: PureAbility, useExisting: Ability }
|
|
202
|
-
]
|
|
203
|
-
// other properties
|
|
204
|
-
})
|
|
205
|
-
export class AppModule {}
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
See docs of `@casl/angular` for details
|
|
209
|
-
|
|
210
|
-
* **pipe:** `CanPipe` is deprecated in favor of `AblePipe`
|
|
211
|
-
|
|
212
|
-
Before
|
|
213
|
-
|
|
214
|
-
```html
|
|
215
|
-
<div *ngIf="'Post' | can: 'read'">hidden content</div>
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
After
|
|
219
|
-
|
|
220
|
-
```html
|
|
221
|
-
<div *ngIf="'read' | able: 'Post'">hidden content</div>
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
## [3.0.6](https://github.com/stalniy/casl/compare/@casl/angular@3.0.5...@casl/angular@3.0.6) (2020-03-06)
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
### Bug Fixes
|
|
228
|
-
|
|
229
|
-
* **angular:** reverts back anngular to not use Ivy as it was not recommend by angular team ([b883118](https://github.com/stalniy/casl/commit/b8831184f4bbfc3924e95f1fd4f2861d88b43fdf)), closes [#270](https://github.com/stalniy/casl/issues/270)
|
|
230
|
-
|
|
231
|
-
## [3.0.5](https://github.com/stalniy/casl/compare/@casl/angular@3.0.4...@casl/angular@3.0.5) (2020-02-21)
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
### Bug Fixes
|
|
235
|
-
|
|
236
|
-
* **angular:** moves postinstall hook to postbootstrap hook which links modules ([769e099](https://github.com/stalniy/casl/commit/769e099902eca821e17d4f6a3e5a44fd29191915)), closes [#266](https://github.com/stalniy/casl/issues/266)
|
|
237
|
-
|
|
238
|
-
## [3.0.4](https://github.com/stalniy/casl/compare/@casl/angular@3.0.3...@casl/angular@3.0.4) (2020-02-21)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
### Bug Fixes
|
|
242
|
-
|
|
243
|
-
* **angular:** adds postinstall script into npm package ([c753d44](https://github.com/stalniy/casl/commit/c753d446532a994766860631939f8000b69f06ae)), closes [#266](https://github.com/stalniy/casl/issues/266)
|
|
244
|
-
|
|
245
|
-
## [3.0.3](https://github.com/stalniy/casl/compare/@casl/angular@3.0.2...@casl/angular@3.0.3) (2020-02-21)
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
### Bug Fixes
|
|
249
|
-
|
|
250
|
-
* **angular:** reverts back prerelease hook ([1fc60c2](https://github.com/stalniy/casl/commit/1fc60c248d7e837fae39eb760cb308a73959b59d)), closes [#266](https://github.com/stalniy/casl/issues/266)
|
|
251
|
-
|
|
252
|
-
## [3.0.2](https://github.com/stalniy/casl/compare/@casl/angular@3.0.1...@casl/angular@3.0.2) (2020-02-20)
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
### Bug Fixes
|
|
256
|
-
|
|
257
|
-
* **angular:** adds missing file exists utility ([732e253](https://github.com/stalniy/casl/commit/732e253f65801631a3128fc92e2514bdb6f79987)), closes [#266](https://github.com/stalniy/casl/issues/266)
|
|
258
|
-
|
|
259
|
-
## [3.0.1](https://github.com/stalniy/casl/compare/@casl/angular@3.0.0...@casl/angular@3.0.1) (2020-02-20)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
### Bug Fixes
|
|
263
|
-
|
|
264
|
-
* **angular:** ensures postinstall script uses node to check whether file exists ([eba8ef4](https://github.com/stalniy/casl/commit/eba8ef460dec655783204819fbb0e0721c34db13))
|
|
265
|
-
|
|
266
|
-
# [3.0.0](https://github.com/stalniy/casl/compare/@casl/angular@2.2.0...@casl/angular@3.0.0) (2020-02-17)
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
### Bug Fixes
|
|
270
|
-
|
|
271
|
-
* **angular:** ensure postinstall hook is executed only during local dev ([a47bac8](https://github.com/stalniy/casl/commit/a47bac8f60c544b90be476ae73a17e0ddfdc479c))
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
### BREAKING CHANGES
|
|
275
|
-
|
|
276
|
-
* **angular:** upgrades angular to v9
|
|
277
|
-
|
|
278
|
-
# [2.2.0](https://github.com/stalniy/casl/compare/@casl/angular@2.1.1...@casl/angular@2.2.0) (2020-02-17)
|
|
279
|
-
|
|
280
|
-
**Deprecated because of invalid package.json peerDependencies and postinstall hook**
|
|
281
|
-
|
|
282
|
-
### Features
|
|
283
|
-
|
|
284
|
-
* **angular:** upgrades angular to v9 ([#260](https://github.com/stalniy/casl/issues/260)) ([3452636](https://github.com/stalniy/casl/commit/34526360ddd3c03605127223823c3beadc6fff84)), closes [#265](https://github.com/stalniy/casl/issues/265)
|
|
285
|
-
|
|
286
|
-
# [@casl/angular-v2.1.1](https://github.com/stalniy/casl/compare/@casl/angular@2.1.0...@casl/angular@2.1.1) (2019-12-09)
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
### Performance Improvements
|
|
290
|
-
|
|
291
|
-
* **angular:** makes casl-angular much smaller by utilizing tslib.es6 ([093cefa](https://github.com/stalniy/casl/commit/093cefa2e26aa4b2cd9e733b0e77aaff1664dbcf))
|
|
292
|
-
|
|
293
|
-
# [@casl/angular-v2.1.0](https://github.com/stalniy/casl/compare/@casl/angular@2.0.0...@casl/angular@2.1.0) (2019-07-01)
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
### Features
|
|
297
|
-
|
|
298
|
-
* **angular:** upgrades Angular and typescript ([08591f4](https://github.com/stalniy/casl/commit/08591f4)), closes [#158](https://github.com/stalniy/casl/issues/158) [#195](https://github.com/stalniy/casl/issues/195)
|
|
299
|
-
|
|
300
|
-
# [@casl/angular-v2.0.0](https://github.com/stalniy/casl/compare/@casl/angular@1.0.0...@casl/angular@2.0.0) (2019-02-10)
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
### Bug Fixes
|
|
304
|
-
|
|
305
|
-
* **packages:** increases peerDependency of [@casl](https://github.com/casl)/ability ([9f6a7b8](https://github.com/stalniy/casl/commit/9f6a7b8)), closes [#119](https://github.com/stalniy/casl/issues/119)
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
### Features
|
|
309
|
-
|
|
310
|
-
* **ability:** adds support for `manage` action ([d9ab56c](https://github.com/stalniy/casl/commit/d9ab56c)), closes [#119](https://github.com/stalniy/casl/issues/119)
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
### BREAKING CHANGES
|
|
314
|
-
|
|
315
|
-
* **ability:** `manage` is not anymore an alias for CRUD but represents any action.
|
|
316
|
-
|
|
317
|
-
Let's consider the next example:
|
|
318
|
-
|
|
319
|
-
```js
|
|
320
|
-
const ability = AbilityBuilder.define((can) => {
|
|
321
|
-
can('manage', 'Post')
|
|
322
|
-
can('read', 'User')
|
|
323
|
-
})
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
In @casl/ability@2.x the definition above produces the next results:
|
|
327
|
-
|
|
328
|
-
```js
|
|
329
|
-
ability.can('read', 'Post') // true
|
|
330
|
-
ability.can('publish', 'Post') // false, because `manage` is an alias for CRUD
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
In @casl/ability@3.x the results:
|
|
334
|
-
|
|
335
|
-
```js
|
|
336
|
-
ability.can('read', 'Post') // true
|
|
337
|
-
ability.can('publish', 'Post') // true, because `manage` represents any action
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
To migrate the code, just replace `manage` with `crud` and everything will work as previously.
|
|
341
|
-
|
|
342
|
-
# [@casl/angular-v1.0.0](https://github.com/stalniy/casl/compare/@casl/angular@0.4.1...@casl/angular@1.0.0) (2018-12-02)
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
### Bug Fixes
|
|
346
|
-
|
|
347
|
-
* **angular:** adds possibility to use angular module in lazy loaded routes ([0c7c3c1](https://github.com/stalniy/casl/commit/0c7c3c1))
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
### BREAKING CHANGES
|
|
351
|
-
|
|
352
|
-
* **angular:** Fixes #131
|
|
353
|
-
|
|
354
|
-
# [@casl/angular-v0.4.1](https://github.com/stalniy/casl/compare/@casl/angular@0.4.0...@casl/angular@0.4.1) (2018-11-11)
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
### Bug Fixes
|
|
358
|
-
|
|
359
|
-
* **angular:** makes `field` to be optional argument ([a3eec63](https://github.com/stalniy/casl/commit/a3eec63)), closes [#126](https://github.com/stalniy/casl/issues/126)
|
|
360
|
-
|
|
361
|
-
# [@casl/angular-v0.4.0](https://github.com/stalniy/casl/compare/@casl/angular@0.3.1...@casl/angular@0.4.0) (2018-11-11)
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
### Bug Fixes
|
|
365
|
-
|
|
366
|
-
* **angular:** converts source to typescript ([565936d](https://github.com/stalniy/casl/commit/565936d)), closes [#126](https://github.com/stalniy/casl/issues/126)
|
|
367
|
-
* **README:** changes links to [@casl](https://github.com/casl)/ability to point to npm package instead to git root [skip ci] ([a74086b](https://github.com/stalniy/casl/commit/a74086b)), closes [#102](https://github.com/stalniy/casl/issues/102)
|
|
368
|
-
* **semantic-release:** test ([cab3f4b](https://github.com/stalniy/casl/commit/cab3f4b)), closes [#94](https://github.com/stalniy/casl/issues/94)
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
### Features
|
|
372
|
-
|
|
373
|
-
* **react:can:** updates typescript declarations ([213dcde](https://github.com/stalniy/casl/commit/213dcde))
|
|
374
|
-
|
|
375
|
-
<a name="@casl/angular-v0.3.1"></a>
|
|
376
|
-
# [@casl/angular-v0.3.1](https://github.com/stalniy/casl/compare/@casl/angular@0.3.0...@casl/angular@0.3.1) (2018-07-02)
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
### Bug Fixes
|
|
380
|
-
|
|
381
|
-
* **package:** changes location of ES5M modules ([2b1ad4e](https://github.com/stalniy/casl/commit/2b1ad4e)), closes [#89](https://github.com/stalniy/casl/issues/89)
|
|
382
|
-
|
|
383
|
-
<a name="0.3.0"></a>
|
|
384
|
-
# 0.3.0 (2018-05-14)
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
### Features
|
|
388
|
-
|
|
389
|
-
* **angular:** supports per field abilities ([8268bb4](https://github.com/stalniy/casl/commit/8268bb4))
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
<a name="0.2.0"></a>
|
|
394
|
-
# 0.2.0 (2018-04-26)
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
### Features
|
|
398
|
-
|
|
399
|
-
* **angular:** adds typings ([98644ba](https://github.com/stalniy/casl/commit/98644ba)), closes [#38](https://github.com/stalniy/casl/issues/38)
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
<a name="0.1.0"></a>
|
|
403
|
-
# 0.1.0 (2018-03-23)
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
### Features
|
|
407
|
-
|
|
408
|
-
* **angular:** adds angular integration and tests, closes [#24](https://github.com/stalniy/casl/issues/24)
|
package/dist/es6m/index.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Pipe, Inject, ChangeDetectorRef, NgModule } from '@angular/core';
|
|
2
|
-
import { PureAbility } from '@casl/ability';
|
|
3
|
-
import { Observable } from 'rxjs';
|
|
4
|
-
|
|
5
|
-
class AbilityPipe {
|
|
6
|
-
constructor(ability, cd) {
|
|
7
|
-
this._ability = ability;
|
|
8
|
-
this._cd = cd;
|
|
9
|
-
}
|
|
10
|
-
transform(...args) {
|
|
11
|
-
if (!this._unsubscribeFromAbility) {
|
|
12
|
-
this._unsubscribeFromAbility = this._ability.on('updated', () => this._cd.markForCheck());
|
|
13
|
-
}
|
|
14
|
-
return this._ability.can(...args);
|
|
15
|
-
}
|
|
16
|
-
ngOnDestroy() {
|
|
17
|
-
if (this._unsubscribeFromAbility) {
|
|
18
|
-
this._unsubscribeFromAbility();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
class CanPipe {
|
|
23
|
-
constructor(ability, cd) {
|
|
24
|
-
this.pipe = new AbilityPipe(ability, cd);
|
|
25
|
-
}
|
|
26
|
-
transform(subject, action, field) {
|
|
27
|
-
return this.pipe.transform(action, subject, field);
|
|
28
|
-
}
|
|
29
|
-
ngOnDestroy() {
|
|
30
|
-
this.pipe.ngOnDestroy();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
CanPipe.decorators = [
|
|
34
|
-
{ type: Pipe, args: [{ name: 'can', pure: false },] }
|
|
35
|
-
];
|
|
36
|
-
CanPipe.ctorParameters = () => [
|
|
37
|
-
{ type: undefined, decorators: [{ type: Inject, args: [PureAbility,] }] },
|
|
38
|
-
{ type: ChangeDetectorRef }
|
|
39
|
-
];
|
|
40
|
-
class AblePipe {
|
|
41
|
-
constructor(ability, cd) {
|
|
42
|
-
this.pipe = new AbilityPipe(ability, cd);
|
|
43
|
-
}
|
|
44
|
-
transform(...args) {
|
|
45
|
-
return this.pipe.transform(...args);
|
|
46
|
-
}
|
|
47
|
-
ngOnDestroy() {
|
|
48
|
-
this.pipe.ngOnDestroy();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
AblePipe.decorators = [
|
|
52
|
-
{ type: Pipe, args: [{ name: 'able', pure: false },] }
|
|
53
|
-
];
|
|
54
|
-
AblePipe.ctorParameters = () => [
|
|
55
|
-
{ type: undefined, decorators: [{ type: Inject, args: [PureAbility,] }] },
|
|
56
|
-
{ type: ChangeDetectorRef }
|
|
57
|
-
];
|
|
58
|
-
class AblePurePipe {
|
|
59
|
-
constructor(ability) {
|
|
60
|
-
this._ability = ability;
|
|
61
|
-
}
|
|
62
|
-
// TODO: `Observable` can be removed after https://github.com/angular/angular/issues/15041
|
|
63
|
-
transform(...args) {
|
|
64
|
-
return new Observable((s) => {
|
|
65
|
-
const emit = () => s.next(this._ability.can(...args));
|
|
66
|
-
emit();
|
|
67
|
-
return this._ability.on('updated', emit);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
AblePurePipe.decorators = [
|
|
72
|
-
{ type: Pipe, args: [{ name: 'ablePure' },] }
|
|
73
|
-
];
|
|
74
|
-
AblePurePipe.ctorParameters = () => [
|
|
75
|
-
{ type: undefined, decorators: [{ type: Inject, args: [PureAbility,] }] }
|
|
76
|
-
];
|
|
77
|
-
|
|
78
|
-
class AbilityModule {
|
|
79
|
-
}
|
|
80
|
-
AbilityModule.decorators = [
|
|
81
|
-
{ type: NgModule, args: [{
|
|
82
|
-
declarations: [
|
|
83
|
-
CanPipe,
|
|
84
|
-
AblePipe,
|
|
85
|
-
AblePurePipe,
|
|
86
|
-
],
|
|
87
|
-
exports: [
|
|
88
|
-
CanPipe,
|
|
89
|
-
AblePipe,
|
|
90
|
-
AblePurePipe,
|
|
91
|
-
],
|
|
92
|
-
},] }
|
|
93
|
-
];
|
|
94
|
-
|
|
95
|
-
export { AbilityModule, AblePipe, AblePurePipe, CanPipe };
|
|
96
|
-
//# sourceMappingURL=index.js.map
|
package/dist/es6m/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/pipes.ts","../../src/AbilityModule.ts"],"sourcesContent":["import { Pipe, ChangeDetectorRef, Inject, PipeTransform } from '@angular/core';\nimport { PureAbility, Unsubscribe, AnyAbility } from '@casl/ability';\nimport { Observable } from 'rxjs';\n\nclass AbilityPipe<T extends AnyAbility> {\n protected _unsubscribeFromAbility?: Unsubscribe;\n private _ability: T;\n private _cd: ChangeDetectorRef;\n\n constructor(ability: T, cd: ChangeDetectorRef) {\n this._ability = ability;\n this._cd = cd;\n }\n\n transform(...args: Parameters<T['can']>): boolean {\n if (!this._unsubscribeFromAbility) {\n this._unsubscribeFromAbility = this._ability.on('updated', () => this._cd.markForCheck());\n }\n return this._ability.can(...args);\n }\n\n ngOnDestroy() {\n if (this._unsubscribeFromAbility) {\n this._unsubscribeFromAbility();\n }\n }\n}\n\n@Pipe({ name: 'can', pure: false })\nexport class CanPipe<T extends AnyAbility> implements PipeTransform {\n protected pipe: AbilityPipe<T>;\n\n constructor(@Inject(PureAbility) ability: T, cd: ChangeDetectorRef) {\n this.pipe = new AbilityPipe(ability, cd);\n }\n\n transform(\n subject: Parameters<T['can']>[1],\n action: Parameters<T['can']>[0],\n field?: string\n ): boolean {\n return (this.pipe as any).transform(action, subject, field);\n }\n\n ngOnDestroy() {\n this.pipe.ngOnDestroy();\n }\n}\n\n@Pipe({ name: 'able', pure: false })\nexport class AblePipe<T extends AnyAbility> implements PipeTransform {\n protected pipe: AbilityPipe<T>;\n\n constructor(@Inject(PureAbility) ability: T, cd: ChangeDetectorRef) {\n this.pipe = new AbilityPipe(ability, cd);\n }\n\n transform(...args: Parameters<T['can']>): boolean {\n return this.pipe.transform(...args);\n }\n\n ngOnDestroy() {\n this.pipe.ngOnDestroy();\n }\n}\n\n@Pipe({ name: 'ablePure' })\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 // TODO: `Observable` can be removed after https://github.com/angular/angular/issues/15041\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 { NgModule } from '@angular/core';\nimport { CanPipe, AblePipe, AblePurePipe } from './pipes';\n\n@NgModule({\n declarations: [\n CanPipe,\n AblePipe,\n AblePurePipe,\n ],\n exports: [\n CanPipe,\n AblePipe,\n AblePurePipe,\n ],\n})\nexport class AbilityModule {\n}\n"],"names":[],"mappings":";;;;AAIA,MAAM,WAAW;IAKf,YAAY,OAAU,EAAE,EAAqB;QAC3C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;KACf;IAED,SAAS,CAAC,GAAG,IAA0B;QACrC,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE;YACjC,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC;SAC3F;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;KACnC;IAED,WAAW;QACT,IAAI,IAAI,CAAC,uBAAuB,EAAE;YAChC,IAAI,CAAC,uBAAuB,EAAE,CAAC;SAChC;KACF;CACF;MAGY,OAAO;IAGlB,YAAiC,OAAU,EAAE,EAAqB;QAChE,IAAI,CAAC,IAAI,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;KAC1C;IAED,SAAS,CACP,OAAgC,EAChC,MAA+B,EAC/B,KAAc;QAEd,OAAQ,IAAI,CAAC,IAAY,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;KAC7D;IAED,WAAW;QACT,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;KACzB;;;YAlBF,IAAI,SAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE;;;4CAInB,MAAM,SAAC,WAAW;YAhClB,iBAAiB;;MAkDnB,QAAQ;IAGnB,YAAiC,OAAU,EAAE,EAAqB;QAChE,IAAI,CAAC,IAAI,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;KAC1C;IAED,SAAS,CAAC,GAAG,IAA0B;QACrC,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC;KACrC;IAED,WAAW;QACT,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;KACzB;;;YAdF,IAAI,SAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE;;;4CAIpB,MAAM,SAAC,WAAW;YArDlB,iBAAiB;;MAmEnB,YAAY;IAGvB,YAAiC,OAAU;QACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;KACzB;;IAGD,SAAS,CAAC,GAAG,IAA0B;QACrC,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC;YACtB,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;YACtD,IAAI,EAAE,CAAC;YACP,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;SAC1C,CAAC,CAAC;KACJ;;;YAfF,IAAI,SAAC,EAAE,IAAI,EAAE,UAAU,EAAE;;;4CAIX,MAAM,SAAC,WAAW;;;MCvDpB,aAAa;;;YAZzB,QAAQ,SAAC;gBACR,YAAY,EAAE;oBACZ,OAAO;oBACP,QAAQ;oBACR,YAAY;iBACb;gBACD,OAAO,EAAE;oBACP,OAAO;oBACP,QAAQ;oBACR,YAAY;iBACb;aACF;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"__symbolic":"module","version":4,"metadata":{"CanPipe":{"__symbolic":"class","arity":1,"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Pipe","line":28,"character":1},"arguments":[{"name":"can","pure":false}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":32,"character":15},"arguments":[{"__symbolic":"reference","module":"@casl/ability","name":"PureAbility","line":32,"character":22}]}],null],"parameters":[{"__symbolic":"error","message":"Could not resolve type","line":32,"character":44,"context":{"typeName":"T"},"module":"./pipes"},{"__symbolic":"reference","module":"@angular/core","name":"ChangeDetectorRef","line":32,"character":51}]}],"transform":[{"__symbolic":"method"}],"ngOnDestroy":[{"__symbolic":"method"}]}},"AblePipe":{"__symbolic":"class","arity":1,"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Pipe","line":49,"character":1},"arguments":[{"name":"able","pure":false}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":53,"character":15},"arguments":[{"__symbolic":"reference","module":"@casl/ability","name":"PureAbility","line":53,"character":22}]}],null],"parameters":[{"__symbolic":"error","message":"Could not resolve type","line":53,"character":44,"context":{"typeName":"T"},"module":"./pipes"},{"__symbolic":"reference","module":"@angular/core","name":"ChangeDetectorRef","line":32,"character":51}]}],"transform":[{"__symbolic":"method"}],"ngOnDestroy":[{"__symbolic":"method"}]}},"AblePurePipe":{"__symbolic":"class","arity":1,"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Pipe","line":66,"character":1},"arguments":[{"name":"ablePure"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":70,"character":15},"arguments":[{"__symbolic":"reference","module":"@casl/ability","name":"PureAbility","line":70,"character":22}]}]],"parameters":[{"__symbolic":"error","message":"Could not resolve type","line":70,"character":44,"context":{"typeName":"T"},"module":"./pipes"}]}],"transform":[{"__symbolic":"method"}]}},"AbilityModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":3,"character":1},"arguments":[{"declarations":[{"__symbolic":"reference","name":"CanPipe"},{"__symbolic":"reference","name":"AblePipe"},{"__symbolic":"reference","name":"AblePurePipe"}],"exports":[{"__symbolic":"reference","name":"CanPipe"},{"__symbolic":"reference","name":"AblePipe"},{"__symbolic":"reference","name":"AblePurePipe"}]}]}],"members":{}}},"origins":{"CanPipe":"./pipes","AblePipe":"./pipes","AblePurePipe":"./pipes","AbilityModule":"./AbilityModule"},"importAs":"@casl/angular"}
|