@mongosh/service-provider-core 3.1.0 → 3.3.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/all-transport-types.d.ts +1 -1
- package/lib/printable-bson.d.ts +3 -1
- package/lib/printable-bson.js +31 -1
- package/lib/printable-bson.js.map +1 -1
- package/lib/writable.d.ts +2 -1
- package/package.json +3 -2
- package/src/all-transport-types.ts +3 -0
- package/src/printable-bson.spec.ts +28 -0
- package/src/printable-bson.ts +60 -8
- package/src/writable.ts +15 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { AggregateOptions, AggregationCursor, AnyBulkWriteOperation, Batch, BulkWriteOptions, BulkWriteResult, ChangeStream, ChangeStreamOptions, ClientSession, CollationOptions, Collection, CommandOperationOptions, CountDocumentsOptions, CountOptions, CreateCollectionOptions, CreateIndexesOptions, ClientSessionOptions, ClusterTime, FindCursor, CursorFlag, RunCommandCursor, Db, DbOptions, DeleteOptions, DeleteResult, DistinctOptions, Document, DropCollectionOptions, DropDatabaseOptions, EstimatedDocumentCountOptions, ExplainOptions, ExplainVerbosityLike, FindOneAndDeleteOptions, FindOneAndUpdateOptions, FindOneAndReplaceOptions, FindOperators, FindOptions, HedgeOptions, IndexDescription, InsertManyResult, InsertOneOptions, InsertOneResult, ListCollectionsOptions, ListDatabasesOptions, ListIndexesOptions, MongoClientOptions, OrderedBulkOperation, ReadConcern, ReadConcernLike, ReadConcernLevel, ReadPreference, ReadPreferenceLike, ReadPreferenceFromOptions, ReadPreferenceMode, RenameOptions, ReplaceOptions, ResumeToken, RunCommandOptions, SearchIndexDescription, ServerSessionId, TagSet, TransactionOptions, UpdateOptions, UpdateResult, UnorderedBulkOperation, WriteConcern, ObjectId as ObjectIdType, Timestamp as TimestampType, Binary as BinaryType, TopologyDescription, TopologyType, ServerType, AutoEncryptionOptions, ServerApi, ServerApiVersion, MongoClient, } from 'mongodb';
|
|
1
|
+
export type { AggregateOptions, AggregationCursor, AnyBulkWriteOperation, AnyClientBulkWriteModel, Batch, BulkWriteOptions, BulkWriteResult, ClientBulkWriteResult, ClientBulkWriteOptions, ChangeStream, ChangeStreamOptions, ClientSession, CollationOptions, Collection, CommandOperationOptions, CountDocumentsOptions, CountOptions, CreateCollectionOptions, CreateIndexesOptions, ClientSessionOptions, ClusterTime, FindCursor, CursorFlag, RunCommandCursor, Db, DbOptions, DeleteOptions, DeleteResult, DistinctOptions, Document, DropCollectionOptions, DropDatabaseOptions, EstimatedDocumentCountOptions, ExplainOptions, ExplainVerbosityLike, FindOneAndDeleteOptions, FindOneAndUpdateOptions, FindOneAndReplaceOptions, FindOperators, FindOptions, HedgeOptions, IndexDescription, InsertManyResult, InsertOneOptions, InsertOneResult, ListCollectionsOptions, ListDatabasesOptions, ListIndexesOptions, MongoClientOptions, OrderedBulkOperation, ReadConcern, ReadConcernLike, ReadConcernLevel, ReadPreference, ReadPreferenceLike, ReadPreferenceFromOptions, ReadPreferenceMode, RenameOptions, ReplaceOptions, ResumeToken, RunCommandOptions, SearchIndexDescription, ServerSessionId, TagSet, TransactionOptions, UpdateOptions, UpdateResult, UnorderedBulkOperation, WriteConcern, ObjectId as ObjectIdType, Timestamp as TimestampType, Binary as BinaryType, TopologyDescription, TopologyType, ServerType, AutoEncryptionOptions, ServerApi, ServerApiVersion, MongoClient, } from 'mongodb';
|
package/lib/printable-bson.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { bson as BSON } from './bson-export';
|
|
3
|
+
import type { CustomInspectFunction } from 'util';
|
|
2
4
|
type BSONClassKey = (typeof BSON)[Exclude<keyof typeof BSON, 'EJSON' | 'calculateObjectSize'>]['prototype']['_bsontype'];
|
|
3
|
-
export declare const bsonStringifiers: Record<BSONClassKey | 'ObjectID',
|
|
5
|
+
export declare const bsonStringifiers: Record<BSONClassKey | 'ObjectID', CustomInspectFunction>;
|
|
4
6
|
export declare function makePrintableBson(bson?: typeof BSON): void;
|
|
5
7
|
export {};
|
package/lib/printable-bson.js
CHANGED
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makePrintableBson = exports.bsonStringifiers = void 0;
|
|
4
4
|
const bson_export_1 = require("./bson-export");
|
|
5
|
+
const util_1 = require("util");
|
|
5
6
|
const inspectCustom = Symbol.for('nodejs.util.inspect.custom');
|
|
6
7
|
function removeNewFromInspectResult(str) {
|
|
7
|
-
return
|
|
8
|
+
return str.replace(/^(\s*)(new )/, '$1');
|
|
9
|
+
}
|
|
10
|
+
function removeTypedArrayPrefixFromInspectResult(str) {
|
|
11
|
+
return str.replace(/^\s*\S+\s*\(\d+\)\s*/, '');
|
|
8
12
|
}
|
|
9
13
|
function makeClasslessInspect(className) {
|
|
10
14
|
const originalInspect = bson_export_1.bson[className].prototype.inspect;
|
|
@@ -13,6 +17,30 @@ function makeClasslessInspect(className) {
|
|
|
13
17
|
};
|
|
14
18
|
}
|
|
15
19
|
const binaryInspect = makeClasslessInspect('Binary');
|
|
20
|
+
const binaryVectorInspect = function (depth, options) {
|
|
21
|
+
switch (this.buffer[0]) {
|
|
22
|
+
case bson_export_1.bson.Binary.VECTOR_TYPE.Int8:
|
|
23
|
+
return `Binary.fromInt8Array(new Int8Array(${removeTypedArrayPrefixFromInspectResult((0, util_1.inspect)(this.toInt8Array(), {
|
|
24
|
+
depth,
|
|
25
|
+
...options,
|
|
26
|
+
maxArrayLength: util_1.inspect.defaultOptions.maxArrayLength,
|
|
27
|
+
}))}))`;
|
|
28
|
+
case bson_export_1.bson.Binary.VECTOR_TYPE.Float32:
|
|
29
|
+
return `Binary.fromFloat32Array(new Float32Array(${removeTypedArrayPrefixFromInspectResult((0, util_1.inspect)(this.toFloat32Array(), {
|
|
30
|
+
depth,
|
|
31
|
+
...options,
|
|
32
|
+
maxArrayLength: util_1.inspect.defaultOptions.maxArrayLength,
|
|
33
|
+
}))}))`;
|
|
34
|
+
case bson_export_1.bson.Binary.VECTOR_TYPE.PackedBit:
|
|
35
|
+
return `Binary.fromPackedBits(new Uint8Array(${removeTypedArrayPrefixFromInspectResult((0, util_1.inspect)(this.toPackedBits(), {
|
|
36
|
+
depth,
|
|
37
|
+
...options,
|
|
38
|
+
maxArrayLength: util_1.inspect.defaultOptions.maxArrayLength,
|
|
39
|
+
}))}))`;
|
|
40
|
+
default:
|
|
41
|
+
return binaryInspect.call(this, depth, options);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
16
44
|
exports.bsonStringifiers = {
|
|
17
45
|
ObjectId: makeClasslessInspect('ObjectId'),
|
|
18
46
|
ObjectID: makeClasslessInspect('ObjectId'),
|
|
@@ -30,6 +58,8 @@ exports.bsonStringifiers = {
|
|
|
30
58
|
Binary: function (...args) {
|
|
31
59
|
const hexString = this.toString('hex');
|
|
32
60
|
switch (this.sub_type) {
|
|
61
|
+
case bson_export_1.bson.Binary.SUBTYPE_VECTOR:
|
|
62
|
+
return binaryVectorInspect.apply(this, args);
|
|
33
63
|
case bson_export_1.bson.Binary.SUBTYPE_MD5:
|
|
34
64
|
return `MD5('${hexString}')`;
|
|
35
65
|
case bson_export_1.bson.Binary.SUBTYPE_UUID:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"printable-bson.js","sourceRoot":"","sources":["../src/printable-bson.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;
|
|
1
|
+
{"version":3,"file":"printable-bson.js","sourceRoot":"","sources":["../src/printable-bson.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;AAE7C,+BAA8C;AAC9C,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAO/D,SAAS,0BAA0B,CAAC,GAAW;IAC7C,OAAO,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;AAC3C,CAAC;AAID,SAAS,uCAAuC,CAAC,GAAW;IAC1D,OAAO,GAAG,CAAC,OAAO,CAA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AAC,SAAS,CAAE;yBAChB,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;yBACX,IAAI,CAAC,GAAG,CAAC,CAAC;oBACb,OAAO,SAAS,MAAM,IAAI,CAAC;gBAC7B,CAAC;YAGH;gBACE,OAAO,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC3C,CAAC;IACH,CAAiC;CAClC,CAAC;AAOF,SAAgB,iBAAiB,CAAC,IAAkB;IAClD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,IAAI,GAAG,kBAAI,CAAC;IACd,CAAC;IAED,KAAK,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,wBAAgB,CAAC,EAAE,CAAC;QAClE,IAAI,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC;YACnB,SAAS;QACX,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAwB,CAAC,CAAC;QAC3C,KAAK,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,EAAE,CAAC;YAC5C,GAAW,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC;QAC5C,CAAC;IACH,CAAC;AACH,CAAC;AAdD,8CAcC"}
|
package/lib/writable.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RunCursorCommandOptions } from 'mongodb';
|
|
2
|
-
import type { Document, InsertOneOptions, InsertOneResult, Collection, RenameOptions, FindOneAndDeleteOptions, FindOneAndReplaceOptions, FindOneAndUpdateOptions, BulkWriteOptions, AnyBulkWriteOperation, DeleteOptions, DeleteResult, InsertManyResult, ReplaceOptions, UpdateResult, UpdateOptions, DropDatabaseOptions, CreateIndexesOptions, DropCollectionOptions, BulkWriteResult, RunCommandOptions, DbOptions, OrderedBulkOperation, UnorderedBulkOperation, SearchIndexDescription } from './all-transport-types';
|
|
2
|
+
import type { Document, InsertOneOptions, InsertOneResult, Collection, RenameOptions, FindOneAndDeleteOptions, FindOneAndReplaceOptions, FindOneAndUpdateOptions, BulkWriteOptions, AnyBulkWriteOperation, AnyClientBulkWriteModel, ClientBulkWriteResult, ClientBulkWriteOptions, DeleteOptions, DeleteResult, InsertManyResult, ReplaceOptions, UpdateResult, UpdateOptions, DropDatabaseOptions, CreateIndexesOptions, DropCollectionOptions, BulkWriteResult, RunCommandOptions, DbOptions, OrderedBulkOperation, UnorderedBulkOperation, SearchIndexDescription } from './all-transport-types';
|
|
3
3
|
import type { ServiceProviderRunCommandCursor } from './cursors';
|
|
4
4
|
export default interface Writable {
|
|
5
5
|
runCommand(db: string, spec: Document, options: RunCommandOptions, dbOptions?: DbOptions): Promise<Document>;
|
|
@@ -7,6 +7,7 @@ export default interface Writable {
|
|
|
7
7
|
runCursorCommand(db: string, spec: Document, options: RunCursorCommandOptions, dbOptions?: DbOptions): ServiceProviderRunCommandCursor;
|
|
8
8
|
dropDatabase(database: string, options: DropDatabaseOptions, dbOptions?: DbOptions): Promise<Document>;
|
|
9
9
|
bulkWrite(database: string, collection: string, requests: AnyBulkWriteOperation[], options: BulkWriteOptions, dbOptions?: DbOptions): Promise<BulkWriteResult>;
|
|
10
|
+
clientBulkWrite(models: AnyClientBulkWriteModel<Document>[], options: ClientBulkWriteOptions): Promise<ClientBulkWriteResult>;
|
|
10
11
|
deleteMany(database: string, collection: string, filter: Document, options: DeleteOptions, dbOptions?: DbOptions): Promise<DeleteResult>;
|
|
11
12
|
deleteOne(database: string, collection: string, filter: Document, options: DeleteOptions, dbOptions?: DbOptions): Promise<DeleteResult>;
|
|
12
13
|
findOneAndDelete(database: string, collection: string, filter: Document, options: FindOneAndDeleteOptions, dbOptions?: DbOptions): Promise<Document | null>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mongosh/service-provider-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "MongoDB Shell Core Service Provider Package",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"bson": "^6.10.3",
|
|
49
49
|
"mongodb": "^6.14.2",
|
|
50
50
|
"mongodb-build-info": "^1.7.2",
|
|
51
|
+
"mongodb-client-encryption": "^6.3.0",
|
|
51
52
|
"mongodb-connection-string-url": "^3.0.1"
|
|
52
53
|
},
|
|
53
54
|
"optionalDependencies": {
|
|
@@ -61,5 +62,5 @@
|
|
|
61
62
|
"eslint": "^7.25.0",
|
|
62
63
|
"prettier": "^2.8.8"
|
|
63
64
|
},
|
|
64
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "eb9376b475937a7e7b16683a1028299aab75ff7e"
|
|
65
66
|
}
|
|
@@ -2,9 +2,12 @@ export type {
|
|
|
2
2
|
AggregateOptions,
|
|
3
3
|
AggregationCursor,
|
|
4
4
|
AnyBulkWriteOperation,
|
|
5
|
+
AnyClientBulkWriteModel,
|
|
5
6
|
Batch,
|
|
6
7
|
BulkWriteOptions,
|
|
7
8
|
BulkWriteResult,
|
|
9
|
+
ClientBulkWriteResult,
|
|
10
|
+
ClientBulkWriteOptions,
|
|
8
11
|
ChangeStream,
|
|
9
12
|
ChangeStreamOptions,
|
|
10
13
|
ClientSession,
|
|
@@ -95,6 +95,34 @@ describe('BSON printers', function () {
|
|
|
95
95
|
).to.equal("MD5('0123456789abcdef0123456789abcdef')");
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
+
describe('with Vector types', function () {
|
|
99
|
+
it('formats Int8Array correctly', function () {
|
|
100
|
+
expect(
|
|
101
|
+
inspect(bson.Binary.fromInt8Array(new Int8Array([1, 2, 3])))
|
|
102
|
+
).to.equal('Binary.fromInt8Array(new Int8Array([ 1, 2, 3 ]))');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('formats PackedBits correctly', function () {
|
|
106
|
+
expect(
|
|
107
|
+
inspect(bson.Binary.fromPackedBits(new Uint8Array([1, 2, 3])))
|
|
108
|
+
).to.equal('Binary.fromPackedBits(new Uint8Array([ 1, 2, 3 ]))');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('formats Float32Array correctly', function () {
|
|
112
|
+
expect(
|
|
113
|
+
inspect(
|
|
114
|
+
bson.Binary.fromFloat32Array(
|
|
115
|
+
new Float32Array([1.1111, 2.2222, 3.3333])
|
|
116
|
+
),
|
|
117
|
+
{ compact: true }
|
|
118
|
+
)
|
|
119
|
+
).matches(
|
|
120
|
+
// Precision is lost because of float handling, so we use regex to match
|
|
121
|
+
/Binary.fromFloat32Array\(new Float32Array\(\[ 1\.1\d*, 2\.2\d*, 3\.3\d* \]\)\)/
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
98
126
|
it('formats any other value with the new format using createfromBase64', function () {
|
|
99
127
|
expect(
|
|
100
128
|
inspect(bson.Binary.createFromBase64('SGVsbG8sIFdvcmxkIQo='))
|
package/src/printable-bson.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { bson as BSON } from './bson-export';
|
|
2
|
+
import type { InspectOptionsStylized, CustomInspectFunction } from 'util';
|
|
3
|
+
import { inspect as utilInspect } from 'util';
|
|
2
4
|
const inspectCustom = Symbol.for('nodejs.util.inspect.custom');
|
|
3
5
|
type BSONClassKey = (typeof BSON)[Exclude<
|
|
4
6
|
keyof typeof BSON,
|
|
@@ -7,26 +9,73 @@ type BSONClassKey = (typeof BSON)[Exclude<
|
|
|
7
9
|
|
|
8
10
|
// Turn e.g. 'new Double(...)' into 'Double(...)' but preserve possible leading whitespace
|
|
9
11
|
function removeNewFromInspectResult(str: string): string {
|
|
10
|
-
return
|
|
12
|
+
return str.replace(/^(\s*)(new )/, '$1');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Typed array such as Int8Array have a format like 'Int8Array(3) [1, 2, 3]'
|
|
16
|
+
* and we want to remove the prefix and keep just the array contents. */
|
|
17
|
+
function removeTypedArrayPrefixFromInspectResult(str: string): string {
|
|
18
|
+
return str.replace(/^\s*\S+\s*\(\d+\)\s*/, '');
|
|
11
19
|
}
|
|
12
20
|
|
|
13
21
|
// Create a Node.js-util-inspect() style custom inspect function that
|
|
14
22
|
// strips 'new ' from inspect results but otherwise uses the Node.js
|
|
15
23
|
// driver's bson library's inspect functions.
|
|
16
|
-
function makeClasslessInspect<K extends BSONClassKey>(
|
|
24
|
+
function makeClasslessInspect<K extends BSONClassKey>(
|
|
25
|
+
className: K
|
|
26
|
+
): CustomInspectFunction {
|
|
17
27
|
const originalInspect = BSON[className].prototype.inspect;
|
|
18
28
|
return function (
|
|
19
29
|
this: (typeof BSON)[typeof className]['prototype'],
|
|
20
|
-
...args:
|
|
30
|
+
...args: Parameters<typeof originalInspect>
|
|
21
31
|
) {
|
|
22
|
-
return removeNewFromInspectResult(originalInspect.apply(this, args
|
|
23
|
-
};
|
|
32
|
+
return removeNewFromInspectResult(originalInspect.apply(this, args));
|
|
33
|
+
} satisfies CustomInspectFunction;
|
|
24
34
|
}
|
|
25
35
|
|
|
26
36
|
const binaryInspect = makeClasslessInspect('Binary');
|
|
37
|
+
|
|
38
|
+
const binaryVectorInspect = function (
|
|
39
|
+
this: typeof BSON.Binary.prototype,
|
|
40
|
+
depth: number,
|
|
41
|
+
options: InspectOptionsStylized
|
|
42
|
+
): string {
|
|
43
|
+
switch (this.buffer[0]) {
|
|
44
|
+
case BSON.Binary.VECTOR_TYPE.Int8:
|
|
45
|
+
return `Binary.fromInt8Array(new Int8Array(${removeTypedArrayPrefixFromInspectResult(
|
|
46
|
+
utilInspect(this.toInt8Array(), {
|
|
47
|
+
depth,
|
|
48
|
+
...options,
|
|
49
|
+
// These arrays can be very large, so would prefer to use the default options instead.
|
|
50
|
+
maxArrayLength: utilInspect.defaultOptions.maxArrayLength,
|
|
51
|
+
})
|
|
52
|
+
)}))`;
|
|
53
|
+
case BSON.Binary.VECTOR_TYPE.Float32:
|
|
54
|
+
return `Binary.fromFloat32Array(new Float32Array(${removeTypedArrayPrefixFromInspectResult(
|
|
55
|
+
utilInspect(this.toFloat32Array(), {
|
|
56
|
+
depth,
|
|
57
|
+
...options,
|
|
58
|
+
// These arrays can be very large, so would prefer to use the default options instead.
|
|
59
|
+
maxArrayLength: utilInspect.defaultOptions.maxArrayLength,
|
|
60
|
+
})
|
|
61
|
+
)}))`;
|
|
62
|
+
case BSON.Binary.VECTOR_TYPE.PackedBit:
|
|
63
|
+
return `Binary.fromPackedBits(new Uint8Array(${removeTypedArrayPrefixFromInspectResult(
|
|
64
|
+
utilInspect(this.toPackedBits(), {
|
|
65
|
+
depth,
|
|
66
|
+
...options,
|
|
67
|
+
// These arrays can be very large, so would prefer to use the default options instead.
|
|
68
|
+
maxArrayLength: utilInspect.defaultOptions.maxArrayLength,
|
|
69
|
+
})
|
|
70
|
+
)}))`;
|
|
71
|
+
default:
|
|
72
|
+
return binaryInspect.call(this, depth, options);
|
|
73
|
+
}
|
|
74
|
+
} satisfies CustomInspectFunction;
|
|
75
|
+
|
|
27
76
|
export const bsonStringifiers: Record<
|
|
28
77
|
BSONClassKey | 'ObjectID',
|
|
29
|
-
|
|
78
|
+
CustomInspectFunction
|
|
30
79
|
> = {
|
|
31
80
|
ObjectId: makeClasslessInspect('ObjectId'),
|
|
32
81
|
ObjectID: makeClasslessInspect('ObjectId'),
|
|
@@ -43,10 +92,13 @@ export const bsonStringifiers: Record<
|
|
|
43
92
|
BSONRegExp: makeClasslessInspect('BSONRegExp'),
|
|
44
93
|
Binary: function (
|
|
45
94
|
this: typeof BSON.Binary.prototype,
|
|
46
|
-
...args:
|
|
95
|
+
...args: Parameters<CustomInspectFunction>
|
|
47
96
|
): string {
|
|
48
97
|
const hexString = this.toString('hex');
|
|
98
|
+
|
|
49
99
|
switch (this.sub_type) {
|
|
100
|
+
case BSON.Binary.SUBTYPE_VECTOR:
|
|
101
|
+
return binaryVectorInspect.apply(this, args);
|
|
50
102
|
case BSON.Binary.SUBTYPE_MD5:
|
|
51
103
|
return `MD5('${hexString}')`;
|
|
52
104
|
case BSON.Binary.SUBTYPE_UUID:
|
|
@@ -64,7 +116,7 @@ export const bsonStringifiers: Record<
|
|
|
64
116
|
default:
|
|
65
117
|
return binaryInspect.apply(this, args);
|
|
66
118
|
}
|
|
67
|
-
},
|
|
119
|
+
} satisfies CustomInspectFunction,
|
|
68
120
|
};
|
|
69
121
|
|
|
70
122
|
/**
|
package/src/writable.ts
CHANGED
|
@@ -10,6 +10,9 @@ import type {
|
|
|
10
10
|
FindOneAndUpdateOptions,
|
|
11
11
|
BulkWriteOptions,
|
|
12
12
|
AnyBulkWriteOperation,
|
|
13
|
+
AnyClientBulkWriteModel,
|
|
14
|
+
ClientBulkWriteResult,
|
|
15
|
+
ClientBulkWriteOptions,
|
|
13
16
|
DeleteOptions,
|
|
14
17
|
DeleteResult,
|
|
15
18
|
InsertManyResult,
|
|
@@ -108,6 +111,18 @@ export default interface Writable {
|
|
|
108
111
|
dbOptions?: DbOptions
|
|
109
112
|
): Promise<BulkWriteResult>;
|
|
110
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Executes a client bulk write operation, available on server 8.0+.
|
|
116
|
+
* @param models - The client bulk write models.
|
|
117
|
+
* @param options - The bulk write options.
|
|
118
|
+
*
|
|
119
|
+
* @returns {Promise} The promise of the result.
|
|
120
|
+
*/
|
|
121
|
+
clientBulkWrite(
|
|
122
|
+
models: AnyClientBulkWriteModel<Document>[],
|
|
123
|
+
options: ClientBulkWriteOptions
|
|
124
|
+
): Promise<ClientBulkWriteResult>;
|
|
125
|
+
|
|
111
126
|
/**
|
|
112
127
|
* Delete multiple documents from the collection.
|
|
113
128
|
*
|