@tomsd/mongodbclient 4.0.0 → 4.0.2

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
@@ -3,12 +3,17 @@
3
3
  It's a handy mongodb client for easy-use.
4
4
  See [mongodbclient.netlify.app](https://mongodbclient.netlify.app/) for details.
5
5
 
6
- ![npm](https://img.shields.io/npm/v/@tomsd/mongodbclient)
7
- ![NPM](https://img.shields.io/npm/l/@tomsd/mongodbclient)
8
- ![npms.io (quality)](https://img.shields.io/npms-io/quality-score/@tomsd/mongodbclient)
9
- ![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/@tomsd/mongodbclient)
10
- ![Maintenance](https://img.shields.io/maintenance/yes/2024)
11
- ![depends on mongodb@6](https://img.shields.io/badge/depends%20on-mongodb@6-informational)
6
+ ![npm](https://img.shields.io/npm/v/@tomsd/mongodbclient?style=for-the-badge&logo=npm)
7
+ ![NPM](https://img.shields.io/npm/l/@tomsd/mongodbclient?style=for-the-badge&logo=npm)
8
+ ![release date](https://img.shields.io/github/release-date/tomsdoo/mongodbclient?style=for-the-badge&logo=npm)
9
+ ![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/@tomsd/mongodbclient?style=for-the-badge&logo=npm)
10
+
11
+ ![ci](https://img.shields.io/github/actions/workflow/status/tomsdoo/mongodbclient/ci.yml?style=social&logo=github)
12
+ ![checks](https://img.shields.io/github/check-runs/tomsdoo/mongodbclient/main?style=social&logo=github)
13
+ ![top language](https://img.shields.io/github/languages/top/tomsdoo/mongodbclient?style=social&logo=typescript)
14
+ ![Maintenance](https://img.shields.io/maintenance/yes/2024?style=social&logo=github)
15
+ ![depends on mongodb@6](https://img.shields.io/badge/mongodb-mongodb@6-informational?style=social&logo=mongodb)
16
+ ![depends on node greater or equal 18](https://img.shields.io/badge/node.js-%3E%3D%2018-lightyellow?style=social&logo=nodedotjs)
12
17
 
13
18
  ## Installation
14
19
  ``` sh
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -24,8 +25,8 @@ __export(mongodbclient_exports, {
24
25
  default: () => mongodbclient_default
25
26
  });
26
27
  module.exports = __toCommonJS(mongodbclient_exports);
27
- var import_uuid = require("uuid");
28
28
  var import_mongodb = require("mongodb");
29
+ var import_uuid = require("uuid");
29
30
  var MongoConnection = class {
30
31
  _client;
31
32
  _db;
@@ -145,7 +146,7 @@ var MClient = class {
145
146
  }
146
147
  ]).toArray();
147
148
  return collStats;
148
- } catch (e) {
149
+ } catch (_) {
149
150
  return null;
150
151
  } finally {
151
152
  await connection.client.close();
@@ -169,6 +170,7 @@ var MClient = class {
169
170
  }));
170
171
  try {
171
172
  return await connection.collection.insertMany(
173
+ // biome-ignore lint: Array<T>
172
174
  savingItems,
173
175
  {
174
176
  writeConcern: { w: 1 }
@@ -0,0 +1,33 @@
1
+ import { MongoClient, Db, Collection, UpdateResult, WithId, Document, DeleteResult, InsertManyResult } from 'mongodb';
2
+
3
+ declare class MongoConnection {
4
+ private readonly _client;
5
+ private readonly _db;
6
+ private readonly _collection;
7
+ constructor(client: MongoClient, db: Db, collection: Collection);
8
+ get client(): MongoClient;
9
+ get db(): Db;
10
+ get collection(): Collection;
11
+ }
12
+ declare class MClient {
13
+ private readonly m_uri;
14
+ private readonly m_db;
15
+ private readonly m_collection;
16
+ constructor(uri: string, db: string, collection: string);
17
+ get uri(): string;
18
+ get db(): string;
19
+ get collection(): string;
20
+ connect(): Promise<MongoConnection>;
21
+ protected getConnected(): Promise<MongoConnection>;
22
+ upsert(pobj: any): Promise<UpdateResult>;
23
+ read(condition?: any, opt?: any): Promise<WithId<Document>[]>;
24
+ distinct(key: string, condition?: any): Promise<any[]>;
25
+ remove(condition: any): Promise<DeleteResult>;
26
+ stats(): Promise<Document | null>;
27
+ count(condition?: any): Promise<number>;
28
+ insertMany(items: any[]): Promise<InsertManyResult<Document>>;
29
+ dbStats(): Promise<Document>;
30
+ getCollections(): Promise<Collection[]>;
31
+ }
32
+
33
+ export { MClient, MongoConnection, MClient as default };
@@ -1,6 +1,6 @@
1
- import type { Db, Collection, DeleteResult, Document, InsertManyResult, UpdateResult, WithId } from "mongodb";
2
- import { MongoClient } from "mongodb";
3
- export declare class MongoConnection {
1
+ import { MongoClient, Db, Collection, UpdateResult, WithId, Document, DeleteResult, InsertManyResult } from 'mongodb';
2
+
3
+ declare class MongoConnection {
4
4
  private readonly _client;
5
5
  private readonly _db;
6
6
  private readonly _collection;
@@ -9,7 +9,7 @@ export declare class MongoConnection {
9
9
  get db(): Db;
10
10
  get collection(): Collection;
11
11
  }
12
- export declare class MClient {
12
+ declare class MClient {
13
13
  private readonly m_uri;
14
14
  private readonly m_db;
15
15
  private readonly m_collection;
@@ -20,7 +20,7 @@ export declare class MClient {
20
20
  connect(): Promise<MongoConnection>;
21
21
  protected getConnected(): Promise<MongoConnection>;
22
22
  upsert(pobj: any): Promise<UpdateResult>;
23
- read(condition?: any, opt?: any): Promise<Array<WithId<Document>>>;
23
+ read(condition?: any, opt?: any): Promise<WithId<Document>[]>;
24
24
  distinct(key: string, condition?: any): Promise<any[]>;
25
25
  remove(condition: any): Promise<DeleteResult>;
26
26
  stats(): Promise<Document | null>;
@@ -29,4 +29,5 @@ export declare class MClient {
29
29
  dbStats(): Promise<Document>;
30
30
  getCollections(): Promise<Collection[]>;
31
31
  }
32
- export default MClient;
32
+
33
+ export { MClient, MongoConnection, MClient as default };
@@ -1,6 +1,6 @@
1
1
  // src/mongodbclient.ts
2
- import { v4 as uuidv4 } from "uuid";
3
2
  import { MongoClient, ServerApiVersion } from "mongodb";
3
+ import { v4 as uuidv4 } from "uuid";
4
4
  var MongoConnection = class {
5
5
  _client;
6
6
  _db;
@@ -120,7 +120,7 @@ var MClient = class {
120
120
  }
121
121
  ]).toArray();
122
122
  return collStats;
123
- } catch (e) {
123
+ } catch (_) {
124
124
  return null;
125
125
  } finally {
126
126
  await connection.client.close();
@@ -144,6 +144,7 @@ var MClient = class {
144
144
  }));
145
145
  try {
146
146
  return await connection.collection.insertMany(
147
+ // biome-ignore lint: Array<T>
147
148
  savingItems,
148
149
  {
149
150
  writeConcern: { w: 1 }
package/package.json CHANGED
@@ -1,36 +1,34 @@
1
1
  {
2
2
  "name": "@tomsd/mongodbclient",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "It's a handy mongodb client for easy-use.",
5
- "main": "dist/mongodbclient.cjs.js",
6
- "module": "dist/mongodbclient.esm.js",
7
- "types": "dist/esm/mongodbclient.d.ts",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/mongodbclient.d.ts",
8
+ "import": "./dist/mongodbclient.esm.js",
9
+ "require": "./dist/mongodbclient.cjs.js"
10
+ }
11
+ },
8
12
  "files": [
9
13
  "dist"
10
14
  ],
11
15
  "scripts": {
12
- "build": "tsup && tsc --project tsconfig.esm.json",
13
- "format": "npm run format:src && npm run format:test",
14
- "format:document": "prettier --write docs/**/*.html",
15
- "format:src": "prettier --write src/**/*.ts",
16
- "format:test": "prettier --write __test__/**/*.ts",
17
- "lint:src": "ESLINT_USE_FLAT_CONFIG=false eslint src/**/*.ts",
18
- "lint:test": "ESLINT_USE_FLAT_CONFIG=false eslint __test__/**/*.ts",
16
+ "build": "tsup",
17
+ "lint": "biome check",
19
18
  "prepare": "husky",
20
19
  "serve:doc": "mdbook --serve --directory docs",
20
+ "test:local": "docker run --name mongodb-mongodbclient --rm -d -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=user -e MONGO_INITDB_ROOT_PASSWORD=password mongodb/mongodb-community-server:6.0.3-ubuntu2204 && npx vitest run && docker container stop mongodb-mongodbclient",
21
21
  "test": "vitest"
22
22
  },
23
23
  "lint-staged": {
24
24
  "docs/**/*.html": [
25
- "npm run format:document"
25
+ "npm run lint"
26
26
  ],
27
27
  "src/**/*.ts": [
28
- "npm run lint:src",
29
- "npm run format:src"
28
+ "npm run lint"
30
29
  ],
31
30
  "__test__/**/*.ts": [
32
- "npm run lint:test",
33
- "npm run format:test"
31
+ "npm run lint"
34
32
  ]
35
33
  },
36
34
  "keywords": [
@@ -43,25 +41,19 @@
43
41
  "url": "https://github.com/tomsdoo/mongodbclient"
44
42
  },
45
43
  "dependencies": {
46
- "mongodb": "6.6.2",
47
- "uuid": "9.0.1"
44
+ "mongodb": "6.11.0",
45
+ "uuid": "11.0.3"
48
46
  },
49
47
  "devDependencies": {
50
- "@tomsd/md-book": "1.2.0",
51
- "@types/node": "20.12.12",
52
- "@types/uuid": "9.0.8",
53
- "@typescript-eslint/eslint-plugin": "7.9.0",
48
+ "@biomejs/biome": "1.9.4",
49
+ "@tomsd/md-book": "1.3.3",
50
+ "@types/node": "22.9.3",
51
+ "@types/uuid": "10.0.0",
54
52
  "dotenv": "16.4.5",
55
- "eslint": "8.57.0",
56
- "eslint-config-prettier": "9.1.0",
57
- "eslint-plugin-import": "2.29.1",
58
- "eslint-plugin-n": "17.7.0",
59
- "eslint-plugin-promise": "6.1.1",
60
- "husky": "9.0.11",
61
- "lint-staged": "15.2.2",
62
- "prettier": "3.2.5",
63
- "tsup": "8.0.2",
64
- "typescript": "5.4.5",
65
- "vitest": "1.6.0"
53
+ "husky": "9.1.7",
54
+ "lint-staged": "15.2.10",
55
+ "tsup": "8.3.5",
56
+ "typescript": "5.7.2",
57
+ "vitest": "2.1.5"
66
58
  }
67
59
  }
@@ -1,187 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { v4 as uuidv4 } from "uuid";
11
- import { MongoClient, ServerApiVersion } from "mongodb";
12
- export class MongoConnection {
13
- constructor(client, db, collection) {
14
- this._client = client;
15
- this._db = db;
16
- this._collection = collection;
17
- }
18
- get client() {
19
- return this._client;
20
- }
21
- get db() {
22
- return this._db;
23
- }
24
- get collection() {
25
- return this._collection;
26
- }
27
- }
28
- export class MClient {
29
- constructor(uri, db, collection) {
30
- this.m_uri = uri;
31
- this.m_db = db;
32
- this.m_collection = collection;
33
- }
34
- get uri() {
35
- return this.m_uri;
36
- }
37
- get db() {
38
- return this.m_db;
39
- }
40
- get collection() {
41
- return this.m_collection;
42
- }
43
- connect() {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- return yield this.getConnected();
46
- });
47
- }
48
- getConnected() {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- const client = new MongoClient(this.m_uri, {
51
- serverApi: ServerApiVersion.v1,
52
- });
53
- return yield client.connect().then((client) => {
54
- const db = client.db(this.m_db);
55
- const collection = db.collection(this.m_collection);
56
- return new MongoConnection(client, db, collection);
57
- });
58
- });
59
- }
60
- upsert(pobj) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- const savingObj = Object.assign({ _id: uuidv4() }, pobj);
63
- const connection = yield this.getConnected();
64
- try {
65
- return yield connection.collection.updateOne({ _id: savingObj._id }, { $set: savingObj }, { upsert: true, writeConcern: { w: 1 } });
66
- }
67
- finally {
68
- yield connection.client.close();
69
- }
70
- });
71
- }
72
- read() {
73
- return __awaiter(this, arguments, void 0, function* (condition = {}, opt) {
74
- const connection = yield this.getConnected();
75
- try {
76
- return yield connection.collection
77
- .find(condition, opt)
78
- .toArray();
79
- }
80
- finally {
81
- yield connection.client.close();
82
- }
83
- });
84
- }
85
- distinct(key_1) {
86
- return __awaiter(this, arguments, void 0, function* (key, condition = {}) {
87
- const connection = yield this.getConnected();
88
- try {
89
- return (yield connection.collection.distinct(key, condition));
90
- }
91
- finally {
92
- yield connection.client.close();
93
- }
94
- });
95
- }
96
- remove(condition) {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- const connection = yield this.getConnected();
99
- try {
100
- return yield connection.collection.deleteMany(condition, {
101
- writeConcern: { w: 1 },
102
- });
103
- }
104
- finally {
105
- yield connection.client.close();
106
- }
107
- });
108
- }
109
- stats() {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- const connection = yield this.getConnected();
112
- try {
113
- const [collStats] = yield connection.collection
114
- .aggregate([
115
- {
116
- $collStats: {
117
- latencyStats: {
118
- histograms: true,
119
- },
120
- count: {},
121
- queryExecStats: {},
122
- storageStats: {
123
- scale: 1,
124
- },
125
- },
126
- },
127
- ])
128
- .toArray();
129
- return collStats;
130
- }
131
- catch (e) {
132
- return null;
133
- }
134
- finally {
135
- yield connection.client.close();
136
- }
137
- });
138
- }
139
- count() {
140
- return __awaiter(this, arguments, void 0, function* (condition = {}) {
141
- const connection = yield this.getConnected();
142
- try {
143
- return (yield connection.collection.countDocuments(condition));
144
- }
145
- finally {
146
- yield connection.client.close();
147
- }
148
- });
149
- }
150
- insertMany(items) {
151
- return __awaiter(this, void 0, void 0, function* () {
152
- const connection = yield this.getConnected();
153
- const savingItems = items.map((item) => (Object.assign({ _id: uuidv4() }, item)));
154
- try {
155
- return yield connection.collection.insertMany(savingItems, {
156
- writeConcern: { w: 1 },
157
- });
158
- }
159
- finally {
160
- yield connection.client.close();
161
- }
162
- });
163
- }
164
- dbStats() {
165
- return __awaiter(this, void 0, void 0, function* () {
166
- const connection = yield this.getConnected();
167
- try {
168
- return yield connection.db.stats();
169
- }
170
- finally {
171
- yield connection.client.close();
172
- }
173
- });
174
- }
175
- getCollections() {
176
- return __awaiter(this, void 0, void 0, function* () {
177
- const connection = yield this.getConnected();
178
- try {
179
- return yield connection.db.collections();
180
- }
181
- finally {
182
- yield connection.client.close();
183
- }
184
- });
185
- }
186
- }
187
- export default MClient;