Skip to content

Commit 71c60fd

Browse files
committed
feat: add default value for high128 in uuidFromBigInts and create corresponding tests
Signed-off-by: Vladislav Polyakov <[email protected]>
1 parent 8620462 commit 71c60fd

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

packages/value/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"build:esm": "tsc --project tsconfig.json --outDir ./dist/esm",
1414
"test": "vitest --run",
1515
"test:watch": "vitest --watch",
16-
"attw": "attw --pack"
16+
"attw": "attw --pack",
17+
"prepublishOnly": "npm run clean && npm run build:cjs && npm run build:esm && npm run attw"
1718
},
1819
"exports": {
1920
".": {

packages/value/src/uuid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function uuidFromBigInts(low128: bigint, high128: bigint): string {
1+
export function uuidFromBigInts(low128: bigint, high128: bigint = 0n): string {
22
// Create a 16-byte buffer
33
let bytes = Buffer.alloc(16);
44

packages/value/tests/uudi.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect, test } from "vitest";
2+
3+
import { bigIntsFromUuid, uuidFromBigInts } from "../dist/esm/uuid.js";
4+
import { Uuid } from "../dist/esm/primitive.js";
5+
6+
test('UUID', () => {
7+
let uuid = '123e4567-e89b-12d3-a456-426614174000';
8+
let { low128, high128 } = bigIntsFromUuid(uuid);
9+
10+
expect(uuid).toEqual(uuidFromBigInts(low128, high128));
11+
})
12+
13+
test('YDB Uuid Type', () => {
14+
let uuid = new Uuid('123e4567-e89b-12d3-a456-426614174000');
15+
expect(uuid.toString()).toEqual('123e4567-e89b-12d3-a456-426614174000');
16+
})

0 commit comments

Comments
 (0)