@web-ts-toolkit/access-router
ACL-aware Express routers and in-memory data services for Mongoose-backed APIs.
Install
- npm
- Yarn
- pnpm
- Bun
npm install @web-ts-toolkit/access-router express mongoose
yarn add @web-ts-toolkit/access-router express mongoose
pnpm add @web-ts-toolkit/access-router express mongoose
bun add @web-ts-toolkit/access-router express mongoose
What It Exposes
Main entrypoint:
- default export
acl - named export
acl createAccessRuntime()for isolated runtime statecreateOpenApiRouter(...)for/openapi.jsonand Swagger UI routescombineRoutes(...)for mounting multiple routers togetherguard(...)for route guardspermissionsPluginfor schema-based permission accessRootRouter,ModelRouter,DataRouter- option getters and setters for global, model, and data options
Low-level entrypoints:
@web-ts-toolkit/access-router/advanced@web-ts-toolkit/access-router/processors
Quick Start
import acl from '@web-ts-toolkit/access-router';
acl.setGlobalOptions({
globalPermissions(req) {
return req.headers.user === 'admin' ? ['isAdmin'] : [];
},
});
const fruitRouter = acl.createDataRouter('fruit', {
basePath: '/fruit',
data: [{ id: 'apple', name: 'Apple', public: true }],
idField: 'id',
operationAccess: { list: true, read: true },
permissionSchema: {
id: true,
name: 'isAdmin',
public: true,
},
});
const userRouter = acl.createRouter('User', {
basePath: '/users',
});
When To Use It
Use access-router when you want:
- model-backed CRUD routers with ACL-aware filtering and field selection
- in-memory data routers with the same request/permission model
- root batch routes for grouped operations
- OpenAPI generation and Swagger UI without hand-maintaining route docs
- reusable permission helpers, hooks, and request validation
If you only need low-level validation schemas, symbols, or enums, import from the advanced subpath instead.
Package Guide
- Routing: router factories, generated endpoints, and batch routing
- Configuration: global, model, and data router options
- Services: public service methods behind the generated routes
- Hooks: ACL, filter, validation, decoration, and persistence hooks
- Validation: built-in schemas and custom validator adapters
- OpenAPI: generated spec routes, Swagger UI, and custom schema metadata
- Advanced: lower-level types, enums, symbols, and validation helpers
- Processors: document processing helpers