3.0.0 • Published 2 years ago

@willsoto/casbin-objection-adapter v3.0.0

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
2 years ago

Casbin Objection Adapter

tests

Installation

npm install @willsoto/casbin-objection-adapter --save
yarn add @willsoto/casbin-objection-adapter
pnpm add @willsoto/casbin-objection-adapter

Basic usage

See the Casbin adapters documentation for more information.

import { Knex } from "knex";
import { newEnforcer } from "casbin";
import { ObjectionAdapter } from "@willsoto/casbin-objection-adapter";

const knex = Knex({
  /* regular knex options */
});

// All configuration is optional
const adapter = await ObjectionAdapter.newAdapter(knex, {});

// Create the enforcer with the given model
const enforcer = await newEnforcer("basic_model.conf", adapter);

// Supports auto-save
// See: https://casbin.org/docs/en/adapters#autosave
enforcer.enableAutoSave(true);

// No need to save explicitly since auto-save is enabled
await enforcer.addPolicies([
  ["alice", "data1", "read"],
  ["bob", "data2", "write"],
]);

await enforcer.enforce("alice", "data1", "read"); // true
await enforcer.enforce("bob", "data1", "read"); // false

Advanced usage

The following options are available:

OptionDefault valueDescription
createTabletrueWhether or not to create the table when initialized.
modelClassCasbinRuleThe model to use when querying policies. You can override this if you would like to control the table name
loggernoopAn optional logger in case additional visiblity is needed into the adapter. The inteface should match console
3.0.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

3 years ago

1.3.0

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago