@vperms/mongodb-adapter
v0.0.6
Published
MongoDB adapter for VeguiPerms.
Maintainers
Readme
VeguiPerms MongoDB Adapter
@vperms/mongodb-adapter stores VeguiPerms subjects and grants in MongoDB,
using an existing database connection and explicitly managed collection indexes.
MongoDB guide · API reference · GitHub
Install
npm install @vperms/mongodb-adapter vperms mongodbQuick start
import { MongoClient } from "mongodb";
import { VeguiPermsMongoDBAdapter } from "@vperms/mongodb-adapter";
import { createVPerms } from "vperms";
const client = new MongoClient("mongodb://localhost:27017");
await client.connect();
const adapter = new VeguiPermsMongoDBAdapter({ db: client.db("permissions") });
await adapter.migrate();
const perms = createVPerms({ adapter });
await perms.can("alice", "projects.read");
await client.close(); // close on application shutdownmigrate() idempotently creates vperms_subjects, vperms_grants and their unique
indexes. The application owns the connection lifecycle; constructing the adapter
does not implicitly migrate the database.
Use subjectsCollection and grantsCollection to customize collection names.
The adapter only persists data; VeguiPermsService handles authorization semantics.
Build and coverage badges describe the whole VeguiPerms repository. License: MIT.
