mongodb 6.16.0 → 6.17.0-dev.20250605.sha.57ef31be

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.
Files changed (130) hide show
  1. package/README.md +2 -0
  2. package/lib/beta.d.ts +160 -49
  3. package/lib/bulk/common.js +4 -4
  4. package/lib/bulk/common.js.map +1 -1
  5. package/lib/change_stream.js.map +1 -1
  6. package/lib/client-side-encryption/auto_encrypter.js +5 -2
  7. package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
  8. package/lib/client-side-encryption/client_encryption.js.map +1 -1
  9. package/lib/client-side-encryption/state_machine.js +1 -1
  10. package/lib/client-side-encryption/state_machine.js.map +1 -1
  11. package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js +6 -0
  12. package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js.map +1 -1
  13. package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +21 -33
  14. package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js.map +1 -1
  15. package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +14 -21
  16. package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js.map +1 -1
  17. package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +19 -26
  18. package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js.map +1 -1
  19. package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +12 -24
  20. package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js.map +1 -1
  21. package/lib/cmap/auth/mongodb_oidc.js +5 -4
  22. package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
  23. package/lib/cmap/commands.js +10 -8
  24. package/lib/cmap/commands.js.map +1 -1
  25. package/lib/cmap/connect.js +4 -3
  26. package/lib/cmap/connect.js.map +1 -1
  27. package/lib/cmap/connection.js +8 -3
  28. package/lib/cmap/connection.js.map +1 -1
  29. package/lib/cmap/connection_pool.js +6 -1
  30. package/lib/cmap/connection_pool.js.map +1 -1
  31. package/lib/cmap/handshake/client_metadata.js +1 -1
  32. package/lib/cmap/handshake/client_metadata.js.map +1 -1
  33. package/lib/cmap/wire_protocol/compression.js.map +1 -1
  34. package/lib/cmap/wire_protocol/constants.js +2 -2
  35. package/lib/cmap/wire_protocol/on_data.js +4 -0
  36. package/lib/cmap/wire_protocol/on_data.js.map +1 -1
  37. package/lib/cmap/wire_protocol/on_demand/document.js +16 -15
  38. package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -1
  39. package/lib/cmap/wire_protocol/responses.js +11 -4
  40. package/lib/cmap/wire_protocol/responses.js.map +1 -1
  41. package/lib/collection.js.map +1 -1
  42. package/lib/connection_string.js +4 -0
  43. package/lib/connection_string.js.map +1 -1
  44. package/lib/constants.js +0 -1
  45. package/lib/constants.js.map +1 -1
  46. package/lib/cursor/abstract_cursor.js.map +1 -1
  47. package/lib/encrypter.js +3 -7
  48. package/lib/encrypter.js.map +1 -1
  49. package/lib/error.js +28 -1
  50. package/lib/error.js.map +1 -1
  51. package/lib/index.js +4 -3
  52. package/lib/index.js.map +1 -1
  53. package/lib/mongo_client.js +66 -20
  54. package/lib/mongo_client.js.map +1 -1
  55. package/lib/operations/aggregate.js +0 -1
  56. package/lib/operations/aggregate.js.map +1 -1
  57. package/lib/operations/client_bulk_write/command_builder.js +20 -13
  58. package/lib/operations/client_bulk_write/command_builder.js.map +1 -1
  59. package/lib/operations/distinct.js +1 -0
  60. package/lib/operations/distinct.js.map +1 -1
  61. package/lib/operations/find_and_modify.js +1 -1
  62. package/lib/operations/find_and_modify.js.map +1 -1
  63. package/lib/operations/rename.js.map +1 -1
  64. package/lib/operations/run_command.js.map +1 -1
  65. package/lib/operations/search_indexes/create.js.map +1 -1
  66. package/lib/operations/search_indexes/drop.js.map +1 -1
  67. package/lib/operations/search_indexes/update.js.map +1 -1
  68. package/lib/operations/update.js +6 -2
  69. package/lib/operations/update.js.map +1 -1
  70. package/lib/sdam/server.js +4 -1
  71. package/lib/sdam/server.js.map +1 -1
  72. package/lib/sdam/topology.js +9 -4
  73. package/lib/sdam/topology.js.map +1 -1
  74. package/lib/sort.js +13 -6
  75. package/lib/sort.js.map +1 -1
  76. package/lib/utils.js +15 -2
  77. package/lib/utils.js.map +1 -1
  78. package/lib/write_concern.js +2 -4
  79. package/lib/write_concern.js.map +1 -1
  80. package/mongodb.d.ts +160 -49
  81. package/package.json +21 -21
  82. package/src/bulk/common.ts +14 -11
  83. package/src/change_stream.ts +38 -13
  84. package/src/client-side-encryption/auto_encrypter.ts +10 -2
  85. package/src/client-side-encryption/client_encryption.ts +5 -0
  86. package/src/client-side-encryption/state_machine.ts +8 -5
  87. package/src/cmap/auth/mongodb_oidc/automated_callback_workflow.ts +6 -0
  88. package/src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts +23 -35
  89. package/src/cmap/auth/mongodb_oidc/gcp_machine_workflow.ts +16 -23
  90. package/src/cmap/auth/mongodb_oidc/k8s_machine_workflow.ts +17 -25
  91. package/src/cmap/auth/mongodb_oidc/token_machine_workflow.ts +11 -24
  92. package/src/cmap/auth/mongodb_oidc.ts +13 -8
  93. package/src/cmap/commands.ts +31 -16
  94. package/src/cmap/connect.ts +4 -3
  95. package/src/cmap/connection.ts +11 -4
  96. package/src/cmap/connection_pool.ts +8 -1
  97. package/src/cmap/handshake/client_metadata.ts +5 -1
  98. package/src/cmap/wire_protocol/compression.ts +2 -1
  99. package/src/cmap/wire_protocol/constants.ts +2 -2
  100. package/src/cmap/wire_protocol/on_data.ts +5 -0
  101. package/src/cmap/wire_protocol/on_demand/document.ts +20 -15
  102. package/src/cmap/wire_protocol/responses.ts +10 -10
  103. package/src/collection.ts +2 -1
  104. package/src/connection_string.ts +4 -0
  105. package/src/constants.ts +0 -1
  106. package/src/cursor/abstract_cursor.ts +6 -4
  107. package/src/encrypter.ts +3 -10
  108. package/src/error.ts +28 -0
  109. package/src/index.ts +3 -0
  110. package/src/mongo_client.ts +73 -21
  111. package/src/operations/aggregate.ts +0 -1
  112. package/src/operations/client_bulk_write/command_builder.ts +32 -14
  113. package/src/operations/client_bulk_write/common.ts +5 -0
  114. package/src/operations/distinct.ts +1 -0
  115. package/src/operations/find_and_modify.ts +1 -1
  116. package/src/operations/rename.ts +8 -5
  117. package/src/operations/run_command.ts +17 -4
  118. package/src/operations/search_indexes/create.ts +6 -4
  119. package/src/operations/search_indexes/drop.ts +6 -4
  120. package/src/operations/search_indexes/update.ts +8 -5
  121. package/src/operations/update.ts +12 -3
  122. package/src/sdam/server.ts +5 -1
  123. package/src/sdam/topology.ts +10 -4
  124. package/src/sort.ts +32 -23
  125. package/src/utils.ts +29 -9
  126. package/src/write_concern.ts +2 -4
  127. package/tsconfig.json +2 -1
  128. package/lib/cmap/auth/mongodb_oidc/machine_workflow.js +0 -110
  129. package/lib/cmap/auth/mongodb_oidc/machine_workflow.js.map +0 -1
  130. package/src/cmap/auth/mongodb_oidc/machine_workflow.ts +0 -142
