How granitebps/mongoose-log-history works
mongoose-log-history is a Mongoose audit-history plugin. An application attaches the plugin to a schema; hooks capture create, update, delete, soft-delete, and bulk operations, calculate configured field/array changes and context, then persist audit entries in single or per-model collections. Optional snapshots can be gzip-compressed, and callers can prune retained history or use exported helpers manually. The sampled plugin excerpt is partial, so detailed hook-to-diff dispatch is not fully verified; README capability statements preserve those branches without inventing internal call links.
Main entry points: plugin.ts Model hooks · index.ts Plugin API · schema.ts Log model selection · change-tracking.ts Field and array diffs
Components 15
Mongoose integration
- Plugin API
src/index.ts - Model hooks
src/plugin.ts
Change capture
- CRUD and bulk capture
src/plugin.ts - Soft-delete detection
src/plugin.ts - Field and array diffs
src/change-tracking.ts - Context and user data
src/plugin.ts
History storage
- Log entry schema
src/schema.ts - Log model selection
src/schema.ts - MongoDB log collections
Helpers and API
- Value utilities
src/utils.ts - Snapshot compression
src/compression.ts - History pruning
src/prune.ts - Manual logging helpers
src/plugin.ts - Typed configuration
src/types.ts
Other components
- Application
Connections 15
- Application → Plugin API: applies plugin
README.md - Plugin API → Model hooks: exports plugin
src/index.ts - Model hooks → CRUD and bulk capture: registers hooks
src/plugin.ts - Model hooks → Log model selection: selects log model
src/plugin.ts - CRUD and bulk capture → Soft-delete detection: detects transition
src/plugin.ts - CRUD and bulk capture → Field and array diffs: calculates changes
src/plugin.ts - CRUD and bulk capture → Context and user data: extracts metadata
src/plugin.ts - Field and array diffs → Value utilities: uses utilities
src/change-tracking.ts - Model hooks → Snapshot compression: compresses snapshots
src/plugin.ts - Model hooks → Log entry schema: builds entries
src/plugin.ts - Log model selection → MongoDB log collections: models collections
src/schema.ts - Application → History pruning: requests pruning
README.md - History pruning → Log model selection: selects history model
src/prune.ts - Application → Manual logging helpers: calls helpers
README.md - Plugin API → Typed configuration: exports types
src/index.ts