@data-fair/lib-node 2.1.2 → 2.1.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/events-queue.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { internalError } from '@data-fair/lib-node/observer.js'
2
2
  import axios from './axios.js'
3
+ import Debug from 'debug'
4
+ const debug = Debug('events-queue')
3
5
  let _options
4
6
  const options = () => {
5
7
  if (!_options) { throw new Error('events queue was not initialized') }
@@ -26,11 +28,13 @@ const drain = async () => {
26
28
  if (eventsQueue.length) {
27
29
  const events = eventsQueue
28
30
  eventsQueue = []
31
+ debug('drain events', events.length)
29
32
  await axios.post(options().eventsUrl + '/api/events', events, { headers: { 'x-secret-key': options().eventsSecret } })
30
33
  }
31
34
  if (notificationsQueue.length) {
32
35
  const notifications = notificationsQueue
33
36
  notificationsQueue = []
37
+ debug('drain notifications', notifications.length)
34
38
  for (const notification of notifications) {
35
39
  await axios.post(options().eventsUrl + '/api/notifications', notification, { headers: { 'x-secret-key': options().eventsSecret } })
36
40
  }
@@ -46,12 +50,16 @@ export const stop = async () => {
46
50
  await drain()
47
51
  }
48
52
  export const pushEvent = (event) => {
53
+ options()
49
54
  if (stopped) { throw new Error('events queue has been stopped') }
50
55
  event.date = new Date().toISOString()
56
+ debug('pushEvent', event)
51
57
  eventsQueue.push(event)
52
58
  }
53
59
  export const pushNotification = (notification) => {
60
+ options()
54
61
  if (stopped) { throw new Error('notifications queue has been stopped') }
55
62
  notification.date = new Date().toISOString()
63
+ debug('pushNotification', notification)
56
64
  notificationsQueue.push(notification)
57
65
  }
package/mongo.js CHANGED
@@ -43,6 +43,11 @@ export class Mongo {
43
43
  */
44
44
  configure = async (indexDefinitions) => {
45
45
  for (const collectionName in indexDefinitions) {
46
+ try {
47
+ await this.db.createCollection(collectionName)
48
+ } catch (err) {
49
+ // nothing TODO
50
+ }
46
51
  for (const indexName in indexDefinitions[collectionName]) {
47
52
  let key, options
48
53
  const indexDefinition = indexDefinitions[collectionName][indexName]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-fair/lib-node",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "Small nodejs related utility functions for the data-fair stack.",
5
5
  "main": "index.js",
6
6
  "files": [