bson 7.2.0 → 7.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/timestamp.ts CHANGED
@@ -4,20 +4,53 @@ import type { Int32 } from './int_32';
4
4
  import { Long } from './long';
5
5
  import { type InspectFn, defaultInspect } from './parser/utils';
6
6
 
7
- /** @public */
7
+ /**
8
+ * @public
9
+ * @deprecated This type is no longer used internally and will be removed in a future version.
10
+ */
8
11
  export type TimestampOverrides =
9
12
  | '_bsontype'
10
13
  | 'toExtendedJSON'
11
14
  | 'fromExtendedJSON'
12
15
  | 'inspect'
13
16
  | typeof bsonType;
17
+
18
+ /**
19
+ * @public
20
+ *
21
+ * Inherited `Long` members surfaced on `Timestamp`.
22
+ * When `Long` gains a new member: add it here if it should pass through, or
23
+ * add a `@deprecated declare` line on the `Timestamp` class if it should be
24
+ * surfaced as deprecated. Anything left unclassified is silently dropped from
25
+ * the public type — preventing accidental behavioral bleed-through.
26
+ */
27
+ type TimestampKept =
28
+ | 'toBigInt'
29
+ | 'toString'
30
+ | 'compare'
31
+ | 'equals'
32
+ | 'eq'
33
+ | 'notEquals'
34
+ | 'neq'
35
+ | 'ne'
36
+ | 'lessThan'
37
+ | 'lt'
38
+ | 'lessThanOrEqual'
39
+ | 'lte'
40
+ | 'le'
41
+ | 'greaterThan'
42
+ | 'gt'
43
+ | 'greaterThanOrEqual'
44
+ | 'gte'
45
+ | 'ge';
46
+
14
47
  /** @public */
15
48
  export type LongWithoutOverrides = new (
16
49
  low: unknown,
17
50
  high?: number | boolean,
18
51
  unsigned?: boolean
19
52
  ) => {
20
- [P in Exclude<keyof Long, TimestampOverrides>]: Long[P];
53
+ [P in TimestampKept]: Long[P];
21
54
  };
22
55
  /** @public */
23
56
  export const LongWithoutOverridesClass: LongWithoutOverrides =
@@ -45,6 +78,9 @@ export class Timestamp extends LongWithoutOverridesClass {
45
78
  return 'Timestamp';
46
79
  }
47
80
 
81
+ /**
82
+ * @deprecated Use `Long.MAX_UNSIGNED_VALUE` instead.
83
+ */
48
84
  static readonly MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
49
85
 
50
86
  /**
@@ -116,16 +152,23 @@ export class Timestamp extends LongWithoutOverridesClass {
116
152
 
117
153
  toJSON(): { $timestamp: string } {
118
154
  return {
155
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
119
156
  $timestamp: this.toString()
120
157
  };
121
158
  }
122
159
 
123
- /** Returns a Timestamp represented by the given (32-bit) integer value. */
160
+ /**
161
+ * Returns a Timestamp represented by the given (32-bit) integer value.
162
+ * @deprecated Stores `value` in the low 32 bits (increment), leaving t = 0. Use `new Timestamp({ t, i })` or `Timestamp.fromBits(lowBits, highBits)` for explicit construction.
163
+ */
124
164
  static fromInt(value: number): Timestamp {
125
165
  return new Timestamp(Long.fromInt(value, true));
126
166
  }
127
167
 
128
- /** Returns a Timestamp representing the given number value, provided that it is a finite number. Otherwise, zero is returned. */
168
+ /**
169
+ * Returns a Timestamp representing the given number value, provided that it is a finite number. Otherwise, zero is returned.
170
+ * @deprecated Splits `value` across (t, i) as a uint64; the result rarely matches user intent. Use `new Timestamp({ t, i })` or `Timestamp.fromBits(lowBits, highBits)` for explicit construction.
171
+ */
129
172
  static fromNumber(value: number): Timestamp {
130
173
  return new Timestamp(Long.fromNumber(value, true));
131
174
  }
@@ -173,4 +216,115 @@ export class Timestamp extends LongWithoutOverridesClass {
173
216
  const i = inspect(this.i, options);
174
217
  return `new Timestamp({ t: ${t}, i: ${i} })`;
175
218
  }
