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
4 changes: 1 addition & 3 deletions packages/db-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@
"@types/node": "^22.10.2",
"debug": "^4.4.0",
"google-protobuf": "^3.21.4",
"semver": "^7.7.2",
"uuid": "11.0.3"
"semver": "^7.7.2"
},
"devDependencies": {
"@types/semver": "^7.7.0",
"@types/uuid": "^10.0.0",
"grpc-tools": "^1.13.1",
"grpc_tools_node_protoc_ts": "^5.3.3",
"nx": "20.1.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/db-client/src/Client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isAbsolute, resolve } from "path";
import { Readable, Writable, Duplex, finished } from "stream";
import * as bridge from "@kurrent/bridge";

import { v4 as uuid } from "uuid";
import { randomUUID } from "crypto";

import {
CallCredentials as grpcCallCredentials,
Expand Down Expand Up @@ -320,7 +320,7 @@ export class Client {
keepAliveInterval = 10_000,
keepAliveTimeout = 10_000,
defaultDeadline = 10_000,
connectionName = uuid(),
connectionName = randomUUID(),
...connectionSettings
}: ConnectionSettings,
channelCredentials: ChannelCredentialOptions = { insecure: false },
Expand Down
4 changes: 2 additions & 2 deletions packages/db-client/src/events/binaryEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { v4 as uuid } from "uuid";
import { randomUUID } from "crypto";

import type { BinaryEventType, EventData } from "../types";

Expand All @@ -19,7 +19,7 @@ export const binaryEvent = <E extends BinaryEventType = BinaryEventType>({
type,
data,
metadata,
id = uuid(),
id = randomUUID(),
}: BinaryEventOptions<E>): EventData<E> =>
({
id,
Expand Down
4 changes: 2 additions & 2 deletions packages/db-client/src/events/jsonEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { v4 as uuid } from "uuid";
import { randomUUID } from "crypto";

import type { EventData, JSONEventType } from "../types";

Expand All @@ -15,7 +15,7 @@ export const jsonEvent = <E extends JSONEventType>({
type,
data,
metadata,
id = uuid(),
id = randomUUID(),
}: JSONEventOptions<E>): EventData<E> =>
({
id,
Expand Down
4 changes: 2 additions & 2 deletions packages/db-client/src/streams/appendToStream/batchAppend.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { v4 as uuid } from "uuid";
import { randomUUID } from "crypto";
import { Timestamp } from "google-protobuf/google/protobuf/timestamp_pb";

import { StreamsClient } from "../../../generated/kurrentdb/protocols/v1/streams_grpc_pb";
Expand Down Expand Up @@ -50,7 +50,7 @@ export const batchAppend = async function (
...baseOptions
}: InternalOptions<AppendToStreamOptions>
): Promise<AppendResult> {
const correlationId = uuid();
const correlationId = randomUUID();

const stream = await this.GRPCStreamCreator(
StreamsClient,
Expand Down
30 changes: 16 additions & 14 deletions packages/db-client/src/utils/grpcUUID.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { stringify, v4 } from "uuid";
import { randomUUID } from "crypto";
import { UUID } from "../../generated/kurrentdb/protocols/v1/shared_pb";

export const createUUID = (id: string = v4()): UUID => {
export const createUUID = (id: string = randomUUID()): UUID => {
const uuid = new UUID();
uuid.setString(id);
return uuid;
Expand All @@ -13,19 +13,21 @@ export function parseUUID(uuid: UUID | undefined): string | undefined {
if (!uuid) return undefined;

if (uuid.hasStructured()) {
const structured = uuid.getStructured()!;
const leastSignificantBits = BigInt(structured.getLeastSignificantBits());
const mostSignificantBits = BigInt(structured.getMostSignificantBits());
const buffer = new ArrayBuffer(16);
const dataView = new DataView(buffer);

dataView.setBigUint64(0, mostSignificantBits);
dataView.setBigUint64(8, leastSignificantBits);

const uint8Array = new Uint8Array(buffer);

return stringify(uint8Array);
return structuredUUIDToString(uuid.getStructured()!);
}

return uuid.getString();
}

export const structuredUUIDToString = (structured: UUID.Structured): string => {
const ms = toUnsignedHex(structured.getMostSignificantBits());
const ls = toUnsignedHex(structured.getLeastSignificantBits());
return `${ms.slice(0, 8)}-${ms.slice(8, 12)}-${ms.slice(12)}-${ls.slice(
0,
4
)}-${ls.slice(4)}`;
};

const U64_MASK = (1n << 64n) - 1n;
const toUnsignedHex = (value: string): string =>
(BigInt(value) & U64_MASK).toString(16).padStart(16, "0");
4 changes: 1 addition & 3 deletions packages/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"@opentelemetry/semantic-conventions": "^1.28.0",
"@types/debug": "^4.1.12",
"@types/jest": "^29.5.14",
"@types/uuid": "^9.0.8",
"cross-env": "^7.0.3",
"debug": "^4.4.0",
"docker-compose": "^0.24.8",
Expand All @@ -51,7 +50,6 @@
"jest": "^29.7.0",
"jest-environment-node": "^29.7.0",
"shx": "^0.3.4",
"ts-jest": "^29.2.5",
"uuid": "11.0.3"
"ts-jest": "^29.2.5"
}
}
2 changes: 1 addition & 1 deletion packages/test/src/connection/determineBestNode.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { v4 as uuid } from "uuid";
import { randomUUID as uuid } from "crypto";

import {
FOLLOWER,
Expand Down
2 changes: 1 addition & 1 deletion packages/test/src/extra/dispose.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jest-environment ./src/utils/enableVersionCheck.ts */

import type { Stream } from "stream";
import { v4 as uuid } from "uuid";
import { randomUUID as uuid } from "crypto";

import {
createTestNode,
Expand Down
48 changes: 48 additions & 0 deletions packages/test/src/extra/grpcUUID.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {
parseUUID,
structuredUUIDToString,
} from "@kurrent/kurrentdb-client/dist/utils/grpcUUID";
import { UUID } from "@kurrent/kurrentdb-client/generated/kurrentdb/protocols/v1/shared_pb";

const makeStructured = (msb: string, lsb: string): UUID.Structured => {
const s = new UUID.Structured();
s.setMostSignificantBits(msb);
s.setLeastSignificantBits(lsb);
return s;
};

describe("grpcUUID", () => {
describe("structuredUUIDToString", () => {
test.each([
["0", "0", "00000000-0000-0000-0000-000000000000"],
["-1", "-1", "ffffffff-ffff-ffff-ffff-ffffffffffff"],
["-9223372036854775808", "0", "80000000-0000-0000-0000-000000000000"],
["0", "-9223372036854775808", "00000000-0000-0000-8000-000000000000"],
[
"81985529216486895",
"81985529216486895",
"01234567-89ab-cdef-0123-456789abcdef",
],
])("msb=%s lsb=%s -> %s", (msb, lsb, expected) => {
expect(structuredUUIDToString(makeStructured(msb, lsb))).toBe(expected);
});
});

describe("parseUUID", () => {
test("returns undefined when given undefined", () => {
expect(parseUUID(undefined)).toBeUndefined();
});

test("returns the string form unchanged", () => {
const u = new UUID();
u.setString("01234567-89ab-cdef-0123-456789abcdef");
expect(parseUUID(u)).toBe("01234567-89ab-cdef-0123-456789abcdef");
});

test("decodes structured form with high bit set", () => {
const u = new UUID();
u.setStructured(makeStructured("-1", "-1"));
expect(parseUUID(u)).toBe("ffffffff-ffff-ffff-ffff-ffffffffffff");
});
});
});
2 changes: 1 addition & 1 deletion packages/test/src/extra/http2-assertion-failure.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { v4 as uuid } from "uuid";
import { randomUUID as uuid } from "crypto";
import { createInsecureTestNode, delay, jsonTestEvents } from "@test-utils";
import {
KurrentDBClient,
Expand Down
2 changes: 1 addition & 1 deletion packages/test/src/extra/typedEvents-more.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { v4 as uuid } from "uuid";
import { randomUUID as uuid } from "crypto";

import { createTestNode } from "@test-utils";
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/test/src/opentelemetry/instrumentation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "@opentelemetry/semantic-conventions";
import { KurrentDBInstrumentation } from "@kurrent/opentelemetry";
import { KurrentAttributes } from "@kurrent/opentelemetry/dist/attributes";
import { v4 } from "uuid";
import { randomUUID as v4 } from "crypto";
import { collect } from "@test-utils";

const tracerProvider = new NodeTracerProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { pipeline, Writable, Readable, Transform } from "stream";
import { promisify } from "util";

import { v4 as uuid } from "uuid";
import { randomUUID as uuid } from "crypto";

import {
createTestCluster,
Expand Down
2 changes: 1 addition & 1 deletion packages/test/src/samples/appending-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
WrongExpectedVersionError,
} from "@kurrent/kurrentdb-client";
import { createTestNode } from "@test-utils";
import { v4 as uuid } from "uuid";
import { randomUUID as uuid } from "crypto";

describe("[sample] appending-events", () => {
const node = createTestNode();
Expand Down
2 changes: 1 addition & 1 deletion packages/test/src/samples/get-started.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
JSONEventType,
} from "@kurrent/kurrentdb-client";
import { optionalDescribe } from "@test-utils";
import { v4 as uuid } from "uuid";
import { randomUUID as uuid } from "crypto";

const CLOUD_ID = process.env.EVENTSTORE_CLOUD_ID!;
const STREAM_NAME = uuid();
Expand Down
2 changes: 1 addition & 1 deletion packages/test/src/samples/opentelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {

import * as kurrentdb from "@kurrent/kurrentdb-client";
import { KurrentAttributes } from "@kurrent/opentelemetry/src/attributes";
import { v4 } from "uuid";
import { randomUUID as v4 } from "crypto";
import { multiStreamAppend } from "@kurrent/kurrentdb-client/src/streams/appendToStream/multiStreamAppend";
import { appendRecords } from "@kurrent/kurrentdb-client/src/streams/appendToStream/appendRecords";
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/test/src/samples/projection-management.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @jest-environment ./src/utils/enableVersionCheck.ts */

import { v4 as uuid } from "uuid";
import { randomUUID as uuid } from "crypto";

import { KurrentDBClient, isCommandError } from "@kurrent/kurrentdb-client";
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/test/src/samples/user-certificates.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { KurrentDBClient } from "@kurrent/kurrentdb-client";
import { createTestNode, jsonTestEvents } from "@test-utils";
import { v4 as uuid } from "uuid";
import { randomUUID as uuid } from "crypto";

const STREAM_NAME = uuid();

Expand Down
2 changes: 1 addition & 1 deletion packages/test/src/streams/appendRecords.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
jsonEvent,
} from "@kurrent/kurrentdb-client";

import { v4 } from "uuid";
import { randomUUID as v4 } from "crypto";

describe("appendRecords", () => {
const supported = matchServerVersion`>=26.0`;
Expand Down
2 changes: 1 addition & 1 deletion packages/test/src/streams/multiAppendStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
binaryEvent,
} from "@kurrent/kurrentdb-client";

import { v4 } from "uuid";
import { randomUUID as v4 } from "crypto";

describe("multiAppend", () => {
const supported = matchServerVersion`>=25.0`;
Expand Down
2 changes: 1 addition & 1 deletion packages/test/src/utils/Cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from "fs";
import { promisify } from "util";
import * as cp from "child_process";

import { v4 as uuid } from "uuid";
import { randomUUID as uuid } from "crypto";
import getPort from "get-port";
import { upAll, down, exec, stopOne, logs } from "docker-compose/dist/v2";

Expand Down
Loading
Loading