mongodb 6.5.0 → 6.6.0-dev.20240504.sha.2609953
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/README.md +9 -9
- package/lib/admin.js +9 -9
- package/lib/admin.js.map +1 -1
- package/lib/bson.js +33 -22
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +13 -12
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +28 -18
- package/lib/change_stream.js.map +1 -1
- package/lib/client-side-encryption/auto_encrypter.js +2 -2
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
- package/lib/client-side-encryption/client_encryption.js +6 -6
- package/lib/client-side-encryption/client_encryption.js.map +1 -1
- package/lib/client-side-encryption/providers/aws.js +13 -10
- package/lib/client-side-encryption/providers/aws.js.map +1 -1
- package/lib/client-side-encryption/providers/azure.js +6 -3
- package/lib/client-side-encryption/providers/azure.js.map +1 -1
- package/lib/cmap/auth/aws_temporary_credentials.js +140 -0
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -0
- package/lib/cmap/auth/gssapi.js +7 -6
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +8 -101
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js +2 -1
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js +1 -1
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -1
- package/lib/cmap/auth/scram.js +2 -2
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/commands.js +24 -111
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +4 -4
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +61 -36
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +22 -13
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/handshake/client_metadata.js +2 -2
- package/lib/cmap/handshake/client_metadata.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js +8 -8
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/on_demand/document.js +218 -0
- package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
- package/lib/cmap/wire_protocol/responses.js +184 -0
- package/lib/cmap/wire_protocol/responses.js.map +1 -0
- package/lib/collection.js +42 -38
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +4 -6
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +76 -43
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +16 -33
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +36 -18
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/cursor/run_command_cursor.js +3 -2
- package/lib/cursor/run_command_cursor.js.map +1 -1
- package/lib/db.js +15 -19
- package/lib/db.js.map +1 -1
- package/lib/deps.js +31 -26
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js +14 -5
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +4 -3
- package/lib/error.js.map +1 -1
- package/lib/gridfs/download.js +19 -14
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +6 -1
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/mongo_client.js +11 -7
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_logger.js +3 -0
- package/lib/mongo_logger.js.map +1 -1
- package/lib/operations/aggregate.js +2 -1
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/command.js +1 -1
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/create_collection.js +1 -1
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +4 -3
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/drop.js +1 -1
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/execute_operation.js +23 -8
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +4 -4
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/get_more.js +2 -1
- package/lib/operations/get_more.js.map +1 -1
- package/lib/operations/indexes.js +29 -121
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +3 -3
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/kill_cursors.js +3 -1
- package/lib/operations/kill_cursors.js.map +1 -1
- package/lib/operations/list_collections.js +1 -1
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js +1 -1
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/run_command.js +4 -2
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/search_indexes/create.js.map +1 -1
- package/lib/operations/stats.js +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +1 -1
- package/lib/operations/update.js.map +1 -1
- package/lib/sdam/common.js.map +1 -1
- package/lib/sdam/monitor.js +139 -42
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +5 -15
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +1 -0
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +1 -1
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +2 -1
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +67 -54
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +10 -0
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +133 -93
- package/lib/sessions.js.map +1 -1
- package/lib/timeout.js +77 -0
- package/lib/timeout.js.map +1 -0
- package/lib/utils.js +61 -28
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +150 -38
- package/package.json +17 -14
- package/src/admin.ts +9 -9
- package/src/bson.ts +14 -0
- package/src/bulk/common.ts +3 -2
- package/src/change_stream.ts +39 -30
- package/src/client-side-encryption/auto_encrypter.ts +2 -2
- package/src/client-side-encryption/client_encryption.ts +6 -6
- package/src/client-side-encryption/providers/aws.ts +17 -10
- package/src/client-side-encryption/providers/azure.ts +5 -3
- package/src/cmap/auth/aws_temporary_credentials.ts +169 -0
- package/src/cmap/auth/gssapi.ts +9 -11
- package/src/cmap/auth/mongodb_aws.ts +19 -126
- package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +1 -1
- package/src/cmap/auth/mongodb_oidc/callback_lock_cache.ts +2 -1
- package/src/cmap/auth/mongodb_oidc/service_workflow.ts +1 -1
- package/src/cmap/auth/scram.ts +2 -2
- package/src/cmap/commands.ts +28 -132
- package/src/cmap/connect.ts +4 -4
- package/src/cmap/connection.ts +107 -43
- package/src/cmap/connection_pool.ts +32 -29
- package/src/cmap/handshake/client_metadata.ts +2 -5
- package/src/cmap/wire_protocol/compression.ts +11 -13
- package/src/cmap/wire_protocol/on_demand/document.ts +338 -0
- package/src/cmap/wire_protocol/responses.ts +237 -0
- package/src/collection.ts +87 -58
- package/src/connection_string.ts +9 -7
- package/src/cursor/abstract_cursor.ts +102 -38
- package/src/cursor/aggregation_cursor.ts +32 -34
- package/src/cursor/find_cursor.ts +33 -21
- package/src/cursor/list_search_indexes_cursor.ts +1 -1
- package/src/cursor/run_command_cursor.ts +3 -2
- package/src/db.ts +42 -21
- package/src/deps.ts +52 -40
- package/src/encrypter.ts +14 -5
- package/src/error.ts +9 -3
- package/src/gridfs/download.ts +19 -31
- package/src/gridfs/index.ts +2 -0
- package/src/gridfs/upload.ts +11 -8
- package/src/index.ts +13 -5
- package/src/mongo_client.ts +21 -15
- package/src/mongo_logger.ts +3 -0
- package/src/mongo_types.ts +1 -1
- package/src/operations/aggregate.ts +2 -1
- package/src/operations/command.ts +1 -1
- package/src/operations/create_collection.ts +7 -2
- package/src/operations/delete.ts +4 -3
- package/src/operations/drop.ts +1 -1
- package/src/operations/execute_operation.ts +29 -10
- package/src/operations/find.ts +13 -14
- package/src/operations/get_more.ts +9 -1
- package/src/operations/indexes.ts +103 -176
- package/src/operations/insert.ts +2 -2
- package/src/operations/kill_cursors.ts +3 -2
- package/src/operations/list_collections.ts +5 -1
- package/src/operations/list_databases.ts +1 -1
- package/src/operations/operation.ts +3 -0
- package/src/operations/run_command.ts +6 -4
- package/src/operations/search_indexes/create.ts +4 -1
- package/src/operations/stats.ts +1 -1
- package/src/operations/update.ts +7 -7
- package/src/sdam/common.ts +8 -2
- package/src/sdam/monitor.ts +178 -61
- package/src/sdam/server.ts +27 -20
- package/src/sdam/server_description.ts +8 -3
- package/src/sdam/server_selection.ts +2 -3
- package/src/sdam/srv_polling.ts +3 -2
- package/src/sdam/topology.ts +114 -117
- package/src/sdam/topology_description.ts +14 -4
- package/src/sessions.ts +168 -148
- package/src/timeout.ts +96 -0
- package/src/utils.ts +85 -32
- package/lib/operations/common_functions.js +0 -38
- package/lib/operations/common_functions.js.map +0 -1
- package/src/operations/common_functions.ts +0 -79
package/src/utils.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as crypto from 'crypto';
|
|
2
2
|
import type { SrvRecord } from 'dns';
|
|
3
3
|
import { type EventEmitter } from 'events';
|
|
4
|
+
import { promises as fs } from 'fs';
|
|
4
5
|
import * as http from 'http';
|
|
5
|
-
import { clearTimeout, setTimeout } from 'timers';
|
|
6
6
|
import * as url from 'url';
|
|
7
7
|
import { URL } from 'url';
|
|
8
8
|
import { promisify } from 'util';
|
|
@@ -64,6 +64,19 @@ export const ByteUtils = {
|
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Returns true if value is a Uint8Array or a Buffer
|
|
69
|
+
* @param value - any value that may be a Uint8Array
|
|
70
|
+
*/
|
|
71
|
+
export function isUint8Array(value: unknown): value is Uint8Array {
|
|
72
|
+
return (
|
|
73
|
+
value != null &&
|
|
74
|
+
typeof value === 'object' &&
|
|
75
|
+
Symbol.toStringTag in value &&
|
|
76
|
+
value[Symbol.toStringTag] === 'Uint8Array'
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
67
80
|
/**
|
|
68
81
|
* Determines if a connection's address matches a user provided list
|
|
69
82
|
* of domain wildcards.
|
|
@@ -178,6 +191,7 @@ export function isPromiseLike<T = unknown>(value?: unknown): value is PromiseLik
|
|
|
178
191
|
value != null &&
|
|
179
192
|
typeof value === 'object' &&
|
|
180
193
|
'then' in value &&
|
|
194
|
+
// eslint-disable-next-line github/no-then
|
|
181
195
|
typeof value.then === 'function'
|
|
182
196
|
);
|
|
183
197
|
}
|
|
@@ -1156,7 +1170,7 @@ export async function request(
|
|
|
1156
1170
|
uri: string,
|
|
1157
1171
|
options: RequestOptions = {}
|
|
1158
1172
|
): Promise<string | Record<string, any>> {
|
|
1159
|
-
return new Promise<string | Record<string, any>>((resolve, reject) => {
|
|
1173
|
+
return await new Promise<string | Record<string, any>>((resolve, reject) => {
|
|
1160
1174
|
const requestOptions = {
|
|
1161
1175
|
method: 'GET',
|
|
1162
1176
|
timeout: 10000,
|
|
@@ -1201,33 +1215,6 @@ export async function request(
|
|
|
1201
1215
|
});
|
|
1202
1216
|
}
|
|
1203
1217
|
|
|
1204
|
-
/**
|
|
1205
|
-
* A custom AbortController that aborts after a specified timeout.
|
|
1206
|
-
*
|
|
1207
|
-
* If `timeout` is undefined or \<=0, the abort controller never aborts.
|
|
1208
|
-
*
|
|
1209
|
-
* This class provides two benefits over the built-in AbortSignal.timeout() method.
|
|
1210
|
-
* - This class provides a mechanism for cancelling the timeout
|
|
1211
|
-
* - This class supports infinite timeouts by interpreting a timeout of 0 as infinite. This is
|
|
1212
|
-
* consistent with existing timeout options in the Node driver (serverSelectionTimeoutMS, for example).
|
|
1213
|
-
* @internal
|
|
1214
|
-
*/
|
|
1215
|
-
export class TimeoutController extends AbortController {
|
|
1216
|
-
constructor(
|
|
1217
|
-
timeout = 0,
|
|
1218
|
-
private timeoutId = timeout > 0 ? setTimeout(() => this.abort(), timeout) : null
|
|
1219
|
-
) {
|
|
1220
|
-
super();
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
clear() {
|
|
1224
|
-
if (this.timeoutId != null) {
|
|
1225
|
-
clearTimeout(this.timeoutId);
|
|
1226
|
-
}
|
|
1227
|
-
this.timeoutId = null;
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
1218
|
/** @internal */
|
|
1232
1219
|
export const DOCUMENT_DB_CHECK = /(\.docdb\.amazonaws\.com$)|(\.docdb-elastic\.amazonaws\.com$)/;
|
|
1233
1220
|
/** @internal */
|
|
@@ -1245,9 +1232,13 @@ export function isHostMatch(match: RegExp, host?: string): boolean {
|
|
|
1245
1232
|
return host && match.test(host.toLowerCase()) ? true : false;
|
|
1246
1233
|
}
|
|
1247
1234
|
|
|
1248
|
-
export function promiseWithResolvers<T>() {
|
|
1249
|
-
|
|
1250
|
-
|
|
1235
|
+
export function promiseWithResolvers<T>(): {
|
|
1236
|
+
promise: Promise<T>;
|
|
1237
|
+
resolve: (value: T) => void;
|
|
1238
|
+
reject: (error: Error) => void;
|
|
1239
|
+
} {
|
|
1240
|
+
let resolve!: (value: T) => void;
|
|
1241
|
+
let reject!: (error: Error) => void;
|
|
1251
1242
|
const promise = new Promise<T>(function withResolversExecutor(promiseResolve, promiseReject) {
|
|
1252
1243
|
resolve = promiseResolve;
|
|
1253
1244
|
reject = promiseReject;
|
|
@@ -1255,6 +1246,20 @@ export function promiseWithResolvers<T>() {
|
|
|
1255
1246
|
return { promise, resolve, reject } as const;
|
|
1256
1247
|
}
|
|
1257
1248
|
|
|
1249
|
+
/**
|
|
1250
|
+
* A noop function intended for use in preventing unhandled rejections.
|
|
1251
|
+
*
|
|
1252
|
+
* @example
|
|
1253
|
+
* ```js
|
|
1254
|
+
* const promise = myAsyncTask();
|
|
1255
|
+
* // eslint-disable-next-line github/no-then
|
|
1256
|
+
* promise.then(undefined, squashError);
|
|
1257
|
+
* ```
|
|
1258
|
+
*/
|
|
1259
|
+
export function squashError(_error: unknown) {
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1258
1263
|
export const randomBytes = promisify(crypto.randomBytes);
|
|
1259
1264
|
|
|
1260
1265
|
/**
|
|
@@ -1280,3 +1285,51 @@ export async function once<T>(ee: EventEmitter, name: string): Promise<T> {
|
|
|
1280
1285
|
throw error;
|
|
1281
1286
|
}
|
|
1282
1287
|
}
|
|
1288
|
+
|
|
1289
|
+
export function maybeAddIdToDocuments(
|
|
1290
|
+
coll: Collection,
|
|
1291
|
+
docs: Document[],
|
|
1292
|
+
options: { forceServerObjectId?: boolean }
|
|
1293
|
+
): Document[];
|
|
1294
|
+
export function maybeAddIdToDocuments(
|
|
1295
|
+
coll: Collection,
|
|
1296
|
+
docs: Document,
|
|
1297
|
+
options: { forceServerObjectId?: boolean }
|
|
1298
|
+
): Document;
|
|
1299
|
+
export function maybeAddIdToDocuments(
|
|
1300
|
+
coll: Collection,
|
|
1301
|
+
docOrDocs: Document[] | Document,
|
|
1302
|
+
options: { forceServerObjectId?: boolean }
|
|
1303
|
+
): Document[] | Document {
|
|
1304
|
+
const forceServerObjectId =
|
|
1305
|
+
typeof options.forceServerObjectId === 'boolean'
|
|
1306
|
+
? options.forceServerObjectId
|
|
1307
|
+
: coll.s.db.options?.forceServerObjectId;
|
|
1308
|
+
|
|
1309
|
+
// no need to modify the docs if server sets the ObjectId
|
|
1310
|
+
if (forceServerObjectId === true) {
|
|
1311
|
+
return docOrDocs;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
const transform = (doc: Document): Document => {
|
|
1315
|
+
if (doc._id == null) {
|
|
1316
|
+
doc._id = coll.s.pkFactory.createPk();
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
return doc;
|
|
1320
|
+
};
|
|
1321
|
+
return Array.isArray(docOrDocs) ? docOrDocs.map(transform) : transform(docOrDocs);
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
export async function fileIsAccessible(fileName: string, mode?: number) {
|
|
1325
|
+
try {
|
|
1326
|
+
await fs.access(fileName, mode);
|
|
1327
|
+
return true;
|
|
1328
|
+
} catch {
|
|
1329
|
+
return false;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
export function noop() {
|
|
1334
|
+
return;
|
|
1335
|
+
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.maybeAddIdToDocuments = exports.indexInformation = void 0;
|
|
4
|
-
async function indexInformation(db, name, options) {
|
|
5
|
-
if (options == null) {
|
|
6
|
-
options = {};
|
|
7
|
-
}
|
|
8
|
-
// If we specified full information
|
|
9
|
-
const full = options.full == null ? false : options.full;
|
|
10
|
-
// Get the list of indexes of the specified collection
|
|
11
|
-
const indexes = await db.collection(name).listIndexes(options).toArray();
|
|
12
|
-
if (full)
|
|
13
|
-
return indexes;
|
|
14
|
-
const info = {};
|
|
15
|
-
for (const index of indexes) {
|
|
16
|
-
info[index.name] = Object.entries(index.key);
|
|
17
|
-
}
|
|
18
|
-
return info;
|
|
19
|
-
}
|
|
20
|
-
exports.indexInformation = indexInformation;
|
|
21
|
-
function maybeAddIdToDocuments(coll, docOrDocs, options) {
|
|
22
|
-
const forceServerObjectId = typeof options.forceServerObjectId === 'boolean'
|
|
23
|
-
? options.forceServerObjectId
|
|
24
|
-
: coll.s.db.options?.forceServerObjectId;
|
|
25
|
-
// no need to modify the docs if server sets the ObjectId
|
|
26
|
-
if (forceServerObjectId === true) {
|
|
27
|
-
return docOrDocs;
|
|
28
|
-
}
|
|
29
|
-
const transform = (doc) => {
|
|
30
|
-
if (doc._id == null) {
|
|
31
|
-
doc._id = coll.s.pkFactory.createPk();
|
|
32
|
-
}
|
|
33
|
-
return doc;
|
|
34
|
-
};
|
|
35
|
-
return Array.isArray(docOrDocs) ? docOrDocs.map(transform) : transform(docOrDocs);
|
|
36
|
-
}
|
|
37
|
-
exports.maybeAddIdToDocuments = maybeAddIdToDocuments;
|
|
38
|
-
//# sourceMappingURL=common_functions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common_functions.js","sourceRoot":"","sources":["../../src/operations/common_functions.ts"],"names":[],"mappings":";;;AAwBO,KAAK,UAAU,gBAAgB,CACpC,EAAM,EACN,IAAY,EACZ,OAAiC;IAEjC,IAAI,OAAO,IAAI,IAAI,EAAE;QACnB,OAAO,GAAG,EAAE,CAAC;KACd;IACD,mCAAmC;IACnC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IACzD,sDAAsD;IACtD,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;IACzE,IAAI,IAAI;QAAE,OAAO,OAAO,CAAC;IAEzB,MAAM,IAAI,GAA6C,EAAE,CAAC;IAC1D,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE;QAC3B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;KAC9C;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAnBD,4CAmBC;AAYD,SAAgB,qBAAqB,CACnC,IAAgB,EAChB,SAAgC,EAChC,OAA0C;IAE1C,MAAM,mBAAmB,GACvB,OAAO,OAAO,CAAC,mBAAmB,KAAK,SAAS;QAC9C,CAAC,CAAC,OAAO,CAAC,mBAAmB;QAC7B,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,mBAAmB,CAAC;IAE7C,yDAAyD;IACzD,IAAI,mBAAmB,KAAK,IAAI,EAAE;QAChC,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,SAAS,GAAG,CAAC,GAAa,EAAY,EAAE;QAC5C,IAAI,GAAG,CAAC,GAAG,IAAI,IAAI,EAAE;YACnB,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;SACvC;QAED,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;IACF,OAAO,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AACpF,CAAC;AAvBD,sDAuBC"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { Document } from '../bson';
|
|
2
|
-
import type { Collection } from '../collection';
|
|
3
|
-
import type { Db } from '../db';
|
|
4
|
-
import type { ReadPreference } from '../read_preference';
|
|
5
|
-
import type { ClientSession } from '../sessions';
|
|
6
|
-
|
|
7
|
-
/** @public */
|
|
8
|
-
export interface IndexInformationOptions {
|
|
9
|
-
full?: boolean;
|
|
10
|
-
readPreference?: ReadPreference;
|
|
11
|
-
session?: ClientSession;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Retrieves this collections index info.
|
|
15
|
-
*
|
|
16
|
-
* @param db - The Db instance on which to retrieve the index info.
|
|
17
|
-
* @param name - The name of the collection.
|
|
18
|
-
*/
|
|
19
|
-
export async function indexInformation(db: Db, name: string): Promise<any>;
|
|
20
|
-
export async function indexInformation(
|
|
21
|
-
db: Db,
|
|
22
|
-
name: string,
|
|
23
|
-
options?: IndexInformationOptions
|
|
24
|
-
): Promise<any>;
|
|
25
|
-
export async function indexInformation(
|
|
26
|
-
db: Db,
|
|
27
|
-
name: string,
|
|
28
|
-
options?: IndexInformationOptions
|
|
29
|
-
): Promise<any> {
|
|
30
|
-
if (options == null) {
|
|
31
|
-
options = {};
|
|
32
|
-
}
|
|
33
|
-
// If we specified full information
|
|
34
|
-
const full = options.full == null ? false : options.full;
|
|
35
|
-
// Get the list of indexes of the specified collection
|
|
36
|
-
const indexes = await db.collection(name).listIndexes(options).toArray();
|
|
37
|
-
if (full) return indexes;
|
|
38
|
-
|
|
39
|
-
const info: Record<string, Array<[string, unknown]>> = {};
|
|
40
|
-
for (const index of indexes) {
|
|
41
|
-
info[index.name] = Object.entries(index.key);
|
|
42
|
-
}
|
|
43
|
-
return info;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function maybeAddIdToDocuments(
|
|
47
|
-
coll: Collection,
|
|
48
|
-
docs: Document[],
|
|
49
|
-
options: { forceServerObjectId?: boolean }
|
|
50
|
-
): Document[];
|
|
51
|
-
export function maybeAddIdToDocuments(
|
|
52
|
-
coll: Collection,
|
|
53
|
-
docs: Document,
|
|
54
|
-
options: { forceServerObjectId?: boolean }
|
|
55
|
-
): Document;
|
|
56
|
-
export function maybeAddIdToDocuments(
|
|
57
|
-
coll: Collection,
|
|
58
|
-
docOrDocs: Document[] | Document,
|
|
59
|
-
options: { forceServerObjectId?: boolean }
|
|
60
|
-
): Document[] | Document {
|
|
61
|
-
const forceServerObjectId =
|
|
62
|
-
typeof options.forceServerObjectId === 'boolean'
|
|
63
|
-
? options.forceServerObjectId
|
|
64
|
-
: coll.s.db.options?.forceServerObjectId;
|
|
65
|
-
|
|
66
|
-
// no need to modify the docs if server sets the ObjectId
|
|
67
|
-
if (forceServerObjectId === true) {
|
|
68
|
-
return docOrDocs;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const transform = (doc: Document): Document => {
|
|
72
|
-
if (doc._id == null) {
|
|
73
|
-
doc._id = coll.s.pkFactory.createPk();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return doc;
|
|
77
|
-
};
|
|
78
|
-
return Array.isArray(docOrDocs) ? docOrDocs.map(transform) : transform(docOrDocs);
|
|
79
|
-
}
|