@tomsd/mongodbclient 2.7.9 → 2.8.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.
@@ -25,7 +25,7 @@ export declare class MClient {
25
25
  connect(): Promise<any>;
26
26
  protected getConnected(): Promise<any>;
27
27
  upsert(pobj: any): Promise<any>;
28
- read(condition?: any, opt?: any): Promise<any>;
28
+ read<T = any>(condition?: any, opt?: any): Promise<T[]>;
29
29
  distinct(key: string, condition?: any): Promise<any>;
30
30
  remove(condition: any): Promise<any>;
31
31
  stats(): Promise<any>;
@@ -25,7 +25,7 @@ export declare class MClient {
25
25
  connect(): Promise<any>;
26
26
  protected getConnected(): Promise<any>;
27
27
  upsert(pobj: any): Promise<any>;
28
- read(condition?: any, opt?: any): Promise<any>;
28
+ read<T = any>(condition?: any, opt?: any): Promise<T[]>;
29
29
  distinct(key: string, condition?: any): Promise<any>;
30
30
  remove(condition: any): Promise<any>;
31
31
  stats(): Promise<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomsd/mongodbclient",
3
- "version": "2.7.9",
3
+ "version": "2.8.0",
4
4
  "description": "",
5
5
  "main": "dist/cjs/mongodbclient.js",
6
6
  "module": "dist/esm/mongodbclient.js",
package/test/test.ts CHANGED
@@ -13,7 +13,9 @@ const collName = uuidv4();
13
13
 
14
14
  const mdbc = new MClient(mongouri, dbName, collName);
15
15
 
16
- const items = [
16
+ type Seed = { name: string; };
17
+
18
+ const items: Seed[] = [
17
19
  {name:"alice"},
18
20
  {name:"bob"},
19
21
  {name:"charlie"},
@@ -32,8 +34,10 @@ describe("MClient", () => {
32
34
  });
33
35
 
34
36
  it("read()", async () => {
35
- const docs = (await mdbc.read()) as any[];
36
- assert.equal(docs.length, items.length);
37
+ const docs = await mdbc.read<Seed & { _id: string; }>();
38
+ const getNames = (items: Seed[]) =>
39
+ Array.from(new Set(items.map(({ name }) => name))).sort().join("\n");
40
+ assert.equal(getNames(docs), getNames(docs));
37
41
  });
38
42
 
39
43
  it("upsert()", async () => {