@pi-r/mongodb 0.7.2 → 0.7.4

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 CHANGED
@@ -1,9 +1,9 @@
1
- ### @pi-r/mongodb
2
-
3
- https://e-mc.readthedocs.io/en/latest/db/mongodb.html
4
-
5
- PEP 402 - Forever Dodgers
6
-
7
- ### LICENSE
8
-
1
+ ### @pi-r/mongodb
2
+
3
+ https://e-mc.readthedocs.io/en/latest/db/mongodb.html
4
+
5
+ PEP 402 - Forever Dodgers
6
+
7
+ ### LICENSE
8
+
9
9
  MIT
package/client/index.js CHANGED
@@ -243,7 +243,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
243
243
  parallel = false;
244
244
  }
245
245
  else if (parallel === undefined) {
246
- parallel = !batch.some(item => item.parallel === false);
246
+ parallel = !batch.some(item => item.parallel === false || !!item.update);
247
247
  }
248
248
  if (!parallel) {
249
249
  outResult ||= new Array(length);
package/client/pool.js ADDED
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ const util_1 = require("@e-mc/db/util");
3
+ const DbPool = require('@e-mc/db/pool');
4
+ const POOL_ACTIVE = new WeakSet();
5
+ class MongoDBPool extends DbPool {
6
+ static asString(credential) {
7
+ const { options, uri } = credential;
8
+ if (uri && options) {
9
+ return uri + JSON.stringify(options);
10
+ }
11
+ return super.asString(credential);
12
+ }
13
+ static sanitize(credential) {
14
+ const target = credential.options;
15
+ if (!target || !POOL_ACTIVE.has(credential) || credential.uuidKey) {
16
+ return credential;
17
+ }
18
+ const options = super.sanitize(target);
19
+ return options !== target ? { uri: credential.uri, options } : credential;
20
+ }
21
+ async detach(force) {
22
+ this.remove();
23
+ if (this.closed) {
24
+ return;
25
+ }
26
+ return this.close(force);
27
+ }
28
+ get closeable() {
29
+ const topology = this.client.topology;
30
+ return topology ? super.closeable || topology.s.state === 'closing' : true;
31
+ }
32
+ async getConnection(credential) {
33
+ if (credential) {
34
+ POOL_ACTIVE.add(credential);
35
+ }
36
+ return this.client.connect();
37
+ }
38
+ async close(force = false) {
39
+ return this.client.close(force);
40
+ }
41
+ isEmpty() {
42
+ if (this.closed) {
43
+ return true;
44
+ }
45
+ const topology = this.client.topology;
46
+ if (topology) {
47
+ const name = Object.getOwnPropertySymbols(topology).find(sym => sym.toString() === 'Symbol(waitQueue)');
48
+ return (0, util_1.checkEmpty)(name ? topology[name] : topology.s.servers);
49
+ }
50
+ return false;
51
+ }
52
+ get closed() {
53
+ const topology = this.client.topology;
54
+ if (topology && (this.success > 0 || this.failed > 0)) {
55
+ return topology.isDestroyed();
56
+ }
57
+ return this.client.s?.hasBeenClosed === true;
58
+ }
59
+ }
60
+ MongoDBPool.CACHE_UNUSED = ['maxPoolSize', 'minPoolSize', 'connectTimeoutMS', 'socketTimeoutMS', 'maxConnecting', 'maxIdleTimeMS', 'waitQueueTimeoutMS', 'maxStalenessSeconds', 'localThresholdMS', 'serverSelectionTimeoutMS', 'heartbeatFrequencyMS', 'minHeartbeatFrequencyMS', 'compressors', 'zlibCompressionLevel', 'srvMaxHosts'];
61
+ module.exports = MongoDBPool;
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "name": "@pi-r/mongodb",
3
- "version": "0.7.2",
4
- "description": "MongoDB client driver for E-mc.",
5
- "main": "client/index.js",
6
- "types": "client/index.d.ts",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/anpham6/pi-r.git",
13
- "directory": "src/db/mongodb"
14
- },
15
- "keywords": [
16
- "squared",
17
- "e-mc",
18
- "squared-functions"
19
- ],
20
- "author": "An Pham <anpham6@gmail.com>",
21
- "license": "MIT",
22
- "homepage": "https://github.com/anpham6/pi-r#readme",
23
- "dependencies": {
24
- "@e-mc/db": "^0.9.4",
25
- "@e-mc/request": "^0.9.4",
26
- "@e-mc/types": "^0.9.4",
27
- "mongodb": "^6.7.0"
28
- }
29
- }
1
+ {
2
+ "name": "@pi-r/mongodb",
3
+ "version": "0.7.4",
4
+ "description": "MongoDB client driver for E-mc.",
5
+ "main": "client/index.js",
6
+ "types": "client/index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/anpham6/pi-r.git",
13
+ "directory": "src/db/mongodb"
14
+ },
15
+ "keywords": [
16
+ "squared",
17
+ "e-mc",
18
+ "squared-functions"
19
+ ],
20
+ "author": "An Pham <anpham6@gmail.com>",
21
+ "license": "MIT",
22
+ "homepage": "https://github.com/anpham6/pi-r#readme",
23
+ "dependencies": {
24
+ "@e-mc/db": "^0.9.12",
25
+ "@e-mc/request": "^0.9.12",
26
+ "@e-mc/types": "^0.9.12",
27
+ "mongodb": "^6.9.0"
28
+ }
29
+ }
package/types/index.d.ts CHANGED
@@ -1,43 +1,43 @@
1
- import type { DbDataSource } from '@e-mc/types/lib/squared';
2
-
3
- import type { CascadeAction, ServerAuth } from '@e-mc/types/lib/db';
4
-
5
- import type { AggregateOptions, CollectionOptions, CommandOperationOptions, DbOptions, Document, Filter, MongoClientOptions, OptionalUnlessRequiredId, RunCommandOptions, Sort, SortDirection, UpdateFilter } from 'mongodb';
6
-
7
- export interface MongoDBDataSource extends DbDataSource<Filter<Document> | MongoDBFilterValue, MongoClientOptions, UpdateFilter<Document> | OptionalUnlessRequiredId<unknown>[], MongoDBCredential, string>, MongoDBClientDBOptions, CascadeAction {
8
- source: "mongodb";
9
- id?: string;
10
- updateType?: 0 | 1 | 2 | 3;
11
- }
12
-
13
- export interface MongoDBCredential extends ServerAuth, Pick<MongoClientOptions, "auth" | "authMechanism" | "authSource" | "tlsCertificateKeyFile" | "tlsCertificateKeyFilePassword" | "tlsCAFile" | "tlsCRLFile" | "tlsAllowInvalidHostnames" | "tlsAllowInvalidCertificates" | "tlsInsecure"> {}
14
-
15
- export interface MongoDBSortValue {
16
- value?: Sort;
17
- direction?: SortDirection;
18
- }
19
-
20
- export interface MongoDBAggregate {
21
- pipeline?: Document[];
22
- options?: AggregateOptions;
23
- }
24
-
25
- export interface MongoDBClientDBOptions {
26
- client?: {
27
- db?: DbOptions;
28
- collection?: CollectionOptions;
29
- command?: RunCommandOptions;
30
- };
31
- execute?: {
32
- insert?: CommandOperationOptions;
33
- update?: CommandOperationOptions;
34
- };
35
- command?: ArrayOf<Document>;
36
- aggregate?: MongoDBAggregate | Document[];
37
- sort?: Sort | string | MongoDBSortValue;
38
- }
39
-
40
- export interface MongoDBFilterValue {
41
- value?: Filter<Document>;
42
- options?: CommandOperationOptions;
1
+ import type { DbDataSource } from '@e-mc/types/lib/squared';
2
+
3
+ import type { CascadeAction, ServerAuth } from '@e-mc/types/lib/db';
4
+
5
+ import type { AggregateOptions, CollectionOptions, CommandOperationOptions, DbOptions, Document, Filter, MongoClientOptions, OptionalUnlessRequiredId, RunCommandOptions, Sort, SortDirection, UpdateFilter } from 'mongodb';
6
+
7
+ export interface MongoDBDataSource extends DbDataSource<Filter<Document> | MongoDBFilterValue, MongoClientOptions, UpdateFilter<Document> | OptionalUnlessRequiredId<unknown>[], MongoDBCredential, string>, MongoDBClientDBOptions, CascadeAction {
8
+ source: "mongodb";
9
+ id?: string;
10
+ updateType?: 0 | 1 | 2 | 3;
11
+ }
12
+
13
+ export interface MongoDBCredential extends ServerAuth, Pick<MongoClientOptions, "auth" | "authMechanism" | "authSource" | "tlsCertificateKeyFile" | "tlsCertificateKeyFilePassword" | "tlsCAFile" | "tlsCRLFile" | "tlsAllowInvalidHostnames" | "tlsAllowInvalidCertificates" | "tlsInsecure"> {}
14
+
15
+ export interface MongoDBSortValue {
16
+ value?: Sort;
17
+ direction?: SortDirection;
18
+ }
19
+
20
+ export interface MongoDBAggregate {
21
+ pipeline?: Document[];
22
+ options?: AggregateOptions;
23
+ }
24
+
25
+ export interface MongoDBClientDBOptions {
26
+ client?: {
27
+ db?: DbOptions;
28
+ collection?: CollectionOptions;
29
+ command?: RunCommandOptions;
30
+ };
31
+ execute?: {
32
+ insert?: CommandOperationOptions;
33
+ update?: CommandOperationOptions;
34
+ };
35
+ command?: ArrayOf<Document>;
36
+ aggregate?: MongoDBAggregate | Document[];
37
+ sort?: Sort | string | MongoDBSortValue;
38
+ }
39
+
40
+ export interface MongoDBFilterValue {
41
+ value?: Filter<Document>;
42
+ options?: CommandOperationOptions;
43
43
  }