vimcord 1.0.46 → 1.0.48

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
@@ -1787,7 +1787,7 @@ var VimcordErrorHandler = class {
1787
1787
  var import_chalk2 = __toESM(require("chalk"));
1788
1788
 
1789
1789
  // package.json
1790
- var version = "1.0.45";
1790
+ var version = "1.0.48";
1791
1791
 
1792
1792
  // src/client/vimcord.logger.ts
1793
1793
  var clientLoggerFactory = (client) => new Logger({ prefixEmoji: "\u26A1", prefix: `vimcord (i${client.clientId})` }).extend({
@@ -3104,10 +3104,10 @@ var MongoSchemaBuilder = class _MongoSchemaBuilder {
3104
3104
  this.globalPlugins.push(plugin);
3105
3105
  }
3106
3106
  constructor(collection, definition, options = {}) {
3107
- const { instanceId = 0 } = options;
3107
+ const { instanceId = 0, ...schemaOptions } = options;
3108
3108
  this.instanceId = instanceId;
3109
3109
  this.collection = collection;
3110
- this.schema = new import_mongoose2.Schema(definition, { versionKey: false });
3110
+ this.schema = new import_mongoose2.Schema(definition, { versionKey: false, ...schemaOptions });
3111
3111
  this.logger = new Logger({
3112
3112
  prefixEmoji: "\u{1F96D}",
3113
3113
  prefix: `MongoSchema (i${instanceId}) [${collection}]`,
@@ -3159,7 +3159,7 @@ var MongoSchemaBuilder = class _MongoSchemaBuilder {
3159
3159
  * @param maxRetries [default: 3]
3160
3160
  */
3161
3161
  async execute(fn, maxRetries = 3) {
3162
- return await import_qznt6.$.async.retry(
3162
+ return (0, import_qznt6.retry)(
3163
3163
  async () => {
3164
3164
  const model = await this.getModel();
3165
3165
  return await fn(model);
@@ -3168,19 +3168,19 @@ var MongoSchemaBuilder = class _MongoSchemaBuilder {
3168
3168
  );
3169
3169
  }
3170
3170
  async startSession(options) {
3171
- return await this.execute(async () => {
3171
+ return this.execute(async () => {
3172
3172
  if (!this.db) throw new Error("No database instance found");
3173
3173
  return await this.db.startSession(options);
3174
3174
  });
3175
3175
  }
3176
3176
  async useTransaction(fn) {
3177
- return await this.execute(async (model) => {
3177
+ return this.execute(async (model) => {
3178
3178
  if (!this.db) throw new Error("No database instance found");
3179
3179
  return await this.db.useTransaction((session) => fn(session, model));
3180
3180
  });
3181
3181
  }
3182
3182
  async createHexId(bytes, path2, maxRetries = 10) {
3183
- return await this.execute(async (model) => {
3183
+ return this.execute(async (model) => {
3184
3184
  const createHex = () => (0, import_node_crypto4.randomBytes)(bytes).toString("hex");
3185
3185
  let id = createHex();
3186
3186
  let tries = 0;
@@ -3193,57 +3193,57 @@ var MongoSchemaBuilder = class _MongoSchemaBuilder {
3193
3193
  });
3194
3194
  }
3195
3195
  async count(filter, options) {
3196
- return await this.execute(async (model) => model.countDocuments(filter, options));
3196
+ return this.execute(async (model) => model.countDocuments(filter, options));
3197
3197
  }
3198
3198
  async exists(filter) {
3199
- return await this.execute(async (model) => !!await model.exists(filter));
3199
+ return this.execute(async (model) => !!await model.exists(filter));
3200
3200
  }
3201
3201
  async create(query, options) {
3202
- return await this.execute(async (model) => model.create(query, options));
3202
+ return this.execute(async (model) => model.create(query, options));
3203
3203
  }
3204
3204
  async upsert(filter, query, options) {
3205
- return await this.execute(
3206
- async (model) => model.findOneAndUpdate(filter, query, { ...options, upsert: true, new: true })
3205
+ return this.execute(
3206
+ async (model) => model.findOneAndUpdate(filter, query, { returnDocument: "after", ...options, upsert: true })
3207
3207
  );
3208
3208
  }
3209
3209
  async delete(filter, options) {
3210
- return await this.execute(async (model) => model.deleteOne(filter, options));
3210
+ return this.execute(async (model) => model.deleteOne(filter, options));
3211
3211
  }
3212
3212
  async deleteAll(filter, options) {
3213
- return await this.execute(async (model) => model.deleteMany(filter, options));
3213
+ return this.execute(async (model) => model.deleteMany(filter, options));
3214
3214
  }
3215
3215
  async distinct(key, filter, options) {
3216
- return await this.execute(async (model) => model.distinct(key, filter, options));
3216
+ return this.execute(async (model) => model.distinct(key, filter, options));
3217
3217
  }
3218
3218
  async fetch(filter, projection, options) {
3219
- return await this.execute(
3219
+ const result = await this.execute(
3220
3220
  async (model) => model.findOne(filter, projection, { ...options, lean: options?.lean ?? true })
3221
3221
  );
3222
+ if (options?.required && !result) throw new Error("Document not found");
3223
+ return result;
3222
3224
  }
3223
3225
  async fetchAll(filter = {}, projection, options) {
3224
- return await this.execute(
3225
- async (model) => model.find(filter, projection, { ...options, lean: options?.lean ?? true })
3226
- );
3226
+ return this.execute(async (model) => model.find(filter, projection, { ...options, lean: options?.lean ?? true }));
3227
3227
  }
3228
3228
  async update(filter, update, options) {
3229
- return await this.execute(
3229
+ return this.execute(
3230
3230
  async (model) => model.findOneAndUpdate(filter, update, { ...options, lean: options?.lean ?? true })
3231
3231
  );
3232
3232
  }
3233
3233
  async updateAll(filter, update, options) {
3234
- return await this.execute(async (model) => model.updateMany(filter, update, options));
3234
+ return this.execute(async (model) => model.updateMany(filter, update, options));
3235
3235
  }
3236
3236
  async aggregate(pipeline, options) {
3237
- return await this.execute(async (model) => {
3237
+ return this.execute(async (model) => {
3238
3238
  const result = await model.aggregate(pipeline, options);
3239
3239
  return result?.length ? result : [];
3240
3240
  });
3241
3241
  }
3242
3242
  async bulkWrite(ops, options) {
3243
- return await this.execute(async (model) => model.bulkWrite(ops, options));
3243
+ return this.execute(async (model) => model.bulkWrite(ops, options));
3244
3244
  }
3245
3245
  async bulkSave(docs, options) {
3246
- return await this.execute(async (model) => model.bulkSave(docs, options));
3246
+ return this.execute(async (model) => model.bulkSave(docs, options));
3247
3247
  }
3248
3248
  };
3249
3249