elseware-nodejs 1.8.1 → 1.8.3

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
@@ -344,7 +344,8 @@ function loadEnv(options) {
344
344
  handleError(result.error);
345
345
  }
346
346
  logger.success("Env Configurations validated");
347
- return options.transform ? options.transform(result.data) : result.data;
347
+ const env = result.data;
348
+ return options.transform ? options.transform(env) : env;
348
349
  }
349
350
  function handleError(error) {
350
351
  logger.danger("Env validation failed");
@@ -354,20 +355,17 @@ function handleError(error) {
354
355
  const rawValue = key !== "unknown" ? process.env[key] : void 0;
355
356
  const isSecret = key.toLowerCase().includes("secret");
356
357
  const safeValue = isSecret ? "***" : rawValue;
357
- const messageParts = [
358
+ const message = [
358
359
  `message: ${err.message}`,
359
360
  `code: ${err.code}`,
360
361
  rawValue !== void 0 ? `value: ${JSON.stringify(safeValue)}` : null
361
- ].filter(Boolean);
362
- const fullMessage = messageParts.join(" | ");
362
+ ].filter(Boolean).join(" | ");
363
363
  if (!grouped[key]) grouped[key] = [];
364
- grouped[key].push(fullMessage);
364
+ grouped[key].push(message);
365
365
  });
366
366
  Object.entries(grouped).forEach(([key, messages]) => {
367
- logger.info(`${key}`);
368
- messages.forEach((msg) => {
369
- logger.log(` - ${msg}`);
370
- });
367
+ logger.info(key);
368
+ messages.forEach((msg) => logger.log(` - ${msg}`));
371
369
  });
372
370
  logger.danger("Application startup aborted!");
373
371
  process.exit(1);
@@ -5177,81 +5175,98 @@ var validate = (schema) => (req, _res, next) => {
5177
5175
  next();
5178
5176
  };
5179
5177
 
