-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(example): replaces ESM with CommonJS in helloworld
To understand why check stalniy/casl#331. Also adds note that it's possible to use any package manager to run an example
- Loading branch information
Showing
8 changed files
with
20 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
# CASL hello world | ||
|
||
This is a basic example that illustrates the easiest CASL configuration. | ||
This is a basic example that allows to play around with [CASL](https://stalniy.github.io/casl/v4). | ||
|
||
## Requirements | ||
|
||
Node version that support experimental modules. Tested on node v12.13 | ||
**Note**: this example uses CommonJS as `@casl/ability` currently doesn't support new `exports` field in package.json and codesandbox doesn't allow to change the version of nodejs (10.x only at the time of writing). | ||
|
||
## Run | ||
|
||
```sh | ||
pnpm install | ||
pnpm start | ||
npm install | ||
npm start | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const { defineAbility } = require('@casl/ability'); | ||
|
||
module.exports = defineAbility((can, cannot) => { | ||
can('manage', 'all'); | ||
cannot('delete', 'User'); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const ability = require('./defineAbility'); | ||
|
||
console.log('can read Post', ability.can('read', 'Post')) // true | ||
console.log('can read User', ability.can('read', 'User')) // true | ||
console.log('can update User', ability.can('update', 'User')) // true | ||
console.log('can delete User', ability.can('delete', 'User')) // false | ||
console.log('cannot delete User', ability.cannot('delete', 'User')) // true |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters