@lenne.tech/nest-server 11.24.0 → 11.24.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.
@@ -0,0 +1,67 @@
1
+ # Migration Guide: 11.24.0 → 11.24.1
2
+
3
+ ## Overview
4
+
5
+ | Category | Details |
6
+ |----------|---------|
7
+ | **Breaking Changes** | None |
8
+ | **New Features** | `pushToArray()`/`pullFromArray()` now accept `ObjectId` and objects with `id`/`_id` property |
9
+ | **Migration Effort** | 0 minutes (no code changes required) |
10
+
11
+ ---
12
+
13
+ ## Quick Migration
14
+
15
+ No code changes required.
16
+
17
+ ```bash
18
+ # Update package
19
+ pnpm add @lenne.tech/nest-server@11.24.1
20
+
21
+ # Verify build
22
+ pnpm run build
23
+
24
+ # Run tests
25
+ pnpm test
26
+ ```
27
+
28
+ ---
29
+
30
+ ## What's New in 11.24.1
31
+
32
+ ### Flexible `id` Parameter on `pushToArray()` / `pullFromArray()`
33
+
34
+ Both methods now accept `string`, `Types.ObjectId`, or any object with an `id`/`_id` property (e.g. a Mongoose Document). IDs are normalized internally via `getStringIds()`, consistent with the rest of the framework.
35
+
36
+ **Before (11.24.0):** Only `string` was accepted.
37
+ ```typescript
38
+ await this.entityService.pushToArray(entity.id, 'logs', newLog);
39
+ await this.entityService.pullFromArray(entity.id.toString(), 'tags', 'old');
40
+ ```
41
+
42
+ **After (11.24.1):** All ID types work directly.
43
+ ```typescript
44
+ // String (still works)
45
+ await this.entityService.pushToArray('507f1f77bcf86cd799439011', 'logs', newLog);
46
+
47
+ // ObjectId
48
+ await this.entityService.pushToArray(new Types.ObjectId(id), 'logs', newLog);
49
+
50
+ // Object with id property (e.g. Mongoose Document or entity reference)
51
+ await this.entityService.pushToArray(entity, 'logs', newLog);
52
+
53
+ // Same for pullFromArray
54
+ await this.entityService.pullFromArray(entity, 'tags', 'obsolete');
55
+ ```
56
+
57
+ ---
58
+
59
+ ## Compatibility Notes
60
+
61
+ Existing code using `string` IDs continues to work unchanged. The wider type signature is additive — no existing call sites break.
62
+
63
+ ---
64
+
65
+ ## References
66
+
67
+ - [Migration Guide 11.23.x → 11.24.0](./11.23.x-to-11.24.0.md) — Full list of changes in 11.24.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "11.24.0",
3
+ "version": "11.24.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",
@@ -9,6 +9,7 @@ import {
9
9
  Query,
10
10
  QueryFilter,
11
11
  QueryOptions,
12
+ Types,
12
13
  } from 'mongoose';
13
14
 
14
15
  import { FilterArgs } from '../args/filter.args';
@@ -707,13 +708,13 @@ export abstract class CrudService<
707
708
  * await this.pushToArray(id, 'logs', newLog);
708
709
  * await this.pushToArray(id, 'logs', newLog, { $slice: -500 }); // Keep last 500
709
710
  *
710
- * @param id - Document ID
711
+ * @param id - Document ID (string, ObjectId, or object with id/_id property)
711
712
  * @param field - Array field name. MUST be a compile-time constant — never pass user-controlled input.
712
713
  * @param items - Item(s) to append
713
714
  * @param options - MongoDB $push modifiers ($slice, $position, $sort)
714
715
  */
715
716
  async pushToArray(
716
- id: string,
717
+ id: string | Types.ObjectId | { id?: any; _id?: any },
717
718
  field: string,
718
719
  items: any | any[],
719
720
  options?: { $slice?: number; $position?: number; $sort?: Record<string, 1 | -1> },
@@ -727,6 +728,7 @@ export abstract class CrudService<
727
728
  return;
728
729
  }
729
730
 
731
+ const stringId = getStringIds(id);
730
732
  const pushOp: any = { $each: itemsArray };
731
733
  if (options?.$slice !== undefined) {
732
734
  pushOp.$slice = options.$slice;
@@ -739,7 +741,7 @@ export abstract class CrudService<
739
741
  }
740
742
 
741
743
  await this.mainDbModel
742
- .findByIdAndUpdate(id, { $push: { [field]: pushOp } } as any)
744
+ .findByIdAndUpdate(stringId, { $push: { [field]: pushOp } } as any)
743
745
  .lean()
744
746
  .exec();
745
747
  }
@@ -756,17 +758,22 @@ export abstract class CrudService<
756
758
  * // Remove by condition
757
759
  * await this.pullFromArray(id, 'logs', { level: 'DEBUG' });
758
760
  *
759
- * @param id - Document ID
761
+ * @param id - Document ID (string, ObjectId, or object with id/_id property)
760
762
  * @param field - Array field name. MUST be a compile-time constant — never pass user-controlled input.
761
763
  * @param condition - Match condition for removal. MUST be application-controlled.
762
764
  */
763
- async pullFromArray(id: string, field: string, condition: any): Promise<void> {
765
+ async pullFromArray(
766
+ id: string | Types.ObjectId | { id?: any; _id?: any },
767
+ field: string,
768
+ condition: any,
769
+ ): Promise<void> {
764
770
  if (typeof field !== 'string' || field.startsWith('$') || field.includes('\0')) {
765
771
  throw new Error(`pullFromArray: invalid field name "${field}"`);
766
772
  }
767
773
 
774
+ const stringId = getStringIds(id);
768
775
  await this.mainDbModel
769
- .findByIdAndUpdate(id, { $pull: { [field]: condition } } as any)
776
+ .findByIdAndUpdate(stringId, { $pull: { [field]: condition } } as any)
770
777
  .lean()
771
778
  .exec();
772
779
  }