@data-fair/lib-node 2.5.0 → 2.6.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/events-queue.d.ts +2 -1
- package/events-queue.js +14 -1
- package/mongo.d.ts +3 -2
- package/mongo.js +4 -1
- package/observer.js +2 -2
- package/package.json +1 -1
package/events-queue.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Event } from '@data-fair/lib-common-types/event/index.js';
|
|
2
2
|
import { type Notification } from '@data-fair/lib-common-types/notification/index.js';
|
|
3
|
+
import { SessionState } from '@data-fair/lib-common-types/session/index.js';
|
|
3
4
|
type EventsQueueOptions = {
|
|
4
5
|
eventsUrl: string;
|
|
5
6
|
eventsSecret: string;
|
|
@@ -15,7 +16,7 @@ export declare class EventsQueue {
|
|
|
15
16
|
stop: () => Promise<void>;
|
|
16
17
|
loop(): Promise<void>;
|
|
17
18
|
drain(): Promise<void>;
|
|
18
|
-
pushEvent(event: Omit<Event, 'date'
|
|
19
|
+
pushEvent(event: Omit<Event, 'date'>, sessionState?: SessionState): void;
|
|
19
20
|
pushNotification(notification: Omit<Notification, 'date'>): void;
|
|
20
21
|
}
|
|
21
22
|
declare const eventsQueue: EventsQueue;
|
package/events-queue.js
CHANGED
|
@@ -65,11 +65,24 @@ export class EventsQueue {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
pushEvent (event) {
|
|
68
|
+
pushEvent (event, sessionState) {
|
|
69
69
|
this.options()
|
|
70
70
|
if (this.stopped) { throw new Error('events queue has been stopped') }
|
|
71
71
|
event.date = new Date().toISOString()
|
|
72
72
|
debug('pushEvent', event)
|
|
73
|
+
if (sessionState && sessionState.user) {
|
|
74
|
+
event.originator = {
|
|
75
|
+
user: { id: sessionState.user.id, name: sessionState.user.name }
|
|
76
|
+
}
|
|
77
|
+
if (sessionState.organization) {
|
|
78
|
+
event.originator.organization = {
|
|
79
|
+
id: sessionState.organization.id,
|
|
80
|
+
name: sessionState.organization.name,
|
|
81
|
+
department: sessionState.organization.department,
|
|
82
|
+
departmentName: sessionState.organization.departmentName
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
73
86
|
this.eventsQueue.push(event)
|
|
74
87
|
}
|
|
75
88
|
|
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():
|
|
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
|
-
|
|
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-
|
|
97
|
-
GET /heap-
|
|
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 () => {
|