@data-fair/lib-node 2.5.0 → 2.5.1

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/mongo.d.ts CHANGED
@@ -1,11 +1,12 @@
1
- import type { IndexSpecification, CreateIndexesOptions, MongoClientOptions, IndexDirection } from 'mongodb';
1
+ import type { IndexSpecification, CreateIndexesOptions, MongoClientOptions, IndexDirection, Db } from 'mongodb';
2
2
  import { MongoClient } from 'mongodb';
3
3
  type IndexDirections = Record<string, IndexDirection>;
4
4
  export type IndexDefinitions = Record<string, Record<string, null | IndexDirections | [IndexDirections, CreateIndexesOptions]>>;
5
5
  export declare class Mongo {
6
6
  private _client;
7
+ private _db;
7
8
  get client(): MongoClient;
8
- get db(): import("mongodb").Db;
9
+ get db(): Db;
9
10
  connect: (mongoUrl: string, options?: MongoClientOptions) => Promise<void>;
10
11
  ensureIndex: (collection: string, key: IndexSpecification, options?: CreateIndexesOptions) => Promise<void>;
11
12
  /**
package/mongo.js CHANGED
@@ -1,13 +1,15 @@
1
1
  import { MongoClient, MongoError } from 'mongodb'
2
2
  export class Mongo {
3
3
  _client
4
+ _db
4
5
  get client () {
5
6
  if (!this._client) { throw new Error('db was not connected') }
6
7
  return this._client
7
8
  }
8
9
 
9
10
  get db () {
10
- return this.client.db()
11
+ if (!this._db) { throw new Error('db was not connected') }
12
+ return this._db
11
13
  }
12
14
 
13
15
  connect = async (mongoUrl, options = {}) => {
@@ -17,6 +19,7 @@ export class Mongo {
17
19
  }
18
20
  console.log('connecting to mongodb...')
19
21
  this._client = await MongoClient.connect(mongoUrl, { maxPoolSize: 5, ignoreUndefined: true, ...options })
22
+ this._db = this._client.db()
20
23
  console.log('...ok')
21
24
  }
22
25
 
package/observer.js CHANGED
@@ -93,8 +93,8 @@ export const startObserver = async (port = 9090) => {
93
93
  GET /metrics -> get prometheus metrics for this instance
94
94
  GET /service-metrics -> get prometheus metrics shared accross all instances
95
95
  GET /cpu-profile -> generate and fetch a CPU profile
96
- GET /heap-snapshot -> generate and fetch a sampled heap allocation snapshot
97
- GET /heap-snapshot-all -> generate and fetch a sampled heap allocation snapshot including objects collected by GC
96
+ GET /heap-profile -> generate and fetch a sampled heap allocation snapshot
97
+ GET /heap-profile-all -> generate and fetch a sampled heap allocation snapshot including objects collected by GC
98
98
  `)
99
99
  }
100
100
  export const stopObserver = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-fair/lib-node",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "Small nodejs related utility functions for the data-fair stack.",
5
5
  "main": "index.js",
6
6
  "files": [