@casl/vue 2.2.2 → 2.2.5
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 +32 -30
- package/dist/es5m/index.js +1 -1
- package/dist/es5m/index.js.map +1 -1
- package/dist/es6m/index.mjs +1 -1
- package/dist/es6m/index.mjs.map +1 -1
- package/dist/types/component/can.d.ts +2 -34
- package/dist/types/useAbility.d.ts +2 -2
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -2,32 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/%40casl%2Fvue)
|
|
4
4
|
[](https://www.npmjs.com/package/%40casl%2Fvue)
|
|
5
|
-
[](https://github.com/stalniy/casl/discussions)
|
|
6
6
|
|
|
7
7
|
This package allows to integrate `@casl/ability` with [Vue 3] application. So, you can show or hide UI elements based on user ability to see them.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
-
**For Vue 2.x**:
|
|
12
|
-
|
|
13
11
|
```sh
|
|
14
|
-
npm install @casl/vue
|
|
12
|
+
npm install @casl/vue @casl/ability
|
|
15
13
|
# or
|
|
16
|
-
yarn add @casl/vue
|
|
14
|
+
yarn add @casl/vue @casl/ability
|
|
17
15
|
# or
|
|
18
|
-
pnpm add @casl/vue
|
|
16
|
+
pnpm add @casl/vue @casl/ability
|
|
19
17
|
```
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
<details>
|
|
20
|
+
<summary>For Vue 2.x</summary>
|
|
22
21
|
|
|
23
22
|
```sh
|
|
24
|
-
npm install @casl/vue @casl/ability
|
|
23
|
+
npm install @casl/vue@1.x @casl/ability
|
|
25
24
|
# or
|
|
26
|
-
yarn add @casl/vue @casl/ability
|
|
25
|
+
yarn add @casl/vue@1.x @casl/ability
|
|
27
26
|
# or
|
|
28
|
-
pnpm add @casl/vue @casl/ability
|
|
27
|
+
pnpm add @casl/vue@1.x @casl/ability
|
|
29
28
|
```
|
|
30
29
|
|
|
30
|
+
</details>
|
|
31
|
+
|
|
32
|
+
|
|
31
33
|
## Getting started
|
|
32
34
|
|
|
33
35
|
This package provides a Vue plugin, several hooks for new [Vue Composition API](https://v3.vuejs.org/guide/composition-api-introduction.html) and `Can` component.
|
|
@@ -234,6 +236,17 @@ There are several other property aliases which allow constructing a readable que
|
|
|
234
236
|
|
|
235
237
|
Let's consider PROS and CONS of both solutions in order to make the decision.
|
|
236
238
|
|
|
239
|
+
**Reactive Ability**:
|
|
240
|
+
|
|
241
|
+
**PROS**:
|
|
242
|
+
* easy to use
|
|
243
|
+
* declarative in template with `v-if`
|
|
244
|
+
* easy to pass as a prop to another component
|
|
245
|
+
* easy to use in complex boolean expressions (either in js or in template)
|
|
246
|
+
|
|
247
|
+
**CONS**:
|
|
248
|
+
* more expensive to check, conditions are re-evaluated on each re-render
|
|
249
|
+
|
|
237
250
|
**Can Component**:
|
|
238
251
|
|
|
239
252
|
**PROS**:
|
|
@@ -246,17 +259,6 @@ Let's consider PROS and CONS of both solutions in order to make the decision.
|
|
|
246
259
|
* harder to use in complex boolean expressions
|
|
247
260
|
* harder to pass permission check as a prop to another component
|
|
248
261
|
|
|
249
|
-
**Reactive Ability**:
|
|
250
|
-
|
|
251
|
-
**PROS**:
|
|
252
|
-
* easy to use
|
|
253
|
-
* declarative in template with `v-if`
|
|
254
|
-
* easy to pass as a prop to another component
|
|
255
|
-
* easy to use in complex boolean expressions (either in js or in template)
|
|
256
|
-
|
|
257
|
-
**CONS**:
|
|
258
|
-
* more expensive to check, conditions are re-evaluated on each re-render
|
|
259
|
-
|
|
260
262
|
Despite the fact that reactive ability check is a bit more expensive, they are still very fast and it's recommended to use reactive ability instead of `<Can>` component.
|
|
261
263
|
|
|
262
264
|
## TypeScript support
|
|
@@ -267,13 +269,12 @@ There are few ways to use TypeScript in a Vue app, depending on your preferences
|
|
|
267
269
|
|
|
268
270
|
|
|
269
271
|
```ts @{data-filename="AppAbility.ts"}
|
|
270
|
-
import {
|
|
272
|
+
import { MongoAbility } from '@casl/ability';
|
|
271
273
|
|
|
272
274
|
type Actions = 'create' | 'read' | 'update' | 'delete';
|
|
273
275
|
type Subjects = 'Article' | 'User'
|
|
274
276
|
|
|
275
|
-
export type AppAbility =
|
|
276
|
-
export const AppAbility = Ability as AbilityClass<AppAbility>;
|
|
277
|
+
export type AppAbility = MongoAbility<[Actions, Subjects]>;
|
|
277
278
|
```
|
|
278
279
|
|
|
279
280
|
### Augment Vue types
|
|
@@ -343,13 +344,13 @@ export default defineComponent({
|
|
|
343
344
|
ability: { from: TOKEN }
|
|
344
345
|
},
|
|
345
346
|
created() {
|
|
346
|
-
this.ability // AppAbility
|
|
347
|
+
this.ability // AppAbility instance
|
|
347
348
|
}
|
|
348
349
|
});
|
|
349
350
|
</script>
|
|
350
351
|
```
|
|
351
352
|
|
|
352
|
-
> Read [Vue TypeScript](https://v3.vuejs.org/guide/typescript-support.html) for more details
|
|
353
|
+
> Read [Vue TypeScript](https://v3.vuejs.org/guide/typescript-support.html) for more details
|
|
353
354
|
|
|
354
355
|
## Update Ability instance
|
|
355
356
|
|
|
@@ -367,8 +368,9 @@ Let's imagine that server returns user with a role on login:
|
|
|
367
368
|
</template>
|
|
368
369
|
|
|
369
370
|
<script>
|
|
370
|
-
import { AbilityBuilder,
|
|
371
|
+
import { AbilityBuilder, createMongoAbility } from '@casl/ability';
|
|
371
372
|
import { ABILITY_TOKEN } from '@casl/vue';
|
|
373
|
+
import { AppAbility } from '../ability';
|
|
372
374
|
|
|
373
375
|
export default {
|
|
374
376
|
name: 'LoginForm',
|
|
@@ -389,7 +391,7 @@ export default {
|
|
|
389
391
|
.then(({ user }) => this.updateAbility(user));
|
|
390
392
|
},
|
|
391
393
|
updateAbility(user) {
|
|
392
|
-
const { can, rules } = new AbilityBuilder(
|
|
394
|
+
const { can, rules } = new AbilityBuilder<AppAbility>(createMongoAbility);
|
|
393
395
|
|
|
394
396
|
if (user.role === 'admin') {
|
|
395
397
|
can('manage', 'all');
|
|
@@ -404,7 +406,7 @@ export default {
|
|
|
404
406
|
</script>
|
|
405
407
|
```
|
|
406
408
|
|
|
407
|
-
> See [Define rules](https://casl.js.org/v5/en/guide/define-rules) to get more information of how to define `Ability
|
|
409
|
+
> See [Define rules](https://casl.js.org/v5/en/guide/define-rules) to get more information of how to define `Ability`.
|
|
408
410
|
|
|
409
411
|
## Want to help?
|
|
410
412
|
|
|
@@ -412,7 +414,7 @@ Want to file a bug, contribute some code, or improve documentation? Excellent! R
|
|
|
412
414
|
|
|
413
415
|
If you'd like to help us sustain our community and project, consider [to become a financial contributor on Open Collective](https://opencollective.com/casljs/contribute)
|
|
414
416
|
|
|
415
|
-
> See [Support CASL](https://casl.js.org/v5/en/support-casljs) for details
|
|
417
|
+
> See [Support CASL](https://casl.js.org/v5/en/support-casljs) for details.
|
|
416
418
|
|
|
417
419
|
## License
|
|
418
420
|
|
package/dist/es5m/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ref as i,inject as r,provide as t,defineComponent as n}from"vue";import{PureAbility as e}from"@casl/ability";function reactiveAbility(r){if(Object.hasOwn(r,"possibleRulesFor"))return r;var t=i(true);r.on("updated",
|
|
1
|
+
import{ref as i,inject as r,provide as t,defineComponent as n}from"vue";import{PureAbility as e}from"@casl/ability";function reactiveAbility(r){if(Object.hasOwn(r,"possibleRulesFor"))return r;var t=i(true);r.on("updated",function(){t.value=!t.value});var n=r.possibleRulesFor.bind(r);r.possibleRulesFor=function(i,r){t.value=t.value;return n(i,r)};r.can=r.can.bind(r);r.cannot=r.cannot.bind(r);return r}var o=Symbol("ability");function useAbility(){var i=r(o);if(!i)throw new Error("Cannot inject Ability instance because it was not provided");return i}function provideAbility(i){t(o,reactiveAbility(i))}function a(i){if(i.a!==void 0)return"a";if(i.this!==void 0)return"this";if(i.an!==void 0)return"an";return""}var u=n({name:"Can",props:{I:String,do:String,a:[String,Function],an:[String,Function],this:[String,Function,Object],on:[String,Function,Object],not:Boolean,passThrough:Boolean,field:String},setup:function i(r,t){var n=t.slots;var e=r;var o="do";var u="on";if(e[o]===void 0){o="I";u=a(r)}if(!e[o])throw new Error("Neither `I` nor `do` prop was passed in <Can>");if(!n.default)throw new Error("Expects to receive default slot");var l=useAbility();return function(){var i=l.can(e[o],e[u],e.field);var t=r.not?!i:i;if(!r.passThrough)return t?n.default():null;return n.default({allowed:t,ability:l})}}});function l(i,r,t){if(!r||!(r instanceof e))throw new Error("Please provide an Ability instance to abilitiesPlugin plugin");i.provide(o,reactiveAbility(r));if(t&&t.useGlobalProperties){i.config.globalProperties.$ability=r;i.config.globalProperties.$can=r.can.bind(r)}}export{o as ABILITY_TOKEN,u as Can,l as abilitiesPlugin,provideAbility,useAbility};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/es5m/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/reactiveAbility.ts","../../src/useAbility.ts","../../src/component/can.ts","../../src/plugin.ts"],"sourcesContent":["import { AnyAbility, SubjectType } from '@casl/ability';\nimport { ref } from 'vue';\n\nexport function reactiveAbility(ability: AnyAbility) {\n if (Object.hasOwn(ability, 'possibleRulesFor')) {\n return ability;\n }\n\n const watcher = ref(true);\n ability.on('updated', () => {\n watcher.value = !watcher.value;\n });\n\n const possibleRulesFor = ability.possibleRulesFor.bind(ability);\n ability.possibleRulesFor = (action: string, subject: SubjectType) => {\n watcher.value = watcher.value; // eslint-disable-line\n return possibleRulesFor(action, subject);\n };\n ability.can = ability.can.bind(ability);\n ability.cannot = ability.cannot.bind(ability);\n\n return ability;\n}\n","import {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/reactiveAbility.ts","../../src/useAbility.ts","../../src/component/can.ts","../../src/plugin.ts"],"sourcesContent":["import { AnyAbility, SubjectType } from '@casl/ability';\nimport { ref } from 'vue';\n\nexport function reactiveAbility(ability: AnyAbility) {\n if (Object.hasOwn(ability, 'possibleRulesFor')) {\n return ability;\n }\n\n const watcher = ref(true);\n ability.on('updated', () => {\n watcher.value = !watcher.value;\n });\n\n const possibleRulesFor = ability.possibleRulesFor.bind(ability);\n ability.possibleRulesFor = (action: string, subject: SubjectType) => {\n watcher.value = watcher.value; // eslint-disable-line\n return possibleRulesFor(action, subject);\n };\n ability.can = ability.can.bind(ability);\n ability.cannot = ability.cannot.bind(ability);\n\n return ability;\n}\n","import type { AnyAbility, MongoAbility } from '@casl/ability';\nimport { inject, InjectionKey, provide } from 'vue';\nimport { reactiveAbility } from './reactiveAbility';\n\nexport const ABILITY_TOKEN: InjectionKey<AnyAbility> = Symbol('ability');\n\nexport function useAbility<T extends AnyAbility = MongoAbility>(): T {\n const ability = inject<T>(ABILITY_TOKEN);\n\n if (!ability) {\n throw new Error('Cannot inject Ability instance because it was not provided');\n }\n\n return ability;\n}\n\nexport function provideAbility(ability: AnyAbility) {\n provide(ABILITY_TOKEN, reactiveAbility(ability));\n}\n","import {\n Abilities,\n AbilityTuple,\n AnyAbility,\n Generics,\n IfString,\n MongoAbility,\n SubjectType\n} from '@casl/ability';\nimport { ComponentCustomProperties, defineComponent } from 'vue';\nimport { useAbility } from '../useAbility';\n\ntype AbilityCanProps<\n T extends Abilities,\n Else = IfString<T, { do: T } | { I: T }>\n> = T extends AbilityTuple\n ? { do: T[0], on: T[1], field?: string } |\n { I: T[0], a: Extract<T[1], SubjectType>, field?: string } |\n { I: T[0], an: Extract<T[1], SubjectType>, field?: string } |\n { I: T[0], this: Exclude<T[1], SubjectType>, field?: string }\n : Else;\n\nexport type CanProps<T extends AnyAbility> = AbilityCanProps<Generics<T>['abilities']> & {\n not?: boolean,\n passThrough?: boolean\n};\n\ntype VueAbility = ComponentCustomProperties extends { $ability: AnyAbility }\n ? ComponentCustomProperties['$ability']\n : MongoAbility;\n\nfunction detectSubjectProp(props: Record<string, unknown>) {\n if (props.a !== undefined) {\n return 'a';\n }\n\n if (props.this !== undefined) {\n return 'this';\n }\n\n if (props.an !== undefined) {\n return 'an';\n }\n\n return '';\n}\n\nexport const Can = defineComponent<CanProps<VueAbility>>({\n name: 'Can',\n props: {\n I: String,\n do: String,\n a: [String, Function],\n an: [String, Function],\n this: [String, Function, Object],\n on: [String, Function, Object],\n not: Boolean,\n passThrough: Boolean,\n field: String\n } as any,\n setup(props, { slots }) {\n const $props = props as Record<string, any>;\n let actionProp = 'do';\n let subjectProp = 'on';\n\n if ($props[actionProp] === undefined) {\n actionProp = 'I';\n subjectProp = detectSubjectProp(props);\n }\n\n if (!$props[actionProp]) {\n throw new Error('Neither `I` nor `do` prop was passed in <Can>');\n }\n\n if (!slots.default) {\n throw new Error('Expects to receive default slot');\n }\n\n const ability = useAbility<VueAbility>();\n\n return () => {\n const isAllowed = ability.can($props[actionProp], $props[subjectProp], $props.field);\n const canRender = props.not ? !isAllowed : isAllowed;\n\n if (!props.passThrough) {\n return canRender ? slots.default!() : null;\n }\n\n return slots.default!({\n allowed: canRender,\n ability,\n });\n };\n }\n});\n","import { App } from 'vue';\nimport { AnyAbility, PureAbility } from '@casl/ability';\nimport { ABILITY_TOKEN } from './useAbility';\nimport { reactiveAbility } from './reactiveAbility';\n\nexport interface AbilityPluginOptions {\n useGlobalProperties?: boolean\n}\n\nexport function abilitiesPlugin(app: App, ability: AnyAbility, options?: AbilityPluginOptions) {\n if (!ability || !(ability instanceof PureAbility)) {\n throw new Error('Please provide an Ability instance to abilitiesPlugin plugin');\n }\n\n app.provide(ABILITY_TOKEN, reactiveAbility(ability));\n\n if (options && options.useGlobalProperties) {\n app.config.globalProperties.$ability = ability;\n app.config.globalProperties.$can = ability.can.bind(ability);\n }\n}\n"],"names":["reactiveAbility","ability","Object","hasOwn","watcher","ref","on","value","possibleRulesFor","bind","action","subject","can","cannot","ABILITY_TOKEN","Symbol","useAbility","inject","Error","provideAbility","provide","detectSubjectProp","props","a","undefined","this","an","Can","defineComponent","name","I","String","do","Function","not","Boolean","passThrough","field","setup","_ref","slots","$props","actionProp","subjectProp","default","isAllowed","canRender","allowed","abilitiesPlugin","app","options","PureAbility","useGlobalProperties","config","globalProperties","$ability","$can"],"mappings":"oHAGO,SAASA,gBAAgBC,GAC9B,GAAIC,OAAOC,OAAOF,EAAS,oBACzB,OAAOA,EAGT,IAAMG,EAAUC,EAAI,MACpBJ,EAAQK,GAAG,UAAW,WACpBF,EAAQG,OAASH,EAAQG,KAC3B,GAEA,IAAMC,EAAmBP,EAAQO,iBAAiBC,KAAKR,GACvDA,EAAQO,iBAAmB,SAACE,EAAgBC,GAC1CP,EAAQG,MAAQH,EAAQG,MACxB,OAAOC,EAAiBE,EAAQC,EAClC,EACAV,EAAQW,IAAMX,EAAQW,IAAIH,KAAKR,GAC/BA,EAAQY,OAASZ,EAAQY,OAAOJ,KAAKR,GAErC,OAAOA,CACT,KClBaa,EAA0CC,OAAO,WAEvD,SAASC,aACd,IAAMf,EAAUgB,EAAUH,GAE1B,IAAKb,EACH,MAAM,IAAIiB,MAAM,8DAGlB,OAAOjB,CACT,CAEO,SAASkB,eAAelB,GAC7BmB,EAAQN,EAAed,gBAAgBC,GACzC,CCaA,SAASoB,EAAkBC,GACzB,GAAIA,EAAMC,SAAMC,EACd,MAAO,IAGT,GAAIF,EAAMG,YAASD,EACjB,MAAO,OAGT,GAAIF,EAAMI,UAAOF,EACf,MAAO,KAGT,MAAO,EACT,CAEO,IAAMG,EAAMC,EAAsC,CACvDC,KAAM,MACNP,MAAO,CACLQ,EAAGC,OACHC,GAAID,OACJR,EAAG,CAACQ,OAAQE,UACZP,GAAI,CAACK,OAAQE,UACbR,KAAM,CAACM,OAAQE,SAAU/B,QACzBI,GAAI,CAACyB,OAAQE,SAAU/B,QACvBgC,IAAKC,QACLC,YAAaD,QACbE,MAAON,QAETO,eAAAA,EAAMhB,EAAKiB,GAAa,IAATC,EAAKD,EAALC,MACb,IAAMC,EAASnB,EACf,IAAIoB,EAAa,KACjB,IAAIC,EAAc,KAElB,GAAIF,EAAOC,UAAgBlB,EAAW,CACpCkB,EAAa,IACbC,EAActB,EAAkBC,EAClC,CAEA,IAAKmB,EAAOC,GACV,MAAM,IAAIxB,MAAM,iDAGlB,IAAKsB,EAAMI,QACT,MAAM,IAAI1B,MAAM,mCAGlB,IAAMjB,EAAUe,aAEhB,OAAO,WACL,IAAM6B,EAAY5C,EAAQW,IAAI6B,EAAOC,GAAaD,EAAOE,GAAcF,EAAOJ,OAC9E,IAAMS,EAAYxB,EAAMY,KAAOW,EAAYA,EAE3C,IAAKvB,EAAMc,YACT,OAAOU,EAAYN,EAAMI,UAAa,KAGxC,OAAOJ,EAAMI,QAAS,CACpBG,QAASD,EACT7C,QAAAA,GAEJ,CACF,ICpFK,SAAS+C,EAAgBC,EAAUhD,EAAqBiD,GAC7D,IAAKjD,KAAaA,aAAmBkD,GACnC,MAAM,IAAIjC,MAAM,gEAGlB+B,EAAI7B,QAAQN,EAAed,gBAAgBC,IAE3C,GAAIiD,GAAWA,EAAQE,oBAAqB,CAC1CH,EAAII,OAAOC,iBAAiBC,SAAWtD,EACvCgD,EAAII,OAAOC,iBAAiBE,KAAOvD,EAAQW,IAAIH,KAAKR,EACtD,CACF"}
|
package/dist/es6m/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ref as t,inject as i,provide as n,defineComponent as r}from"vue";import{PureAbility as o}from"@casl/ability";function reactiveAbility(i){if(Object.hasOwn(i,"possibleRulesFor"))return i;const n=t(true);i.on("updated",(
|
|
1
|
+
import{ref as t,inject as i,provide as n,defineComponent as r}from"vue";import{PureAbility as o}from"@casl/ability";function reactiveAbility(i){if(Object.hasOwn(i,"possibleRulesFor"))return i;const n=t(true);i.on("updated",()=>{n.value=!n.value});const r=i.possibleRulesFor.bind(i);i.possibleRulesFor=(t,i)=>{n.value=n.value;return r(t,i)};i.can=i.can.bind(i);i.cannot=i.cannot.bind(i);return i}const e=Symbol("ability");function useAbility(){const t=i(e);if(!t)throw new Error("Cannot inject Ability instance because it was not provided");return t}function provideAbility(t){n(e,reactiveAbility(t))}function s(t){if(t.a!==void 0)return"a";if(t.this!==void 0)return"this";if(t.an!==void 0)return"an";return""}const u=r({name:"Can",props:{I:String,do:String,a:[String,Function],an:[String,Function],this:[String,Function,Object],on:[String,Function,Object],not:Boolean,passThrough:Boolean,field:String},setup(t,{slots:i}){const n=t;let r="do";let o="on";if(n[r]===void 0){r="I";o=s(t)}if(!n[r])throw new Error("Neither `I` nor `do` prop was passed in <Can>");if(!i.default)throw new Error("Expects to receive default slot");const e=useAbility();return()=>{const s=e.can(n[r],n[o],n.field);const u=t.not?!s:s;if(!t.passThrough)return u?i.default():null;return i.default({allowed:u,ability:e})}}});function l(t,i,n){if(!i||!(i instanceof o))throw new Error("Please provide an Ability instance to abilitiesPlugin plugin");t.provide(e,reactiveAbility(i));if(n&&n.useGlobalProperties){t.config.globalProperties.$ability=i;t.config.globalProperties.$can=i.can.bind(i)}}export{e as ABILITY_TOKEN,u as Can,l as abilitiesPlugin,provideAbility,useAbility};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/es6m/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/reactiveAbility.ts","../../src/useAbility.ts","../../src/component/can.ts","../../src/plugin.ts"],"sourcesContent":["import { AnyAbility, SubjectType } from '@casl/ability';\nimport { ref } from 'vue';\n\nexport function reactiveAbility(ability: AnyAbility) {\n if (Object.hasOwn(ability, 'possibleRulesFor')) {\n return ability;\n }\n\n const watcher = ref(true);\n ability.on('updated', () => {\n watcher.value = !watcher.value;\n });\n\n const possibleRulesFor = ability.possibleRulesFor.bind(ability);\n ability.possibleRulesFor = (action: string, subject: SubjectType) => {\n watcher.value = watcher.value; // eslint-disable-line\n return possibleRulesFor(action, subject);\n };\n ability.can = ability.can.bind(ability);\n ability.cannot = ability.cannot.bind(ability);\n\n return ability;\n}\n","import {
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/reactiveAbility.ts","../../src/useAbility.ts","../../src/component/can.ts","../../src/plugin.ts"],"sourcesContent":["import { AnyAbility, SubjectType } from '@casl/ability';\nimport { ref } from 'vue';\n\nexport function reactiveAbility(ability: AnyAbility) {\n if (Object.hasOwn(ability, 'possibleRulesFor')) {\n return ability;\n }\n\n const watcher = ref(true);\n ability.on('updated', () => {\n watcher.value = !watcher.value;\n });\n\n const possibleRulesFor = ability.possibleRulesFor.bind(ability);\n ability.possibleRulesFor = (action: string, subject: SubjectType) => {\n watcher.value = watcher.value; // eslint-disable-line\n return possibleRulesFor(action, subject);\n };\n ability.can = ability.can.bind(ability);\n ability.cannot = ability.cannot.bind(ability);\n\n return ability;\n}\n","import type { AnyAbility, MongoAbility } from '@casl/ability';\nimport { inject, InjectionKey, provide } from 'vue';\nimport { reactiveAbility } from './reactiveAbility';\n\nexport const ABILITY_TOKEN: InjectionKey<AnyAbility> = Symbol('ability');\n\nexport function useAbility<T extends AnyAbility = MongoAbility>(): T {\n const ability = inject<T>(ABILITY_TOKEN);\n\n if (!ability) {\n throw new Error('Cannot inject Ability instance because it was not provided');\n }\n\n return ability;\n}\n\nexport function provideAbility(ability: AnyAbility) {\n provide(ABILITY_TOKEN, reactiveAbility(ability));\n}\n","import {\n Abilities,\n AbilityTuple,\n AnyAbility,\n Generics,\n IfString,\n MongoAbility,\n SubjectType\n} from '@casl/ability';\nimport { ComponentCustomProperties, defineComponent } from 'vue';\nimport { useAbility } from '../useAbility';\n\ntype AbilityCanProps<\n T extends Abilities,\n Else = IfString<T, { do: T } | { I: T }>\n> = T extends AbilityTuple\n ? { do: T[0], on: T[1], field?: string } |\n { I: T[0], a: Extract<T[1], SubjectType>, field?: string } |\n { I: T[0], an: Extract<T[1], SubjectType>, field?: string } |\n { I: T[0], this: Exclude<T[1], SubjectType>, field?: string }\n : Else;\n\nexport type CanProps<T extends AnyAbility> = AbilityCanProps<Generics<T>['abilities']> & {\n not?: boolean,\n passThrough?: boolean\n};\n\ntype VueAbility = ComponentCustomProperties extends { $ability: AnyAbility }\n ? ComponentCustomProperties['$ability']\n : MongoAbility;\n\nfunction detectSubjectProp(props: Record<string, unknown>) {\n if (props.a !== undefined) {\n return 'a';\n }\n\n if (props.this !== undefined) {\n return 'this';\n }\n\n if (props.an !== undefined) {\n return 'an';\n }\n\n return '';\n}\n\nexport const Can = defineComponent<CanProps<VueAbility>>({\n name: 'Can',\n props: {\n I: String,\n do: String,\n a: [String, Function],\n an: [String, Function],\n this: [String, Function, Object],\n on: [String, Function, Object],\n not: Boolean,\n passThrough: Boolean,\n field: String\n } as any,\n setup(props, { slots }) {\n const $props = props as Record<string, any>;\n let actionProp = 'do';\n let subjectProp = 'on';\n\n if ($props[actionProp] === undefined) {\n actionProp = 'I';\n subjectProp = detectSubjectProp(props);\n }\n\n if (!$props[actionProp]) {\n throw new Error('Neither `I` nor `do` prop was passed in <Can>');\n }\n\n if (!slots.default) {\n throw new Error('Expects to receive default slot');\n }\n\n const ability = useAbility<VueAbility>();\n\n return () => {\n const isAllowed = ability.can($props[actionProp], $props[subjectProp], $props.field);\n const canRender = props.not ? !isAllowed : isAllowed;\n\n if (!props.passThrough) {\n return canRender ? slots.default!() : null;\n }\n\n return slots.default!({\n allowed: canRender,\n ability,\n });\n };\n }\n});\n","import { App } from 'vue';\nimport { AnyAbility, PureAbility } from '@casl/ability';\nimport { ABILITY_TOKEN } from './useAbility';\nimport { reactiveAbility } from './reactiveAbility';\n\nexport interface AbilityPluginOptions {\n useGlobalProperties?: boolean\n}\n\nexport function abilitiesPlugin(app: App, ability: AnyAbility, options?: AbilityPluginOptions) {\n if (!ability || !(ability instanceof PureAbility)) {\n throw new Error('Please provide an Ability instance to abilitiesPlugin plugin');\n }\n\n app.provide(ABILITY_TOKEN, reactiveAbility(ability));\n\n if (options && options.useGlobalProperties) {\n app.config.globalProperties.$ability = ability;\n app.config.globalProperties.$can = ability.can.bind(ability);\n }\n}\n"],"names":["reactiveAbility","ability","Object","hasOwn","watcher","ref","on","value","possibleRulesFor","bind","action","subject","can","cannot","ABILITY_TOKEN","Symbol","useAbility","inject","Error","provideAbility","provide","detectSubjectProp","props","a","undefined","this","an","Can","defineComponent","name","I","String","do","Function","not","Boolean","passThrough","field","setup","slots","$props","actionProp","subjectProp","default","isAllowed","canRender","allowed","abilitiesPlugin","app","options","PureAbility","useGlobalProperties","config","globalProperties","$ability","$can"],"mappings":"oHAGO,SAASA,gBAAgBC,GAC9B,GAAIC,OAAOC,OAAOF,EAAS,oBACzB,OAAOA,EAGT,MAAMG,EAAUC,EAAI,MACpBJ,EAAQK,GAAG,UAAW,KACpBF,EAAQG,OAASH,EAAQG,QAG3B,MAAMC,EAAmBP,EAAQO,iBAAiBC,KAAKR,GACvDA,EAAQO,iBAAmB,CAACE,EAAgBC,KAC1CP,EAAQG,MAAQH,EAAQG,MACxB,OAAOC,EAAiBE,EAAQC,IAElCV,EAAQW,IAAMX,EAAQW,IAAIH,KAAKR,GAC/BA,EAAQY,OAASZ,EAAQY,OAAOJ,KAAKR,GAErC,OAAOA,CACT,OClBaa,EAA0CC,OAAO,WAEvD,SAASC,aACd,MAAMf,EAAUgB,EAAUH,GAE1B,IAAKb,EACH,MAAM,IAAIiB,MAAM,8DAGlB,OAAOjB,CACT,CAEO,SAASkB,eAAelB,GAC7BmB,EAAQN,EAAed,gBAAgBC,GACzC,CCaA,SAASoB,EAAkBC,GACzB,GAAIA,EAAMC,SAAMC,EACd,MAAO,IAGT,GAAIF,EAAMG,YAASD,EACjB,MAAO,OAGT,GAAIF,EAAMI,UAAOF,EACf,MAAO,KAGT,MAAO,EACT,CAEO,MAAMG,EAAMC,EAAsC,CACvDC,KAAM,MACNP,MAAO,CACLQ,EAAGC,OACHC,GAAID,OACJR,EAAG,CAACQ,OAAQE,UACZP,GAAI,CAACK,OAAQE,UACbR,KAAM,CAACM,OAAQE,SAAU/B,QACzBI,GAAI,CAACyB,OAAQE,SAAU/B,QACvBgC,IAAKC,QACLC,YAAaD,QACbE,MAAON,QAETO,KAAAA,CAAMhB,GAAOiB,MAAEA,IACb,MAAMC,EAASlB,EACf,IAAImB,EAAa,KACjB,IAAIC,EAAc,KAElB,GAAIF,EAAOC,UAAgBjB,EAAW,CACpCiB,EAAa,IACbC,EAAcrB,EAAkBC,EAClC,CAEA,IAAKkB,EAAOC,GACV,MAAM,IAAIvB,MAAM,iDAGlB,IAAKqB,EAAMI,QACT,MAAM,IAAIzB,MAAM,mCAGlB,MAAMjB,EAAUe,aAEhB,MAAO,KACL,MAAM4B,EAAY3C,EAAQW,IAAI4B,EAAOC,GAAaD,EAAOE,GAAcF,EAAOH,OAC9E,MAAMQ,EAAYvB,EAAMY,KAAOU,EAAYA,EAE3C,IAAKtB,EAAMc,YACT,OAAOS,EAAYN,EAAMI,UAAa,KAGxC,OAAOJ,EAAMI,QAAS,CACpBG,QAASD,EACT5C,YAGN,ICpFK,SAAS8C,EAAgBC,EAAU/C,EAAqBgD,GAC7D,IAAKhD,KAAaA,aAAmBiD,GACnC,MAAM,IAAIhC,MAAM,gEAGlB8B,EAAI5B,QAAQN,EAAed,gBAAgBC,IAE3C,GAAIgD,GAAWA,EAAQE,oBAAqB,CAC1CH,EAAII,OAAOC,iBAAiBC,SAAWrD,EACvC+C,EAAII,OAAOC,iBAAiBE,KAAOtD,EAAQW,IAAIH,KAAKR,EACtD,CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Abilities, AbilityTuple, AnyAbility, Generics, IfString, MongoAbility, SubjectType } from '@casl/ability';
|
|
2
2
|
type AbilityCanProps<T extends Abilities, Else = IfString<T, {
|
|
3
3
|
do: T;
|
|
4
4
|
} | {
|
|
@@ -24,37 +24,5 @@ export type CanProps<T extends AnyAbility> = AbilityCanProps<Generics<T>['abilit
|
|
|
24
24
|
not?: boolean;
|
|
25
25
|
passThrough?: boolean;
|
|
26
26
|
};
|
|
27
|
-
export declare const Can: import("vue").DefineComponent<CanProps<
|
|
28
|
-
do: string;
|
|
29
|
-
on: import("@casl/ability").Subject;
|
|
30
|
-
field?: string | undefined;
|
|
31
|
-
} & {
|
|
32
|
-
not?: boolean | undefined;
|
|
33
|
-
passThrough?: boolean | undefined;
|
|
34
|
-
}> | Readonly<{
|
|
35
|
-
I: string;
|
|
36
|
-
a: SubjectType;
|
|
37
|
-
field?: string | undefined;
|
|
38
|
-
} & {
|
|
39
|
-
not?: boolean | undefined;
|
|
40
|
-
passThrough?: boolean | undefined;
|
|
41
|
-
}> | Readonly<{
|
|
42
|
-
I: string;
|
|
43
|
-
an: SubjectType;
|
|
44
|
-
field?: string | undefined;
|
|
45
|
-
} & {
|
|
46
|
-
not?: boolean | undefined;
|
|
47
|
-
passThrough?: boolean | undefined;
|
|
48
|
-
}> | Readonly<{
|
|
49
|
-
I: string;
|
|
50
|
-
this: {
|
|
51
|
-
[x: string]: any;
|
|
52
|
-
[x: number]: any;
|
|
53
|
-
[x: symbol]: any;
|
|
54
|
-
};
|
|
55
|
-
field?: string | undefined;
|
|
56
|
-
} & {
|
|
57
|
-
not?: boolean | undefined;
|
|
58
|
-
passThrough?: boolean | undefined;
|
|
59
|
-
}>, {} | {} | {} | {}, {}>;
|
|
27
|
+
export declare const Can: import("vue").DefineComponent<CanProps<MongoAbility<AbilityTuple, import("@casl/ability").MongoQuery>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CanProps<MongoAbility<AbilityTuple, import("@casl/ability").MongoQuery>>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
60
28
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { AnyAbility, MongoAbility } from '@casl/ability';
|
|
1
2
|
import { InjectionKey } from 'vue';
|
|
2
|
-
import type { AnyAbility, Ability } from '@casl/ability';
|
|
3
3
|
export declare const ABILITY_TOKEN: InjectionKey<AnyAbility>;
|
|
4
|
-
export declare function useAbility<T extends AnyAbility =
|
|
4
|
+
export declare function useAbility<T extends AnyAbility = MongoAbility>(): T;
|
|
5
5
|
export declare function provideAbility(ability: AnyAbility): void;
|
package/dist/umd/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(i,t){typeof exports==="object"&&typeof module!=="undefined"?t(exports,require("vue"),require("@casl/ability")):typeof define==="function"&&define.amd?define(["exports","vue","@casl/ability"],t):(i=typeof globalThis!=="undefined"?globalThis:i||self,t((i.casl=i.casl||{},i.casl.vue={}),i.Vue,i.casl))})(this,
|
|
1
|
+
(function(i,t){typeof exports==="object"&&typeof module!=="undefined"?t(exports,require("vue"),require("@casl/ability")):typeof define==="function"&&define.amd?define(["exports","vue","@casl/ability"],t):(i=typeof globalThis!=="undefined"?globalThis:i||self,t((i.casl=i.casl||{},i.casl.vue={}),i.Vue,i.casl))})(this,function(i,t,n){"use strict";function reactiveAbility(i){if(Object.hasOwn(i,"possibleRulesFor"))return i;var n=t.ref(true);i.on("updated",function(){n.value=!n.value});var e=i.possibleRulesFor.bind(i);i.possibleRulesFor=function(i,t){n.value=n.value;return e(i,t)};i.can=i.can.bind(i);i.cannot=i.cannot.bind(i);return i}var e=Symbol("ability");function useAbility(){var i=t.inject(e);if(!i)throw new Error("Cannot inject Ability instance because it was not provided");return i}function provideAbility(i){t.provide(e,reactiveAbility(i))}function r(i){if(i.a!==void 0)return"a";if(i.this!==void 0)return"this";if(i.an!==void 0)return"an";return""}var o=t.defineComponent({name:"Can",props:{I:String,do:String,a:[String,Function],an:[String,Function],this:[String,Function,Object],on:[String,Function,Object],not:Boolean,passThrough:Boolean,field:String},setup:function i(t,n){var e=n.slots;var o=t;var u="do";var a="on";if(o[u]===void 0){u="I";a=r(t)}if(!o[u])throw new Error("Neither `I` nor `do` prop was passed in <Can>");if(!e.default)throw new Error("Expects to receive default slot");var l=useAbility();return function(){var i=l.can(o[u],o[a],o.field);var n=t.not?!i:i;if(!t.passThrough)return n?e.default():null;return e.default({allowed:n,ability:l})}}});function u(i,t,r){if(!t||!(t instanceof n.PureAbility))throw new Error("Please provide an Ability instance to abilitiesPlugin plugin");i.provide(e,reactiveAbility(t));if(r&&r.useGlobalProperties){i.config.globalProperties.$ability=t;i.config.globalProperties.$can=t.can.bind(t)}}i.ABILITY_TOKEN=e;i.Can=o;i.abilitiesPlugin=u;i.provideAbility=provideAbility;i.useAbility=useAbility});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/umd/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/reactiveAbility.ts","../../src/useAbility.ts","../../src/component/can.ts","../../src/plugin.ts"],"sourcesContent":["import { AnyAbility, SubjectType } from '@casl/ability';\nimport { ref } from 'vue';\n\nexport function reactiveAbility(ability: AnyAbility) {\n if (Object.hasOwn(ability, 'possibleRulesFor')) {\n return ability;\n }\n\n const watcher = ref(true);\n ability.on('updated', () => {\n watcher.value = !watcher.value;\n });\n\n const possibleRulesFor = ability.possibleRulesFor.bind(ability);\n ability.possibleRulesFor = (action: string, subject: SubjectType) => {\n watcher.value = watcher.value; // eslint-disable-line\n return possibleRulesFor(action, subject);\n };\n ability.can = ability.can.bind(ability);\n ability.cannot = ability.cannot.bind(ability);\n\n return ability;\n}\n","import {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/reactiveAbility.ts","../../src/useAbility.ts","../../src/component/can.ts","../../src/plugin.ts"],"sourcesContent":["import { AnyAbility, SubjectType } from '@casl/ability';\nimport { ref } from 'vue';\n\nexport function reactiveAbility(ability: AnyAbility) {\n if (Object.hasOwn(ability, 'possibleRulesFor')) {\n return ability;\n }\n\n const watcher = ref(true);\n ability.on('updated', () => {\n watcher.value = !watcher.value;\n });\n\n const possibleRulesFor = ability.possibleRulesFor.bind(ability);\n ability.possibleRulesFor = (action: string, subject: SubjectType) => {\n watcher.value = watcher.value; // eslint-disable-line\n return possibleRulesFor(action, subject);\n };\n ability.can = ability.can.bind(ability);\n ability.cannot = ability.cannot.bind(ability);\n\n return ability;\n}\n","import type { AnyAbility, MongoAbility } from '@casl/ability';\nimport { inject, InjectionKey, provide } from 'vue';\nimport { reactiveAbility } from './reactiveAbility';\n\nexport const ABILITY_TOKEN: InjectionKey<AnyAbility> = Symbol('ability');\n\nexport function useAbility<T extends AnyAbility = MongoAbility>(): T {\n const ability = inject<T>(ABILITY_TOKEN);\n\n if (!ability) {\n throw new Error('Cannot inject Ability instance because it was not provided');\n }\n\n return ability;\n}\n\nexport function provideAbility(ability: AnyAbility) {\n provide(ABILITY_TOKEN, reactiveAbility(ability));\n}\n","import {\n Abilities,\n AbilityTuple,\n AnyAbility,\n Generics,\n IfString,\n MongoAbility,\n SubjectType\n} from '@casl/ability';\nimport { ComponentCustomProperties, defineComponent } from 'vue';\nimport { useAbility } from '../useAbility';\n\ntype AbilityCanProps<\n T extends Abilities,\n Else = IfString<T, { do: T } | { I: T }>\n> = T extends AbilityTuple\n ? { do: T[0], on: T[1], field?: string } |\n { I: T[0], a: Extract<T[1], SubjectType>, field?: string } |\n { I: T[0], an: Extract<T[1], SubjectType>, field?: string } |\n { I: T[0], this: Exclude<T[1], SubjectType>, field?: string }\n : Else;\n\nexport type CanProps<T extends AnyAbility> = AbilityCanProps<Generics<T>['abilities']> & {\n not?: boolean,\n passThrough?: boolean\n};\n\ntype VueAbility = ComponentCustomProperties extends { $ability: AnyAbility }\n ? ComponentCustomProperties['$ability']\n : MongoAbility;\n\nfunction detectSubjectProp(props: Record<string, unknown>) {\n if (props.a !== undefined) {\n return 'a';\n }\n\n if (props.this !== undefined) {\n return 'this';\n }\n\n if (props.an !== undefined) {\n return 'an';\n }\n\n return '';\n}\n\nexport const Can = defineComponent<CanProps<VueAbility>>({\n name: 'Can',\n props: {\n I: String,\n do: String,\n a: [String, Function],\n an: [String, Function],\n this: [String, Function, Object],\n on: [String, Function, Object],\n not: Boolean,\n passThrough: Boolean,\n field: String\n } as any,\n setup(props, { slots }) {\n const $props = props as Record<string, any>;\n let actionProp = 'do';\n let subjectProp = 'on';\n\n if ($props[actionProp] === undefined) {\n actionProp = 'I';\n subjectProp = detectSubjectProp(props);\n }\n\n if (!$props[actionProp]) {\n throw new Error('Neither `I` nor `do` prop was passed in <Can>');\n }\n\n if (!slots.default) {\n throw new Error('Expects to receive default slot');\n }\n\n const ability = useAbility<VueAbility>();\n\n return () => {\n const isAllowed = ability.can($props[actionProp], $props[subjectProp], $props.field);\n const canRender = props.not ? !isAllowed : isAllowed;\n\n if (!props.passThrough) {\n return canRender ? slots.default!() : null;\n }\n\n return slots.default!({\n allowed: canRender,\n ability,\n });\n };\n }\n});\n","import { App } from 'vue';\nimport { AnyAbility, PureAbility } from '@casl/ability';\nimport { ABILITY_TOKEN } from './useAbility';\nimport { reactiveAbility } from './reactiveAbility';\n\nexport interface AbilityPluginOptions {\n useGlobalProperties?: boolean\n}\n\nexport function abilitiesPlugin(app: App, ability: AnyAbility, options?: AbilityPluginOptions) {\n if (!ability || !(ability instanceof PureAbility)) {\n throw new Error('Please provide an Ability instance to abilitiesPlugin plugin');\n }\n\n app.provide(ABILITY_TOKEN, reactiveAbility(ability));\n\n if (options && options.useGlobalProperties) {\n app.config.globalProperties.$ability = ability;\n app.config.globalProperties.$can = ability.can.bind(ability);\n }\n}\n"],"names":["reactiveAbility","ability","Object","hasOwn","watcher","ref","on","value","possibleRulesFor","bind","action","subject","can","cannot","ABILITY_TOKEN","Symbol","useAbility","inject","Error","provideAbility","provide","detectSubjectProp","props","a","undefined","this","an","Can","defineComponent","name","I","String","do","Function","not","Boolean","passThrough","field","setup","_ref","slots","$props","actionProp","subjectProp","default","isAllowed","canRender","allowed","abilitiesPlugin","app","options","PureAbility","useGlobalProperties","config","globalProperties","$ability","$can"],"mappings":"yVAGO,SAASA,gBAAgBC,GAC9B,GAAIC,OAAOC,OAAOF,EAAS,oBACzB,OAAOA,EAGT,IAAMG,EAAUC,EAAAA,IAAI,MACpBJ,EAAQK,GAAG,UAAW,WACpBF,EAAQG,OAASH,EAAQG,KAC3B,GAEA,IAAMC,EAAmBP,EAAQO,iBAAiBC,KAAKR,GACvDA,EAAQO,iBAAmB,SAACE,EAAgBC,GAC1CP,EAAQG,MAAQH,EAAQG,MACxB,OAAOC,EAAiBE,EAAQC,EAClC,EACAV,EAAQW,IAAMX,EAAQW,IAAIH,KAAKR,GAC/BA,EAAQY,OAASZ,EAAQY,OAAOJ,KAAKR,GAErC,OAAOA,CACT,KClBaa,EAA0CC,OAAO,WAEvD,SAASC,aACd,IAAMf,EAAUgB,EAAAA,OAAUH,GAE1B,IAAKb,EACH,MAAM,IAAIiB,MAAM,8DAGlB,OAAOjB,CACT,CAEO,SAASkB,eAAelB,GAC7BmB,EAAAA,QAAQN,EAAed,gBAAgBC,GACzC,CCaA,SAASoB,EAAkBC,GACzB,GAAIA,EAAMC,SAAMC,EACd,MAAO,IAGT,GAAIF,EAAMG,YAASD,EACjB,MAAO,OAGT,GAAIF,EAAMI,UAAOF,EACf,MAAO,KAGT,MAAO,EACT,CAEO,IAAMG,EAAMC,EAAAA,gBAAsC,CACvDC,KAAM,MACNP,MAAO,CACLQ,EAAGC,OACHC,GAAID,OACJR,EAAG,CAACQ,OAAQE,UACZP,GAAI,CAACK,OAAQE,UACbR,KAAM,CAACM,OAAQE,SAAU/B,QACzBI,GAAI,CAACyB,OAAQE,SAAU/B,QACvBgC,IAAKC,QACLC,YAAaD,QACbE,MAAON,QAETO,eAAAA,EAAMhB,EAAKiB,GAAa,IAATC,EAAKD,EAALC,MACb,IAAMC,EAASnB,EACf,IAAIoB,EAAa,KACjB,IAAIC,EAAc,KAElB,GAAIF,EAAOC,UAAgBlB,EAAW,CACpCkB,EAAa,IACbC,EAActB,EAAkBC,EAClC,CAEA,IAAKmB,EAAOC,GACV,MAAM,IAAIxB,MAAM,iDAGlB,IAAKsB,EAAMI,QACT,MAAM,IAAI1B,MAAM,mCAGlB,IAAMjB,EAAUe,aAEhB,OAAO,WACL,IAAM6B,EAAY5C,EAAQW,IAAI6B,EAAOC,GAAaD,EAAOE,GAAcF,EAAOJ,OAC9E,IAAMS,EAAYxB,EAAMY,KAAOW,EAAYA,EAE3C,IAAKvB,EAAMc,YACT,OAAOU,EAAYN,EAAMI,UAAa,KAGxC,OAAOJ,EAAMI,QAAS,CACpBG,QAASD,EACT7C,QAAAA,GAEJ,CACF,ICpFK,SAAS+C,EAAgBC,EAAUhD,EAAqBiD,GAC7D,IAAKjD,KAAaA,aAAmBkD,EAAAA,aACnC,MAAM,IAAIjC,MAAM,gEAGlB+B,EAAI7B,QAAQN,EAAed,gBAAgBC,IAE3C,GAAIiD,GAAWA,EAAQE,oBAAqB,CAC1CH,EAAII,OAAOC,iBAAiBC,SAAWtD,EACvCgD,EAAII,OAAOC,iBAAiBE,KAAOvD,EAAQW,IAAIH,KAAKR,EACtD,CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@casl/vue",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"description": "Vue plugin for CASL which makes it easy to add permissions in any Vue application",
|
|
5
5
|
"main": "dist/umd/index.js",
|
|
6
6
|
"module": "dist/es5m/index.js",
|
|
@@ -22,15 +22,6 @@
|
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "BUILD_TYPES=es5m,es6m,umd dx rollup -n casl.vue -g vue:Vue,@casl/ability:casl",
|
|
27
|
-
"build.types": "dx tsc -p tsconfig.build.json",
|
|
28
|
-
"prebuild": "rm -rf dist/* && npm run build.types",
|
|
29
|
-
"lint": "dx eslint src/ spec/",
|
|
30
|
-
"test": "dx jest --env jsdom --config ../dx/config/jest.chai.config.js",
|
|
31
|
-
"prerelease": "npm run lint && npm test && NODE_ENV=production npm run build",
|
|
32
|
-
"release": "dx semantic-release"
|
|
33
|
-
},
|
|
34
25
|
"keywords": [
|
|
35
26
|
"casl",
|
|
36
27
|
"vue",
|
|
@@ -46,7 +37,7 @@
|
|
|
46
37
|
},
|
|
47
38
|
"devDependencies": {
|
|
48
39
|
"@casl/ability": "^6.0.0",
|
|
49
|
-
"@casl/dx": "
|
|
40
|
+
"@casl/dx": "^1.0.0",
|
|
50
41
|
"@types/jest": "^29.0.0",
|
|
51
42
|
"chai": "^4.1.0",
|
|
52
43
|
"chai-spies": "^1.0.0",
|
|
@@ -55,5 +46,14 @@
|
|
|
55
46
|
"files": [
|
|
56
47
|
"dist",
|
|
57
48
|
"*.d.ts"
|
|
58
|
-
]
|
|
59
|
-
|
|
49
|
+
],
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build.prepare": "rm -rf dist/* && npm run build.types",
|
|
52
|
+
"build": "npm run build.prepare && BUILD_TYPES=es5m,es6m,umd dx rollup -n casl.vue -g vue:Vue,@casl/ability:casl",
|
|
53
|
+
"build.types": "dx tsc -p tsconfig.build.json",
|
|
54
|
+
"lint": "dx eslint src/ spec/",
|
|
55
|
+
"test": "dx jest --env jsdom",
|
|
56
|
+
"release.prepare": "npm run lint && npm test && NODE_ENV=production npm run build",
|
|
57
|
+
"release": "npm run release.prepare && pnpm publish"
|
|
58
|
+
}
|
|
59
|
+
}
|