From ce55ca9f5c7ea81058627b60e2cec5482d2be1f6 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Thu, 4 Apr 2024 17:13:49 -0400 Subject: [PATCH] fix(NODE-6066): ClusterTime.signature can be undefined (#4069) --- src/sdam/common.ts | 10 ++++++++-- test/types/sessions.test-d.ts | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/sdam/common.ts b/src/sdam/common.ts index e4b84d83f6..fab8124d4c 100644 --- a/src/sdam/common.ts +++ b/src/sdam/common.ts @@ -55,10 +55,16 @@ export function drainTimerQueue(queue: TimerQueue): void { queue.clear(); } -/** @public */ +/** + * @public + * Gossiped in component for the cluster time tracking the state of user databases + * across the cluster. It may optionally include a signature identifying the process that + * generated such a value. + */ export interface ClusterTime { clusterTime: Timestamp; - signature: { + /** Used to validate the identity of a request or response's ClusterTime. */ + signature?: { hash: Binary; keyId: Long; }; diff --git a/test/types/sessions.test-d.ts b/test/types/sessions.test-d.ts index 48c8fcb0dc..ec6f5a1bf3 100644 --- a/test/types/sessions.test-d.ts +++ b/test/types/sessions.test-d.ts @@ -1,6 +1,6 @@ -import { expectError, expectType } from 'tsd'; +import { expectAssignable, expectError, expectType } from 'tsd'; -import type { ClientSession } from '../mongodb'; +import type { Binary, ClientSession, ClusterTime, Long, Timestamp } from '../mongodb'; import { MongoClient, ReadConcern, ReadConcernLevel } from '../mongodb'; // test mapped cursor types @@ -25,3 +25,9 @@ const unknownFn: () => Promise = async () => 2; expectType(await client.withSession(unknownFn)); // Not a promise returning function expectError(await client.withSession(() => null)); + +declare const ct: ClusterTime; +expectType(ct.clusterTime); +expectAssignable(undefined); +expectType(ct.signature?.hash); +expectType(ct.signature?.keyId);