5180
- // src/repositories/mongo.repository.ts
5178
+ // src/repositories/providers/mongo.repository.ts
5181
5179
  var BaseMongoRepository = class {
5182
5180
  model;
5183
5181
  constructor(model) {
5184
5182
  this.model = model;
5185
5183
  }
5186
- async findAll(filter = {}, options = {}) {
5187
- let query = this.model.find(filter);
5188
- if (options.select) query = query.select(options.select);
5184
+ buildSelect(select) {
5185
+ if (!select) return void 0;
5186
+ if (Array.isArray(select)) {
5187
+ return select.join(" ");
5188
+ }
5189
+ return select;
5190
+ }
5191
+ applyQueryOptions(query, options) {
5192
+ const select = this.buildSelect(options.select);
5193
+ if (select) query = query.select(select);
5189
5194
  if (options.sort) query = query.sort(options.sort);
5190
5195
  if (options.limit) query = query.limit(options.limit);
5191
5196
  if (options.skip) query = query.skip(options.skip);
5192
- return query.exec();
5197
+ return query;
5193
5198
  }
5194
- async findById(id) {
5195
- return this.model.findById(id).exec();
5196
- }
5197
- async findOne(filter) {
5198
- return this.model.findOne(filter).exec();
5199
+ toPlain(doc) {
5200
+ return doc.toObject();
5199
5201
  }
5202
+ /**
5203
+ * Create
5204
+ */
5200
5205
  async create(data) {
5201
- return this.model.create(data);
5206
+ const doc = await this.model.create(data);
5207
+ return this.toPlain(doc);
5202
5208
  }
5203
- async updateById(id, data) {
5204
- return this.model.findByIdAndUpdate(id, data, {
5205
- new: true,
5206
- runValidators: true
5207
- }).exec();
5209
+ async createMany(data) {
5210
+ const docs = await this.model.insertMany(data);
5211
+ return docs.map((doc) => this.toPlain(doc));
5208
5212
  }
5209
- async deleteById(id) {
5210
- return this.model.findByIdAndDelete(id).exec();
5213
+ /**
5214
+ * Read
5215
+ */
5216
+ async findAll(filter = {}, options = {}) {
5217
+ let query = this.model.find(filter);
5218
+ query = this.applyQueryOptions(query, options);
5219
+ return query.exec();
5211
5220
  }
5212
- };
5213
-
5214
- // src/repositories/postgres.repository.ts
5215
- var BasePostgresRepository = class {
5216
- model;
5217
- // prisma model (e.g. prisma.testPost)
5218
- constructor(model) {
5219
- this.model = model;
5221
+ async findById(id, options = {}) {
5222
+ let query = this.model.findById(id);
5223
+ query = this.applyQueryOptions(query, options);
5224
+ return query.exec();
5220
5225
  }
5221
- async findAll(filter = {}, options = {}) {
5222
- return this.model.findMany({
5223
- where: filter,
5224
- select: options.select,
5225
- orderBy: options.sort,
5226
- take: options.limit,
5227
- skip: options.skip
5228
- });
5226
+ async findOne(filter = {}, options = {}) {
5227
+ let query = this.model.findOne(filter);
5228
+ query = this.applyQueryOptions(query, options);
5229
+ return query.exec();
5229
5230
  }
5230
- async findById(id) {
5231
- return this.model.findUnique({
5232
- where: { id }
5233
- });
5231
+ async findManyByIds(ids, options = {}) {
5232
+ let query = this.model.find({ _id: { $in: ids } });
5233
+ query = this.applyQueryOptions(query, options);
5234
+ return query.exec();
5234
5235
  }
5235
- async findOne(filter) {
5236
- return this.model.findFirst({
5237
- where: filter
5238
- });
5236
+ async count(filter) {
5237
+ return this.model.countDocuments(filter).exec();
5239
5238
  }
5240
- async create(data) {
5241
- return this.model.create({
5242
- data
5243
- });
5239
+ async exists(filter) {
5240
+ const result = await this.model.exists(filter);
5241
+ return result !== null;
5244
5242
  }
5245
- async updateById(id, data) {
5246
- return this.model.update({
5247
- where: { id },
5248
- data
5249
- });
5243
+ /**
5244
+ * Update
5245
+ */
5246
+ async updateById(id, data, options) {
5247
+ const finalOptions = { new: true, runValidators: true, ...options };
5248
+ return this.model.findByIdAndUpdate(id, data, finalOptions).exec();
5249
+ }
5250
+ async updateOne(filter, data, options) {
5251
+ const finalOptions = { new: true, runValidators: true, ...options };
5252
+ return this.model.findOneAndUpdate(filter, data, finalOptions).exec();
5250
5253
  }
5254
+ async updateMany(filter, data) {
5255
+ const result = await this.model.updateMany(filter, data).exec();
5256
+ return result.modifiedCount;
5257
+ }
5258
+ /**
5259
+ * Delete
5260
+ */
5251
5261
  async deleteById(id) {
5252
- return this.model.delete({
5253
- where: { id }
5254
- });
5262
+ return this.model.findByIdAndDelete(id).exec();
5263
+ }
5264
+ async deleteOne(filter) {
5265
+ return this.model.findOneAndDelete(filter).exec();
5266
+ }
5267
+ async deleteMany(filter) {
5268
+ const result = await this.model.deleteMany(filter).exec();
5269
+ return result.deletedCount ?? 0;
5255
5270
  }
5256
5271
  };
5257
5272
  var AzureBlobStorageService = class {
@@ -5717,7 +5732,6 @@ exports.AzureBlobStorageService = AzureBlobStorageService;
5717
5732
  exports.BPlusTree = BPlusTree;
5718
5733
  exports.BTree = BTree;
5719
5734
  exports.BaseMongoRepository = BaseMongoRepository;
5720
- exports.BasePostgresRepository = BasePostgresRepository;
5721
5735
  exports.BinaryHeap = BinaryHeap;
5722
5736
  exports.BinarySearchTree = BinarySearchTree;
5723
5737
  exports.BinaryTree = BinaryTree;