@pryv/monitor 2.4.5 → 2.4.6
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 +3 -2
- package/src/index.d.ts +156 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pryv/monitor",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.6",
|
|
4
4
|
"description": "Extends `pryv` with event-driven notifications for changes on a Pryv.io account",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Pryv",
|
|
@@ -19,5 +19,6 @@
|
|
|
19
19
|
},
|
|
20
20
|
"license": "BSD-3-Clause",
|
|
21
21
|
"author": "Pryv S.A. <info@pryv.com> (https://pryv.com)",
|
|
22
|
-
"main": "src/index.js"
|
|
22
|
+
"main": "src/index.js",
|
|
23
|
+
"types": "src/index.d.ts"
|
|
23
24
|
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import pryv from 'pryv';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Extends a `pryv` instance with monitoring capabilities.
|
|
6
|
+
*
|
|
7
|
+
* Typical usage:
|
|
8
|
+
* ```ts
|
|
9
|
+
* import pryv from 'pryv';
|
|
10
|
+
* import monitor from '@pryv/monitor';
|
|
11
|
+
*
|
|
12
|
+
* extendPryvMonitor(pryv);
|
|
13
|
+
*
|
|
14
|
+
* const monitor = new pryv.Monitor('https://token@user.pryv.me', {
|
|
15
|
+
* streams: ['data'],
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* monitor.on(pryv.Monitor.Changes.EVENT, (event) => {
|
|
19
|
+
* // handle new or changed event
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* await monitor.start();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export default function extendPryvMonitor(pryvLib: typeof pryv): typeof pryv.Monitor;
|
|
26
|
+
|
|
27
|
+
declare module 'pryv' {
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Event scope used by Monitor, based on events.get parameters.
|
|
31
|
+
*/
|
|
32
|
+
export type MonitorScope = {
|
|
33
|
+
fromTime?: number;
|
|
34
|
+
toTime?: number;
|
|
35
|
+
streams?: string[];
|
|
36
|
+
tags?: string[];
|
|
37
|
+
types?: string[];
|
|
38
|
+
running?: boolean;
|
|
39
|
+
sortAscending?: boolean;
|
|
40
|
+
state?: 'default' | 'trashed' | 'all';
|
|
41
|
+
includeDeletions?: boolean;
|
|
42
|
+
modifiedSince?: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Enum of change types emitted by Monitor.
|
|
47
|
+
*/
|
|
48
|
+
export const MonitorChanges: {
|
|
49
|
+
EVENT: 'event';
|
|
50
|
+
EVENT_DELETE: 'eventDelete';
|
|
51
|
+
STREAMS: 'streams';
|
|
52
|
+
ERROR: 'error';
|
|
53
|
+
READY: 'ready';
|
|
54
|
+
STOP: 'stop';
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Monitor changes on a Pryv.io account.
|
|
59
|
+
*/
|
|
60
|
+
export class Monitor extends EventEmitter {
|
|
61
|
+
constructor(apiEndpointOrConnection: APIEndpoint | Connection, eventsGetScope?: MonitorScope);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Start the monitor and perform initial sync.
|
|
65
|
+
* Resolves with the same monitor instance.
|
|
66
|
+
*/
|
|
67
|
+
start(): Promise<Monitor>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Request an events update according to the current scope.
|
|
71
|
+
*/
|
|
72
|
+
updateEvents(): Promise<Monitor>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Request a streams update.
|
|
76
|
+
*/
|
|
77
|
+
updateStreams(): Promise<Monitor>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Stop monitoring. No further events will be emitted.
|
|
81
|
+
*/
|
|
82
|
+
stop(): Monitor;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* True when the monitor has been started and not yet stopped.
|
|
86
|
+
*/
|
|
87
|
+
readonly started: boolean;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Current events.get scope used by the monitor.
|
|
91
|
+
*/
|
|
92
|
+
eventsGetScope: MonitorScope;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Attach an auto-update method implementation.
|
|
96
|
+
*/
|
|
97
|
+
addUpdateMethod(updateMethod: MonitorUpdateMethod): Monitor;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Listen to monitor-level changes.
|
|
101
|
+
*
|
|
102
|
+
* Events:
|
|
103
|
+
* - `event` – new or updated event
|
|
104
|
+
* - `eventDelete` – deleted event
|
|
105
|
+
* - `streams` – updated streams list
|
|
106
|
+
* - `error` – error object
|
|
107
|
+
* - `ready` – monitor is ready for next update
|
|
108
|
+
* - `stop` – monitor has been stopped
|
|
109
|
+
*/
|
|
110
|
+
on(event: 'event', listener: (event: Event) => void): this;
|
|
111
|
+
on(event: 'eventDelete', listener: (event: Event) => void): this;
|
|
112
|
+
on(event: 'streams', listener: (streams: Stream[]) => void): this;
|
|
113
|
+
on(event: 'error', listener: (error: any) => void): this;
|
|
114
|
+
on(event: 'ready', listener: () => void): this;
|
|
115
|
+
on(event: 'stop', listener: () => void): this;
|
|
116
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Static access to available update methods.
|
|
120
|
+
*/
|
|
121
|
+
static UpdateMethod: {
|
|
122
|
+
Null: typeof MonitorUpdateMethod;
|
|
123
|
+
Socket: typeof SocketUpdateMethod;
|
|
124
|
+
EventsTimer: typeof EventsTimerUpdateMethod;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Static enum of change names.
|
|
129
|
+
*/
|
|
130
|
+
static Changes: typeof MonitorChanges;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Base interface for update methods used by Monitor.
|
|
135
|
+
*/
|
|
136
|
+
export class MonitorUpdateMethod {
|
|
137
|
+
protected monitor?: Monitor;
|
|
138
|
+
setMonitor(monitor: Monitor): void;
|
|
139
|
+
ready(): Promise<void>;
|
|
140
|
+
stop(): Promise<void>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Update method that polls for event changes at a fixed interval.
|
|
145
|
+
*/
|
|
146
|
+
export class EventsTimerUpdateMethod extends MonitorUpdateMethod {
|
|
147
|
+
constructor(updateRateMS: number);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Update method that uses @pryv/socket.io events.
|
|
152
|
+
*/
|
|
153
|
+
export class SocketUpdateMethod extends MonitorUpdateMethod {}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
|