Skip to content

Commit

Permalink
feat(knex): adds infra code for @casl/knex package
Browse files Browse the repository at this point in the history
Relates #8
  • Loading branch information
stalniy committed Jun 5, 2020
1 parent 55bce37 commit 8571671
Show file tree
Hide file tree
Showing 8 changed files with 506 additions and 2 deletions.
21 changes: 21 additions & 0 deletions packages/casl-knex/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017-present Sergii Stotskyi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
33 changes: 33 additions & 0 deletions packages/casl-knex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# [CASL Knex](https://stalniy.github.io/casl/) [![@casl/knex NPM version](https://badge.fury.io/js/%40casl%2Fknex.svg)](https://badge.fury.io/js/%40casl%2Fknex) [![](https://img.shields.io/npm/dm/%40casl%2Fknex.svg)](https://www.npmjs.com/package/%40casl%2Fknex) [![CASL Join the chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/stalniy-casl/casl)

This package integrates [CASL] and [RDBMS] using [knex]. In other words, it allows to fetch records based on CASL rules from SQL databases and answer questions like: "Which records can be read?" or "Which records can be updated?".

## Installation

```sh
npm install @casl/knex @casl/ability
# or
yarn add @casl/knex @casl/ability
# or
pnpm add @casl/knex @casl/ability
```

## TODO


## Want to help?

Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on guidelines for [contributing].

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)

> See [Support CASL](../../support) for details
## License

[MIT License](http://www.opensource.org/licenses/MIT)

[contributing]: https://github.com/stalniy/casl/blob/master/CONTRIBUTING.md
[knex]: http://knexjs.org/
[CASL]: https://github.com/stalniy/casl
[RDBMS]: https://en.wikipedia.org/wiki/Relational_database
76 changes: 76 additions & 0 deletions packages/casl-knex/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "@casl/knex",
"version": "0.0.1",
"description": "Allows to query accessible records from SQL databases based on CASL rules",
"main": "index.js",
"es2015": "dist/es6/index.js",
"typings": "./index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/stalniy/casl.git"
},
"publishConfig": {
"access": "public"
},
"homepage": "https://stalniy.github.io/casl/",
"scripts": {
"prebuild": "npm run build.types",
"build": "BUILD_TYPES=es6,umd:cjs rollup -c ../../rollup.config.js -e @casl/ability/extra,@casl/ability,knex",
"build.types": "rm -rf dist/types/* && tsc",
"lint": "eslint --ext .ts,.js src/ spec/",
"test": "NODE_ENV=test jest --config ../../tools/jest.config.js --env node",
"prerelease": "npm run lint && npm test && NODE_ENV=production npm run build",
"release": "semantic-release -e ../../tools/semantic-release"
},
"keywords": [
"access control",
"authorization",
"acl",
"security",
"permissions",
"rdbms",
"sql",
"postgres",
"mysql"
],
"author": "Sergii Stotskyi <sergiy.stotskiy@freaksidea.com>",
"license": "MIT",
"engines": {
"npm": "^6.0.0"
},
"peerDependencies": {
"@casl/ability": "^2.0.0 || ^3.0.0 || ^4.0.0",
"knex": "~0.21.1"
},
"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.10.0",
"@babel/plugin-transform-typescript": "^7.10.0",
"@babel/preset-env": "^7.8.4",
"@casl/ability": "^4.0.0",
"@rollup/plugin-babel": "^5.0.2",
"@rollup/plugin-node-resolve": "^8.0.0",
"@semantic-release/changelog": "^3.0.0",
"@semantic-release/git": "^7.0.0",
"@typescript-eslint/eslint-plugin": "2.24.0",
"babel-jest": "^26.0.0",
"chai": "^4.1.0",
"chai-spies": "^1.0.0",
"eslint": "^7.1.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-config-airbnb-typescript": "^7.2.1",
"eslint-plugin-import": "^2.20.2",
"jest": "^26.0.0",
"knex": "~0.21.1",
"rollup": "^2.10.9",
"rollup-plugin-terser": "^6.1.0",
"semantic-release": "15.9.17",
"typescript": "~3.8.0"
},
"files": [
"dist",
"*.d.ts",
"index.js"
]
}
5 changes: 5 additions & 0 deletions packages/casl-knex/spec/rulesToKnexQuery.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('rulesToKnexQuery', () => {
it('returns knex query builder', () => {
expect(true).to.be.true
})
})
1 change: 1 addition & 0 deletions packages/casl-knex/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './rulesToKnexQuery';
9 changes: 9 additions & 0 deletions packages/casl-knex/src/rulesToKnexQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { AnyAbility, Subject } from '@casl/ability';

interface RulesToKnexOptions {
isRelation(field: string, subject: Subject, ability: AnyAbility): boolean
}

export function rulesToKnexQuery(ability: AnyAbility, action: string, subject: Subject, options: RulesToKnexOptions) {
// TODO
}
10 changes: 10 additions & 0 deletions packages/casl-knex/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig",
"include": [
"src/*",
"spec/*"
],
"compilerOptions": {
"outDir": "dist/types"
}
}
Loading

0 comments on commit 8571671

Please sign in to comment.