@lenne.tech/nest-server 11.23.0 → 11.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CLAUDE.md CHANGED
@@ -207,20 +207,39 @@ Details: [`docs/native-driver-security.md`](docs/native-driver-security.md)
207
207
 
208
208
  The `process()` pipeline (prepareInput → checkRights → serviceFunc → processFieldSelection → prepareOutput → checkRights) adds memory overhead per call through object cloning, Mongoose hydration, and populate operations. For typical API usage this is negligible, but it can become significant in:
209
209
 
210
- - **High-frequency operations** (e.g. monitor checks running every 10-60 seconds)
210
+ - **High-frequency operations** (e.g. monitor checks running every 10-60 seconds per monitor)
211
211
  - **Service cascades** (Service A → Service B → Service C, each going through process())
212
212
  - **Populate chains** (3-5 levels of nested population)
213
213
 
214
214
  **If a project experiences memory issues under high traffic**, check whether `process()` wrapping is the cause. Alternatives that preserve security:
215
215
 
216
- | Instead of | Use | Security |
217
- |-----------|-----|----------|
218
- | `CrudService.create(input)` | `Model.insertMany([input])` — triggers all Mongoose plugins | Tenant, Audit, RoleGuard, Password all active |
219
- | `CrudService.update(id, input)` | `Model.findByIdAndUpdate(id, input)` — triggers all Mongoose plugins | Tenant filter, Audit, RoleGuard all active |
220
- | `CrudService.updateForce(id, input)` | `Model.findByIdAndUpdate(id, { $set: input }).lean()` for system-internal updates | Plugins active, no process() overhead |
216
+ | Instead of | Use | Speed | Memory | Security |
217
+ |-----------|-----|-------|--------|----------|
218
+ | `CrudService.create(input)` | `Model.create(input)` — fastest for single docs | 0.19ms | 98 KB | All plugins active |
219
+ | `CrudService.create(input)` (batch N) | `Model.insertMany(docs)` — fastest for N>1 docs | 0.89ms/20 | 196 KB/20 | All plugins active |
220
+ | `CrudService.update(id, input)` | `Model.findByIdAndUpdate(id, input).lean()` | 0.16ms | 64 KB | All plugins active |
221
+ | `CrudService.get(id)` / `getForce(id)` | `Model.findById(id).lean()` — 5x less memory | 0.33ms | 51 KB | Tenant filter active |
222
+
223
+ > **Note:** `new Model().save()` (0.57ms, 867 KB) is 3x slower and 9x more memory than `Model.create()`.
224
+ > `findById().lean()` is 2x slower than hydrated `findById()` but uses 5x less memory — prefer lean in high-frequency paths where memory stability matters more than per-call latency.
225
+ > `Model.create()` internally calls `new Model().save()` but is optimized by Mongoose — it triggers all `pre('save')` hooks (Tenant, Audit, RoleGuard, Password).
221
226
 
222
227
  **NEVER** bypass Mongoose entirely via `collection.*` — see section above. The CheckSecurityInterceptor acts as a safety net on HTTP responses regardless of how data was written.
223
228
 
229
+ ### High-Frequency Path Design Rules
230
+
231
+ These rules apply when building features that execute many times per minute (monitoring, metrics, queue processors):
232
+
233
+ 1. **`Model.create(doc)` over `new Model().save()`** for single documents — `create()` is 3x faster (0.19ms vs 0.57ms) and uses 9x less memory (98 KB vs 867 KB). For batch inserts (N>1), use `Model.insertMany(docs)` — a single call with N documents is 2.5x faster than N parallel `save()` calls.
234
+
235
+ 2. **`Model.findById().lean()` over `getForce()`** for read-only lookups in high-frequency paths — lean uses 5x less memory (51 KB vs 250 KB) but is 2x slower per call (0.33ms vs 0.16ms). In hot paths, the memory savings outweigh the latency cost because reduced GC pressure improves overall throughput. For low-frequency paths, hydrated `findById()` is faster.
236
+
237
+ 3. **Defer complex logic to cron/queue** — high-frequency paths should only write data (checks, metrics). Processing that data (incident creation, notifications, escalation) belongs in low-frequency cron jobs or separate queue processors that run in bounded batches.
238
+
239
+ 4. **Avoid service cascades in hot paths** — if Service A calls Service B which calls Service C, each with `process()`, the objects from all three levels live in the heap simultaneously. In hot paths, call Mongoose directly instead of going through other services.
240
+
241
+ 5. **WebSocket emits should use lean data** — `emitUpdated()` with `getForce()` triggers a full `process()` pipeline per emit. Use `Model.findById().lean()` instead — WebSocket clients receive JSON, not Mongoose Documents.
242
+
224
243
  Details: [`docs/process-performance-optimization.md`](docs/process-performance-optimization.md)
225
244
 
226
245
  ## In-Depth Documentation
package/FRAMEWORK-API.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @lenne.tech/nest-server — Framework API Reference
2
2
 
3
- > Auto-generated from source code on 2026-04-07 (v11.23.0)
3
+ > Auto-generated from source code on 2026-04-07 (v11.23.1)
4
4
  > File: `FRAMEWORK-API.md` — compact, machine-readable API surface for Claude Code
5
5
 
6
6
  ## CoreModule.forRoot()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "11.23.0",
3
+ "version": "11.23.1",
4
4
  "description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
5
5
  "keywords": [
6
6
  "node",