@tellescope/utilities 1.72.2 → 1.74.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/lib/cjs/ObjectId/bson_value.d.ts +10 -0
- package/lib/cjs/ObjectId/bson_value.d.ts.map +1 -0
- package/lib/cjs/ObjectId/bson_value.js +20 -0
- package/lib/cjs/ObjectId/bson_value.js.map +1 -0
- package/lib/cjs/ObjectId/constants.d.ts +107 -0
- package/lib/cjs/ObjectId/constants.d.ts.map +1 -0
- package/lib/cjs/ObjectId/constants.js +108 -0
- package/lib/cjs/ObjectId/constants.js.map +1 -0
- package/lib/cjs/ObjectId/error.d.ts +50 -0
- package/lib/cjs/ObjectId/error.d.ts.map +1 -0
- package/lib/cjs/ObjectId/error.js +117 -0
- package/lib/cjs/ObjectId/error.js.map +1 -0
- package/lib/cjs/ObjectId/objectid.d.ts +96 -0
- package/lib/cjs/ObjectId/objectid.d.ts.map +1 -0
- package/lib/cjs/ObjectId/objectid.js +300 -0
- package/lib/cjs/ObjectId/objectid.js.map +1 -0
- package/lib/cjs/ObjectId/parser/utils.d.ts +8 -0
- package/lib/cjs/ObjectId/parser/utils.d.ts.map +1 -0
- package/lib/cjs/ObjectId/parser/utils.js +32 -0
- package/lib/cjs/ObjectId/parser/utils.js.map +1 -0
- package/lib/cjs/ObjectId/utils/byte_utils.d.ts +46 -0
- package/lib/cjs/ObjectId/utils/byte_utils.d.ts.map +1 -0
- package/lib/cjs/ObjectId/utils/byte_utils.js +48 -0
- package/lib/cjs/ObjectId/utils/byte_utils.js.map +1 -0
- package/lib/cjs/ObjectId/utils/node_byte_utils.d.ts +31 -0
- package/lib/cjs/ObjectId/utils/node_byte_utils.d.ts.map +1 -0
- package/lib/cjs/ObjectId/utils/node_byte_utils.js +95 -0
- package/lib/cjs/ObjectId/utils/node_byte_utils.js.map +1 -0
- package/lib/cjs/ObjectId/utils/web_byte_utils.d.ts +27 -0
- package/lib/cjs/ObjectId/utils/web_byte_utils.d.ts.map +1 -0
- package/lib/cjs/ObjectId/utils/web_byte_utils.js +126 -0
- package/lib/cjs/ObjectId/utils/web_byte_utils.js.map +1 -0
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.d.ts.map +1 -1
- package/lib/cjs/utils.js +5 -4
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/ObjectId/bson_value.d.ts +10 -0
- package/lib/esm/ObjectId/bson_value.d.ts.map +1 -0
- package/lib/esm/ObjectId/bson_value.js +17 -0
- package/lib/esm/ObjectId/bson_value.js.map +1 -0
- package/lib/esm/ObjectId/constants.d.ts +107 -0
- package/lib/esm/ObjectId/constants.d.ts.map +1 -0
- package/lib/esm/ObjectId/constants.js +105 -0
- package/lib/esm/ObjectId/constants.js.map +1 -0
- package/lib/esm/ObjectId/error.d.ts +50 -0
- package/lib/esm/ObjectId/error.d.ts.map +1 -0
- package/lib/esm/ObjectId/error.js +114 -0
- package/lib/esm/ObjectId/error.js.map +1 -0
- package/lib/esm/ObjectId/objectid.d.ts +96 -0
- package/lib/esm/ObjectId/objectid.d.ts.map +1 -0
- package/lib/esm/ObjectId/objectid.js +297 -0
- package/lib/esm/ObjectId/objectid.js.map +1 -0
- package/lib/esm/ObjectId/parser/utils.d.ts +8 -0
- package/lib/esm/ObjectId/parser/utils.d.ts.map +1 -0
- package/lib/esm/ObjectId/parser/utils.js +22 -0
- package/lib/esm/ObjectId/parser/utils.js.map +1 -0
- package/lib/esm/ObjectId/utils/byte_utils.d.ts +46 -0
- package/lib/esm/ObjectId/utils/byte_utils.d.ts.map +1 -0
- package/lib/esm/ObjectId/utils/byte_utils.js +45 -0
- package/lib/esm/ObjectId/utils/byte_utils.js.map +1 -0
- package/lib/esm/ObjectId/utils/node_byte_utils.d.ts +31 -0
- package/lib/esm/ObjectId/utils/node_byte_utils.d.ts.map +1 -0
- package/lib/esm/ObjectId/utils/node_byte_utils.js +91 -0
- package/lib/esm/ObjectId/utils/node_byte_utils.js.map +1 -0
- package/lib/esm/ObjectId/utils/web_byte_utils.d.ts +27 -0
- package/lib/esm/ObjectId/utils/web_byte_utils.d.ts.map +1 -0
- package/lib/esm/ObjectId/utils/web_byte_utils.js +122 -0
- package/lib/esm/ObjectId/utils/web_byte_utils.js.map +1 -0
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.d.ts.map +1 -1
- package/lib/esm/utils.js +2 -1
- package/lib/esm/utils.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -6
- package/src/ObjectId/LICENSE.md +201 -0
- package/src/ObjectId/README.txt +1 -0
- package/src/ObjectId/bson_value.ts +18 -0
- package/src/ObjectId/constants.ts +141 -0
- package/src/ObjectId/error.ts +83 -0
- package/src/ObjectId/objectid.ts +325 -0
- package/src/ObjectId/parser/utils.ts +29 -0
- package/src/ObjectId/utils/byte_utils.ts +61 -0
- package/src/ObjectId/utils/node_byte_utils.ts +141 -0
- package/src/ObjectId/utils/web_byte_utils.ts +190 -0
- package/src/utils.ts +3 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
export var BSON_MAJOR_VERSION = 5;
|
|
3
|
+
/** @internal */
|
|
4
|
+
export var BSON_INT32_MAX = 0x7fffffff;
|
|
5
|
+
/** @internal */
|
|
6
|
+
export var BSON_INT32_MIN = -0x80000000;
|
|
7
|
+
/** @internal */
|
|
8
|
+
export var BSON_INT64_MAX = Math.pow(2, 63) - 1;
|
|
9
|
+
/** @internal */
|
|
10
|
+
export var BSON_INT64_MIN = -Math.pow(2, 63);
|
|
11
|
+
/**
|
|
12
|
+
* Any integer up to 2^53 can be precisely represented by a double.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export var JS_INT_MAX = Math.pow(2, 53);
|
|
16
|
+
/**
|
|
17
|
+
* Any integer down to -2^53 can be precisely represented by a double.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export var JS_INT_MIN = -Math.pow(2, 53);
|
|
21
|
+
/** Number BSON Type @internal */
|
|
22
|
+
export var BSON_DATA_NUMBER = 1;
|
|
23
|
+
/** String BSON Type @internal */
|
|
24
|
+
export var BSON_DATA_STRING = 2;
|
|
25
|
+
/** Object BSON Type @internal */
|
|
26
|
+
export var BSON_DATA_OBJECT = 3;
|
|
27
|
+
/** Array BSON Type @internal */
|
|
28
|
+
export var BSON_DATA_ARRAY = 4;
|
|
29
|
+
/** Binary BSON Type @internal */
|
|
30
|
+
export var BSON_DATA_BINARY = 5;
|
|
31
|
+
/** Binary BSON Type @internal */
|
|
32
|
+
export var BSON_DATA_UNDEFINED = 6;
|
|
33
|
+
/** ObjectId BSON Type @internal */
|
|
34
|
+
export var BSON_DATA_OID = 7;
|
|
35
|
+
/** Boolean BSON Type @internal */
|
|
36
|
+
export var BSON_DATA_BOOLEAN = 8;
|
|
37
|
+
/** Date BSON Type @internal */
|
|
38
|
+
export var BSON_DATA_DATE = 9;
|
|
39
|
+
/** null BSON Type @internal */
|
|
40
|
+
export var BSON_DATA_NULL = 10;
|
|
41
|
+
/** RegExp BSON Type @internal */
|
|
42
|
+
export var BSON_DATA_REGEXP = 11;
|
|
43
|
+
/** Code BSON Type @internal */
|
|
44
|
+
export var BSON_DATA_DBPOINTER = 12;
|
|
45
|
+
/** Code BSON Type @internal */
|
|
46
|
+
export var BSON_DATA_CODE = 13;
|
|
47
|
+
/** Symbol BSON Type @internal */
|
|
48
|
+
export var BSON_DATA_SYMBOL = 14;
|
|
49
|
+
/** Code with Scope BSON Type @internal */
|
|
50
|
+
export var BSON_DATA_CODE_W_SCOPE = 15;
|
|
51
|
+
/** 32 bit Integer BSON Type @internal */
|
|
52
|
+
export var BSON_DATA_INT = 16;
|
|
53
|
+
/** Timestamp BSON Type @internal */
|
|
54
|
+
export var BSON_DATA_TIMESTAMP = 17;
|
|
55
|
+
/** Long BSON Type @internal */
|
|
56
|
+
export var BSON_DATA_LONG = 18;
|
|
57
|
+
/** Decimal128 BSON Type @internal */
|
|
58
|
+
export var BSON_DATA_DECIMAL128 = 19;
|
|
59
|
+
/** MinKey BSON Type @internal */
|
|
60
|
+
export var BSON_DATA_MIN_KEY = 0xff;
|
|
61
|
+
/** MaxKey BSON Type @internal */
|
|
62
|
+
export var BSON_DATA_MAX_KEY = 0x7f;
|
|
63
|
+
/** Binary Default Type @internal */
|
|
64
|
+
export var BSON_BINARY_SUBTYPE_DEFAULT = 0;
|
|
65
|
+
/** Binary Function Type @internal */
|
|
66
|
+
export var BSON_BINARY_SUBTYPE_FUNCTION = 1;
|
|
67
|
+
/** Binary Byte Array Type @internal */
|
|
68
|
+
export var BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
|
|
69
|
+
/** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
|
|
70
|
+
export var BSON_BINARY_SUBTYPE_UUID = 3;
|
|
71
|
+
/** Binary UUID Type @internal */
|
|
72
|
+
export var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
|
|
73
|
+
/** Binary MD5 Type @internal */
|
|
74
|
+
export var BSON_BINARY_SUBTYPE_MD5 = 5;
|
|
75
|
+
/** Encrypted BSON type @internal */
|
|
76
|
+
export var BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
|
|
77
|
+
/** Column BSON type @internal */
|
|
78
|
+
export var BSON_BINARY_SUBTYPE_COLUMN = 7;
|
|
79
|
+
/** Binary User Defined Type @internal */
|
|
80
|
+
export var BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
|
|
81
|
+
/** @public */
|
|
82
|
+
export var BSONType = Object.freeze({
|
|
83
|
+
double: 1,
|
|
84
|
+
string: 2,
|
|
85
|
+
object: 3,
|
|
86
|
+
array: 4,
|
|
87
|
+
binData: 5,
|
|
88
|
+
undefined: 6,
|
|
89
|
+
objectId: 7,
|
|
90
|
+
bool: 8,
|
|
91
|
+
date: 9,
|
|
92
|
+
null: 10,
|
|
93
|
+
regex: 11,
|
|
94
|
+
dbPointer: 12,
|
|
95
|
+
javascript: 13,
|
|
96
|
+
symbol: 14,
|
|
97
|
+
javascriptWithScope: 15,
|
|
98
|
+
int: 16,
|
|
99
|
+
timestamp: 17,
|
|
100
|
+
long: 18,
|
|
101
|
+
decimal: 19,
|
|
102
|
+
minKey: -1,
|
|
103
|
+
maxKey: 127
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/ObjectId/constants.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,MAAM,CAAC,IAAM,kBAAkB,GAAG,CAAU,CAAC;AAE7C,gBAAgB;AAChB,MAAM,CAAC,IAAM,cAAc,GAAG,UAAU,CAAC;AACzC,gBAAgB;AAChB,MAAM,CAAC,IAAM,cAAc,GAAG,CAAC,UAAU,CAAC;AAC1C,gBAAgB;AAChB,MAAM,CAAC,IAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;AAClD,gBAAgB;AAChB,MAAM,CAAC,IAAM,cAAc,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,IAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAE1C;;;GAGG;AACH,MAAM,CAAC,IAAM,UAAU,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAE3C,iCAAiC;AACjC,MAAM,CAAC,IAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,iCAAiC;AACjC,MAAM,CAAC,IAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,iCAAiC;AACjC,MAAM,CAAC,IAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,gCAAgC;AAChC,MAAM,CAAC,IAAM,eA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
*
|
|
7
|
+
* This is the parent class for all the other errors thrown by this library.
|
|
8
|
+
*/
|
|
9
|
+
export declare class BSONError extends Error {
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
* The underlying algorithm for isBSONError may change to improve how strict it is
|
|
13
|
+
* about determining if an input is a BSONError. But it must remain backwards compatible
|
|
14
|
+
* with previous minors & patches of the current major version.
|
|
15
|
+
*/
|
|
16
|
+
protected get bsonError(): true;
|
|
17
|
+
get name(): string;
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
/**
|
|
20
|
+
* @public
|
|
21
|
+
*
|
|
22
|
+
* All errors thrown from the BSON library inherit from `BSONError`.
|
|
23
|
+
* This method can assist with determining if an error originates from the BSON library
|
|
24
|
+
* even if it does not pass an `instanceof` check against this class' constructor.
|
|
25
|
+
*
|
|
26
|
+
* @param value - any javascript value that needs type checking
|
|
27
|
+
*/
|
|
28
|
+
static isBSONError(value: unknown): value is BSONError;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @public
|
|
32
|
+
* @category Error
|
|
33
|
+
*/
|
|
34
|
+
export declare class BSONVersionError extends BSONError {
|
|
35
|
+
get name(): 'BSONVersionError';
|
|
36
|
+
constructor();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @public
|
|
40
|
+
* @category Error
|
|
41
|
+
*
|
|
42
|
+
* An error generated when BSON functions encounter an unexpected input
|
|
43
|
+
* or reaches an unexpected/invalid internal state
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
export declare class BSONRuntimeError extends BSONError {
|
|
47
|
+
get name(): 'BSONRuntimeError';
|
|
48
|
+
constructor(message: string);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/ObjectId/error.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC;;;;;OAKG;IACH,SAAS,KAAK,SAAS,IAAI,IAAI,CAE9B;IAED,IAAa,IAAI,IAAI,MAAM,CAE1B;gBAEW,OAAO,EAAE,MAAM;IAI3B;;;;;;;;OAQG;WACW,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS;CAY9D;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;IAC7C,IAAI,IAAI,IAAI,kBAAkB,CAE7B;;CAKF;AAED;;;;;;;GAOG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;IAC7C,IAAI,IAAI,IAAI,kBAAkB,CAE7B;gBAEW,OAAO,EAAE,MAAM;CAG5B"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
import { BSON_MAJOR_VERSION } from './constants';
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
* @category Error
|
|
20
|
+
*
|
|
21
|
+
* `BSONError` objects are thrown when BSON ecounters an error.
|
|
22
|
+
*
|
|
23
|
+
* This is the parent class for all the other errors thrown by this library.
|
|
24
|
+
*/
|
|
25
|
+
var BSONError = /** @class */ (function (_super) {
|
|
26
|
+
__extends(BSONError, _super);
|
|
27
|
+
function BSONError(message) {
|
|
28
|
+
return _super.call(this, message) || this;
|
|
29
|
+
}
|
|
30
|
+
Object.defineProperty(BSONError.prototype, "bsonError", {
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
* The underlying algorithm for isBSONError may change to improve how strict it is
|
|
34
|
+
* about determining if an input is a BSONError. But it must remain backwards compatible
|
|
35
|
+
* with previous minors & patches of the current major version.
|
|
36
|
+
*/
|
|
37
|
+
get: function () {
|
|
38
|
+
return true;
|
|
39
|
+
},
|
|
40
|
+
enumerable: false,
|
|
41
|
+
configurable: true
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(BSONError.prototype, "name", {
|
|
44
|
+
get: function () {
|
|
45
|
+
return 'BSONError';
|
|
46
|
+
},
|
|
47
|
+
enumerable: false,
|
|
48
|
+
configurable: true
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* @public
|
|
52
|
+
*
|
|
53
|
+
* All errors thrown from the BSON library inherit from `BSONError`.
|
|
54
|
+
* This method can assist with determining if an error originates from the BSON library
|
|
55
|
+
* even if it does not pass an `instanceof` check against this class' constructor.
|
|
56
|
+
*
|
|
57
|
+
* @param value - any javascript value that needs type checking
|
|
58
|
+
*/
|
|
59
|
+
BSONError.isBSONError = function (value) {
|
|
60
|
+
return (value != null &&
|
|
61
|
+
typeof value === 'object' &&
|
|
62
|
+
'bsonError' in value &&
|
|
63
|
+
value.bsonError === true &&
|
|
64
|
+
// Do not access the following properties, just check existence
|
|
65
|
+
'name' in value &&
|
|
66
|
+
'message' in value &&
|
|
67
|
+
'stack' in value);
|
|
68
|
+
};
|
|
69
|
+
return BSONError;
|
|
70
|
+
}(Error));
|
|
71
|
+
export { BSONError };
|
|
72
|
+
/**
|
|
73
|
+
* @public
|
|
74
|
+
* @category Error
|
|
75
|
+
*/
|
|
76
|
+
var BSONVersionError = /** @class */ (function (_super) {
|
|
77
|
+
__extends(BSONVersionError, _super);
|
|
78
|
+
function BSONVersionError() {
|
|
79
|
+
return _super.call(this, "Unsupported BSON version, bson types must be from bson ".concat(BSON_MAJOR_VERSION, ".x.x")) || this;
|
|
80
|
+
}
|
|
81
|
+
Object.defineProperty(BSONVersionError.prototype, "name", {
|
|
82
|
+
get: function () {
|
|
83
|
+
return 'BSONVersionError';
|
|
84
|
+
},
|
|
85
|
+
enumerable: false,
|
|
86
|
+
configurable: true
|
|
87
|
+
});
|
|
88
|
+
return BSONVersionError;
|
|
89
|
+
}(BSONError));
|
|
90
|
+
export { BSONVersionError };
|
|
91
|
+
/**
|
|
92
|
+
* @public
|
|
93
|
+
* @category Error
|
|
94
|
+
*
|
|
95
|
+
* An error generated when BSON functions encounter an unexpected input
|
|
96
|
+
* or reaches an unexpected/invalid internal state
|
|
97
|
+
*
|
|
98
|
+
*/
|
|
99
|
+
var BSONRuntimeError = /** @class */ (function (_super) {
|
|
100
|
+
__extends(BSONRuntimeError, _super);
|
|
101
|
+
function BSONRuntimeError(message) {
|
|
102
|
+
return _super.call(this, message) || this;
|
|
103
|
+
}
|
|
104
|
+
Object.defineProperty(BSONRuntimeError.prototype, "name", {
|
|
105
|
+
get: function () {
|
|
106
|
+
return 'BSONRuntimeError';
|
|
107
|
+
},
|
|
108
|
+
enumerable: false,
|
|
109
|
+
configurable: true
|
|
110
|
+
});
|
|
111
|
+
return BSONRuntimeError;
|
|
112
|
+
}(BSONError));
|
|
113
|
+
export { BSONRuntimeError };
|
|
114
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/ObjectId/error.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;;;GAOG;AACH;IAA+B,6BAAK;IAelC,mBAAY,OAAe;eACzB,kBAAM,OAAO,CAAC;IAChB,CAAC;IAVD,sBAAc,gCAAS;QANvB;;;;;WAKG;aACH;YACE,OAAO,IAAI,CAAC;QACd,CAAC;;;OAAA;IAED,sBAAa,2BAAI;aAAjB;YACE,OAAO,WAAW,CAAC;QACrB,CAAC;;;OAAA;IAMD;;;;;;;;OAQG;IACW,qBAAW,GAAzB,UAA0B,KAAc;QACtC,OAAO,CACL,KAAK,IAAI,IAAI;YACb,OAAO,KAAK,KAAK,QAAQ;YACzB,WAAW,IAAI,KAAK;YACpB,KAAK,CAAC,SAAS,KAAK,IAAI;YACxB,+DAA+D;YAC/D,MAAM,IAAI,KAAK;YACf,SAAS,IAAI,KAAK;YAClB,OAAO,IAAI,KAAK,CACjB,CAAC;IACJ,CAAC;IACH,gBAAC;AAAD,CAAC,AAxCD,CAA+B,KAAK,GAwCnC;;AAED;;;GAGG;AACH;IAAsC,oCAAS;IAK7C;eACE,kBAAM,iEAA0D,kBAAkB,SAAM,CAAC;IAC3F,CAAC;IAND,sBAAI,kCAAI;aAAR;YACE,OAAO,kBAAkB,CAAC;QAC5B,CAAC;;;OAAA;IAKH,uBAAC;AAAD,CAAC,AARD,CAAsC,SAAS,GAQ9C;;AAED;;;;;;;GAOG;AACH;IAAsC,oCAAS;IAK7C,0BAAY,OAAe;eACzB,kBAAM,OAAO,CAAC;IAChB,CAAC;IAND,sBAAI,kCAAI;aAAR;YACE,OAAO,kBAAkB,CAAC;QAC5B,CAAC;;;OAAA;IAKH,uBAAC;AAAD,CAAC,AARD,CAAsC,SAAS,GAQ9C"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { BSONValue } from './bson_value';
|
|
2
|
+
/** @public */
|
|
3
|
+
export interface ObjectIdLike {
|
|
4
|
+
id: string | Uint8Array;
|
|
5
|
+
__id?: string;
|
|
6
|
+
toHexString(): string;
|
|
7
|
+
}
|
|
8
|
+
/** @public */
|
|
9
|
+
export interface ObjectIdExtended {
|
|
10
|
+
$oid: string;
|
|
11
|
+
}
|
|
12
|
+
declare const kId: unique symbol;
|
|
13
|
+
/**
|
|
14
|
+
* A class representation of the BSON ObjectId type.
|
|
15
|
+
* @public
|
|
16
|
+
* @category BSONType
|
|
17
|
+
*/
|
|
18
|
+
export declare class ObjectId extends BSONValue {
|
|
19
|
+
get _bsontype(): 'ObjectId';
|
|
20
|
+
/** @internal */
|
|
21
|
+
private static index;
|
|
22
|
+
static cacheHexString: boolean;
|
|
23
|
+
/** ObjectId Bytes @internal */
|
|
24
|
+
private [kId];
|
|
25
|
+
/** ObjectId hexString cache @internal */
|
|
26
|
+
private __id?;
|
|
27
|
+
/**
|
|
28
|
+
* Create an ObjectId type
|
|
29
|
+
*
|
|
30
|
+
* @param inputId - Can be a 24 character hex string, 12 byte binary Buffer, or a number.
|
|
31
|
+
*/
|
|
32
|
+
constructor(inputId?: string | number | ObjectId | ObjectIdLike | Uint8Array);
|
|
33
|
+
/**
|
|
34
|
+
* The ObjectId bytes
|
|
35
|
+
* @readonly
|
|
36
|
+
*/
|
|
37
|
+
get id(): Uint8Array;
|
|
38
|
+
set id(value: Uint8Array);
|
|
39
|
+
/** Returns the ObjectId id as a 24 character hex string representation */
|
|
40
|
+
toHexString(): string;
|
|
41
|
+
/**
|
|
42
|
+
* Update the ObjectId index
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
private static getInc;
|
|
46
|
+
/**
|
|
47
|
+
* Generate a 12 byte id buffer used in ObjectId's
|
|
48
|
+
*
|
|
49
|
+
* @param time - pass in a second based timestamp.
|
|
50
|
+
*/
|
|
51
|
+
static generate(time?: number): Uint8Array;
|
|
52
|
+
/**
|
|
53
|
+
* Converts the id into a 24 character hex string for printing, unless encoding is provided.
|
|
54
|
+
* @param encoding - hex or base64
|
|
55
|
+
*/
|
|
56
|
+
toString(encoding?: 'hex' | 'base64'): string;
|
|
57
|
+
/** Converts to its JSON the 24 character hex string representation. */
|
|
58
|
+
toJSON(): string;
|
|
59
|
+
/**
|
|
60
|
+
* Compares the equality of this ObjectId with `otherID`.
|
|
61
|
+
*
|
|
62
|
+
* @param otherId - ObjectId instance to compare against.
|
|
63
|
+
*/
|
|
64
|
+
equals(otherId: string | ObjectId | ObjectIdLike): boolean;
|
|
65
|
+
/** Returns the generation date (accurate up to the second) that this ID was generated. */
|
|
66
|
+
getTimestamp(): Date;
|
|
67
|
+
/** @internal */
|
|
68
|
+
static createPk(): ObjectId;
|
|
69
|
+
/**
|
|
70
|
+
* Creates an ObjectId from a second based number, with the rest of the ObjectId zeroed out. Used for comparisons or sorting the ObjectId.
|
|
71
|
+
*
|
|
72
|
+
* @param time - an integer number representing a number of seconds.
|
|
73
|
+
*/
|
|
74
|
+
static createFromTime(time: number): ObjectId;
|
|
75
|
+
/**
|
|
76
|
+
* Creates an ObjectId from a hex string representation of an ObjectId.
|
|
77
|
+
*
|
|
78
|
+
* @param hexString - create a ObjectId from a passed in 24 character hexstring.
|
|
79
|
+
*/
|
|
80
|
+
static createFromHexString(hexString: string): ObjectId;
|
|
81
|
+
/** Creates an ObjectId instance from a base64 string */
|
|
82
|
+
static createFromBase64(base64: string): ObjectId;
|
|
83
|
+
/**
|
|
84
|
+
* Checks if a value is a valid bson ObjectId
|
|
85
|
+
*
|
|
86
|
+
* @param id - ObjectId instance to validate.
|
|
87
|
+
*/
|
|
88
|
+
static isValid(id: string | number | ObjectId | ObjectIdLike | Uint8Array): boolean;
|
|
89
|
+
/** @internal */
|
|
90
|
+
toExtendedJSON(): ObjectIdExtended;
|
|
91
|
+
/** @internal */
|
|
92
|
+
static fromExtendedJSON(doc: ObjectIdExtended): ObjectId;
|
|
93
|
+
inspect(): string;
|
|
94
|
+
}
|
|
95
|
+
export {};
|
|
96
|
+
//# sourceMappingURL=objectid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectid.d.ts","sourceRoot":"","sources":["../../../src/ObjectId/objectid.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAWzC,cAAc;AACd,MAAM,WAAW,YAAY;IAC3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CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ;IAQ7C;;;;OAIG;IACH,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ;IAQvD,wDAAwD;IACxD,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ;IAQjD;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,YAAY,GAAG,UAAU,GAAG,OAAO;IAWnF,gBAAgB;IAChB,cAAc,IAAI,gBAAgB;IAKlC,gBAAgB;IAChB,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,gBAAgB,GAAG,QAAQ;IAcxD,OAAO,IAAI,MAAM;CAGlB"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
//
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
import { BSONValue } from './bson_value';
|
|
18
|
+
import { BSONError } from './error';
|
|
19
|
+
import { isUint8Array } from './parser/utils';
|
|
20
|
+
import { BSONDataView, ByteUtils } from './utils/byte_utils';
|
|
21
|
+
// Regular expression that checks for hex value
|
|
22
|
+
var checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$');
|
|
23
|
+
// Unique sequence for the current process (initialized on first use)
|
|
24
|
+
var PROCESS_UNIQUE = null;
|
|
25
|
+
var kId = Symbol('id');
|
|
26
|
+
/**
|
|
27
|
+
* A class representation of the BSON ObjectId type.
|
|
28
|
+
* @public
|
|
29
|
+
* @category BSONType
|
|
30
|
+
*/
|
|
31
|
+
var ObjectId = /** @class */ (function (_super) {
|
|
32
|
+
__extends(ObjectId, _super);
|
|
33
|
+
/**
|
|
34
|
+
* Create an ObjectId type
|
|
35
|
+
*
|
|
36
|
+
* @param inputId - Can be a 24 character hex string, 12 byte binary Buffer, or a number.
|
|
37
|
+
*/
|
|
38
|
+
function ObjectId(inputId) {
|
|
39
|
+
var _this = _super.call(this) || this;
|
|
40
|
+
// workingId is set based on type of input and whether valid id exists for the input
|
|
41
|
+
var workingId;
|
|
42
|
+
if (typeof inputId === 'object' && inputId && 'id' in inputId) {
|
|
43
|
+
if (typeof inputId.id !== 'string' && !ArrayBuffer.isView(inputId.id)) {
|
|
44
|
+
throw new BSONError('Argument passed in must have an id that is of type string or Buffer');
|
|
45
|
+
}
|
|
46
|
+
if ('toHexString' in inputId && typeof inputId.toHexString === 'function') {
|
|
47
|
+
workingId = ByteUtils.fromHex(inputId.toHexString());
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
workingId = inputId.id;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
workingId = inputId;
|
|
55
|
+
}
|
|
56
|
+
// the following cases use workingId to construct an ObjectId
|
|
57
|
+
if (workingId == null || typeof workingId === 'number') {
|
|
58
|
+
// The most common use case (blank id, new objectId instance)
|
|
59
|
+
// Generate a new id
|
|
60
|
+
_this[kId] = ObjectId.generate(typeof workingId === 'number' ? workingId : undefined);
|
|
61
|
+
}
|
|
62
|
+
else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
|
|
63
|
+
// If intstanceof matches we can escape calling ensure buffer in Node.js environments
|
|
64
|
+
_this[kId] = ByteUtils.toLocalBufferType(workingId);
|
|
65
|
+
}
|
|
66
|
+
else if (typeof workingId === 'string') {
|
|
67
|
+
if (workingId.length === 12) {
|
|
68
|
+
// TODO(NODE-4361): Remove string of length 12 support
|
|
69
|
+
var bytes = ByteUtils.fromUTF8(workingId);
|
|
70
|
+
if (bytes.byteLength === 12) {
|
|
71
|
+
_this[kId] = bytes;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
throw new BSONError('Argument passed in must be a string of 12 bytes');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (workingId.length === 24 && checkForHexRegExp.test(workingId)) {
|
|
78
|
+
_this[kId] = ByteUtils.fromHex(workingId);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
throw new BSONError('Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
throw new BSONError('Argument passed in does not match the accepted types');
|
|
86
|
+
}
|
|
87
|
+
// If we are caching the hex string
|
|
88
|
+
if (ObjectId.cacheHexString) {
|
|
89
|
+
_this.__id = ByteUtils.toHex(_this.id);
|
|
90
|
+
}
|
|
91
|
+
return _this;
|
|
92
|
+
}
|
|
93
|
+
Object.defineProperty(ObjectId.prototype, "_bsontype", {
|
|
94
|
+
get: function () {
|
|
95
|
+
return 'ObjectId';
|
|
96
|
+
},
|
|
97
|
+
enumerable: false,
|
|
98
|
+
configurable: true
|
|
99
|
+
});
|
|
100
|
+
Object.defineProperty(ObjectId.prototype, "id", {
|
|
101
|
+
/**
|
|
102
|
+
* The ObjectId bytes
|
|
103
|
+
* @readonly
|
|
104
|
+
*/
|
|
105
|
+
get: function () {
|
|
106
|
+
return this[kId];
|
|
107
|
+
},
|
|
108
|
+
set: function (value) {
|
|
109
|
+
this[kId] = value;
|
|
110
|
+
if (ObjectId.cacheHexString) {
|
|
111
|
+
this.__id = ByteUtils.toHex(value);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
enumerable: false,
|
|
115
|
+
configurable: true
|
|
116
|
+
});
|
|
117
|
+
/** Returns the ObjectId id as a 24 character hex string representation */
|
|
118
|
+
ObjectId.prototype.toHexString = function () {
|
|
119
|
+
if (ObjectId.cacheHexString && this.__id) {
|
|
120
|
+
return this.__id;
|
|
121
|
+
}
|
|
122
|
+
var hexString = ByteUtils.toHex(this.id);
|
|
123
|
+
if (ObjectId.cacheHexString && !this.__id) {
|
|
124
|
+
this.__id = hexString;
|
|
125
|
+
}
|
|
126
|
+
return hexString;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Update the ObjectId index
|
|
130
|
+
* @internal
|
|
131
|
+
*/
|
|
132
|
+
ObjectId.getInc = function () {
|
|
133
|
+
return (ObjectId.index = (ObjectId.index + 1) % 0xffffff);
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Generate a 12 byte id buffer used in ObjectId's
|
|
137
|
+
*
|
|
138
|
+
* @param time - pass in a second based timestamp.
|
|
139
|
+
*/
|
|
140
|
+
ObjectId.generate = function (time) {
|
|
141
|
+
if ('number' !== typeof time) {
|
|
142
|
+
time = Math.floor(Date.now() / 1000);
|
|
143
|
+
}
|
|
144
|
+
var inc = ObjectId.getInc();
|
|
145
|
+
var buffer = ByteUtils.allocate(12);
|
|
146
|
+
// 4-byte timestamp
|
|
147
|
+
BSONDataView.fromUint8Array(buffer).setUint32(0, time, false);
|
|
148
|
+
// set PROCESS_UNIQUE if yet not initialized
|
|
149
|
+
if (PROCESS_UNIQUE === null) {
|
|
150
|
+
PROCESS_UNIQUE = ByteUtils.randomBytes(5);
|
|
151
|
+
}
|
|
152
|
+
// 5-byte process unique
|
|
153
|
+
buffer[4] = PROCESS_UNIQUE[0];
|
|
154
|
+
buffer[5] = PROCESS_UNIQUE[1];
|
|
155
|
+
buffer[6] = PROCESS_UNIQUE[2];
|
|
156
|
+
buffer[7] = PROCESS_UNIQUE[3];
|
|
157
|
+
buffer[8] = PROCESS_UNIQUE[4];
|
|
158
|
+
// 3-byte counter
|
|
159
|
+
buffer[11] = inc & 0xff;
|
|
160
|
+
buffer[10] = (inc >> 8) & 0xff;
|
|
161
|
+
buffer[9] = (inc >> 16) & 0xff;
|
|
162
|
+
return buffer;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Converts the id into a 24 character hex string for printing, unless encoding is provided.
|
|
166
|
+
* @param encoding - hex or base64
|
|
167
|
+
*/
|
|
168
|
+
ObjectId.prototype.toString = function (encoding) {
|
|
169
|
+
// Is the id a buffer then use the buffer toString method to return the format
|
|
170
|
+
if (encoding === 'base64')
|
|
171
|
+
return ByteUtils.toBase64(this.id);
|
|
172
|
+
if (encoding === 'hex')
|
|
173
|
+
return this.toHexString();
|
|
174
|
+
return this.toHexString();
|
|
175
|
+
};
|
|
176
|
+
/** Converts to its JSON the 24 character hex string representation. */
|
|
177
|
+
ObjectId.prototype.toJSON = function () {
|
|
178
|
+
return this.toHexString();
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Compares the equality of this ObjectId with `otherID`.
|
|
182
|
+
*
|
|
183
|
+
* @param otherId - ObjectId instance to compare against.
|
|
184
|
+
*/
|
|
185
|
+
ObjectId.prototype.equals = function (otherId) {
|
|
186
|
+
if (otherId === undefined || otherId === null) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
if (otherId instanceof ObjectId) {
|
|
190
|
+
return this[kId][11] === otherId[kId][11] && ByteUtils.equals(this[kId], otherId[kId]);
|
|
191
|
+
}
|
|
192
|
+
if (typeof otherId === 'string' &&
|
|
193
|
+
ObjectId.isValid(otherId) &&
|
|
194
|
+
otherId.length === 12 &&
|
|
195
|
+
isUint8Array(this.id)) {
|
|
196
|
+
return ByteUtils.equals(this.id, ByteUtils.fromISO88591(otherId));
|
|
197
|
+
}
|
|
198
|
+
if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 24) {
|
|
199
|
+
return otherId.toLowerCase() === this.toHexString();
|
|
200
|
+
}
|
|
201
|
+
if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 12) {
|
|
202
|
+
return ByteUtils.equals(ByteUtils.fromUTF8(otherId), this.id);
|
|
203
|
+
}
|
|
204
|
+
if (typeof otherId === 'object' &&
|
|
205
|
+
'toHexString' in otherId &&
|
|
206
|
+
typeof otherId.toHexString === 'function') {
|
|
207
|
+
var otherIdString = otherId.toHexString();
|
|
208
|
+
var thisIdString = this.toHexString().toLowerCase();
|
|
209
|
+
return typeof otherIdString === 'string' && otherIdString.toLowerCase() === thisIdString;
|
|
210
|
+
}
|
|
211
|
+
return false;
|
|
212
|
+
};
|
|
213
|
+
/** Returns the generation date (accurate up to the second) that this ID was generated. */
|
|
214
|
+
ObjectId.prototype.getTimestamp = function () {
|
|
215
|
+
var timestamp = new Date();
|
|
216
|
+
var time = BSONDataView.fromUint8Array(this.id).getUint32(0, false);
|
|
217
|
+
timestamp.setTime(Math.floor(time) * 1000);
|
|
218
|
+
return timestamp;
|
|
219
|
+
};
|
|
220
|
+
/** @internal */
|
|
221
|
+
ObjectId.createPk = function () {
|
|
222
|
+
return new ObjectId();
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Creates an ObjectId from a second based number, with the rest of the ObjectId zeroed out. Used for comparisons or sorting the ObjectId.
|
|
226
|
+
*
|
|
227
|
+
* @param time - an integer number representing a number of seconds.
|
|
228
|
+
*/
|
|
229
|
+
ObjectId.createFromTime = function (time) {
|
|
230
|
+
var buffer = ByteUtils.fromNumberArray([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
231
|
+
// Encode time into first 4 bytes
|
|
232
|
+
BSONDataView.fromUint8Array(buffer).setUint32(0, time, false);
|
|
233
|
+
// Return the new objectId
|
|
234
|
+
return new ObjectId(buffer);
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Creates an ObjectId from a hex string representation of an ObjectId.
|
|
238
|
+
*
|
|
239
|
+
* @param hexString - create a ObjectId from a passed in 24 character hexstring.
|
|
240
|
+
*/
|
|
241
|
+
ObjectId.createFromHexString = function (hexString) {
|
|
242
|
+
if ((hexString === null || hexString === void 0 ? void 0 : hexString.length) !== 24) {
|
|
243
|
+
throw new BSONError('hex string must be 24 characters');
|
|
244
|
+
}
|
|
245
|
+
return new ObjectId(ByteUtils.fromHex(hexString));
|
|
246
|
+
};
|
|
247
|
+
/** Creates an ObjectId instance from a base64 string */
|
|
248
|
+
ObjectId.createFromBase64 = function (base64) {
|
|
249
|
+
if ((base64 === null || base64 === void 0 ? void 0 : base64.length) !== 16) {
|
|
250
|
+
throw new BSONError('base64 string must be 16 characters');
|
|
251
|
+
}
|
|
252
|
+
return new ObjectId(ByteUtils.fromBase64(base64));
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* Checks if a value is a valid bson ObjectId
|
|
256
|
+
*
|
|
257
|
+
* @param id - ObjectId instance to validate.
|
|
258
|
+
*/
|
|
259
|
+
ObjectId.isValid = function (id) {
|
|
260
|
+
if (id == null)
|
|
261
|
+
return false;
|
|
262
|
+
try {
|
|
263
|
+
new ObjectId(id);
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
catch (_a) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
/** @internal */
|
|
271
|
+
ObjectId.prototype.toExtendedJSON = function () {
|
|
272
|
+
if (this.toHexString)
|
|
273
|
+
return { $oid: this.toHexString() };
|
|
274
|
+
return { $oid: this.toString('hex') };
|
|
275
|
+
};
|
|
276
|
+
/** @internal */
|
|
277
|
+
ObjectId.fromExtendedJSON = function (doc) {
|
|
278
|
+
return new ObjectId(doc.$oid);
|
|
279
|
+
};
|
|
280
|
+
/**
|
|
281
|
+
* Converts to a string representation of this Id.
|
|
282
|
+
*
|
|
283
|
+
* @returns return the 24 character hex string representation.
|
|
284
|
+
* @internal
|
|
285
|
+
*/
|
|
286
|
+
ObjectId.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
|
|
287
|
+
return this.inspect();
|
|
288
|
+
};
|
|
289
|
+
ObjectId.prototype.inspect = function () {
|
|
290
|
+
return "new ObjectId(\"".concat(this.toHexString(), "\")");
|
|
291
|
+
};
|
|
292
|
+
/** @internal */
|
|
293
|
+
ObjectId.index = Math.floor(Math.random() * 0xffffff);
|
|
294
|
+
return ObjectId;
|
|
295
|
+
}(BSONValue));
|
|
296
|
+
export { ObjectId };
|
|
297
|
+
//# sourceMappingURL=objectid.js.map
|