@pryv/socket.io 2.4.0 → 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.
Files changed (2) hide show
  1. package/package.json +2 -1
  2. package/src/index.d.ts +84 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pryv/socket.io",
3
- "version": "2.4.0",
3
+ "version": "2.4.6",
4
4
  "description": "Extends `pryv` with Socket.IO transport",
5
5
  "keywords": [
6
6
  "Pryv",
@@ -19,6 +19,7 @@
19
19
  "license": "BSD-3-Clause",
20
20
  "author": "Pryv S.A. <info@pryv.com> (https://pryv.com)",
21
21
  "main": "src/index.js",
22
+ "types": "src/index.d.ts",
22
23
  "dependencies": {
23
24
  "socket.io-client": "^4.5.1"
24
25
  }
package/src/index.d.ts ADDED
@@ -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
+