vimcord 1.0.47 → 1.0.49
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 +28 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +9 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +32 -34
- package/dist/index.js.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/package.json +8 -3
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.
|
|
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({
|
|
@@ -3072,7 +3072,6 @@ var MongoDatabase = class _MongoDatabase {
|
|
|
3072
3072
|
|
|
3073
3073
|
// src/db/mongo/mongoSchema.builder.ts
|
|
3074
3074
|
var import_mongoose2 = require("mongoose");
|
|
3075
|
-
var import_node_crypto4 = require("crypto");
|
|
3076
3075
|
var import_qznt6 = require("qznt");
|
|
3077
3076
|
try {
|
|
3078
3077
|
import("mongoose");
|
|
@@ -3159,7 +3158,7 @@ var MongoSchemaBuilder = class _MongoSchemaBuilder {
|
|
|
3159
3158
|
* @param maxRetries [default: 3]
|
|
3160
3159
|
*/
|
|
3161
3160
|
async execute(fn, maxRetries = 3) {
|
|
3162
|
-
return
|
|
3161
|
+
return (0, import_qznt6.retry)(
|
|
3163
3162
|
async () => {
|
|
3164
3163
|
const model = await this.getModel();
|
|
3165
3164
|
return await fn(model);
|
|
@@ -3168,82 +3167,81 @@ var MongoSchemaBuilder = class _MongoSchemaBuilder {
|
|
|
3168
3167
|
);
|
|
3169
3168
|
}
|
|
3170
3169
|
async startSession(options) {
|
|
3171
|
-
return
|
|
3170
|
+
return this.execute(async () => {
|
|
3172
3171
|
if (!this.db) throw new Error("No database instance found");
|
|
3173
3172
|
return await this.db.startSession(options);
|
|
3174
3173
|
});
|
|
3175
3174
|
}
|
|
3176
3175
|
async useTransaction(fn) {
|
|
3177
|
-
return
|
|
3176
|
+
return this.execute(async (model) => {
|
|
3178
3177
|
if (!this.db) throw new Error("No database instance found");
|
|
3179
3178
|
return await this.db.useTransaction((session) => fn(session, model));
|
|
3180
3179
|
});
|
|
3181
3180
|
}
|
|
3182
|
-
async
|
|
3183
|
-
return
|
|
3184
|
-
|
|
3185
|
-
let id = createHex();
|
|
3181
|
+
async createUniqueId(collisionPath, fn, maxRetries = 10) {
|
|
3182
|
+
return this.execute(async (model) => {
|
|
3183
|
+
let id;
|
|
3186
3184
|
let tries = 0;
|
|
3187
|
-
|
|
3188
|
-
if (tries >= maxRetries) throw Error(`Failed to generate a unique
|
|
3189
|
-
id =
|
|
3185
|
+
do {
|
|
3186
|
+
if (tries >= maxRetries) throw new Error(`Failed to generate a unique ID after ${tries} attempt(s)`);
|
|
3187
|
+
id = fn();
|
|
3190
3188
|
tries++;
|
|
3191
|
-
}
|
|
3189
|
+
} while (await model.exists({ [collisionPath]: id }));
|
|
3192
3190
|
return id;
|
|
3193
3191
|
});
|
|
3194
3192
|
}
|
|
3195
3193
|
async count(filter, options) {
|
|
3196
|
-
return
|
|
3194
|
+
return this.execute(async (model) => model.countDocuments(filter, options));
|
|
3197
3195
|
}
|
|
3198
3196
|
async exists(filter) {
|
|
3199
|
-
return
|
|
3197
|
+
return this.execute(async (model) => !!await model.exists(filter));
|
|
3200
3198
|
}
|
|
3201
3199
|
async create(query, options) {
|
|
3202
|
-
return
|
|
3200
|
+
return this.execute(async (model) => model.create(query, options));
|
|
3203
3201
|
}
|
|
3204
3202
|
async upsert(filter, query, options) {
|
|
3205
|
-
return
|
|
3206
|
-
async (model) => model.findOneAndUpdate(filter, query, { ...options, upsert: true
|
|
3203
|
+
return this.execute(
|
|
3204
|
+
async (model) => model.findOneAndUpdate(filter, query, { returnDocument: "after", ...options, upsert: true })
|
|
3207
3205
|
);
|
|
3208
3206
|
}
|
|
3209
3207
|
async delete(filter, options) {
|
|
3210
|
-
return
|
|
3208
|
+
return this.execute(async (model) => model.deleteOne(filter, options));
|
|
3211
3209
|
}
|
|
3212
3210
|
async deleteAll(filter, options) {
|
|
3213
|
-
return
|
|
3211
|
+
return this.execute(async (model) => model.deleteMany(filter, options));
|
|
3214
3212
|
}
|
|
3215
3213
|
async distinct(key, filter, options) {
|
|
3216
|
-
return
|
|
3214
|
+
return this.execute(async (model) => model.distinct(key, filter, options));
|
|
3217
3215
|
}
|
|
3218
3216
|
async fetch(filter, projection, options) {
|
|
3219
|
-
|
|
3217
|
+
const result = await this.execute(
|
|
3220
3218
|
async (model) => model.findOne(filter, projection, { ...options, lean: options?.lean ?? true })
|
|
3221
3219
|
);
|
|
3220
|
+
if (options?.required && !result) throw new Error("Document not found");
|
|
3221
|
+
return result;
|
|
3222
3222
|
}
|
|
3223
3223
|
async fetchAll(filter = {}, projection, options) {
|
|
3224
|
-
return
|
|
3225
|
-
async (model) => model.find(filter, projection, { ...options, lean: options?.lean ?? true })
|
|
3226
|
-
);
|
|
3224
|
+
return this.execute(async (model) => model.find(filter, projection, { ...options, lean: options?.lean ?? true }));
|
|
3227
3225
|
}
|
|
3228
3226
|
async update(filter, update, options) {
|
|
3229
|
-
return
|
|
3227
|
+
return this.execute(
|
|
3230
3228
|
async (model) => model.findOneAndUpdate(filter, update, { ...options, lean: options?.lean ?? true })
|
|
3231
3229
|
);
|
|
3232
3230
|
}
|
|
3233
3231
|
async updateAll(filter, update, options) {
|
|
3234
|
-
return
|
|
3232
|
+
return this.execute(async (model) => model.updateMany(filter, update, options));
|
|
3235
3233
|
}
|
|
3236
3234
|
async aggregate(pipeline, options) {
|
|
3237
|
-
return
|
|
3235
|
+
return this.execute(async (model) => {
|
|
3238
3236
|
const result = await model.aggregate(pipeline, options);
|
|
3239
3237
|
return result?.length ? result : [];
|
|
3240
3238
|
});
|
|
3241
3239
|
}
|
|
3242
3240
|
async bulkWrite(ops, options) {
|
|
3243
|
-
return
|
|
3241
|
+
return this.execute(async (model) => model.bulkWrite(ops, options));
|
|
3244
3242
|
}
|
|
3245
3243
|
async bulkSave(docs, options) {
|
|
3246
|
-
return
|
|
3244
|
+
return this.execute(async (model) => model.bulkSave(docs, options));
|
|
3247
3245
|
}
|
|
3248
3246
|
};
|
|
3249
3247
|
|