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

@casbin/mongo-changestream-watcher

Package Overview
Dependencies
Maintainers
4
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@casbin/mongo-changestream-watcher

Casbin Watcher based on MongoDB Change Streams

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.5K
decreased by-6.88%
Maintainers
4
Weekly downloads
 
Created
Source

Node-Casbin Watcher based on MongoDB Change Streams

NPM version NPM download codebeat badge Coverage Status Gitter tests

For more information about MongoDB Change Streams, look here.

More information about Casbin Watchers, look here.

Installation

# NPM
npm install --save @casbin/mongo-changestream-watcher

# Yarn
yarn add @casbin/mongo-changestream-watcher

Simple Example using Mongoose Adapter

import { MongoChangeStreamWatcher } from '@casbin/mongo-changestream-watcher';
import { newEnforcer } from 'casbin';

// Initialize the watcher by connecting to a replica set.
const watcher = await MongoChangeStreamWatcher.newWatcher('mongodb://localhost:27001,localhost:27002/casbin?replicaSet=rs0', {collectionName: 'casbin_rule'});
const adapter = await MongooseAdapter.newAdapter('mongodb://localhost:27001,localhost:27002/casbin?replicaSet=rs0');
const enforcer = await newEnforcer('test/fixtures/basic_model.conf', adapter);

// Initialize the enforcer.
const enforcer = await newEnforcer('examples/authz_model.conf', 'examples/authz_policy.csv');

enforcer.setWatcher(watcher);

// By default, the watcher's callback is automatically set to the
// enforcer's loadPolicy() in the setWatcher() call.
// We can change it by explicitly setting a callback.
watcher.setUpdateCallback(() => console.log('Casbin need update'));

Notes

This watcher does not operate with update-calls typically found in other watchers. Mongo Change Stream directly reacts to changes in the database collection, and therefore all other watchers listening to the same stream will be automatically notified when changes do occur. However, this means that watcher also gets notified by its own changes.

Keywords

FAQs

Package last updated on 26 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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