@casl/angular
Advanced tools
Comparing version 8.2.8 to 8.3.0
import * as i0 from '@angular/core'; | ||
import { Pipe, Inject, NgModule, Injectable } from '@angular/core'; | ||
import { Pipe, Inject, Injectable, signal, inject } from '@angular/core'; | ||
import { PureAbility } from '@casl/ability'; | ||
import { Observable } from 'rxjs'; | ||
/** | ||
* @deprecated use AbilityService instead | ||
*/ | ||
var AblePipe = /** @class */ (function () { | ||
@@ -19,3 +22,3 @@ function AblePipe(ability) { | ||
AblePipe.ɵfac = function AblePipe_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AblePipe)(i0.ɵɵdirectiveInject(PureAbility, 16)); }; | ||
AblePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "able", type: AblePipe, pure: false }); | ||
AblePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "able", type: AblePipe, pure: false, standalone: true }); | ||
return AblePipe; | ||
@@ -25,3 +28,3 @@ }()); | ||
type: Pipe, | ||
args: [{ name: 'able', pure: false }] | ||
args: [{ name: 'able', pure: false, standalone: true }] | ||
}], function () { return [{ type: undefined, decorators: [{ | ||
@@ -31,2 +34,5 @@ type: Inject, | ||
}] }]; }, null); })(); | ||
/** | ||
* @deprecated use AbilityService instead | ||
*/ | ||
var AblePurePipe = /** @class */ (function () { | ||
@@ -36,3 +42,2 @@ function AblePurePipe(ability) { | ||
} | ||
// TODO: use computed signals https://github.com/angular/angular/issues/47553 | ||
AblePurePipe.prototype.transform = function () { | ||
@@ -54,3 +59,3 @@ var _this = this; | ||
AblePurePipe.ɵfac = function AblePurePipe_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AblePurePipe)(i0.ɵɵdirectiveInject(PureAbility, 16)); }; | ||
AblePurePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "ablePure", type: AblePurePipe, pure: true }); | ||
AblePurePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "ablePure", type: AblePurePipe, pure: true, standalone: true }); | ||
return AblePurePipe; | ||
@@ -60,3 +65,3 @@ }()); | ||
type: Pipe, | ||
args: [{ name: 'ablePure' }] | ||
args: [{ name: 'ablePure', standalone: true }] | ||
}], function () { return [{ type: undefined, decorators: [{ | ||
@@ -67,30 +72,4 @@ type: Inject, | ||
var AbilityModule = /** @class */ (function () { | ||
function AbilityModule() { | ||
} | ||
AbilityModule.ɵfac = function AbilityModule_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AbilityModule)(); }; | ||
AbilityModule.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: AbilityModule }); | ||
AbilityModule.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({}); | ||
return AbilityModule; | ||
}()); | ||
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AbilityModule, [{ | ||
type: NgModule, | ||
args: [{ | ||
declarations: [ | ||
AblePipe, | ||
AblePurePipe, | ||
], | ||
exports: [ | ||
AblePipe, | ||
AblePurePipe, | ||
], | ||
}] | ||
}], null, null); })(); | ||
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(AbilityModule, { declarations: [AblePipe, | ||
AblePurePipe], exports: [AblePipe, | ||
AblePurePipe] }); })(); | ||
var AbilityService = /** @class */ (function () { | ||
function AbilityService(ability) { | ||
// IGNORE: this comment. it's for release debugging | ||
this.ability$ = new Observable(function (observer) { | ||
@@ -102,7 +81,8 @@ observer.next(ability); | ||
AbilityService.ɵfac = function AbilityService_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AbilityService)(i0.ɵɵinject(PureAbility)); }; | ||
AbilityService.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: AbilityService, factory: AbilityService.ɵfac }); | ||
AbilityService.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: AbilityService, factory: AbilityService.ɵfac, providedIn: 'root' }); | ||
return AbilityService; | ||
}()); | ||
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AbilityService, [{ | ||
type: Injectable | ||
type: Injectable, | ||
args: [{ providedIn: 'root' }] | ||
}], function () { return [{ type: undefined, decorators: [{ | ||
@@ -113,3 +93,43 @@ type: Inject, | ||
export { AbilityModule, AbilityService, AblePipe, AblePurePipe }; | ||
var AbilityServiceSignal = /** @class */ (function () { | ||
function AbilityServiceSignal() { | ||
var _this = this; | ||
this._rules = signal([]); | ||
this._ability = inject(PureAbility); | ||
this.can = function () { | ||
var _a; | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
_this._rules(); // generate side effect for angular to track changes in this signal | ||
return (_a = _this._ability).can.apply(_a, args); | ||
}; | ||
this.cannot = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return !_this.can.apply(_this, args); | ||
}; | ||
this._disposeAbilitySubscription = this._ability.on('updated', function (event) { | ||
_this._rules.set(event.rules); | ||
}); | ||
} | ||
AbilityServiceSignal.prototype.ngOnDestroy = function () { | ||
this._disposeAbilitySubscription(); | ||
}; | ||
AbilityServiceSignal.prototype.update = function (rules) { | ||
this._ability.update(rules); | ||
}; | ||
AbilityServiceSignal.ɵfac = function AbilityServiceSignal_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AbilityServiceSignal)(); }; | ||
AbilityServiceSignal.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: AbilityServiceSignal, factory: AbilityServiceSignal.ɵfac, providedIn: 'root' }); | ||
return AbilityServiceSignal; | ||
}()); | ||
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AbilityServiceSignal, [{ | ||
type: Injectable, | ||
args: [{ providedIn: 'root' }] | ||
}], function () { return []; }, null); })(); | ||
export { AbilityService, AbilityServiceSignal, AblePipe, AblePurePipe }; | ||
//# sourceMappingURL=index.js.map |
@@ -5,2 +5,5 @@ import { PipeTransform } from '@angular/core'; | ||
import * as i0 from "@angular/core"; | ||
/** | ||
* @deprecated use AbilityService instead | ||
*/ | ||
export declare class AblePipe<T extends AnyAbility> implements PipeTransform { | ||
@@ -11,4 +14,7 @@ private _ability; | ||
static ɵfac: i0.ɵɵFactoryDeclaration<AblePipe<any>, never>; | ||
static ɵpipe: i0.ɵɵPipeDeclaration<AblePipe<any>, "able", false>; | ||
static ɵpipe: i0.ɵɵPipeDeclaration<AblePipe<any>, "able", true>; | ||
} | ||
/** | ||
* @deprecated use AbilityService instead | ||
*/ | ||
export declare class AblePurePipe<T extends AnyAbility> implements PipeTransform { | ||
@@ -19,3 +25,3 @@ private _ability; | ||
static ɵfac: i0.ɵɵFactoryDeclaration<AblePurePipe<any>, never>; | ||
static ɵpipe: i0.ɵɵPipeDeclaration<AblePurePipe<any>, "ablePure", false>; | ||
static ɵpipe: i0.ɵɵPipeDeclaration<AblePurePipe<any>, "ablePure", true>; | ||
} |
export * from './pipes'; | ||
export * from './AbilityModule'; | ||
export * from './AbilityService'; | ||
export * from './AbilityServiceSignal'; |
@@ -26,2 +26,5 @@ (function (global, factory) { | ||
/** | ||
* @deprecated use AbilityService instead | ||
*/ | ||
var AblePipe = /** @class */ (function () { | ||
@@ -40,3 +43,3 @@ function AblePipe(ability) { | ||
AblePipe.ɵfac = function AblePipe_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AblePipe)(i0__namespace.ɵɵdirectiveInject(ability.PureAbility, 16)); }; | ||
AblePipe.ɵpipe = /*@__PURE__*/ i0__namespace.ɵɵdefinePipe({ name: "able", type: AblePipe, pure: false }); | ||
AblePipe.ɵpipe = /*@__PURE__*/ i0__namespace.ɵɵdefinePipe({ name: "able", type: AblePipe, pure: false, standalone: true }); | ||
return AblePipe; | ||
@@ -46,3 +49,3 @@ }()); | ||
type: i0.Pipe, | ||
args: [{ name: 'able', pure: false }] | ||
args: [{ name: 'able', pure: false, standalone: true }] | ||
}], function () { return [{ type: undefined, decorators: [{ | ||
@@ -52,2 +55,5 @@ type: i0.Inject, | ||
}] }]; }, null); })(); | ||
/** | ||
* @deprecated use AbilityService instead | ||
*/ | ||
var AblePurePipe = /** @class */ (function () { | ||
@@ -57,3 +63,2 @@ function AblePurePipe(ability) { | ||
} | ||
// TODO: use computed signals https://github.com/angular/angular/issues/47553 | ||
AblePurePipe.prototype.transform = function () { | ||
@@ -75,3 +80,3 @@ var _this = this; | ||
AblePurePipe.ɵfac = function AblePurePipe_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AblePurePipe)(i0__namespace.ɵɵdirectiveInject(ability.PureAbility, 16)); }; | ||
AblePurePipe.ɵpipe = /*@__PURE__*/ i0__namespace.ɵɵdefinePipe({ name: "ablePure", type: AblePurePipe, pure: true }); | ||
AblePurePipe.ɵpipe = /*@__PURE__*/ i0__namespace.ɵɵdefinePipe({ name: "ablePure", type: AblePurePipe, pure: true, standalone: true }); | ||
return AblePurePipe; | ||
@@ -81,3 +86,3 @@ }()); | ||
type: i0.Pipe, | ||
args: [{ name: 'ablePure' }] | ||
args: [{ name: 'ablePure', standalone: true }] | ||
}], function () { return [{ type: undefined, decorators: [{ | ||
@@ -88,30 +93,4 @@ type: i0.Inject, | ||
var AbilityModule = /** @class */ (function () { | ||
function AbilityModule() { | ||
} | ||
AbilityModule.ɵfac = function AbilityModule_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AbilityModule)(); }; | ||
AbilityModule.ɵmod = /*@__PURE__*/ i0__namespace.ɵɵdefineNgModule({ type: AbilityModule }); | ||
AbilityModule.ɵinj = /*@__PURE__*/ i0__namespace.ɵɵdefineInjector({}); | ||
return AbilityModule; | ||
}()); | ||
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(AbilityModule, [{ | ||
type: i0.NgModule, | ||
args: [{ | ||
declarations: [ | ||
AblePipe, | ||
AblePurePipe, | ||
], | ||
exports: [ | ||
AblePipe, | ||
AblePurePipe, | ||
], | ||
}] | ||
}], null, null); })(); | ||
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0__namespace.ɵɵsetNgModuleScope(AbilityModule, { declarations: [AblePipe, | ||
AblePurePipe], exports: [AblePipe, | ||
AblePurePipe] }); })(); | ||
var AbilityService = /** @class */ (function () { | ||
function AbilityService(ability) { | ||
// IGNORE: this comment. it's for release debugging | ||
this.ability$ = new rxjs.Observable(function (observer) { | ||
@@ -123,7 +102,8 @@ observer.next(ability); | ||
AbilityService.ɵfac = function AbilityService_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AbilityService)(i0__namespace.ɵɵinject(ability.PureAbility)); }; | ||
AbilityService.ɵprov = /*@__PURE__*/ i0__namespace.ɵɵdefineInjectable({ token: AbilityService, factory: AbilityService.ɵfac }); | ||
AbilityService.ɵprov = /*@__PURE__*/ i0__namespace.ɵɵdefineInjectable({ token: AbilityService, factory: AbilityService.ɵfac, providedIn: 'root' }); | ||
return AbilityService; | ||
}()); | ||
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(AbilityService, [{ | ||
type: i0.Injectable | ||
type: i0.Injectable, | ||
args: [{ providedIn: 'root' }] | ||
}], function () { return [{ type: undefined, decorators: [{ | ||
@@ -134,4 +114,44 @@ type: i0.Inject, | ||
exports.AbilityModule = AbilityModule; | ||
var AbilityServiceSignal = /** @class */ (function () { | ||
function AbilityServiceSignal() { | ||
var _this = this; | ||
this._rules = i0.signal([]); | ||
this._ability = i0.inject(ability.PureAbility); | ||
this.can = function () { | ||
var _a; | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
_this._rules(); // generate side effect for angular to track changes in this signal | ||
return (_a = _this._ability).can.apply(_a, args); | ||
}; | ||
this.cannot = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return !_this.can.apply(_this, args); | ||
}; | ||
this._disposeAbilitySubscription = this._ability.on('updated', function (event) { | ||
_this._rules.set(event.rules); | ||
}); | ||
} | ||
AbilityServiceSignal.prototype.ngOnDestroy = function () { | ||
this._disposeAbilitySubscription(); | ||
}; | ||
AbilityServiceSignal.prototype.update = function (rules) { | ||
this._ability.update(rules); | ||
}; | ||
AbilityServiceSignal.ɵfac = function AbilityServiceSignal_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AbilityServiceSignal)(); }; | ||
AbilityServiceSignal.ɵprov = /*@__PURE__*/ i0__namespace.ɵɵdefineInjectable({ token: AbilityServiceSignal, factory: AbilityServiceSignal.ɵfac, providedIn: 'root' }); | ||
return AbilityServiceSignal; | ||
}()); | ||
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(AbilityServiceSignal, [{ | ||
type: i0.Injectable, | ||
args: [{ providedIn: 'root' }] | ||
}], function () { return []; }, null); })(); | ||
exports.AbilityService = AbilityService; | ||
exports.AbilityServiceSignal = AbilityServiceSignal; | ||
exports.AblePipe = AblePipe; | ||
@@ -138,0 +158,0 @@ exports.AblePurePipe = AblePurePipe; |
{ | ||
"name": "@casl/angular", | ||
"version": "8.2.8", | ||
"version": "8.3.0", | ||
"description": "Angular module for CASL which makes it easy to add permissions in any Angular app", | ||
@@ -50,4 +50,4 @@ "main": "dist/umd/index.js", | ||
"peerDependencies": { | ||
"@angular/core": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0", | ||
"@casl/ability": "^3.0.0 || ^4.0.0 || ^5.1.0 || ^6.0.0", | ||
"@angular/core": "^16.0.0 || ^17.0.0 || ^18.0.0", | ||
"@casl/ability": "^4.0.0 || ^5.1.0 || ^6.0.0", | ||
"rxjs": "^7.5.5", | ||
@@ -54,0 +54,0 @@ "tslib": "^2.0.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
51429
418
1