@leancodepl/rx-pipe-client 8.5.0 → 8.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/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # @leancodepl/rx-pipe-client
2
+
3
+ RxJS-based topic functions for real-time data subscriptions using @leancodepl/pipe.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @leancodepl/rx-pipe-client
9
+ # or
10
+ yarn add @leancodepl/rx-pipe-client
11
+ ```
12
+
13
+ ## API
14
+
15
+ ### `mkPipeClient(pipe)`
16
+
17
+ Creates topic functions for data subscriptions using @leancodepl/pipe.
18
+
19
+ **Parameters:**
20
+
21
+ - `pipe: Pipe` - Pipe instance from @leancodepl/pipe
22
+
23
+ **Returns:** Object containing `createTopic` method for creating typed observables
24
+
25
+ ## Usage Examples
26
+
27
+ ### Basic Setup
28
+
29
+ ```typescript
30
+ import { mkPipeClient } from "@leancodepl/rx-pipe-client"
31
+ import { createPipe } from "@leancodepl/pipe"
32
+
33
+ const pipe = createPipe({
34
+ url: "wss://api.example.com/pipe",
35
+ getAccessToken: () => localStorage.getItem("token"),
36
+ })
37
+
38
+ const pipeClient = mkPipeClient({ pipe })
39
+ ```
40
+
41
+ ### Chat Messages
42
+
43
+ ```typescript
44
+ import { mkPipeClient } from "@leancodepl/rx-pipe-client"
45
+ import { createPipe } from "@leancodepl/pipe"
46
+
47
+ interface ChatTopic {
48
+ roomId: string
49
+ }
50
+
51
+ interface ChatNotifications {
52
+ MessageReceived: {
53
+ id: string
54
+ content: string
55
+ authorId: string
56
+ }
57
+ }
58
+
59
+ const pipe = createPipe({
60
+ url: "wss://api.example.com/pipe",
61
+ getAccessToken: () => localStorage.getItem("token"),
62
+ })
63
+ const pipeClient = mkPipeClient({ pipe })
64
+ const chatTopic = pipeClient.createTopic<ChatTopic, ChatNotifications>("chat")
65
+
66
+ chatTopic({ roomId: "room1" }).subscribe(notification => {
67
+ if (notification.type === "MessageReceived") {
68
+ console.log(`New message: ${notification.data.content}`)
69
+ }
70
+ })
71
+ ```
72
+
73
+ ### Live Metrics with RxJS Operators
74
+
75
+ ```typescript
76
+ import { filter, map } from "rxjs/operators"
77
+ import { mkPipeClient } from "@leancodepl/rx-pipe-client"
78
+ import { createPipe } from "@leancodepl/pipe"
79
+
80
+ interface MetricsTopic {
81
+ dashboardId: string
82
+ }
83
+
84
+ interface MetricsNotifications {
85
+ CpuUpdate: { value: number }
86
+ MemoryUpdate: { value: number }
87
+ }
88
+
89
+ const pipe = createPipe({
90
+ url: "wss://api.example.com/pipe",
91
+ getAccessToken: () => localStorage.getItem("token"),
92
+ })
93
+ const pipeClient = mkPipeClient({ pipe })
94
+ const metricsTopic = pipeClient.createTopic<MetricsTopic, MetricsNotifications>("metrics")
95
+
96
+ const cpuUpdates$ = metricsTopic({ dashboardId: "main" }).pipe(
97
+ filter(notification => notification.type === "CpuUpdate"),
98
+ map(notification => notification.data.value),
99
+ )
100
+
101
+ cpuUpdates$.subscribe(value => {
102
+ console.log(`CPU: ${value}%`)
103
+ })
104
+ ```
@@ -0,0 +1 @@
1
+ exports._default = require('./index.cjs.js').default;
package/index.cjs.js ADDED
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Creates RxJS-based topic functions for real-time data subscriptions using "@leancodepl/pipe".
5
+ *
6
+ * @param pipe - Pipe instance from "@leancodepl/pipe"
7
+ * @returns Object containing `createTopic` method for creating typed observables
8
+ * @example
9
+ * ```typescript
10
+ * const pipe = createPipe({ url: 'wss://api.example.com/pipe' });
11
+ * const pipeClient = mkPipeClient({ pipe });
12
+ *
13
+ * const chatTopic = pipeClient.createTopic('chat');
14
+ * const messages$ = chatTopic({ roomId: 'room1' });
15
+ * ```
16
+ */ function mkPipeClient({ pipe }) {
17
+ return {
18
+ createTopic (topicType) {
19
+ return (topic)=>pipe.topic(topicType, topic);
20
+ }
21
+ };
22
+ }
23
+
24
+ exports.mkPipeClient = mkPipeClient;
package/index.cjs.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from './index.cjs.js';
2
+ export { _default as default } from './index.cjs.default.js';
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";
package/index.esm.js ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Creates RxJS-based topic functions for real-time data subscriptions using "@leancodepl/pipe".
3
+ *
4
+ * @param pipe - Pipe instance from "@leancodepl/pipe"
5
+ * @returns Object containing `createTopic` method for creating typed observables
6
+ * @example
7
+ * ```typescript
8
+ * const pipe = createPipe({ url: 'wss://api.example.com/pipe' });
9
+ * const pipeClient = mkPipeClient({ pipe });
10
+ *
11
+ * const chatTopic = pipeClient.createTopic('chat');
12
+ * const messages$ = chatTopic({ roomId: 'room1' });
13
+ * ```
14
+ */ function mkPipeClient({ pipe }) {
15
+ return {
16
+ createTopic (topicType) {
17
+ return (topic)=>pipe.topic(topicType, topic);
18
+ }
19
+ };
20
+ }
21
+
22
+ export { mkPipeClient };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leancodepl/rx-pipe-client",
3
- "version": "8.5.0",
3
+ "version": "8.6.0",
4
4
  "license": "Apache-2.0",
5
5
  "dependencies": {
6
6
  "@leancodepl/pipe": "^1.0.0"
@@ -37,11 +37,6 @@
37
37
  "name": "LeanCode",
38
38
  "url": "https://leancode.co"
39
39
  },
40
- "files": [
41
- "dist",
42
- "README.md",
43
- "CHANGELOG.md"
44
- ],
45
40
  "sideEffects": false,
46
41
  "exports": {
47
42
  "./package.json": "./package.json",
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./lib/mkPipeClient";
@@ -0,0 +1,20 @@
1
+ import { Pipe } from "@leancodepl/pipe";
2
+ /**
3
+ * Creates RxJS-based topic functions for real-time data subscriptions using "@leancodepl/pipe".
4
+ *
5
+ * @param pipe - Pipe instance from "@leancodepl/pipe"
6
+ * @returns Object containing `createTopic` method for creating typed observables
7
+ * @example
8
+ * ```typescript
9
+ * const pipe = createPipe({ url: 'wss://api.example.com/pipe' });
10
+ * const pipeClient = mkPipeClient({ pipe });
11
+ *
12
+ * const chatTopic = pipeClient.createTopic('chat');
13
+ * const messages$ = chatTopic({ roomId: 'room1' });
14
+ * ```
15
+ */
16
+ export declare function mkPipeClient({ pipe }: {
17
+ pipe: Pipe;
18
+ }): {
19
+ createTopic<TTopic, TNotifications extends Record<string, unknown>>(topicType: string): (topic: TTopic) => import("rxjs").Observable<import("@leancodepl/pipe").NotificationsUnion<TNotifications>>;
20
+ };