Skip to content

Commit

Permalink
fix(core): removed xxhash to fix nestjs#11071
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Feb 7, 2023
1 parent 67a58e9 commit bd92969
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 114 deletions.
98 changes: 0 additions & 98 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
]
},
"dependencies": {
"@node-rs/xxhash": "^1.3.0",
"@nuxtjs/opencollective": "0.3.2",
"class-transformer": "0.5.1",
"class-validator": "0.14.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/injector/module-token-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DynamicModule } from '@nestjs/common';
import { Type } from '@nestjs/common/interfaces/type.interface';
import { randomStringGenerator } from '@nestjs/common/utils/random-string-generator.util';
import { isFunction, isSymbol } from '@nestjs/common/utils/shared.utils';
import { xxh32 } from '@node-rs/xxhash';
import { createHash } from 'crypto';
import stringify from 'fast-safe-stringify';

const CLASS_STR = 'class ';
Expand Down Expand Up @@ -64,7 +64,7 @@ export class ModuleTokenFactory {
}

private hashString(value: string): string {
return xxh32(value).toString();
return createHash('sha256').update(value).digest('hex');
}

private replacer(key: string, value: any) {
Expand Down
23 changes: 11 additions & 12 deletions packages/core/inspector/deterministic-uuid-registry.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { xxh32 } from '@node-rs/xxhash';

const DEFAULT_UUID_NAMESPACE = 'efa0df42-88af-474f-9cad-4206a2319f07';
import { createHash } from 'crypto';

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

static get(str: string, namespace: string = DEFAULT_UUID_NAMESPACE, inc = 0) {
const id = inc
? xxh32(`${namespace}_${str}_${inc}`)
: xxh32(`${namespace}_${str}`);
const idAsString = `${id}`;
static get(str: string, namespace: string = '', inc = 0) {
const key = inc ? `${str}_${inc}` : str;

if (this.registry.has(idAsString)) {
if (this.registry.has(key)) {
return this.get(str, namespace, inc + 1);
}
this.registry.add(idAsString);
return idAsString;

const id = createHash('sha256').update(key).digest('hex');

this.registry.set(id, true);

return id;
}

static clear() {
Expand Down
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
}
},
"dependencies": {
"@node-rs/xxhash": "^1.3.0",
"@nuxtjs/opencollective": "0.3.2",
"fast-safe-stringify": "2.1.1",
"iterare": "1.2.1",
Expand Down

0 comments on commit bd92969

Please sign in to comment.