connectfy-shared 0.0.89 → 0.0.90

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/dist/index.cjs CHANGED
@@ -11360,14 +11360,19 @@ var BaseRepository = class {
11360
11360
  // CREATE AND CREATE MANY FUNCTIONS
11361
11361
  // ================================================
11362
11362
  async create(data, opts) {
11363
+ const virtuals = opts?.lean ?? true;
11363
11364
  const newData = new this.model(data);
11364
11365
  let saved = await newData.save();
11365
11366
  if (opts?.populate) {
11366
11367
  saved = await saved.populate(opts.populate);
11367
11368
  }
11368
- return saved.toObject({ versionKey: false });
11369
+ return saved.toObject({
11370
+ versionKey: false,
11371
+ virtuals
11372
+ });
11369
11373
  }
11370
11374
  async createMany(data, opts) {
11375
+ const virtuals = opts?.lean ?? true;
11371
11376
  const inserted = await this.model.insertMany(data, {
11372
11377
  lean: true,
11373
11378
  ordered: false
@@ -11376,9 +11381,14 @@ var BaseRepository = class {
11376
11381
  const ids = inserted.map((doc) => doc._id);
11377
11382
  const populated = await this.model.find({ _id: { $in: ids } }).populate(
11378
11383
  opts.populate
11379
- ).lean().exec();
11384
+ ).lean({ virtuals }).exec();
11380
11385
  return populated;
11381
11386
  }
11387
+ if (virtuals) {
11388
+ return inserted.map(
11389
+ (doc) => doc.toObject({ versionKey: false, virtuals })
11390
+ );
11391
+ }
11382
11392
  return inserted;
11383
11393
  }
11384
11394
  // ================================================
@@ -11390,7 +11400,7 @@ var BaseRepository = class {
11390
11400
  new: opts?.new ?? true,
11391
11401
  runValidators: opts?.runValidators ?? true,
11392
11402
  populate: opts?.populate ?? [],
11393
- lean: opts?.lean ?? false
11403
+ lean: opts?.lean ?? true ? { virtuals: true } : false
11394
11404
  };
11395
11405
  const updatedData = await this.model.findOneAndUpdate(
11396
11406
  query,
@@ -11439,24 +11449,27 @@ var BaseRepository = class {
11439
11449
  // ================================================
11440
11450
  // FINE ONE AND FIND MANY FUNCTIONS
11441
11451
  // ================================================
11442
- async findOne(params = {}) {
11452
+ async findOne(params = {}, opts) {
11443
11453
  const {
11444
11454
  query = {},
11445
11455
  fields = "",
11446
11456
  sort = { createdAt: -1 },
11447
11457
  populate = []
11448
11458
  } = params;
11449
- return await this.model.findOne(query).select(fields).sort(sort).populate(populate).lean().exec();
11459
+ const virtuals = opts?.lean ?? true;
11460
+ return await this.model.findOne(query).select(fields).sort(sort).populate(populate).lean({ virtuals }).exec();
11450
11461
  }
11451
- async findOneById(_id, params = {}) {
11462
+ async findOneById(_id, params = {}, opts) {
11452
11463
  const { fields = "", sort = { createdAt: -1 }, populate = [] } = params;
11453
- return await this.model.findOne({ _id }).select(fields).sort(sort).populate(populate).lean().exec();
11464
+ const virtuals = opts?.lean ?? true;
11465
+ return await this.model.findOne({ _id }).select(fields).sort(sort).populate(populate).lean({ virtuals }).exec();
11454
11466
  }
11455
- async findOneByUserId(userId, params = {}) {
11467
+ async findOneByUserId(userId, params = {}, opts) {
11456
11468
  const { fields = "", sort = { createdAt: -1 }, populate = [] } = params;
11457
- return await this.model.findOne({ userId }).select(fields).sort(sort).populate(populate).lean().exec();
11469
+ const virtuals = opts?.lean ?? true;
11470
+ return await this.model.findOne({ userId }).select(fields).sort(sort).populate(populate).lean({ virtuals }).exec();
11458
11471
  }
11459
- async findMany(params = {}) {
11472
+ async findMany(params = {}, opts) {
11460
11473
  const {
11461
11474
  query = {},
11462
11475
  fields = "",
@@ -11465,16 +11478,18 @@ var BaseRepository = class {
11465
11478
  skip = 0,
11466
11479
  limit = 10
11467
11480
  } = params;
11468
- return await this.model.find(query).select(fields).skip(skip).limit(limit).sort(sort).populate(populate).lean().exec();
11481
+ const virtuals = opts?.lean ?? true;
11482
+ return await this.model.find(query).select(fields).skip(skip).limit(limit).sort(sort).populate(populate).lean({ virtuals }).exec();
11469
11483
  }
11470
- async findAll(params = {}) {
11484
+ async findAll(params = {}, opts) {
11471
11485
  const {
11472
11486
  query = {},
11473
11487
  fields = "",
11474
11488
  sort = { createdAt: -1 },
11475
11489
  populate = []
11476
11490
  } = params;
11477
- return await this.model.find(query).select(fields).sort(sort).populate(populate).lean().exec();
11491
+ const virtuals = opts?.lean ?? true;
11492
+ return await this.model.find(query).select(fields).sort(sort).populate(populate).lean({ virtuals }).exec();
11478
11493
  }
11479
11494
  // ================================================
11480
11495
  // EXIST AND COUNT FUNCTIONS
package/dist/index.d.cts CHANGED
@@ -745,11 +745,11 @@ declare abstract class BaseRepository<TDocument extends Document, TInterface ext
745
745
  remove(data: BaseRemoveDto, opts?: IBaseRepositoryRemoveOptions): Promise<TInterface>;
746
746
  removeOne(query: Record<string, any>, opts?: IBaseRepositoryRemoveOptions): Promise<TInterface>;
747
747
  removeMany(data: BaseRemoveAllDto, opts?: IBaseRepositoryRemoveOptions): Promise<TInterface[]>;
748
- findOne(params?: BaseFindDto): Promise<TInterface | null>;
749
- findOneById(_id: string, params?: BaseFindDto): Promise<TInterface | null>;
750
- findOneByUserId(userId: string, params?: BaseFindDto): Promise<TInterface | null>;
751
- findMany(params?: BaseFindDto): Promise<TInterface[]>;
752
- findAll(params?: BaseFindDto): Promise<TInterface[]>;
748
+ findOne(params?: BaseFindDto, opts?: IBaseRepositoryOptions): Promise<TInterface | null>;
749
+ findOneById(_id: string, params?: BaseFindDto, opts?: IBaseRepositoryOptions): Promise<TInterface | null>;
750
+ findOneByUserId(userId: string, params?: BaseFindDto, opts?: IBaseRepositoryOptions): Promise<TInterface | null>;
751
+ findMany(params?: BaseFindDto, opts?: IBaseRepositoryOptions): Promise<TInterface[]>;
752
+ findAll(params?: BaseFindDto, opts?: IBaseRepositoryOptions): Promise<TInterface[]>;
753
753
  existsByField(query: Record<string, any>): Promise<boolean>;
754
754
  count(query: Record<string, any>): Promise<number>;
755
755
  }
package/dist/index.d.ts CHANGED
@@ -745,11 +745,11 @@ declare abstract class BaseRepository<TDocument extends Document, TInterface ext
745
745
  remove(data: BaseRemoveDto, opts?: IBaseRepositoryRemoveOptions): Promise<TInterface>;
746
746
  removeOne(query: Record<string, any>, opts?: IBaseRepositoryRemoveOptions): Promise<TInterface>;
747
747
  removeMany(data: BaseRemoveAllDto, opts?: IBaseRepositoryRemoveOptions): Promise<TInterface[]>;
748
- findOne(params?: BaseFindDto): Promise<TInterface | null>;
749
- findOneById(_id: string, params?: BaseFindDto): Promise<TInterface | null>;
750
- findOneByUserId(userId: string, params?: BaseFindDto): Promise<TInterface | null>;
751
- findMany(params?: BaseFindDto): Promise<TInterface[]>;
752
- findAll(params?: BaseFindDto): Promise<TInterface[]>;
748
+ findOne(params?: BaseFindDto, opts?: IBaseRepositoryOptions): Promise<TInterface | null>;
749
+ findOneById(_id: string, params?: BaseFindDto, opts?: IBaseRepositoryOptions): Promise<TInterface | null>;
750
+ findOneByUserId(userId: string, params?: BaseFindDto, opts?: IBaseRepositoryOptions): Promise<TInterface | null>;
751
+ findMany(params?: BaseFindDto, opts?: IBaseRepositoryOptions): Promise<TInterface[]>;
752
+ findAll(params?: BaseFindDto, opts?: IBaseRepositoryOptions): Promise<TInterface[]>;
753
753
  existsByField(query: Record<string, any>): Promise<boolean>;
754
754
  count(query: Record<string, any>): Promise<number>;
755
755
  }
package/dist/index.mjs CHANGED
@@ -11317,14 +11317,19 @@ var BaseRepository = class {
11317
11317
  // CREATE AND CREATE MANY FUNCTIONS
11318
11318
  // ================================================
11319
11319
  async create(data, opts) {
11320
+ const virtuals = opts?.lean ?? true;
11320
11321
  const newData = new this.model(data);
11321
11322
  let saved = await newData.save();
11322
11323
  if (opts?.populate) {
11323
11324
  saved = await saved.populate(opts.populate);
11324
11325
  }
11325
- return saved.toObject({ versionKey: false });
11326
+ return saved.toObject({
11327
+ versionKey: false,
11328
+ virtuals
11329
+ });
11326
11330
  }
11327
11331
  async createMany(data, opts) {
11332
+ const virtuals = opts?.lean ?? true;
11328
11333
  const inserted = await this.model.insertMany(data, {
11329
11334
  lean: true,
11330
11335
  ordered: false
@@ -11333,9 +11338,14 @@ var BaseRepository = class {
11333
11338
  const ids = inserted.map((doc) => doc._id);
11334
11339
  const populated = await this.model.find({ _id: { $in: ids } }).populate(
11335
11340
  opts.populate
11336
- ).lean().exec();
11341
+ ).lean({ virtuals }).exec();
11337
11342
  return populated;
11338
11343
  }
11344
+ if (virtuals) {
11345
+ return inserted.map(
11346
+ (doc) => doc.toObject({ versionKey: false, virtuals })
11347
+ );
11348
+ }
11339
11349
  return inserted;
11340
11350
  }
11341
11351
  // ================================================
@@ -11347,7 +11357,7 @@ var BaseRepository = class {
11347
11357
  new: opts?.new ?? true,
11348
11358
  runValidators: opts?.runValidators ?? true,
11349
11359
  populate: opts?.populate ?? [],
11350
- lean: opts?.lean ?? false
11360
+ lean: opts?.lean ?? true ? { virtuals: true } : false
11351
11361
  };
11352
11362
  const updatedData = await this.model.findOneAndUpdate(
11353
11363
  query,
@@ -11396,24 +11406,27 @@ var BaseRepository = class {
11396
11406
  // ================================================
11397
11407
  // FINE ONE AND FIND MANY FUNCTIONS
11398
11408
  // ================================================
11399
- async findOne(params = {}) {
11409
+ async findOne(params = {}, opts) {
11400
11410
  const {
11401
11411
  query = {},
11402
11412
  fields = "",
11403
11413
  sort = { createdAt: -1 },
11404
11414
  populate = []
11405
11415
  } = params;
11406
- return await this.model.findOne(query).select(fields).sort(sort).populate(populate).lean().exec();
11416
+ const virtuals = opts?.lean ?? true;
11417
+ return await this.model.findOne(query).select(fields).sort(sort).populate(populate).lean({ virtuals }).exec();
11407
11418
  }
11408
- async findOneById(_id, params = {}) {
11419
+ async findOneById(_id, params = {}, opts) {
11409
11420
  const { fields = "", sort = { createdAt: -1 }, populate = [] } = params;
11410
- return await this.model.findOne({ _id }).select(fields).sort(sort).populate(populate).lean().exec();
11421
+ const virtuals = opts?.lean ?? true;
11422
+ return await this.model.findOne({ _id }).select(fields).sort(sort).populate(populate).lean({ virtuals }).exec();
11411
11423
  }
11412
- async findOneByUserId(userId, params = {}) {
11424
+ async findOneByUserId(userId, params = {}, opts) {
11413
11425
  const { fields = "", sort = { createdAt: -1 }, populate = [] } = params;
11414
- return await this.model.findOne({ userId }).select(fields).sort(sort).populate(populate).lean().exec();
11426
+ const virtuals = opts?.lean ?? true;
11427
+ return await this.model.findOne({ userId }).select(fields).sort(sort).populate(populate).lean({ virtuals }).exec();
11415
11428
  }
11416
- async findMany(params = {}) {
11429
+ async findMany(params = {}, opts) {
11417
11430
  const {
11418
11431
  query = {},
11419
11432
  fields = "",
@@ -11422,16 +11435,18 @@ var BaseRepository = class {
11422
11435
  skip = 0,
11423
11436
  limit = 10
11424
11437
  } = params;
11425
- return await this.model.find(query).select(fields).skip(skip).limit(limit).sort(sort).populate(populate).lean().exec();
11438
+ const virtuals = opts?.lean ?? true;
11439
+ return await this.model.find(query).select(fields).skip(skip).limit(limit).sort(sort).populate(populate).lean({ virtuals }).exec();
11426
11440
  }
11427
- async findAll(params = {}) {
11441
+ async findAll(params = {}, opts) {
11428
11442
  const {
11429
11443
  query = {},
11430
11444
  fields = "",
11431
11445
  sort = { createdAt: -1 },
11432
11446
  populate = []
11433
11447
  } = params;
11434
- return await this.model.find(query).select(fields).sort(sort).populate(populate).lean().exec();
11448
+ const virtuals = opts?.lean ?? true;
11449
+ return await this.model.find(query).select(fields).sort(sort).populate(populate).lean({ virtuals }).exec();
11435
11450
  }
11436
11451
  // ================================================
11437
11452
  // EXIST AND COUNT FUNCTIONS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "connectfy-shared",
3
- "version": "0.0.89",
3
+ "version": "0.0.90",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {