@mongosh/service-provider-core 3.5.0 → 3.6.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/admin.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import type ShellAuthOptions from './shell-auth-options';
2
2
  import type { MongoClientOptions, ReadConcern, ReadPreference, WriteConcern, Document, CreateCollectionOptions, ClientSession, DbOptions, ClientSessionOptions, ListDatabasesOptions, AutoEncryptionOptions, Collection } from './all-transport-types';
3
- import type { bson as BSON, ConnectionExtraInfo } from './index';
3
+ import type { ConnectionExtraInfo } from './index';
4
4
  import type { ReplPlatform } from './platform';
5
5
  import type { AWSEncryptionKeyOptions, AzureEncryptionKeyOptions, ClientEncryption as MongoCryptClientEncryption, ClientEncryptionDataKeyProvider, GCPEncryptionKeyOptions, ClientEncryption, ClientEncryptionOptions } from './all-fle-types';
6
+ import type { BSON } from '@mongosh/shell-bson';
6
7
  export interface CreateEncryptedCollectionOptions {
7
8
  provider: ClientEncryptionDataKeyProvider;
8
9
  createCollectionOptions: Omit<CreateCollectionOptions, 'encryptedFields'> & {
@@ -26,7 +27,7 @@ export interface ConnectionInfo {
26
27
  export default interface Admin {
27
28
  platform: ReplPlatform;
28
29
  initialDb: string;
29
- bsonLibrary: typeof BSON;
30
+ bsonLibrary: BSON;
30
31
  listDatabases(database: string, options?: ListDatabasesOptions): Promise<Document>;
31
32
  getNewConnection(uri: string, options: MongoClientOptions): Promise<any>;
32
33
  getURI(): string | undefined;
package/lib/cursors.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { CollationOptions, CountOptions, CursorFlag, Document, ExplainVerbosityLike, ReadConcernLike, ReadPreferenceLike, ResumeToken } from './all-transport-types';
2
- interface ServiceProviderBaseCursor<TSchema = Document> {
2
+ export interface ServiceProviderBaseCursor<TSchema = Document> {
3
3
  close(): Promise<void>;
4
4
  hasNext(): Promise<boolean>;
5
5
  next(): Promise<TSchema | null>;
@@ -45,4 +45,3 @@ export interface ServiceProviderChangeStream<TSchema = Document> extends Service
45
45
  next(): Promise<TSchema>;
46
46
  readonly resumeToken: ResumeToken;
47
47
  }
48
- export {};
package/lib/index.d.ts CHANGED
@@ -3,13 +3,11 @@ import ServiceProvider, { ServiceProviderCore } from './service-provider';
3
3
  import getConnectExtraInfo, { ConnectionExtraInfo } from './connect-info';
4
4
  import type { ReplPlatform } from './platform';
5
5
  declare const DEFAULT_DB = "test";
6
- import { bsonStringifiers } from './printable-bson';
7
6
  import ShellAuthOptions from './shell-auth-options';
8
7
  export * from './all-transport-types';
9
8
  export * from './all-fle-types';
10
9
  export { MapReduceOptions, FinalizeFunction } from './map-reduce-options';
11
10
  export { TopologyDescription, ServerDescription } from './readable';
12
11
  export { CreateEncryptedCollectionOptions, CheckMetadataConsistencyOptions, ConnectionInfo, } from './admin';
13
- export { bson } from './bson-export';
14
- export { ServiceProviderAbstractCursor, ServiceProviderAggregationCursor, ServiceProviderFindCursor, ServiceProviderRunCommandCursor, ServiceProviderChangeStream, } from './cursors';
15
- export { ServiceProvider, ShellAuthOptions, getConnectExtraInfo, ReplPlatform, DEFAULT_DB, ServiceProviderCore, bsonStringifiers, ConnectionExtraInfo, };
12
+ export { ServiceProviderAbstractCursor, ServiceProviderAggregationCursor, ServiceProviderBaseCursor, ServiceProviderFindCursor, ServiceProviderRunCommandCursor, ServiceProviderChangeStream, } from './cursors';
13
+ export { ServiceProvider, ShellAuthOptions, getConnectExtraInfo, ReplPlatform, DEFAULT_DB, ServiceProviderCore, ConnectionExtraInfo, };
package/lib/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.bsonStringifiers = exports.ServiceProviderCore = exports.DEFAULT_DB = exports.getConnectExtraInfo = exports.bson = void 0;
20
+ exports.ServiceProviderCore = exports.DEFAULT_DB = exports.getConnectExtraInfo = void 0;
21
21
  require("./textencoder-polyfill");
22
22
  const service_provider_1 = require("./service-provider");
23
23
  Object.defineProperty(exports, "ServiceProviderCore", { enumerable: true, get: function () { return service_provider_1.ServiceProviderCore; } });
@@ -25,10 +25,6 @@ const connect_info_1 = __importDefault(require("./connect-info"));
25
25
  exports.getConnectExtraInfo = connect_info_1.default;
26
26
  const DEFAULT_DB = 'test';
27
27
  exports.DEFAULT_DB = DEFAULT_DB;
28
- const printable_bson_1 = require("./printable-bson");
29
- Object.defineProperty(exports, "bsonStringifiers", { enumerable: true, get: function () { return printable_bson_1.bsonStringifiers; } });
30
28
  __exportStar(require("./all-transport-types"), exports);
31
29
  __exportStar(require("./all-fle-types"), exports);
32
- var bson_export_1 = require("./bson-export");
33
- Object.defineProperty(exports, "bson", { enumerable: true, get: function () { return bson_export_1.bson; } });
34
30
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,kCAAgC;AAChC,yDAA0E;AAmCxE,oGAnCwB,sCAAmB,OAmCxB;AAlCrB,kEAA0E;AA+BxE,8BA/BK,sBAAmB,CA+BL;AA7BrB,MAAM,UAAU,GAAG,MAAM,CAAC;AA+BxB,gCAAU;AA9BZ,qDAAoD;AAgClD,iGAhCO,iCAAgB,OAgCP;AA9BlB,wDAAsC;AACtC,kDAAgC;AAYhC,6CAAqC;AAA5B,mGAAA,IAAI,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,kCAAgC;AAChC,yDAA0E;AAiCxE,oGAjCwB,sCAAmB,OAiCxB;AAhCrB,kEAA0E;AA6BxE,8BA7BK,sBAAmB,CA6BL;AA3BrB,MAAM,UAAU,GAAG,MAAM,CAAC;AA6BxB,gCAAU;AA3BZ,wDAAsC;AACtC,kDAAgC"}
@@ -2,10 +2,10 @@ import type Admin from './admin';
2
2
  import type Closable from './closable';
3
3
  import type Readable from './readable';
4
4
  import type Writable from './writable';
5
- import type { bson as BSON } from './index';
5
+ import type { BSON } from '@mongosh/shell-bson';
6
6
  export default interface ServiceProvider extends Readable, Writable, Closable, Admin {
7
7
  }
8
8
  export declare class ServiceProviderCore {
9
- bsonLibrary: typeof BSON;
10
- constructor(bsonLibrary?: typeof BSON);
9
+ bsonLibrary: BSON;
10
+ constructor(bsonLibrary?: BSON);
11
11
  }
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ServiceProviderCore = void 0;
4
4
  const errors_1 = require("@mongosh/errors");
5
- const printable_bson_1 = require("./printable-bson");
5
+ const shell_bson_1 = require("@mongosh/shell-bson");
6
6
  class ServiceProviderCore {
7
7
  constructor(bsonLibrary) {
8
8
  if (bsonLibrary === undefined) {
9
9
  throw new errors_1.MongoshInternalError('BSON Library is undefined.');
10
10
  }
11
- (0, printable_bson_1.makePrintableBson)(bsonLibrary);
11
+ (0, shell_bson_1.makePrintableBson)(bsonLibrary);
12
12
  this.bsonLibrary = bsonLibrary;
13
13
  }
14
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"service-provider.js","sourceRoot":"","sources":["../src/service-provider.ts"],"names":[],"mappings":";;;AAAA,4CAAuD;AAGvD,qDAAqD;AAcrD,MAAa,mBAAmB;IAE9B,YAAY,WAAyB;QACnC,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAM,IAAI,6BAAoB,CAAC,4BAA4B,CAAC,CAAC;QAC/D,CAAC;QACD,IAAA,kCAAiB,EAAC,WAAW,CAAC,CAAC;QAC/B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;CACF;AATD,kDASC"}
1
+ {"version":3,"file":"service-provider.js","sourceRoot":"","sources":["../src/service-provider.ts"],"names":[],"mappings":";;;AAAA,4CAAuD;AAKvD,oDAAwD;AAYxD,MAAa,mBAAmB;IAE9B,YAAY,WAAkB;QAC5B,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAM,IAAI,6BAAoB,CAAC,4BAA4B,CAAC,CAAC;QAC/D,CAAC;QACD,IAAA,8BAAiB,EAAC,WAAW,CAAC,CAAC;QAC/B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;CACF;AATD,kDASC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mongosh/service-provider-core",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "MongoDB Shell Core Service Provider Package",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -37,10 +37,11 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@mongosh/errors": "2.4.4",
40
+ "@mongosh/shell-bson": "1.0.1",
40
41
  "bson": "^6.10.4",
41
42
  "mongodb": "^6.19.0",
42
43
  "mongodb-build-info": "^1.7.2",
43
- "mongodb-connection-string-url": "^3.0.1"
44
+ "mongodb-connection-string-url": "^3.0.2"
44
45
  },
45
46
  "devDependencies": {
46
47
  "@mongodb-js/eslint-config-mongosh": "^1.0.0",
@@ -50,5 +51,5 @@
50
51
  "eslint": "^7.25.0",
51
52
  "prettier": "^2.8.8"
52
53
  },
53
- "gitHead": "e019a30c3021026ff8db296171d7d7f68cdac05e"
54
+ "gitHead": "9f0183e375c5422a0e1ced87c9a620384180abf7"
54
55
  }
package/src/admin.ts CHANGED
@@ -13,7 +13,7 @@ import type {
13
13
  AutoEncryptionOptions,
14
14
  Collection,
15
15
  } from './all-transport-types';
16
- import type { bson as BSON, ConnectionExtraInfo } from './index';
16
+ import type { ConnectionExtraInfo } from './index';
17
17
  import type { ReplPlatform } from './platform';
18
18
  import type {
19
19
  AWSEncryptionKeyOptions,
@@ -24,6 +24,7 @@ import type {
24
24
  ClientEncryption,
25
25
  ClientEncryptionOptions,
26
26
  } from './all-fle-types';
27
+ import type { BSON } from '@mongosh/shell-bson';
27
28
 
28
29
  export interface CreateEncryptedCollectionOptions {
29
30
  provider: ClientEncryptionDataKeyProvider;
@@ -63,7 +64,7 @@ export default interface Admin {
63
64
  /**
64
65
  * The BSON package
65
66
  */
66
- bsonLibrary: typeof BSON;
67
+ bsonLibrary: BSON;
67
68
 
68
69
  /**
69
70
  * list databases.
package/src/cursors.ts CHANGED
@@ -9,7 +9,7 @@ import type {
9
9
  ResumeToken,
10
10
  } from './all-transport-types';
11
11
 
12
- interface ServiceProviderBaseCursor<TSchema = Document> {
12
+ export interface ServiceProviderBaseCursor<TSchema = Document> {
13
13
  close(): Promise<void>;
14
14
  hasNext(): Promise<boolean>;
15
15
  next(): Promise<TSchema | null>;
package/src/index.ts CHANGED
@@ -3,7 +3,6 @@ import ServiceProvider, { ServiceProviderCore } from './service-provider';
3
3
  import getConnectExtraInfo, { ConnectionExtraInfo } from './connect-info';
4
4
  import type { ReplPlatform } from './platform';
5
5
  const DEFAULT_DB = 'test';
6
- import { bsonStringifiers } from './printable-bson';
7
6
  import ShellAuthOptions from './shell-auth-options';
8
7
  export * from './all-transport-types';
9
8
  export * from './all-fle-types';
@@ -18,11 +17,10 @@ export {
18
17
  ConnectionInfo,
19
18
  } from './admin';
20
19
 
21
- export { bson } from './bson-export';
22
-
23
20
  export {
24
21
  ServiceProviderAbstractCursor,
25
22
  ServiceProviderAggregationCursor,
23
+ ServiceProviderBaseCursor,
26
24
  ServiceProviderFindCursor,
27
25
  ServiceProviderRunCommandCursor,
28
26
  ServiceProviderChangeStream,
@@ -35,6 +33,5 @@ export {
35
33
  ReplPlatform,
36
34
  DEFAULT_DB,
37
35
  ServiceProviderCore,
38
- bsonStringifiers,
39
36
  ConnectionExtraInfo,
40
37
  };
@@ -1,10 +1,10 @@
1
1
  import { MongoshInternalError } from '@mongosh/errors';
2
2
  import type Admin from './admin';
3
3
  import type Closable from './closable';
4
- import { makePrintableBson } from './printable-bson';
5
4
  import type Readable from './readable';
6
5
  import type Writable from './writable';
7
- import type { bson as BSON } from './index';
6
+ import { makePrintableBson } from '@mongosh/shell-bson';
7
+ import type { BSON } from '@mongosh/shell-bson';
8
8
 
9
9
  /**
10
10
  * Interface for all service providers.
@@ -16,8 +16,8 @@ export default interface ServiceProvider
16
16
  Admin {}
17
17
 
18
18
  export class ServiceProviderCore {
19
- public bsonLibrary: typeof BSON;
20
- constructor(bsonLibrary?: typeof BSON) {
19
+ public bsonLibrary: BSON;
20
+ constructor(bsonLibrary?: BSON) {
21
21
  if (bsonLibrary === undefined) {
22
22
  throw new MongoshInternalError('BSON Library is undefined.');
23
23
  }
@@ -1,23 +0,0 @@
1
- import { ObjectId, DBRef, MaxKey, MinKey, Timestamp, BSONSymbol, Code, Decimal128, Int32, Long, Binary, calculateObjectSize, Double, BSONRegExp } from 'bson';
2
- export declare const bson: {
3
- ObjectId: typeof ObjectId;
4
- DBRef: typeof DBRef;
5
- MaxKey: typeof MaxKey;
6
- MinKey: typeof MinKey;
7
- Timestamp: typeof Timestamp;
8
- BSONSymbol: typeof BSONSymbol;
9
- Code: typeof Code;
10
- Decimal128: typeof Decimal128;
11
- Int32: typeof Int32;
12
- Long: typeof Long;
13
- Binary: typeof Binary;
14
- calculateObjectSize: typeof calculateObjectSize;
15
- Double: typeof Double;
16
- EJSON: {
17
- parse: (text: string, options?: import("bson").EJSONOptions) => any;
18
- stringify: (value: any, replacer?: (number | string)[] | ((this: any, key: string, value: any) => any) | import("bson").EJSONOptions, space?: string | number, options?: import("bson").EJSONOptions) => string;
19
- serialize: (value: any, options?: import("bson").EJSONOptions) => import("bson").Document;
20
- deserialize: (ejson: import("bson").Document, options?: import("bson").EJSONOptions) => any;
21
- };
22
- BSONRegExp: typeof BSONRegExp;
23
- };
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bson = void 0;
4
- const bson_1 = require("bson");
5
- exports.bson = {
6
- ObjectId: bson_1.ObjectId,
7
- DBRef: bson_1.DBRef,
8
- MaxKey: bson_1.MaxKey,
9
- MinKey: bson_1.MinKey,
10
- Timestamp: bson_1.Timestamp,
11
- BSONSymbol: bson_1.BSONSymbol,
12
- Code: bson_1.Code,
13
- Decimal128: bson_1.Decimal128,
14
- Int32: bson_1.Int32,
15
- Long: bson_1.Long,
16
- Binary: bson_1.Binary,
17
- calculateObjectSize: bson_1.calculateObjectSize,
18
- Double: bson_1.Double,
19
- EJSON: bson_1.EJSON,
20
- BSONRegExp: bson_1.BSONRegExp,
21
- };
22
- //# sourceMappingURL=bson-export.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bson-export.js","sourceRoot":"","sources":["../src/bson-export.ts"],"names":[],"mappings":";;;AAAA,+BAgBc;AAED,QAAA,IAAI,GAAG;IAClB,QAAQ,EAAR,eAAQ;IACR,KAAK,EAAL,YAAK;IACL,MAAM,EAAN,aAAM;IACN,MAAM,EAAN,aAAM;IACN,SAAS,EAAT,gBAAS;IACT,UAAU,EAAV,iBAAU;IACV,IAAI,EAAJ,WAAI;IACJ,UAAU,EAAV,iBAAU;IACV,KAAK,EAAL,YAAK;IACL,IAAI,EAAJ,WAAI;IACJ,MAAM,EAAN,aAAM;IACN,mBAAmB,EAAnB,0BAAmB;IACnB,MAAM,EAAN,aAAM;IACN,KAAK,EAAL,YAAK;IACL,UAAU,EAAV,iBAAU;CACX,CAAC"}
@@ -1,6 +0,0 @@
1
- import { bson as BSON } from './bson-export';
2
- import type { CustomInspectFunction } from 'util';
3
- type BSONClassKey = (typeof BSON)[Exclude<keyof typeof BSON, 'EJSON' | 'calculateObjectSize'>]['prototype']['_bsontype'];
4
- export declare const bsonStringifiers: Record<BSONClassKey | 'ObjectID', CustomInspectFunction>;
5
- export declare function makePrintableBson(bson?: typeof BSON): void;
6
- export {};
@@ -1,95 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bsonStringifiers = void 0;
4
- exports.makePrintableBson = makePrintableBson;
5
- const bson_export_1 = require("./bson-export");
6
- const util_1 = require("util");
7
- const inspectCustom = Symbol.for('nodejs.util.inspect.custom');
8
- function removeNewFromInspectResult(str) {
9
- return str.replace(/^(\s*)(new )/, '$1');
10
- }
11
- function removeTypedArrayPrefixFromInspectResult(str) {
12
- return str.replace(/^\s*\S+\s*\(\d+\)\s*/, '');
13
- }
14
- function makeClasslessInspect(className) {
15
- const originalInspect = bson_export_1.bson[className].prototype.inspect;
16
- return function (...args) {
17
- return removeNewFromInspectResult(originalInspect.apply(this, args));
18
- };
19
- }
20
- const binaryInspect = makeClasslessInspect('Binary');
21
- const binaryVectorInspect = function (depth, options) {
22
- switch (this.buffer[0]) {
23
- case bson_export_1.bson.Binary.VECTOR_TYPE.Int8:
24
- return `Binary.fromInt8Array(new Int8Array(${removeTypedArrayPrefixFromInspectResult((0, util_1.inspect)(this.toInt8Array(), {
25
- depth,
26
- ...options,
27
- maxArrayLength: util_1.inspect.defaultOptions.maxArrayLength,
28
- }))}))`;
29
- case bson_export_1.bson.Binary.VECTOR_TYPE.Float32:
30
- return `Binary.fromFloat32Array(new Float32Array(${removeTypedArrayPrefixFromInspectResult((0, util_1.inspect)(this.toFloat32Array(), {
31
- depth,
32
- ...options,
33
- maxArrayLength: util_1.inspect.defaultOptions.maxArrayLength,
34
- }))}))`;
35
- case bson_export_1.bson.Binary.VECTOR_TYPE.PackedBit: {
36
- const paddingInfo = this.buffer[1] === 0 ? '' : `, ${this.buffer[1]}`;
37
- return `Binary.fromPackedBits(new Uint8Array(${removeTypedArrayPrefixFromInspectResult((0, util_1.inspect)(this.toPackedBits(), {
38
- depth,
39
- ...options,
40
- maxArrayLength: util_1.inspect.defaultOptions.maxArrayLength,
41
- }))})${paddingInfo})`;
42
- }
43
- default:
44
- return binaryInspect.call(this, depth, options);
45
- }
46
- };
47
- exports.bsonStringifiers = {
48
- ObjectId: makeClasslessInspect('ObjectId'),
49
- ObjectID: makeClasslessInspect('ObjectId'),
50
- DBRef: makeClasslessInspect('DBRef'),
51
- MaxKey: makeClasslessInspect('MaxKey'),
52
- MinKey: makeClasslessInspect('MinKey'),
53
- Timestamp: makeClasslessInspect('Timestamp'),
54
- BSONSymbol: makeClasslessInspect('BSONSymbol'),
55
- Code: makeClasslessInspect('Code'),
56
- Decimal128: makeClasslessInspect('Decimal128'),
57
- Int32: makeClasslessInspect('Int32'),
58
- Long: makeClasslessInspect('Long'),
59
- Double: makeClasslessInspect('Double'),
60
- BSONRegExp: makeClasslessInspect('BSONRegExp'),
61
- Binary: function (...args) {
62
- const hexString = this.toString('hex');
63
- switch (this.sub_type) {
64
- case bson_export_1.bson.Binary.SUBTYPE_VECTOR:
65
- return binaryVectorInspect.apply(this, args);
66
- case bson_export_1.bson.Binary.SUBTYPE_MD5:
67
- return `MD5('${hexString}')`;
68
- case bson_export_1.bson.Binary.SUBTYPE_UUID:
69
- if (hexString.length === 32) {
70
- const asUUID = /^(.{8})(.{4})(.{4})(.{4})(.{12})$/
71
- .exec(hexString)
72
- .slice(1, 6)
73
- .join('-');
74
- return `UUID('${asUUID}')`;
75
- }
76
- default:
77
- return binaryInspect.apply(this, args);
78
- }
79
- },
80
- };
81
- function makePrintableBson(bson) {
82
- if (!bson) {
83
- bson = bson_export_1.bson;
84
- }
85
- for (const [key, stringifier] of Object.entries(exports.bsonStringifiers)) {
86
- if (!(key in bson)) {
87
- continue;
88
- }
89
- const cls = bson[key];
90
- for (const key of [inspectCustom, 'inspect']) {
91
- cls.prototype[key] = stringifier;
92
- }
93
- }
94
- }
95
- //# sourceMappingURL=printable-bson.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"printable-bson.js","sourceRoot":"","sources":["../src/printable-bson.ts"],"names":[],"mappings":";;;AAgIA,8CAcC;AA9ID,+CAA6C;AAE7C,+BAA8C;AAC9C,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAO/D,SAAS,0BAA0B,CAAC,GAAW;IAC7C,OAAO,GAAG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decimal128,
10
- Int32,
11
- Long,
12
- Binary,
13
- calculateObjectSize,
14
- Double,
15
- EJSON,
16
- BSONRegExp,
17
- } from 'bson';
18
-
19
- export const bson = {
20
- ObjectId,
21
- DBRef,
22
- MaxKey,
23
- MinKey,
24
- Timestamp,
25
- BSONSymbol,
26
- Code,
27
- Decimal128,
28
- Int32,
29
- Long,
30
- Binary,
31
- calculateObjectSize,
32
- Double,
33
- EJSON,
34
- BSONRegExp,
35
- };
@@ -1,137 +0,0 @@
1
- import { expect } from 'chai';
2
- import { bson } from './index';
3
- import { inspect } from 'util';
4
- import { makePrintableBson } from './printable-bson';
5
-
6
- describe('BSON printers', function () {
7
- before('make BSON objects printable', function () {
8
- makePrintableBson(bson);
9
- });
10
-
11
- it('formats ObjectIds correctly', function () {
12
- expect(inspect(new bson.ObjectId('5fa5694f88211043b23c7f11'))).to.equal(
13
- "ObjectId('5fa5694f88211043b23c7f11')"
14
- );
15
- });
16
-
17
- it('formats DBRefs correctly', function () {
18
- expect(
19
- inspect(
20
- new bson.DBRef('a', new bson.ObjectId('5f16b8bebe434dc98cdfc9cb'), 'db')
21
- )
22
- ).to.equal("DBRef('a', ObjectId('5f16b8bebe434dc98cdfc9cb'), 'db')");
23
- expect(inspect(new bson.DBRef('a', 'foo' as any, 'db'))).to.equal(
24
- "DBRef('a', 'foo', 'db')"
25
- );
26
- expect(inspect(new bson.DBRef('a', { x: 1 } as any, 'db'))).to.equal(
27
- "DBRef('a', { x: 1 }, 'db')"
28
- );
29
- });
30
-
31
- it('formats MinKey and MaxKey correctly', function () {
32
- expect(inspect(new bson.MinKey())).to.equal('MinKey()');
33
- expect(inspect(new bson.MaxKey())).to.equal('MaxKey()');
34
- });
35
-
36
- it('formats NumberInt correctly', function () {
37
- expect(inspect(new bson.Int32(32))).to.equal('Int32(32)');
38
- });
39
-
40
- it('formats NumberLong correctly', function () {
41
- expect(inspect(bson.Long.fromString('64'))).to.equal("Long('64')");
42
- });
43
-
44
- it('formats unsigned NumberLong correctly', function () {
45
- expect(inspect(bson.Long.fromString('64', true))).to.equal(
46
- "Long('64', true)"
47
- );
48
- });
49
-
50
- it('formats NumberDecimal correctly', function () {
51
- expect(inspect(bson.Decimal128.fromString('1'))).to.equal(
52
- "Decimal128('1')"
53
- );
54
- });
55
-
56
- it('formats Timestamp correctly', function () {
57
- expect(inspect(new bson.Timestamp(new bson.Long(100, 1)))).to.equal(
58
- 'Timestamp({ t: 1, i: 100 })'
59
- );
60
- });
61
-
62
- it('formats Symbol correctly', function () {
63
- expect(inspect(new bson.BSONSymbol('abc'))).to.equal("BSONSymbol('abc')");
64
- });
65
-
66
- it('formats Code correctly', function () {
67
- expect(inspect(new bson.Code('abc'))).to.equal("Code('abc')");
68
- });
69
-
70
- it('formats BSONRegExp correctly', function () {
71
- expect(inspect(new bson.BSONRegExp('(?-i)AA_', 'im'))).to.equal(
72
- "BSONRegExp('(?-i)AA_', 'im')"
73
- );
74
- });
75
-
76
- it('formats UUIDs correctly', function () {
77
- expect(
78
- inspect(
79
- new bson.Binary(
80
- Buffer.from('0123456789abcdef0123456789abcdef', 'hex'),
81
- 4
82
- )
83
- )
84
- ).to.equal("UUID('01234567-89ab-cdef-0123-456789abcdef')");
85
- });
86
-
87
- it('formats MD5s correctly', function () {
88
- expect(
89
- inspect(
90
- new bson.Binary(
91
- Buffer.from('0123456789abcdef0123456789abcdef', 'hex'),
92
- 5
93
- )
94
- )
95
- ).to.equal("MD5('0123456789abcdef0123456789abcdef')");
96
- });
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
-
132
- it('formats any other value with the new format using createfromBase64', function () {
133
- expect(
134
- inspect(bson.Binary.createFromBase64('SGVsbG8sIFdvcmxkIQo='))
135
- ).to.equal("Binary.createFromBase64('SGVsbG8sIFdvcmxkIQo=', 0)");
136
- });
137
- });
@@ -1,143 +0,0 @@
1
- import { bson as BSON } from './bson-export';
2
- import type { InspectOptionsStylized, CustomInspectFunction } from 'util';
3
- import { inspect as utilInspect } from 'util';
4
- const inspectCustom = Symbol.for('nodejs.util.inspect.custom');
5
- type BSONClassKey = (typeof BSON)[Exclude<
6
- keyof typeof BSON,
7
- 'EJSON' | 'calculateObjectSize'
8
- >]['prototype']['_bsontype'];
9
-
10
- // Turn e.g. 'new Double(...)' into 'Double(...)' but preserve possible leading whitespace
11
- function removeNewFromInspectResult(str: string): string {
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*/, '');
19
- }
20
-
21
- // Create a Node.js-util-inspect() style custom inspect function that
22
- // strips 'new ' from inspect results but otherwise uses the Node.js
23
- // driver's bson library's inspect functions.
24
- function makeClasslessInspect<K extends BSONClassKey>(
25
- className: K
26
- ): CustomInspectFunction {
27
- const originalInspect = BSON[className].prototype.inspect;
28
- return function (
29
- this: (typeof BSON)[typeof className]['prototype'],
30
- ...args: Parameters<typeof originalInspect>
31
- ) {
32
- return removeNewFromInspectResult(originalInspect.apply(this, args));
33
- } satisfies CustomInspectFunction;
34
- }
35
-
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
-
78
- export const bsonStringifiers: Record<
79
- BSONClassKey | 'ObjectID',
80
- CustomInspectFunction
81
- > = {
82
- ObjectId: makeClasslessInspect('ObjectId'),
83
- ObjectID: makeClasslessInspect('ObjectId'),
84
- DBRef: makeClasslessInspect('DBRef'),
85
- MaxKey: makeClasslessInspect('MaxKey'),
86
- MinKey: makeClasslessInspect('MinKey'),
87
- Timestamp: makeClasslessInspect('Timestamp'),
88
- BSONSymbol: makeClasslessInspect('BSONSymbol'),
89
- Code: makeClasslessInspect('Code'),
90
- Decimal128: makeClasslessInspect('Decimal128'),
91
- Int32: makeClasslessInspect('Int32'),
92
- Long: makeClasslessInspect('Long'),
93
- Double: makeClasslessInspect('Double'),
94
- BSONRegExp: makeClasslessInspect('BSONRegExp'),
95
- Binary: function (
96
- this: typeof BSON.Binary.prototype,
97
- ...args: Parameters<CustomInspectFunction>
98
- ): string {
99
- const hexString = this.toString('hex');
100
-
101
- switch (this.sub_type) {
102
- case BSON.Binary.SUBTYPE_VECTOR:
103
- return binaryVectorInspect.apply(this, args);
104
- case BSON.Binary.SUBTYPE_MD5:
105
- return `MD5('${hexString}')`;
106
- case BSON.Binary.SUBTYPE_UUID:
107
- if (hexString.length === 32) {
108
- // Format '0123456789abcdef0123456789abcdef' into
109
- // '01234567-89ab-cdef-0123-456789abcdef'.
110
- const asUUID = /^(.{8})(.{4})(.{4})(.{4})(.{12})$/
111
- .exec(hexString)!
112
- .slice(1, 6)
113
- .join('-');
114
- return `UUID('${asUUID}')`;
115
- }
116
- // In case somebody did something weird and used an UUID with a
117
- // non-standard length, fall through.
118
- default:
119
- return binaryInspect.apply(this, args);
120
- }
121
- } satisfies CustomInspectFunction,
122
- };
123
-
124
- /**
125
- * This method modifies the BSON class passed in as argument. This is required so that
126
- * we can have the driver return our BSON classes without having to write our own serializer.
127
- * @param {Object} bson
128
- */
129
- export function makePrintableBson(bson?: typeof BSON): void {
130
- if (!bson) {
131
- bson = BSON;
132
- }
133
-
134
- for (const [key, stringifier] of Object.entries(bsonStringifiers)) {
135
- if (!(key in bson)) {
136
- continue;
137
- }
138
- const cls = bson[key as keyof typeof BSON];
139
- for (const key of [inspectCustom, 'inspect']) {
140
- (cls as any).prototype[key] = stringifier;
141
- }
142
- }
143
- }