219
+
220
+ // ********************
221
+ // **** DEPRECATED ****
222
+ // ********************
223
+ // Declare used to avoid runtime effects for field declaration.
224
+ // See: https://www.typescriptlang.org/docs/handbook/2/classes.html#type-only-field-declarations
225
+
226
+ // Arithmetic
227
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
228
+ declare add: Long['add'];
229
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
230
+ declare subtract: Long['subtract'];
231
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
232
+ declare sub: Long['sub'];
233
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
234
+ declare multiply: Long['multiply'];
235
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
236
+ declare mul: Long['mul'];
237
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
238
+ declare divide: Long['divide'];
239
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
240
+ declare div: Long['div'];
241
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
242
+ declare modulo: Long['modulo'];
243
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
244
+ declare mod: Long['mod'];
245
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
246
+ declare rem: Long['rem'];
247
+ /** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned. */
248
+ declare negate: Long['negate'];
249
+ /** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned. */
250
+ declare neg: Long['neg'];
251
+
252
+ // Bitwise / shifts
253
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
254
+ declare and: Long['and'];
255
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
256
+ declare or: Long['or'];
257
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
258
+ declare xor: Long['xor'];
259
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
260
+ declare not: Long['not'];
261
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
262
+ declare shiftLeft: Long['shiftLeft'];
263
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
264
+ declare shl: Long['shl'];
265
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
266
+ declare shiftRight: Long['shiftRight'];
267
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
268
+ declare shr: Long['shr'];
269
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
270
+ declare shiftRightUnsigned: Long['shiftRightUnsigned'];
271
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
272
+ declare shr_u: Long['shr_u'];
273
+ /** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
274
+ declare shru: Long['shru'];
275
+
276
+ // Signing
277
+ /** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned. */
278
+ declare toSigned: Long['toSigned'];
279
+ /** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned (this is a no-op). */
280
+ declare toUnsigned: Long['toUnsigned'];
281
+ /** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned (is always false). */
282
+ declare isNegative: Long['isNegative'];
283
+ /** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned (is always true). */
284
+ declare isPositive: Long['isPositive'];
285
+ /** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned (is always true). */
286
+ declare unsigned: Long['unsigned'];
287
+
288
+ // Conversion
289
+ /** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch, or `.i` for the increment ordinal. */
290
+ declare toInt: Long['toInt'];
291
+ /** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch, or `.i` for the increment ordinal. */
292
+ declare toNumber: Long['toNumber'];
293
+ /** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch, or `.i` for the increment ordinal. */
294
+ declare toBytes: Long['toBytes'];
295
+ /** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch, or `.i` for the increment ordinal. */
296
+ declare toBytesLE: Long['toBytesLE'];
297
+ /** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch, or `.i` for the increment ordinal. */
298
+ declare toBytesBE: Long['toBytesBE'];
299
+
300
+ // Other
301
+ /** @deprecated Incompatible with Timestamp: returns a signed integer, but Timestamp is always unsigned. Use `.t` for seconds since the Unix epoch. */
302
+ declare getHighBits: Long['getHighBits'];
303
+ /** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch. */
304
+ declare getHighBitsUnsigned: Long['getHighBitsUnsigned'];
305
+ /** @deprecated Incompatible with Timestamp: returns a signed integer, but Timestamp is always unsigned. Use `.i` for the increment ordinal. */
306
+ declare getLowBits: Long['getLowBits'];
307
+ /** @deprecated Not applicable to Timestamp; use `.i` for the increment ordinal. */
308
+ declare getLowBitsUnsigned: Long['getLowBitsUnsigned'];
309
+
310
+ /** @deprecated Not applicable to Timestamp; use `.i` instead. */
311
+ declare low: Long['low'];
312
+ /** @deprecated Not applicable to Timestamp; use `.t` instead. */
313
+ declare high: Long['high'];
314
+
315
+ /** @deprecated Use .compare() for general comparison, or .equals(), .lessThan(), .greaterThan() for specific cases. */
316
+ declare comp: Long['comp'];
317
+ /** @deprecated Compare `.t` and `.i` against `0` explicitly. */
318
+ declare isZero: Long['isZero'];
319
+ /** @deprecated Compare `.t` and `.i` against `0` explicitly. */
320
+ declare eqz: Long['eqz'];
321
+
322
+ /** @deprecated Not applicable to Timestamp. Use the bsonType symbol or _bsontype === 'Timestamp' to identify a Timestamp. */
323
+ declare __isLong__: Long['__isLong__'];
324
+ /** @deprecated Not applicable to Timestamp. */
325
+ declare getNumBitsAbs: Long['getNumBitsAbs'];
326
+ /** @deprecated Not applicable to Timestamp; tests parity of the increment only. */
327
+ declare isEven: Long['isEven'];
328
+ /** @deprecated Not applicable to Timestamp; tests parity of the increment only. */
329
+ declare isOdd: Long['isOdd'];
176
330
  }