@leancodepl/hook-pipe-client 8.4.0 → 8.5.1

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,124 @@
1
+ # @leancodepl/hook-pipe-client
2
+
3
+ React hooks for real-time data subscriptions using @leancodepl/pipe.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @leancodepl/hook-pipe-client
9
+ # or
10
+ yarn add @leancodepl/hook-pipe-client
11
+ ```
12
+
13
+ ## API
14
+
15
+ ### `mkPipeClient(pipe)`
16
+
17
+ Creates React hooks for real-time 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 hooks
24
+
25
+ ## Usage Examples
26
+
27
+ ### Basic Setup
28
+
29
+ ```typescript
30
+ import { mkPipeClient } from "@leancodepl/hook-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 React, { useState } from 'react';
45
+
46
+ interface ChatTopic {
47
+ roomId: string;
48
+ }
49
+
50
+ interface ChatNotifications {
51
+ MessageReceived: {
52
+ id: string;
53
+ content: string;
54
+ authorId: string;
55
+ };
56
+ }
57
+
58
+ const useChatTopic = pipeClient.createTopic<ChatTopic, ChatNotifications>('chat');
59
+
60
+ function ChatRoom({ roomId }: { roomId: string }) {
61
+ const [messages, setMessages] = useState<string[]>([]);
62
+
63
+ const { data } = useChatTopic(
64
+ { roomId },
65
+ {
66
+ onData: (notification) => {
67
+ if (notification.type === 'MessageReceived') {
68
+ setMessages(prev => [...prev, notification.data.content]);
69
+ }
70
+ },
71
+ }
72
+ );
73
+
74
+ return (
75
+ <div>
76
+ {messages.map((message, index) => (
77
+ <div key={index}>{message}</div>
78
+ ))}
79
+ </div>
80
+ );
81
+ }
82
+ ```
83
+
84
+ ### Live Metrics
85
+
86
+ ```typescript
87
+ import React, { useState } from 'react';
88
+
89
+ interface MetricsTopic {
90
+ dashboardId: string;
91
+ }
92
+
93
+ interface MetricsNotifications {
94
+ CpuUpdate: { value: number };
95
+ MemoryUpdate: { value: number };
96
+ }
97
+
98
+ const useMetricsTopic = pipeClient.createTopic<MetricsTopic, MetricsNotifications>('metrics');
99
+
100
+ function Dashboard() {
101
+ const [cpu, setCpu] = useState(0);
102
+ const [memory, setMemory] = useState(0);
103
+
104
+ useMetricsTopic(
105
+ { dashboardId: 'main' },
106
+ {
107
+ onData: (notification) => {
108
+ if (notification.type === 'CpuUpdate') {
109
+ setCpu(notification.data.value);
110
+ } else if (notification.type === 'MemoryUpdate') {
111
+ setMemory(notification.data.value);
112
+ }
113
+ },
114
+ }
115
+ );
116
+
117
+ return (
118
+ <div>
119
+ <div>CPU: {cpu}%</div>
120
+ <div>Memory: {memory}%</div>
121
+ </div>
122
+ );
123
+ }
124
+ ```
package/index.cjs.js CHANGED
@@ -4,7 +4,19 @@ var react = require('react');
4
4
  var deepEqual = require('deep-equal');
5
5
  var rxjs = require('rxjs');
6
6
 
7
- function mkPipeClient({ pipe }) {
7
+ /**
8
+ * Creates React hooks for real-time data subscriptions using "@leancodepl/pipe".
9
+ *
10
+ * @param pipe - Pipe instance from "@leancodepl/pipe"
11
+ * @returns Object containing `createTopic` method for creating typed hooks
12
+ * @example
13
+ * ```typescript
14
+ * const pipe = createPipe({ url: 'wss://api.example.com/pipe' });
15
+ * const pipeClient = mkPipeClient({ pipe });
16
+ *
17
+ * const useChatTopic = pipeClient.createTopic('chat');
18
+ * ```
19
+ */ function mkPipeClient({ pipe }) {
8
20
  return {
9
21
  createTopic (topicType) {
10
22
  function useTopic(topic, { onData }) {
package/index.esm.js CHANGED
@@ -2,7 +2,19 @@ import { useState, useRef, useEffect } from 'react';
2
2
  import deepEqual from 'deep-equal';
3
3
  import { share } from 'rxjs';
4
4
 
5
- function mkPipeClient({ pipe }) {
5
+ /**
6
+ * Creates React hooks for real-time data subscriptions using "@leancodepl/pipe".
7
+ *
8
+ * @param pipe - Pipe instance from "@leancodepl/pipe"
9
+ * @returns Object containing `createTopic` method for creating typed hooks
10
+ * @example
11
+ * ```typescript
12
+ * const pipe = createPipe({ url: 'wss://api.example.com/pipe' });
13
+ * const pipeClient = mkPipeClient({ pipe });
14
+ *
15
+ * const useChatTopic = pipeClient.createTopic('chat');
16
+ * ```
17
+ */ function mkPipeClient({ pipe }) {
6
18
  return {
7
19
  createTopic (topicType) {
8
20
  function useTopic(topic, { onData }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leancodepl/hook-pipe-client",
3
- "version": "8.4.0",
3
+ "version": "8.5.1",
4
4
  "license": "Apache-2.0",
5
5
  "dependencies": {
6
6
  "@leancodepl/pipe": "^1.0.0",
@@ -10,16 +10,50 @@
10
10
  "react": "*",
11
11
  "rxjs": ">=7.0.0"
12
12
  },
13
+ "publishConfig": {
14
+ "access": "public",
15
+ "registry": "https://registry.npmjs.org/"
16
+ },
17
+ "engines": {
18
+ "node": ">=18.0.0"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/leancodepl/js_corelibrary.git",
23
+ "directory": "packages/pipe-clients/hook-pipe-client"
24
+ },
25
+ "homepage": "https://github.com/leancodepl/js_corelibrary",
26
+ "bugs": {
27
+ "url": "https://github.com/leancodepl/js_corelibrary/issues"
28
+ },
29
+ "description": "React hooks for real-time data streaming and subscriptions using @leancodepl/pipe",
30
+ "keywords": [
31
+ "react",
32
+ "hooks",
33
+ "real-time",
34
+ "streaming",
35
+ "websocket",
36
+ "signalr",
37
+ "leanpipe",
38
+ "typescript",
39
+ "javascript",
40
+ "leancode"
41
+ ],
42
+ "author": {
43
+ "name": "LeanCode",
44
+ "url": "https://leancode.co"
45
+ },
46
+ "sideEffects": false,
13
47
  "exports": {
14
48
  "./package.json": "./package.json",
15
49
  ".": {
16
50
  "module": "./index.esm.js",
17
- "types": "./index.esm.d.ts",
51
+ "types": "./index.d.ts",
18
52
  "import": "./index.cjs.mjs",
19
53
  "default": "./index.cjs.js"
20
54
  }
21
55
  },
22
56
  "module": "./index.esm.js",
23
57
  "main": "./index.cjs.js",
24
- "types": "./index.esm.d.ts"
58
+ "types": "./index.d.ts"
25
59
  }
@@ -1,4 +1,17 @@
1
1
  import { NotificationsUnion, Pipe } from "@leancodepl/pipe";
2
+ /**
3
+ * Creates React hooks 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 hooks
7
+ * @example
8
+ * ```typescript
9
+ * const pipe = createPipe({ url: 'wss://api.example.com/pipe' });
10
+ * const pipeClient = mkPipeClient({ pipe });
11
+ *
12
+ * const useChatTopic = pipeClient.createTopic('chat');
13
+ * ```
14
+ */
2
15
  export declare function mkPipeClient({ pipe }: {
3
16
  pipe: Pipe;
4
17
  }): {
package/index.esm.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";
File without changes