@nextage/nx-frame-be 1.0.38 → 1.0.39

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.
@@ -289,3 +289,28 @@ it('runs aggregation', () => __awaiter(void 0, void 0, void 0, function* () {
289
289
  expect(data.length).toEqual(1);
290
290
  expect(data[0].count).toEqual(count);
291
291
  }));
292
+ it('bulkWriteVersioned injects version handling on native bulk ops', () => __awaiter(void 0, void 0, void 0, function* () {
293
+ const code = (0, utils_1.uuid)();
294
+ // insertOne without an explicit version -> baseline 0 (same as save())
295
+ yield coded_entity_model_1.ceModel.bulkWriteVersioned([
296
+ { insertOne: { document: { code, name: 'BWV insert', data: { items: [] } } } }
297
+ ]);
298
+ const inserted = yield coded_entity_model_1.ceModel.findOne({ code });
299
+ expect(inserted.version).toEqual(0);
300
+ // updateOne without $inc -> auto +1 (native bulk keeps the query-hook guarantee)
301
+ yield coded_entity_model_1.ceModel.bulkWriteVersioned([
302
+ { updateOne: { filter: { code }, update: { $set: { name: 'BWV update' } } } }
303
+ ]);
304
+ const updated = yield coded_entity_model_1.ceModel.findOne({ code });
305
+ expect(updated.name).toEqual('BWV update');
306
+ expect(updated.version).toEqual(1);
307
+ }));
308
+ it('keeps TDoc-specialised subclasses assignable to BaseModel<any, any, any> (regression: TS2322 from bulkWriteVersioned<TDoc>)', () => {
309
+ // Compile-time guard. `CodedEntity extends BaseModel<..., CodedEntityDoc, ...>` specialises
310
+ // TDoc; if bulkWriteVersioned is typed on AnyBulkWriteOperation<TDoc> (invariant via
311
+ // ReplaceOneModel<TDoc>.filter), the subclass method stops being compatible with
312
+ // BaseModel<any, any, any> and `this` can no longer be passed to a BaseModel<any, any, any>
313
+ // sink -> this is exactly the auth-srv boot failure (user.model.ts KeyOptions.model).
314
+ const sink = (m) => m;
315
+ expect(sink(coded_entity_model_1.ceModel)).toBe(coded_entity_model_1.ceModel);
316
+ });
@@ -252,10 +252,17 @@ export declare class BaseModel<TAttrs, TDoc extends BaseMongoDoc, TMongoModel ex
252
252
  * Upsert ops that do not touch version fall back to $inc (an upsert insert lands at
253
253
  * version 1). Other op kinds (replaceOne, deleteOne, deleteMany) pass through unchanged.
254
254
  *
255
+ * NB: the parameter is intentionally typed on `AnyBulkWriteOperation<any>` (not `<TDoc>`):
256
+ * `AnyBulkWriteOperation<TDoc>` is invariant (via `ReplaceOneModel<TDoc>.filter`), so a
257
+ * `<TDoc>`-typed signature makes each subclass method incompatible with
258
+ * `BaseModel<any, any, any>` and breaks `this`-assignability (e.g. passing `this` to a
259
+ * `BaseModel<any, any, any>` sink). Ops are validated/cast internally, so the loose
260
+ * element type costs nothing.
261
+ *
255
262
  * @param {*} bulkOps
256
263
  * @param {*} options
257
264
  */
258
- bulkWriteVersioned(bulkOps: mongoose.AnyBulkWriteOperation<TDoc>[], options?: mongoose.mongo.BulkWriteOptions): Promise<mongoose.mongo.BulkWriteResult>;
265
+ bulkWriteVersioned(bulkOps: mongoose.AnyBulkWriteOperation<any>[], options?: mongoose.mongo.BulkWriteOptions): Promise<mongoose.mongo.BulkWriteResult>;
259
266
  /**
260
267
  * Inject the version key into a single bulkWrite operation (see bulkWriteVersioned).
261
268
  *
@@ -535,6 +535,13 @@ class BaseModel extends events_1.EventEmitter {
535
535
  * Upsert ops that do not touch version fall back to $inc (an upsert insert lands at
536
536
  * version 1). Other op kinds (replaceOne, deleteOne, deleteMany) pass through unchanged.
537
537
  *
538
+ * NB: the parameter is intentionally typed on `AnyBulkWriteOperation<any>` (not `<TDoc>`):
539
+ * `AnyBulkWriteOperation<TDoc>` is invariant (via `ReplaceOneModel<TDoc>.filter`), so a
540
+ * `<TDoc>`-typed signature makes each subclass method incompatible with
541
+ * `BaseModel<any, any, any>` and breaks `this`-assignability (e.g. passing `this` to a
542
+ * `BaseModel<any, any, any>` sink). Ops are validated/cast internally, so the loose
543
+ * element type costs nothing.
544
+ *
538
545
  * @param {*} bulkOps
539
546
  * @param {*} options
540
547
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextage/nx-frame-be",
3
- "version": "1.0.38",
3
+ "version": "1.0.39",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",