bson 5.1.0 → 5.2.0
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/bson.d.ts +8 -0
- package/lib/bson.bundle.js +19 -3
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +19 -3
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +19 -3
- package/lib/bson.mjs.map +1 -1
- package/package.json +1 -1
- package/src/binary.ts +18 -2
- package/src/objectid.ts +11 -5
package/package.json
CHANGED
package/src/binary.ts
CHANGED
|
@@ -258,6 +258,16 @@ export class Binary extends BSONValue {
|
|
|
258
258
|
);
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
+
/** Creates an Binary instance from a hex digit string */
|
|
262
|
+
static createFromHexString(hex: string, subType?: number): Binary {
|
|
263
|
+
return new Binary(ByteUtils.fromHex(hex), subType);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Creates an Binary instance from a base64 string */
|
|
267
|
+
static createFromBase64(base64: string, subType?: number): Binary {
|
|
268
|
+
return new Binary(ByteUtils.fromBase64(base64), subType);
|
|
269
|
+
}
|
|
270
|
+
|
|
261
271
|
/** @internal */
|
|
262
272
|
static fromExtendedJSON(
|
|
263
273
|
doc: BinaryExtendedLegacy | BinaryExtended | UUIDExtended,
|
|
@@ -292,7 +302,8 @@ export class Binary extends BSONValue {
|
|
|
292
302
|
}
|
|
293
303
|
|
|
294
304
|
inspect(): string {
|
|
295
|
-
|
|
305
|
+
const base64 = ByteUtils.toBase64(this.buffer.subarray(0, this.position));
|
|
306
|
+
return `Binary.createFromBase64("${base64}", ${this.sub_type})`;
|
|
296
307
|
}
|
|
297
308
|
}
|
|
298
309
|
|
|
@@ -464,11 +475,16 @@ export class UUID extends Binary {
|
|
|
464
475
|
* Creates an UUID from a hex string representation of an UUID.
|
|
465
476
|
* @param hexString - 32 or 36 character hex string (dashes excluded/included).
|
|
466
477
|
*/
|
|
467
|
-
static createFromHexString(hexString: string): UUID {
|
|
478
|
+
static override createFromHexString(hexString: string): UUID {
|
|
468
479
|
const buffer = uuidHexStringToBuffer(hexString);
|
|
469
480
|
return new UUID(buffer);
|
|
470
481
|
}
|
|
471
482
|
|
|
483
|
+
/** Creates an UUID from a base64 string representation of an UUID. */
|
|
484
|
+
static override createFromBase64(base64: string): UUID {
|
|
485
|
+
return new UUID(ByteUtils.fromBase64(base64));
|
|
486
|
+
}
|
|
487
|
+
|
|
472
488
|
/**
|
|
473
489
|
* Converts to a string representation of this Id.
|
|
474
490
|
*
|
package/src/objectid.ts
CHANGED
|
@@ -264,16 +264,22 @@ export class ObjectId extends BSONValue {
|
|
|
264
264
|
* @param hexString - create a ObjectId from a passed in 24 character hexstring.
|
|
265
265
|
*/
|
|
266
266
|
static createFromHexString(hexString: string): ObjectId {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
throw new BSONError(
|
|
270
|
-
'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters'
|
|
271
|
-
);
|
|
267
|
+
if (hexString?.length !== 24) {
|
|
268
|
+
throw new BSONError('hex string must be 24 characters');
|
|
272
269
|
}
|
|
273
270
|
|
|
274
271
|
return new ObjectId(ByteUtils.fromHex(hexString));
|
|
275
272
|
}
|
|
276
273
|
|
|
274
|
+
/** Creates an ObjectId instance from a base64 string */
|
|
275
|
+
static createFromBase64(base64: string): ObjectId {
|
|
276
|
+
if (base64?.length !== 16) {
|
|
277
|
+
throw new BSONError('base64 string must be 16 characters');
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return new ObjectId(ByteUtils.fromBase64(base64));
|
|
281
|
+
}
|
|
282
|
+
|
|
277
283
|
/**
|
|
278
284
|
* Checks if a value is a valid bson ObjectId
|
|
279
285
|
*
|