@tomsd/mongodbclient 2.1.1 → 2.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomsd/mongodbclient",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "",
5
5
  "main": "dist/cjs/mongodbclient.js",
6
6
  "module": "dist/esm/mongodbclient.js",
@@ -8,7 +8,7 @@
8
8
  "scripts": {
9
9
  "build": "tsc --project tsconfig.cjs.json && tsc --project tsconfig.esm.json",
10
10
  "test": "exit 0",
11
- "test_with_dburi": "mocha test/test.js --timeout 20000"
11
+ "test_with_dburi": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha -r ts-node/register \"test/test.ts\" --timeout 30000"
12
12
  },
13
13
  "keywords": [
14
14
  "mongodb"
@@ -20,9 +20,13 @@
20
20
  "mongodb": "^3.6.6"
21
21
  },
22
22
  "devDependencies": {
23
+ "@types/mocha": "^9.1.1",
23
24
  "@types/mongodb": "^3.5.31",
24
25
  "@types/node": "^14.14.5",
26
+ "@types/uuid": "^8.3.4",
25
27
  "mocha": "^7.0.1",
26
- "typescript": "^4.0.5"
28
+ "ts-node": "^10.8.1",
29
+ "typescript": "^4.0.5",
30
+ "uuid": "^8.3.2"
27
31
  }
28
32
  }
@@ -1,9 +1,11 @@
1
- const mongouri = "mongodb+srv://...";
2
- const dbName = `db${(new Date()).getTime().toString()}`;
3
- const collName = `col${(new Date()).getTime().toString()}`;
1
+ import {describe, it } from "mocha";
2
+ import { MClient } from "../src/mongodbclient";
3
+ import { strict as assert } from "assert";
4
+ import { v4 as uuidv4 } from "uuid";
4
5
 
5
- const assert = require("assert");
6
- const MClient = require("../dist/cjs/mongodbclient.js").MClient;
6
+ const mongouri = "mongodb+srv://...";
7
+ const dbName = uuidv4();
8
+ const collName = uuidv4();
7
9
 
8
10
  const mdbc = new MClient(mongouri, dbName, collName);
9
11
 
@@ -16,7 +18,7 @@ const items = [
16
18
 
17
19
  describe("MClient", () => {
18
20
  it("insertMany()", async () => {
19
- const { insertedCount } = await mdbc.insertMany(items)
21
+ const { insertedCount } = (await mdbc.insertMany(items)) as { insertedCount: number };
20
22
  assert.equal(insertedCount, items.length);
21
23
  });
22
24
 
@@ -26,23 +28,23 @@ describe("MClient", () => {
26
28
  });
27
29
 
28
30
  it("read()", async () => {
29
- const docs = await mdbc.read();
31
+ const docs = (await mdbc.read({})) as any[];
30
32
  assert.equal(docs.length, items.length);
31
33
  });
32
34
 
33
35
  it("upsert()", async () => {
34
- const docs = await mdbc.read();
35
- const { modifiedCount } = await mdbc.upsert({ _id: docs[0]._id, name: "david" });
36
+ const docs = (await mdbc.read({})) as any[];
37
+ const { modifiedCount } = (await mdbc.upsert({ _id: docs[0]._id, name: "david" })) as { modifiedCount: number };
36
38
  assert.equal(modifiedCount, 1);
37
39
  });
38
40
 
39
41
  it("distinct()", async () => {
40
- const names = await mdbc.distinct("name");
42
+ const names = (await mdbc.distinct("name", {})) as string[];
41
43
  assert.equal(names.length, 4);
42
44
  });
43
45
 
44
46
  it("stats()", async () => {
45
- const { storageSize } = await mdbc.stats();
47
+ const { storageSize } = (await mdbc.stats()) as { storageSize: number };
46
48
  assert(storageSize > 0);
47
49
  });
48
50
 
@@ -52,7 +54,7 @@ describe("MClient", () => {
52
54
  });
53
55
 
54
56
  it("remove()", async () => {
55
- const { deletedCount } = await mdbc.remove();
57
+ const { deletedCount } = (await mdbc.remove({})) as { deletedCount: number };
56
58
  assert.equal(deletedCount, items.length);
57
59
  });
58
60
  });