@pi-r/mongodb 0.2.2 → 0.2.3

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/client/index.js CHANGED
@@ -58,18 +58,26 @@ class MongoDBPool extends DbPool {
58
58
  }
59
59
  }
60
60
  const POOL_STATE = {};
61
+ const POOL_UNUSED = ['maxPoolSize', 'minPoolSize', 'maxConnecting', 'maxIdleTimeMS', 'waitQueueTimeoutMS', 'serverSelectionTimeoutMS', 'heartbeatFrequencyMS', 'minHeartbeatFrequencyMS', 'keepAliveInitialDelay', 'compressors', 'zlibCompressionLevel', 'srvMaxHosts'];
61
62
  function removePoolProperties(credential) {
62
- let options = credential.options;
63
+ const options = credential.options;
63
64
  if (options && !credential.uuidKey) {
65
+ let result;
64
66
  if (MONGODB_V360) {
65
- if ('maxPoolSize' in options || 'minPoolSize' in options || 'maxConnecting' in options || 'maxIdleTimeMS' in options || 'waitQueueTimeoutMS' in options || 'serverSelectionTimeoutMS' in options) {
66
- options = { ...options, maxPoolSize: undefined, minPoolSize: undefined, maxConnecting: undefined, maxIdleTimeMS: undefined, waitQueueTimeoutMS: undefined, serverSelectionTimeoutMS: undefined };
67
+ for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
68
+ const attr = POOL_UNUSED[i];
69
+ if (attr in credential) {
70
+ result || (result = { ...options });
71
+ delete result[attr];
72
+ }
67
73
  }
68
74
  }
69
75
  else if ('poolSize' in options || 'minSize' in options) {
70
- options = { ...options, poolSize: undefined, minSize: undefined };
76
+ result = { ...options, poolSize: undefined, minSize: undefined };
77
+ }
78
+ if (result) {
79
+ return { uri: credential.uri, options: result };
71
80
  }
72
- return { uri: credential.uri, options };
73
81
  }
74
82
  return credential;
75
83
  }
@@ -524,11 +532,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
524
532
  if ((0, types_1.isArray)(update)) {
525
533
  commandType = this.commandType.INSERT;
526
534
  const insertOptions = item.execute?.insert;
527
- if (insertOptions) {
528
- await collection.insertMany(update, coercing ? (0, types_1.coerceObject)(insertOptions) : insertOptions);
535
+ if (insertOptions && coercing) {
536
+ (0, types_1.coerceObject)(insertOptions);
537
+ }
538
+ if (update.length === 1) {
539
+ await collection.insertOne(update[0], insertOptions);
529
540
  }
530
541
  else {
531
- await collection.insertMany(update);
542
+ await collection.insertMany(update, insertOptions);
532
543
  }
533
544
  update = undefined;
534
545
  }
@@ -550,7 +561,10 @@ async function executeBatchQuery(batch, options = '', outResult) {
550
561
  else {
551
562
  if (update) {
552
563
  commandType = this.commandType.UPDATE;
553
- await collection.updateMany(filter, update);
564
+ const updateOptions = item.execute?.update;
565
+ if (updateOptions && coercing) {
566
+ (0, types_1.coerceObject)(updateOptions);
567
+ }
554
568
  }
555
569
  cursor = collection.find(filter, command);
556
570
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mongodb",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "MongoDB client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -24,6 +24,6 @@
24
24
  "@e-mc/db": "^0.5.3",
25
25
  "@e-mc/request": "^0.5.3",
26
26
  "@e-mc/types": "^0.5.3",
27
- "mongodb": "^5.5.0"
27
+ "mongodb": "^5.7.0"
28
28
  }
29
29
  }
package/types/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import type { DbDataSource } from '@e-mc/types/lib/squared';
2
2
 
3
3
  import type { CascadeAction, ServerAuth } from '@e-mc/types/lib/db';
4
4
 
5
- import type { AggregateOptions, BulkWriteOptions, CollectionOptions, CommandOperationOptions, DbOptions, Document, Filter, MongoClientOptions, OptionalUnlessRequiredId, Sort, SortDirection, UpdateFilter } from 'mongodb';
5
+ import type { AggregateOptions, CollectionOptions, CommandOperationOptions, DbOptions, Document, Filter, MongoClientOptions, OptionalUnlessRequiredId, Sort, SortDirection, UpdateFilter } from 'mongodb';
6
6
 
7
7
  export interface MongoDBDataSource extends DbDataSource<Filter<Document> | MongoDBQueryWithOptions, MongoClientOptions, UpdateFilter<Document> | OptionalUnlessRequiredId<unknown>[], string | MongoDBCredential, string>, MongoDBClientDBOptions, CascadeAction {
8
8
  source: "mongodb";
@@ -28,7 +28,8 @@ export interface MongoDBClientDBOptions {
28
28
  collection?: CollectionOptions;
29
29
  };
30
30
  execute?: {
31
- insert?: BulkWriteOptions;
31
+ insert?: CommandOperationOptions;
32
+ update?: CommandOperationOptions;
32
33
  };
33
34
  aggregate?: MongoDBAggregate;
34
35
  sort?: Sort | string | MongoDBSortValue;