@mongosh/service-provider-core 3.1.0 → 3.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.
@@ -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';
@@ -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', (this: any, depth: any, options: any) => string>;
5
+ export declare const bsonStringifiers: Record<BSONClassKey | 'ObjectID', CustomInspectFunction>;
4
6
  export declare function makePrintableBson(bson?: typeof BSON): void;
5
7
  export {};
@@ -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 String(str).replace(/^(\s*)(new )/, '$1');
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,32 @@ 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
+ const paddingInfo = this.buffer[1] === 0 ? '' : `, ${this.buffer[1]}`;
36
+ return `Binary.fromPackedBits(new Uint8Array(${removeTypedArrayPrefixFromInspectResult((0, util_1.inspect)(this.toPackedBits(), {
37
+ depth,
38
+ ...options,
39
+ maxArrayLength: util_1.inspect.defaultOptions.maxArrayLength,
40
+ }))})${paddingInfo})`;
41
+ }
42
+ default:
43
+ return binaryInspect.call(this, depth, options);
44
+ }
45
+ };
16
46
  exports.bsonStringifiers = {
17
47
  ObjectId: makeClasslessInspect('ObjectId'),
18
48
  ObjectID: makeClasslessInspect('ObjectId'),
@@ -30,6 +60,8 @@ exports.bsonStringifiers = {
30
60
  Binary: function (...args) {
31
61
  const hexString = this.toString('hex');
32
62
  switch (this.sub_type) {
63
+ case bson_export_1.bson.Binary.SUBTYPE_VECTOR:
64
+ return binaryVectorInspect.apply(this, args);
33
65
  case bson_export_1.bson.Binary.SUBTYPE_MD5:
34
66
  return `MD5('${hexString}')`;
35
67
  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;AAC7C,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAO/D,SAAS,0BAA0B,CAAC,GAAW;IAC7C,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;AACnD,CAAC;AAKD,SAAS,oBAAoB,CAAyB,SAAY;IAChE,MAAM,eAAe,GAAG,kBAAI,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC;IAC1D,OAAO,UAEL,GAAG,IAAS;QAEZ,OAAO,0BAA0B,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,EAAE,IAAW,CAAC,CAAC,CAAC;IAC9E,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,aAAa,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;AACxC,QAAA,gBAAgB,GAGzB;IACF,QAAQ,EAAE,oBAAoB,CAAC,UAAU,CAAC;IAC1C,QAAQ,EAAE,oBAAoB,CAAC,UAAU,CAAC;IAC1C,KAAK,EAAE,oBAAoB,CAAC,OAAO,CAAC;IACpC,MAAM,EAAE,oBAAoB,CAAC,QAAQ,CAAC;IACtC,MAAM,EAAE,oBAAoB,CAAC,QAAQ,CAAC;IACtC,SAAS,EAAE,oBAAoB,CAAC,WAAW,CAAC;IAC5C,UAAU,EAAE,oBAAoB,CAAC,YAAY,CAAC;IAC9C,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC;IAClC,UAAU,EAAE,oBAAoB,CAAC,YAAY,CAAC;IAC9C,KAAK,EAAE,oBAAoB,CAAC,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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.1.0",
3
+ "version": "3.3.1",
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": "c21eacff12e630a42eda406cb350b1c2a66fe356"
65
+ "gitHead": "1aa5dad224bee72f53686f9b8541483788682e89"
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,40 @@ 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 PackedBits correctly with padding', function () {
112
+ expect(
113
+ inspect(bson.Binary.fromPackedBits(new Uint8Array([1, 2, 3]), 7))
114
+ ).to.equal('Binary.fromPackedBits(new Uint8Array([ 1, 2, 3 ]), 7)');
115
+ });
116
+
117
+ it('formats Float32Array correctly', function () {
118
+ expect(
119
+ inspect(
120
+ bson.Binary.fromFloat32Array(
121
+ new Float32Array([1.1111, 2.2222, 3.3333])
122
+ ),
123
+ { compact: true }
124
+ )
125
+ ).matches(
126
+ // Precision is lost because of float handling, so we use regex to match
127
+ /Binary.fromFloat32Array\(new Float32Array\(\[ 1\.1\d*, 2\.2\d*, 3\.3\d* \]\)\)/
128
+ );
129
+ });
130
+ });
131
+
98
132
  it('formats any other value with the new format using createfromBase64', function () {
99
133
  expect(
100
134
  inspect(bson.Binary.createFromBase64('SGVsbG8sIFdvcmxkIQo='))
@@ -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,75 @@ 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 String(str).replace(/^(\s*)(new )/, '$1');
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>(className: K) {
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: any
30
+ ...args: Parameters<typeof originalInspect>
21
31
  ) {
22
- return removeNewFromInspectResult(originalInspect.apply(this, args as any));
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
+ const paddingInfo = this.buffer[1] === 0 ? '' : `, ${this.buffer[1]}`;
64
+ return `Binary.fromPackedBits(new Uint8Array(${removeTypedArrayPrefixFromInspectResult(
65
+ utilInspect(this.toPackedBits(), {
66
+ depth,
67
+ ...options,
68
+ // These arrays can be very large, so would prefer to use the default options instead.
69
+ maxArrayLength: utilInspect.defaultOptions.maxArrayLength,
70
+ })
71
+ )})${paddingInfo})`;
72
+ }
73
+ default:
74
+ return binaryInspect.call(this, depth, options);
75
+ }
76
+ } satisfies CustomInspectFunction;
77
+
27
78
  export const bsonStringifiers: Record<
28
79
  BSONClassKey | 'ObjectID',
29
- (this: any, depth: any, options: any) => string
80
+ CustomInspectFunction
30
81
  > = {
31
82
  ObjectId: makeClasslessInspect('ObjectId'),
32
83
  ObjectID: makeClasslessInspect('ObjectId'),
@@ -43,10 +94,13 @@ export const bsonStringifiers: Record<
43
94
  BSONRegExp: makeClasslessInspect('BSONRegExp'),
44
95
  Binary: function (
45
96
  this: typeof BSON.Binary.prototype,
46
- ...args: any[]
97
+ ...args: Parameters<CustomInspectFunction>
47
98
  ): string {
48
99
  const hexString = this.toString('hex');
100
+
49
101
  switch (this.sub_type) {
102
+ case BSON.Binary.SUBTYPE_VECTOR:
103
+ return binaryVectorInspect.apply(this, args);
50
104
  case BSON.Binary.SUBTYPE_MD5:
51
105
  return `MD5('${hexString}')`;
52
106
  case BSON.Binary.SUBTYPE_UUID:
@@ -64,7 +118,7 @@ export const bsonStringifiers: Record<
64
118
  default:
65
119
  return binaryInspect.apply(this, args);
66
120
  }
67
- },
121
+ } satisfies CustomInspectFunction,
68
122
  };
69
123
 
70
124
  /**
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
  *