Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

casbin-knex-adapter

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

casbin-knex-adapter - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

dist/lib/utils.d.ts

9

dist/lib/adapter.d.ts
import type Knex from 'knex';
import type { Adapter, BatchAdapter, Model } from 'casbin';
export declare type KnexAdapterOptions = {
tableName?: string;
chunkSize?: number;
};
export declare class KnexAdapter implements Adapter, BatchAdapter {
private readonly knex;
private readonly tableName;
constructor(knex: Knex, tableName?: string);
static newAdapter(knex: Knex): Promise<KnexAdapter>;
private readonly chunkSize;
constructor(knex: Knex, options?: KnexAdapterOptions);
static newAdapter(knex: Knex, options?: KnexAdapterOptions): Promise<KnexAdapter>;
private get policiesTable();

@@ -9,0 +14,0 @@ createTable(): Promise<void>;

@@ -5,9 +5,11 @@ "use strict";

const casbin_1 = require("casbin");
const utils_1 = require("./utils");
class KnexAdapter {
constructor(knex, tableName = 'policies') {
constructor(knex, options) {
this.knex = knex;
this.tableName = tableName;
this.tableName = (options === null || options === void 0 ? void 0 : options.tableName) || 'policies';
this.chunkSize = (options === null || options === void 0 ? void 0 : options.chunkSize) || 100;
}
static async newAdapter(knex) {
const adapter = new KnexAdapter(knex);
static async newAdapter(knex, options) {
const adapter = new KnexAdapter(knex, options);
await adapter.createTable();

@@ -70,3 +72,6 @@ return adapter;

});
await this.policiesTable.insert(policies);
const insertChunks = utils_1.chunk(policies, this.chunkSize);
for (const insertChunk of insertChunks) {
await this.policiesTable.insert(insertChunk);
}
}

@@ -78,5 +83,5 @@ async removePolicy(sec, ptype, rule) {

async removePolicies(sec, ptype, rules) {
// ToDo Execute this in chunks
for (const rule of rules) {
await this.removePolicy(sec, ptype, rule);
const deleteChunks = utils_1.chunk(rules, this.chunkSize);
for (const deleteChunk of deleteChunks) {
await this.removePolicy(sec, ptype, deleteChunk);
}

@@ -83,0 +88,0 @@ }

{
"name": "casbin-knex-adapter",
"version": "0.4.0",
"version": "0.5.0",
"description": "Knex adapter for Casbin",

@@ -26,2 +26,5 @@ "main": "dist/index.js",

},
"dependencies": {
"lodash.chunk": "^4.2.0"
},
"peerDependencies": {

@@ -28,0 +31,0 @@ "knex": ">=0.16.5",

@@ -30,3 +30,3 @@ # Knex Adapter

// Create adapter
const adapter = await KnexAdapter.newAdapter(knex);
const adapter = await KnexAdapter.newAdapter({ knex });

@@ -33,0 +33,0 @@ // Create casbin enforcer

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc