Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 42 additions & 39 deletions infrastructure/w3id/package.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
{
"name": "w3id",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "tsc --watch",
"format": "npx @biomejs/biome format --write ./src",
"check-format": "npx @biomejs/biome format ./src",
"lint": "npx @biomejs/biome lint --write ./src",
"check-lint": "npx @biomejs/biome lint ./src",
"check": "npx @biomejs/biome check ./src",
"check-types": "tsc --noEmit",
"build": "npm run build:node && npm run build:browser",
"build:node": "tsc -p tsconfig.node.json",
"build:browser": "tsc -p tsconfig.browser.json",
"postinstall": "npm run build"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@biomejs/biome": "^1.9.4",
"uuid": "^11.1.0"
},
"devDependencies": {
"typescript": "^5.8.2"
},
"main": "./dist/node/index.js",
"module": "./dist/browser/index.js",
"types": "./dist/types/index.d.ts",
"exports": {
".": {
"require": "./dist/node/index.js",
"import": "./dist/browser/index.js",
"types": "./dist/types/index.d.ts"
},
"./package.json": "./package.json"
},
"files": ["dist/**/*"]
"name": "w3id",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "vitest",
"dev": "tsc --watch",
"check-format": "prettier --check \"src/**/*.ts\"",
"format": "npx @biomejs/biome format --write ./src",
"lint": "npx @biomejs/biome lint --write ./src",
"check": "npx @biomejs/biome check --write ./src",
"check-types": "tsc --noEmit",
"build": "npm run build:node && npm run build:browser",
"build:node": "tsc -p tsconfig.node.json",
"build:browser": "tsc -p tsconfig.browser.json",
"postinstall": "npm run build"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"uuid": "^11.1.0"
},
"devDependencies": {
"@ngneat/falso": "^7.3.0",
"@types/node": "^22.13.10",
"typescript": "^5.8.2",
"vitest": "^3.0.9"
},
"main": "./dist/node/index.js",
"module": "./dist/browser/index.js",
"types": "./dist/types/index.d.ts",
"exports": {
".": {
"require": "./dist/node/index.js",
"import": "./dist/browser/index.js",
"types": "./dist/types/index.d.ts"
},
"./package.json": "./package.json"
},
"files": [
"dist/**/*"
]
}
17 changes: 17 additions & 0 deletions infrastructure/w3id/src/utils/uuid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { v4 as uuidv4, v5 as uuidv5 } from "uuid";

/**
* Generates a UUIDv5 taking namespace from a random UUIDv4 and taking `name`
* part as entropy from the creator of the identifier
*
* @param {String} entropy
* @param {String} namespace - uuid namespace
* @returns string
*/

export function generateUuid(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function name makes it seems like the function has a broad scope, but doc above mentions just v5, its just a nitpick but i think this can be named a little better

entropy: string,
namespace: string = uuidv4(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think having this default behavior would just lead to mistakes

): string {
return uuidv5(entropy, namespace);
}
18 changes: 18 additions & 0 deletions infrastructure/w3id/tests/utils/uuid.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { generateUuid } from "../../src/utils/uuid";
import falso from "@ngneat/falso";
import { describe, test, expect } from "vitest";

describe("UUIDv5 Generation", () => {
test("Create UUID", () => {
const id = generateUuid(falso.randText());
expect(id).toBeDefined();
});

test("UUID is deterministic", () => {
const namespace = falso.randUuid();
const entropy = falso.randText();
const id = generateUuid(entropy, namespace);
const id2 = generateUuid(entropy, namespace);
expect(id).toEqual(id2);
});
});
Loading