Skip to content

Commit 3d3d481

Browse files
author
Perki
committed
2.4.6
1 parent 12b274d commit 3d3d481

File tree

7 files changed

+695
-343
lines changed

7 files changed

+695
-343
lines changed

components/pryv-monitor/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pryv/monitor",
3-
"version": "2.4.5",
3+
"version": "2.4.6",
44
"description": "Extends `pryv` with event-driven notifications for changes on a Pryv.io account",
55
"keywords": [
66
"Pryv",
@@ -19,5 +19,6 @@
1919
},
2020
"license": "BSD-3-Clause",
2121
"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"
2324
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+

components/pryv-socket.io/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pryv/socket.io",
3-
"version": "2.4.5",
3+
"version": "2.4.6",
44
"description": "Extends `pryv` with Socket.IO transport",
55
"keywords": [
66
"Pryv",
@@ -19,6 +19,7 @@
1919
"license": "BSD-3-Clause",
2020
"author": "Pryv S.A. <info@pryv.com> (https://pryv.com)",
2121
"main": "src/index.js",
22+
"types": "src/index.d.ts",
2223
"dependencies": {
2324
"socket.io-client": "^4.5.1"
2425
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import pryv from 'pryv';
2+
import { EventEmitter } from 'events';
3+
4+
/**
5+
* Extends a `pryv` instance with Socket.IO capabilities.
6+
*
7+
* Typical usage:
8+
* ```ts
9+
* import pryv from 'pryv';
10+
* import extendPryvSocketIO from '@pryv/socket.io';
11+
*
12+
* extendPryvSocketIO(pryv);
13+
*
14+
* const connection = new pryv.Connection('https://token@user.pryv.me');
15+
* await connection.socket.open();
16+
* connection.socket.on('eventsChanged', (changes) => {
17+
* // ...
18+
* });
19+
* ```
20+
*/
21+
export default function extendPryvSocketIO(pryvLib: typeof pryv): void;
22+
23+
declare module 'pryv' {
24+
/**
25+
* Socket.IO transport for a `Connection`.
26+
*
27+
* Use `connection.socket` to access the instance associated with a given
28+
* `Connection`.
29+
*/
30+
export class SocketIO extends EventEmitter {
31+
constructor(connection: Connection);
32+
33+
/**
34+
* Open the Socket.IO stream.
35+
* @throws Error on connection failures
36+
* @returns The same `SocketIO` instance once connected.
37+
*/
38+
open(): Promise<SocketIO>;
39+
40+
/**
41+
* Close the underlying socket connection.
42+
*/
43+
close(): void;
44+
45+
/**
46+
* Identical to `Connection.api()` but using the Socket.IO transport.
47+
*/
48+
api<Calls extends APICall[] = APICall[]>(
49+
apiCalls: Calls,
50+
progress?: APICallProgressHandler
51+
): Promise<Array<TypedAPICallResult>>;
52+
53+
/**
54+
* Listen to Socket.IO events emitted by the Pryv.io backend.
55+
*
56+
* Supported events:
57+
* - `eventsChanged`
58+
* - `streamsChanged`
59+
* - `accessesChanged`
60+
* - `disconnect`
61+
* - `error`
62+
*/
63+
on(
64+
eventName:
65+
| 'eventsChanged'
66+
| 'streamsChanged'
67+
| 'accessesChanged'
68+
| 'disconnect'
69+
| 'error',
70+
listener: (...args: any[]) => void
71+
): this;
72+
}
73+
74+
export class Connection {
75+
/**
76+
* Lazily created Socket.IO helper bound to this connection.
77+
*
78+
* Call `await connection.socket.open()` before using it.
79+
*/
80+
get socket(): SocketIO;
81+
}
82+
}
83+
84+

components/pryv/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pryv",
3-
"version": "2.4.5",
3+
"version": "2.4.6",
44
"description": "Pryv JavaScript library",
55
"keywords": [
66
"Pryv",

0 commit comments

Comments
 (0)