vimcord 1.0.48 → 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.d.mts CHANGED
@@ -2460,7 +2460,7 @@ declare class MongoSchemaBuilder<Definition extends object = any> {
2460
2460
  execute<T extends (model: Model<Definition>) => any>(fn: T, maxRetries?: number): Promise<ExtractReturn<T>>;
2461
2461
  startSession(options?: ClientSessionOptions): Promise<mongo.ClientSession>;
2462
2462
  useTransaction(fn: (session: ClientSession, model: Model<Definition>) => any): Promise<void>;
2463
- createHexId(bytes: number, path: keyof Require_id<Definition>, maxRetries?: number): Promise<string>;
2463
+ createUniqueId(collisionPath: keyof Require_id<Definition>, fn: () => string, maxRetries?: number): Promise<string>;
2464
2464
  count(filter?: RootFilterQuery<Definition>, options?: mongo.CountOptions & MongooseBaseQueryOptions<Definition> & mongo.Abortable): Promise<number>;
2465
2465
  exists(filter: RootFilterQuery<Definition>): Promise<boolean>;
2466
2466
  create(query: Partial<Require_id<Definition>>[], options?: CreateOptions): Promise<(Document<unknown, {}, Definition, {}, {}> & (Require_id<Definition> extends infer T ? T extends Require_id<Definition> ? T extends {
package/dist/index.d.ts CHANGED
@@ -2460,7 +2460,7 @@ declare class MongoSchemaBuilder<Definition extends object = any> {
2460
2460
  execute<T extends (model: Model<Definition>) => any>(fn: T, maxRetries?: number): Promise<ExtractReturn<T>>;
2461
2461
  startSession(options?: ClientSessionOptions): Promise<mongo.ClientSession>;
2462
2462
  useTransaction(fn: (session: ClientSession, model: Model<Definition>) => any): Promise<void>;
2463
- createHexId(bytes: number, path: keyof Require_id<Definition>, maxRetries?: number): Promise<string>;
2463
+ createUniqueId(collisionPath: keyof Require_id<Definition>, fn: () => string, maxRetries?: number): Promise<string>;
2464
2464
  count(filter?: RootFilterQuery<Definition>, options?: mongo.CountOptions & MongooseBaseQueryOptions<Definition> & mongo.Abortable): Promise<number>;
2465
2465
  exists(filter: RootFilterQuery<Definition>): Promise<boolean>;
2466
2466
  create(query: Partial<Require_id<Definition>>[], options?: CreateOptions): Promise<(Document<unknown, {}, Definition, {}, {}> & (Require_id<Definition> extends infer T ? T extends Require_id<Definition> ? T extends {
package/dist/index.js CHANGED
@@ -2980,7 +2980,6 @@ var MongoDatabase = class _MongoDatabase {
2980
2980
  import {
2981
2981
  Schema
2982
2982
  } from "mongoose";
2983
- import { randomBytes } from "crypto";
2984
2983
  import { retry } from "qznt";
2985
2984
  try {
2986
2985
  import("mongoose");
@@ -3087,16 +3086,15 @@ var MongoSchemaBuilder = class _MongoSchemaBuilder {
3087
3086
  return await this.db.useTransaction((session) => fn(session, model));
3088
3087
  });
3089
3088
  }
3090
- async createHexId(bytes, path2, maxRetries = 10) {
3089
+ async createUniqueId(collisionPath, fn, maxRetries = 10) {
3091
3090
  return this.execute(async (model) => {
3092
- const createHex = () => randomBytes(bytes).toString("hex");
3093
- let id = createHex();
3091
+ let id;
3094
3092
  let tries = 0;
3095
- while (await model.exists({ [path2]: id })) {
3096
- if (tries >= maxRetries) throw Error(`Failed to generate a unique hex ID after ${tries} attempt(s)`);
3097
- id = createHex();
3093
+ do {
3094
+ if (tries >= maxRetries) throw new Error(`Failed to generate a unique ID after ${tries} attempt(s)`);
3095
+ id = fn();
3098
3096
  tries++;
3099
- }
3097
+ } while (await model.exists({ [collisionPath]: id }));
3100
3098
  return id;
3101
3099
  });
3102
3100
  }