Skip to content

Commit

Permalink
chore(core): remove uuid dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Feb 6, 2023
1 parent 71c987e commit d323edb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/core/injector/modules-container.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { v4 as uuid } from 'uuid';
import { uid } from 'uid';
import { Module } from './module';

export class ModulesContainer extends Map<string, Module> {
private readonly _applicationId = uuid();
private readonly _applicationId = uid(21);

get applicationId(): string {
return this._applicationId;
Expand Down
9 changes: 5 additions & 4 deletions packages/core/inspector/deterministic-uuid-registry.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { v5 as uuid } from 'uuid';

import { xxh32 } from '@node-rs/xxhash';
const DEFAULT_UUID_NAMESPACE = 'efa0df42-88af-474f-9cad-4206a2319f07';

export class DeterministicUuidRegistry {
private static readonly registry = new Set<string>();
private static readonly registry = new Set<number>();

static get(str: string, namespace: string = DEFAULT_UUID_NAMESPACE, inc = 0) {
const id = inc ? uuid(str + `${inc}`, namespace) : uuid(str, namespace);
const id = inc
? xxh32(`${namespace}_${str}_${inc}`)
: xxh32(`${namespace}_${str}`);
if (this.registry.has(id)) {
return this.get(str, namespace, inc + 1);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/middleware/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@nestjs/common/utils/shared.utils';
import { iterate } from 'iterare';
import * as pathToRegexp from 'path-to-regexp';
import { v4 as uuid } from 'uuid';
import { uid } from 'uid';
import { ExcludeRouteMetadata } from '../router/interfaces/exclude-route-metadata.interface';
import { isRouteExcluded } from '../router/utils';

Expand Down Expand Up @@ -99,7 +99,7 @@ export function isMiddlewareClass(middleware: any): middleware is Type<any> {
);
}

export function assignToken(metatype: Type<any>, token = uuid()): Type<any> {
export function assignToken(metatype: Type<any>, token = uid(21)): Type<any> {
Object.defineProperty(metatype, 'name', { value: token });
return metatype;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
"fast-safe-stringify": "2.1.1",
"iterare": "1.2.1",
"path-to-regexp": "3.2.0",
"tslib": "2.5.0",
"uuid": "9.0.0"
"tslib": "2.5.0"
},
"devDependencies": {
"@nestjs/common": "9.3.2"
Expand Down

0 comments on commit d323edb

Please sign in to comment.