You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(types): enhance type safety and fix linting issues
- Improve TypeScript type definitions with jest.MockedFunction
- Replace any[] with unknown[] for better type safety
- Fix unused variable warnings in test files
- Update documentation with latest changes
- Bump version to 0.2.4
Changes:
- Use proper jest.MockedFunction types in test files
- Remove unused socket variables from destructuring
- Add underscore prefix to unused parameters
- Update README with latest features and examples
- Fix ESLint warnings across the codebase
The client-side WebSocket handler with automatic reconnection and message queueing.
94
+
// Nostr Filter Type
95
+
interfaceNostrWSFilter {
96
+
ids?:string[];
97
+
authors?:string[];
98
+
kinds?:number[];
99
+
'#e'?:string[];
100
+
'#p'?:string[];
101
+
since?:number;
102
+
until?:number;
103
+
limit?:number;
104
+
}
142
105
143
-
```typescript
144
-
classNostrWSClient {
145
-
constructor(url:string, options:NostrWSOptions);
146
-
147
-
// Connect to the server
148
-
connect():void;
149
-
150
-
// Subscribe to a channel
151
-
subscribe(channel:string, filter?:unknown):void;
152
-
153
-
// Unsubscribe from a channel
154
-
unsubscribe(channel:string):void;
155
-
156
-
// Send a message to the server
157
-
send(message:NostrWSMessage):Promise<void>;
158
-
159
-
// Close the connection
160
-
close():void;
106
+
// Message Types
107
+
enumNostrWSMessageType {
108
+
EVENT='EVENT',
109
+
REQ='REQ',
110
+
CLOSE='CLOSE',
111
+
NOTICE='NOTICE',
112
+
AUTH='AUTH',
113
+
EOSE='EOSE'
161
114
}
162
115
```
163
116
164
-
### NostrWSMessage
117
+
##Advanced Configuration
165
118
166
-
The standard message format for communication.
119
+
### Server Options
167
120
168
121
```typescript
169
-
interfaceNostrWSMessage {
170
-
id?:string; // Auto-generated UUID if not provided
171
-
type:string; // Message type (e.g., 'subscribe', 'event')
172
-
data: {
173
-
channel?:string; // Target channel for subscription/broadcast
174
-
[key:string]:any; // Additional message data
122
+
interfaceNostrWSServerOptions {
123
+
port:number;
124
+
heartbeatInterval?:number;
125
+
maxPayloadSize?:number;
126
+
cors?: {
127
+
origin?:string|string[];
128
+
methods?:string[];
129
+
};
130
+
handlers: {
131
+
message:MessageHandler;
132
+
error?:ErrorHandler;
133
+
close?:CloseHandler;
175
134
};
176
135
}
177
136
```
178
137
179
-
## Why Choose This Library
180
-
181
-
### 1. Nostr-Optimized
182
-
- Built specifically for Nostr protocol requirements
183
-
- Efficient pub/sub model with filtered subscriptions
184
-
- Type-safe message handling for all Nostr events
185
-
186
-
### 2. Production-Ready
187
-
- Comprehensive error handling and recovery
188
-
- Memory-efficient subscription management
189
-
- Built-in logging and monitoring
190
-
- Extensive test coverage
191
-
192
-
### 3. Developer-Friendly
193
-
- Clear TypeScript definitions
194
-
- Flexible configuration options
195
-
- Detailed documentation
196
-
- Active maintenance
197
-
198
138
## Contributing
199
139
200
-
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
140
+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
201
141
202
142
## License
203
143
204
-
MIT License - see the [LICENSE](LICENSE) file for details.
144
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Copy file name to clipboardExpand all lines: package.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"name": "nostr-websocket-utils",
3
-
"version": "0.2.3",
3
+
"version": "0.2.4",
4
4
"description": "Robust WebSocket utilities for Nostr applications with automatic reconnection, channel-based messaging, and type-safe handlers. Features heartbeat monitoring, message queueing, and comprehensive error handling.",
0 commit comments