1
1
import { Long } from './long' ;
2
+ import { isObjectLike } from './parser/utils' ;
2
3
3
4
/** @public */
4
5
export type TimestampOverrides = '_bsontype' | 'toExtendedJSON' | 'fromExtendedJSON' | 'inspect' ;
5
6
/** @public */
6
- export type LongWithoutOverrides = new ( low : number | Long , high ?: number , unsigned ?: boolean ) => {
7
+ export type LongWithoutOverrides = new ( low : unknown , high ?: number , unsigned ?: boolean ) => {
7
8
[ P in Exclude < keyof Long , TimestampOverrides > ] : Long [ P ] ;
8
9
} ;
9
10
/** @public */
@@ -26,20 +27,26 @@ export class Timestamp extends LongWithoutOverridesClass {
26
27
/**
27
28
* @param low - A 64-bit Long representing the Timestamp.
28
29
*/
29
- constructor ( low : Long ) ;
30
+ constructor ( long : Long ) ;
31
+ /**
32
+ * @param value - A pair of two values indicating timestamp and increment.
33
+ */
34
+ constructor ( value : { t : number ; i : number } ) ;
30
35
/**
31
36
* @param low - the low (signed) 32 bits of the Timestamp.
32
37
* @param high - the high (signed) 32 bits of the Timestamp.
38
+ * @deprecated Please use `Timestamp({ t: high, i: low })` or `Timestamp(Long(low, high))` instead.
33
39
*/
34
- constructor ( low : Long ) ;
35
40
constructor ( low : number , high : number ) ;
36
- constructor ( low : number | Long , high ?: number ) {
41
+ constructor ( low : number | Long | { t : number ; i : number } , high ?: number ) {
37
42
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
38
43
///@ts -expect-error
39
44
if ( ! ( this instanceof Timestamp ) ) return new Timestamp ( low , high ) ;
40
45
41
46
if ( Long . isLong ( low ) ) {
42
47
super ( low . low , low . high , true ) ;
48
+ } else if ( isObjectLike ( low ) && typeof low . t !== 'undefined' && typeof low . i !== 'undefined' ) {
49
+ super ( low . i , low . t , true ) ;
43
50
} else {
44
51
super ( low , high , true ) ;
45
52
}
@@ -94,7 +101,7 @@ export class Timestamp extends LongWithoutOverridesClass {
94
101
95
102
/** @internal */
96
103
static fromExtendedJSON ( doc : TimestampExtended ) : Timestamp {
97
- return new Timestamp ( doc . $timestamp . i , doc . $timestamp . t ) ;
104
+ return new Timestamp ( doc . $timestamp ) ;
98
105
}
99
106
100
107
/** @internal */
0 commit comments