@@ -1,110 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MachineWorkflow = void 0;
4
- const promises_1 = require("timers/promises");
5
- const utils_1 = require("../../../utils");
6
- const command_builders_1 = require("./command_builders");
7
- /** The time to throttle callback calls. */
8
- const THROTTLE_MS = 100;
9
- /**
10
- * Common behaviour for OIDC machine workflows.
11
- * @internal
12
- */
13
- class MachineWorkflow {
14
- /**
15
- * Instantiate the machine workflow.
16
- */
17
- constructor(cache) {
18
- this.cache = cache;
19
- this.callback = this.withLock(this.getToken.bind(this));
20
- this.lastExecutionTime = Date.now() - THROTTLE_MS;
21
- }
22
- /**
23
- * Execute the workflow. Gets the token from the subclass implementation.
24
- */
25
- async execute(connection, credentials) {
26
- const token = await this.getTokenFromCacheOrEnv(connection, credentials);
27
- const command = (0, command_builders_1.finishCommandDocument)(token);
28
- await connection.command((0, utils_1.ns)(credentials.source), command, undefined);
29
- }
30
- /**
31
- * Reauthenticate on a machine workflow just grabs the token again since the server
32
- * has said the current access token is invalid or expired.
33
- */
34
- async reauthenticate(connection, credentials) {
35
- if (this.cache.hasAccessToken) {
36
- // Reauthentication implies the token has expired.
37
- if (connection.accessToken === this.cache.getAccessToken()) {
38
- // If connection's access token is the same as the cache's, remove
39
- // the token from the cache and connection.
40
- this.cache.removeAccessToken();
41
- delete connection.accessToken;
42
- }
43
- else {
44
- // If the connection's access token is different from the cache's, set
45
- // the cache's token on the connection and do not remove from the
46
- // cache.
47
- connection.accessToken = this.cache.getAccessToken();
48
- }
49
- }
50
- await this.execute(connection, credentials);
51
- }
52
- /**
53
- * Get the document to add for speculative authentication.
54
- */
55
- async speculativeAuth(connection, credentials) {
56
- // The spec states only cached access tokens can use speculative auth.
57
- if (!this.cache.hasAccessToken) {
58
- return {};
59
- }
60
- const token = await this.getTokenFromCacheOrEnv(connection, credentials);
61
- const document = (0, command_builders_1.finishCommandDocument)(token);
62
- document.db = credentials.source;
63
- return { speculativeAuthenticate: document };
64
- }
65
- /**
66
- * Get the token from the cache or environment.
67
- */
68
- async getTokenFromCacheOrEnv(connection, credentials) {
69
- if (this.cache.hasAccessToken) {
70
- const token = this.cache.getAccessToken();
71
- // New connections won't have an access token so ensure we set here.
72
- if (!connection.accessToken) {
73
- connection.accessToken = token;
74
- }
75
- return token;
76
- }
77
- else {
78
- const token = await this.callback(credentials);
79
- this.cache.put({ accessToken: token.access_token, expiresInSeconds: token.expires_in });
80
- // Put the access token on the connection as well.
81
- connection.accessToken = token.access_token;
82
- return token.access_token;
83
- }
84
- }
85
- /**
86
- * Ensure the callback is only executed one at a time, and throttled to
87
- * only once per 100ms.
88
- */
89
- withLock(callback) {
90
- let lock = Promise.resolve();
91
- return async (credentials) => {
92
- // We do this to ensure that we would never return the result of the
93
- // previous lock, only the current callback's value would get returned.
94
- await lock;
95
- lock = lock
96
- .catch(() => null)
97
- .then(async () => {
98
- const difference = Date.now() - this.lastExecutionTime;
99
- if (difference <= THROTTLE_MS) {
100
- await (0, promises_1.setTimeout)(THROTTLE_MS - difference);
101
- }
102
- this.lastExecutionTime = Date.now();
103
- return await callback(credentials);
104
- });
105
- return await lock;
106
- };
107
- }
108
- }
109
- exports.MachineWorkflow = MachineWorkflow;
110
- //# sourceMappingURL=machine_workflow.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"machine_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/machine_workflow.ts"],"names":[],"mappings":";;;AAAA,8CAA6C;AAG7C,0CAAoC;AAIpC,yDAA2D;AAG3D,2CAA2C;AAC3C,MAAM,WAAW,GAAG,GAAG,CAAC;AAcxB;;;GAGG;AACH,MAAsB,eAAe;IAKnC;;OAEG;IACH,YAAY,KAAiB;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACxD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,UAAsB,EAAE,WAA6B;QACjE,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QACzE,MAAM,OAAO,GAAG,IAAA,wCAAqB,EAAC,KAAK,CAAC,CAAC;QAC7C,MAAM,UAAU,CAAC,OAAO,CAAC,IAAA,UAAE,EAAC,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IACvE,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,cAAc,CAAC,UAAsB,EAAE,WAA6B;QACxE,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;YAC9B,kDAAkD;YAClD,IAAI,UAAU,CAAC,WAAW,KAAK,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,CAAC;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C;YAC/C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,YAAY,EAAE,gBAAgB,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;YACxF,kDAAkD;YAClD,UAAU,CAAC,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC;YAC5C,OAAO,KAAK,CAAC,YAAY,CAAC;QAC5B,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,QAAQ,CAAC,QAA2B;QAC1C,IAAI,IAAI,GAAiB,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3C,OAAO,KAAK,EAAE,WAA6B,EAAwB,EAAE;YACnE,oEAAoE;YACpE,uEAAuE;YACvE,MAAM,IAAI,CAAC;YACX,IAAI,GAAG,IAAI;iBAER,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;iBAEjB,IAAI,CAAC,KAAK,IAAI,EAAE;gBACf,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,iBAAiB,CAAC;gBACvD,IAAI,UAAU,IAAI,WAAW,EAAE,CAAC;oBAC9B,MAAM,IAAA,qBAAU,EAAC,WAAW,GAAG,UAAU,CAAC,CAAC;gBAC7C,CAAC;gBACD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBACpC,OAAO,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC;YACrC,CAAC,CAAC,CAAC;YACL,OAAO,MAAM,IAAI,CAAC;QACpB,CAAC,CAAC;IACJ,CAAC;CAMF;AAhHD,0CAgHC"}
@@ -1,142 +0,0 @@
1
- import { setTimeout } from 'timers/promises';
2
-
3
- import { type Document } from '../../../bson';
4
- import { ns } from '../../../utils';
5
- import type { Connection } from '../../connection';
6
- import type { MongoCredentials } from '../mongo_credentials';
7
- import type { Workflow } from '../mongodb_oidc';
8
- import { finishCommandDocument } from './command_builders';
9
- import { type TokenCache } from './token_cache';
10
-
11
- /** The time to throttle callback calls. */
12
- const THROTTLE_MS = 100;
13
-
14
- /**
15
- * The access token format.
16
- * @internal
17
- */
18
- export interface AccessToken {
19
- access_token: string;
20
- expires_in?: number;
21
- }
22
-
23
- /** @internal */
24
- export type OIDCTokenFunction = (credentials: MongoCredentials) => Promise<AccessToken>;
25
-
26
- /**
27
- * Common behaviour for OIDC machine workflows.
28
- * @internal
29
- */
30
- export abstract class MachineWorkflow implements Workflow {
31
- cache: TokenCache;
32
- callback: OIDCTokenFunction;
33
- lastExecutionTime: number;
34
-
35
- /**
36
- * Instantiate the machine workflow.
37
- */
38
- constructor(cache: TokenCache) {
39
- this.cache = cache;
40
- this.callback = this.withLock(this.getToken.bind(this));
41
- this.lastExecutionTime = Date.now() - THROTTLE_MS;
42
- }
43
-
44
- /**
45
- * Execute the workflow. Gets the token from the subclass implementation.
46
- */
47
- async execute(connection: Connection, credentials: MongoCredentials): Promise<void> {
48
- const token = await this.getTokenFromCacheOrEnv(connection, credentials);
49
- const command = finishCommandDocument(token);
50
- await connection.command(ns(credentials.source), command, undefined);
51
- }
52
-
53
- /**
54
- * Reauthenticate on a machine workflow just grabs the token again since the server
55
- * has said the current access token is invalid or expired.
56
- */
57
- async reauthenticate(connection: Connection, credentials: MongoCredentials): Promise<void> {
58
- if (this.cache.hasAccessToken) {
59
- // Reauthentication implies the token has expired.
60
- if (connection.accessToken === this.cache.getAccessToken()) {
61
- // If connection's access token is the same as the cache's, remove
62
- // the token from the cache and connection.
63
- this.cache.removeAccessToken();
64
- delete connection.accessToken;
65
- } else {
66
- // If the connection's access token is different from the cache's, set
67
- // the cache's token on the connection and do not remove from the
68
- // cache.
69
- connection.accessToken = this.cache.getAccessToken();
70
- }
71
- }
72
- await this.execute(connection, credentials);
73
- }
74
-
75
- /**
76
- * Get the document to add for speculative authentication.
77
- */
78
- async speculativeAuth(connection: Connection, credentials: MongoCredentials): Promise<Document> {
79
- // The spec states only cached access tokens can use speculative auth.
80
- if (!this.cache.hasAccessToken) {
81
- return {};
82
- }
83
- const token = await this.getTokenFromCacheOrEnv(connection, credentials);
84
- const document = finishCommandDocument(token);
85
- document.db = credentials.source;
86
- return { speculativeAuthenticate: document };
87
- }
88
-
89
- /**
90
- * Get the token from the cache or environment.
91
- */
92
- private async getTokenFromCacheOrEnv(
93
- connection: Connection,
94
- credentials: MongoCredentials
95
- ): Promise<string> {
96
- if (this.cache.hasAccessToken) {
97
- const token = this.cache.getAccessToken();
98
- // New connections won't have an access token so ensure we set here.
99
- if (!connection.accessToken) {
100
- connection.accessToken = token;
101
- }
102
- return token;
103
- } else {
104
- const token = await this.callback(credentials);
105
- this.cache.put({ accessToken: token.access_token, expiresInSeconds: token.expires_in });
106
- // Put the access token on the connection as well.
107
- connection.accessToken = token.access_token;
108
- return token.access_token;
109
- }
110
- }
111
-
112
- /**
113
- * Ensure the callback is only executed one at a time, and throttled to
114
- * only once per 100ms.
115
- */
116
- private withLock(callback: OIDCTokenFunction): OIDCTokenFunction {
117
- let lock: Promise<any> = Promise.resolve();
118
- return async (credentials: MongoCredentials): Promise<AccessToken> => {
119
- // We do this to ensure that we would never return the result of the
120
- // previous lock, only the current callback's value would get returned.
121
- await lock;
122
- lock = lock
123
-
124
- .catch(() => null)
125
-
126
- .then(async () => {
127
- const difference = Date.now() - this.lastExecutionTime;
128
- if (difference <= THROTTLE_MS) {
129
- await setTimeout(THROTTLE_MS - difference);
130
- }
131
- this.lastExecutionTime = Date.now();
132
- return await callback(credentials);
133
- });
134
- return await lock;
135
- };
136
- }
137
-
138
- /**
139
- * Get the token from the environment or endpoint.
140
- */
141
- abstract getToken(credentials: MongoCredentials): Promise<AccessToken>;
142
- }