Skip to content

Commit

Permalink
feat(objection): adds infra code for @casl/objection package
Browse files Browse the repository at this point in the history
Relates stalniy#8
  • Loading branch information
stalniy authored and otaviosoares committed Jun 8, 2020
1 parent 55bce37 commit 91f0a1d
Show file tree
Hide file tree
Showing 8 changed files with 1,913 additions and 98 deletions.
21 changes: 21 additions & 0 deletions packages/casl-objection/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.
34 changes: 34 additions & 0 deletions packages/casl-objection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# [CASL Objection](https://stalniy.github.io/casl/) [![@casl/objection NPM version](https://badge.fury.io/js/%40casl%2Fobjection.svg)](https://badge.fury.io/js/%40casl%2Fobjection) [![](https://img.shields.io/npm/dm/%40casl%2Fobjection.svg)](https://www.npmjs.com/package/%40casl%2Fobjection) [![CASL Join the chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/stalniy-casl/casl)

This package integrates [CASL] and [RDBMS] using [objection]. 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/objection @casl/ability objection knex
# or
yarn add @casl/objection @casl/ability objection knex
# or
pnpm add @casl/objection @casl/ability objection knex
```

## 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
[objection]: https://vincit.github.io/objection.js/
[knex]: http://knexjs.org/
[CASL]: https://github.com/stalniy/casl
[RDBMS]: https://en.wikipedia.org/wiki/Relational_database
78 changes: 78 additions & 0 deletions packages/casl-objection/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"name": "@casl/objection",
"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,objection,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",
"objection": "^2.1.6"
},
"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",
"objection": "^2.1.6",
"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-objection/spec/rulesToObjectionQuery.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('rulesToObjectionQuery', () => {
it('returns an objection query builder', () => {
expect(true).to.be.true
})
})
1 change: 1 addition & 0 deletions packages/casl-objection/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './rulesToObjectionQuery';
9 changes: 9 additions & 0 deletions packages/casl-objection/src/rulesToObjectionQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { AnyAbility, Subject } from '@casl/ability';

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

export function rulesToObjectionQuery(ability: AnyAbility, action: string, subject: Subject, options: RulesToObjetionOptions) {
// TODO
}
10 changes: 10 additions & 0 deletions packages/casl-objection/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 91f0a1d

Please sign in to comment.