Skip to content

Commit

Permalink
fix: remove usage of "uuid" package
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed May 8, 2023
1 parent 97bfa8b commit e30209a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { MongoClient } from 'mongodb';
import { v4 } from 'uuid';
import { MongoMemoryServer } from '../index';
import { assertion, isNullOrUndefined } from '../util/utils';
import { assertion, isNullOrUndefined, uuidv4 } from '../util/utils';

// This is an Example test, do not merge it with others and do not delete this file

Expand All @@ -14,8 +13,8 @@ describe('Restart single MongoMemoryServer instance', () => {

const instance = await MongoMemoryServer.create({ instance: { storageEngine: 'wiredTiger' } });

const databaseName = v4();
const collectionName = v4();
const databaseName = uuidv4();
const collectionName = uuidv4();
let insertedDoc: Record<string, any>;
// first connect and insert
{
Expand Down
3 changes: 1 addition & 2 deletions packages/mongodb-memory-server-core/src/util/lockfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import debug from 'debug';
import * as path from 'path';
import { promises as fspromises } from 'fs';
import { Mutex } from 'async-mutex';
import { v4 as uuidv4 } from 'uuid';
import { UnableToUnlockLockfileError, UnknownLockfileStatusError } from './errors';

const log = debug('MongoMS:LockFile');
Expand Down Expand Up @@ -197,7 +196,7 @@ export class LockFile {
protected static async createLock(file: string): Promise<LockFile> {
// this function only gets called by processed "file" input, so no re-checking
log(`createLock: trying to create a lock file for "${file}"`);
const uuid = uuidv4();
const uuid = utils.uuidv4();

// This is not an ".catch" because in an callback running "return" dosnt "return" the parent function
try {
Expand Down
9 changes: 9 additions & 0 deletions packages/mongodb-memory-server-core/src/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from './errors';
import { tmpdir } from 'os';
import * as path from 'path';
import { randomUUID } from 'crypto';

const log = debug('MongoMS:utils');

Expand Down Expand Up @@ -356,3 +357,11 @@ export async function removeDir(dirPath: string): Promise<void> {
});
}
}

/**
* Helper function to have uuidv4 generation and definition in one place
* @returns a uuid-v4
*/
export function uuidv4(): string {
return randomUUID();
}

0 comments on commit e30209a

Please sign in to comment.