@casl/angular 5.1.0 → 6.0.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/CHANGELOG.md +37 -0
- 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 +21 -47
- package/dist/es6m/index.js +0 -96
- package/dist/es6m/index.js.map +0 -1
- package/dist/types/index.metadata.json +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,43 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
# [6.0.0](https://github.com/stalniy/casl/compare/@casl/angular@5.1.2...@casl/angular@6.0.0) (2021-05-31)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Code Refactoring
|
|
9
|
+
|
|
10
|
+
* **angular:** removes deprecated CanPipe and stick to Ivy compiler ([82b61f5](https://github.com/stalniy/casl/commit/82b61f5e46dc3c031aef42ae499eca25f2698fdb))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### BREAKING CHANGES
|
|
14
|
+
|
|
15
|
+
* **angular:** there are few important changes:
|
|
16
|
+
|
|
17
|
+
* deprecated `CanPipe` was removed, use `AblePipe` instead
|
|
18
|
+
* library is compiled by Ivy and no longer support ViewEngine
|
|
19
|
+
|
|
20
|
+
## [5.1.2](https://github.com/stalniy/casl/compare/@casl/angular@5.1.1...@casl/angular@5.1.2) (2021-05-31)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### chore
|
|
24
|
+
|
|
25
|
+
* **deps:** updates angular to v12 ([#516](https://github.com/stalniy/casl/issues/516)) ([ff4212c](https://github.com/stalniy/casl/commit/ff4212c7f32f1fbc8a73e6b3a6615af65991e39a)), closes [#514](https://github.com/stalniy/casl/issues/514) [#512](https://github.com/stalniy/casl/issues/512)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### BREAKING CHANGES
|
|
29
|
+
|
|
30
|
+
* **deps:** there are 2 important changes:
|
|
31
|
+
|
|
32
|
+
* deprecated CanPipe was removed, use AblePipe instead
|
|
33
|
+
* library is compiled by Ivy and no longer support ViewEngine
|
|
34
|
+
|
|
35
|
+
## [5.1.1](https://github.com/stalniy/casl/compare/@casl/angular@5.1.0...@casl/angular@5.1.1) (2021-05-12)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Bug Fixes
|
|
39
|
+
|
|
40
|
+
* adjusts package tags to improve discoverability ([73e88b0](https://github.com/stalniy/casl/commit/73e88b0a256625b193b2cd9dc4a219f2e1193cbc))
|
|
41
|
+
|
|
5
42
|
# [5.1.0](https://github.com/stalniy/casl/compare/@casl/angular@5.0.2...@casl/angular@5.1.0) (2021-01-14)
|
|
6
43
|
|
|
7
44
|
|
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,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@casl/angular",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.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",
|
|
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
|
},
|
|
@@ -26,70 +26,44 @@
|
|
|
26
26
|
"build.es5m": "TARGET=es5 BUILD=es5m npm run rollup",
|
|
27
27
|
"build.es6": "TARGET=es2015 BUILD=es6m npm run rollup",
|
|
28
28
|
"build.umd": "TARGET=es5 BUILD=umd npm run rollup",
|
|
29
|
-
"build.types": "ngc -p tsconfig.types.json",
|
|
29
|
+
"build.types": "ngc -p tsconfig.types.json && rm -rf dist/types/*.js",
|
|
30
30
|
"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
|
|
31
|
+
"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
32
|
"postrollup": "rm -rf dist/$BUILD/tmp",
|
|
33
|
-
"test": "
|
|
34
|
-
"lint": "eslint
|
|
33
|
+
"test": "dx jest --config ./jest.config.js",
|
|
34
|
+
"lint": "dx eslint src/ spec/",
|
|
35
35
|
"prerelease": "npm run lint && NODE_ENV=production npm run build && npm test",
|
|
36
|
-
"release": "
|
|
36
|
+
"release": "dx semantic-release"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|
|
39
39
|
"casl",
|
|
40
40
|
"angular",
|
|
41
|
-
"access control",
|
|
42
41
|
"authorization",
|
|
43
42
|
"acl",
|
|
44
|
-
"cancan",
|
|
45
|
-
"security",
|
|
46
43
|
"permissions"
|
|
47
44
|
],
|
|
48
45
|
"author": "Sergii Stotskyi <sergiy.stotskiy@gmail.com>",
|
|
49
46
|
"license": "MIT",
|
|
50
47
|
"peerDependencies": {
|
|
51
|
-
"@angular/core": "^
|
|
48
|
+
"@angular/core": "^12.0.0",
|
|
52
49
|
"@casl/ability": "^3.0.0 || ^4.0.0 || ^5.1.0",
|
|
53
|
-
"rxjs": "^6.
|
|
50
|
+
"rxjs": "^6.5.3",
|
|
54
51
|
"tslib": "^2.0.0"
|
|
55
52
|
},
|
|
56
53
|
"devDependencies": {
|
|
57
|
-
"@abraham/reflection": "^0.
|
|
58
|
-
"@angular/common": "^
|
|
59
|
-
"@angular/compiler": "^
|
|
60
|
-
"@angular/compiler-cli": "^
|
|
61
|
-
"@angular/core": "^
|
|
62
|
-
"@angular/platform-browser": "^
|
|
63
|
-
"@angular/platform-browser-dynamic": "^
|
|
64
|
-
"@babel/core": "^7.8.4",
|
|
65
|
-
"@babel/plugin-proposal-class-properties": "^7.8.3",
|
|
66
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.10.0",
|
|
67
|
-
"@babel/plugin-transform-typescript": "^7.10.0",
|
|
68
|
-
"@babel/preset-env": "^7.8.4",
|
|
54
|
+
"@abraham/reflection": "^0.8.0",
|
|
55
|
+
"@angular/common": "^12.0.0",
|
|
56
|
+
"@angular/compiler": "^12.0.0",
|
|
57
|
+
"@angular/compiler-cli": "^12.0.0",
|
|
58
|
+
"@angular/core": "^12.0.0",
|
|
59
|
+
"@angular/platform-browser": "^12.0.0",
|
|
60
|
+
"@angular/platform-browser-dynamic": "^12.0.0",
|
|
69
61
|
"@casl/ability": "^5.1.0",
|
|
70
|
-
"@
|
|
71
|
-
"
|
|
72
|
-
"@semantic-release/changelog": "^5.0.1",
|
|
73
|
-
"@semantic-release/git": "^9.0.0",
|
|
74
|
-
"@semantic-release/github": "^7.0.7",
|
|
75
|
-
"@semantic-release/npm": "^7.0.5",
|
|
76
|
-
"@typescript-eslint/eslint-plugin": "4.13.0",
|
|
77
|
-
"chai": "^4.1.0",
|
|
78
|
-
"chai-spies": "^1.0.0",
|
|
79
|
-
"eslint": "^7.1.0",
|
|
80
|
-
"eslint-config-airbnb-base": "^14.1.0",
|
|
81
|
-
"eslint-config-airbnb-typescript": "^12.0.0",
|
|
82
|
-
"eslint-plugin-import": "^2.20.2",
|
|
83
|
-
"jest": "^26.0.0",
|
|
84
|
-
"rollup": "^2.10.9",
|
|
85
|
-
"rollup-plugin-sourcemaps": "^0.6.2",
|
|
86
|
-
"rollup-plugin-terser": "^7.0.0",
|
|
87
|
-
"rxjs": "^6.0.0",
|
|
88
|
-
"semantic-release": "17.1.1",
|
|
89
|
-
"ts-jest": "^26.4.4",
|
|
62
|
+
"@casl/dx": "workspace:^1.0.0",
|
|
63
|
+
"rxjs": "^6.5.3",
|
|
90
64
|
"tslib": "^2.0.0",
|
|
91
|
-
"typescript": "~4.
|
|
92
|
-
"zone.js": "
|
|
65
|
+
"typescript": "~4.2.3",
|
|
66
|
+
"zone.js": "~0.11.4"
|
|
93
67
|
},
|
|
94
68
|
"files": [
|
|
95
69
|
"dist",
|
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"}
|