jolt-js-api 1.0.0 → 1.1.8
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/.github/workflows/npm-publish.yml +30 -0
- package/README.md +61 -103
- package/package.json +17 -18
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Publish to NPM
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [created]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: actions/setup-node@v4
|
|
14
|
+
with:
|
|
15
|
+
node-version: 20
|
|
16
|
+
- run: npm instal
|
|
17
|
+
|
|
18
|
+
publish-npm:
|
|
19
|
+
needs: build
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v4
|
|
23
|
+
- uses: actions/setup-node@v4
|
|
24
|
+
with:
|
|
25
|
+
node-version: 20
|
|
26
|
+
registry-url: https://registry.npmjs.org/
|
|
27
|
+
- run: npm install
|
|
28
|
+
- run: npm publish
|
|
29
|
+
env:
|
|
30
|
+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# Jolt JavaScript API
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/jolt-js-api)
|
|
4
|
+
[](https://www.npmjs.com/package/jolt-js-api)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
This repository is a JavaScript and Node.js client. This package provides direct access to the Jolt protocol, offering a lightweight, dependency-free interface for building real-time distributed applications, internal services, and event-driven systems.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
✅ TypeScript definitions included
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
The Jolt JavaScript API communicates with our Jolt broker using its native TCP protocol and newline-delimited JSON messaging format. The client exposes a Node.js EventEmitter interface and supports both callback-based and Promise-based usage.
|
|
11
|
+
|
|
12
|
+
This module intentionally relies only on Node.js core libraries to ensure low overhead, portability, and minimal setup requirements. TypeScript definitions are included for typed development environments.
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
@@ -17,50 +17,43 @@ A JavaScript & Node.js client for the [Jolt](https://github.com/Jolt-Database/Jo
|
|
|
17
17
|
npm install jolt-js-api
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
Installation from source:
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
|
-
git clone https://github.com/
|
|
23
|
+
git clone https://github.com/Jolt-Database/jolt-js-api.git
|
|
24
24
|
cd jolt-js-api
|
|
25
25
|
npm install
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
##
|
|
28
|
+
## Usage Example
|
|
29
29
|
|
|
30
30
|
```javascript
|
|
31
31
|
const JoltClient = require('jolt-js-api');
|
|
32
32
|
|
|
33
|
-
// Create client
|
|
34
33
|
const client = new JoltClient({
|
|
35
34
|
host: '127.0.0.1',
|
|
36
35
|
port: 8080
|
|
37
36
|
});
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
client.on('connected', () => console.log('Connected'));
|
|
41
|
-
client.on('ok', () => console.log('✓ OK'));
|
|
42
|
-
client.on('error', (error) => console.log('✗ Error:', error));
|
|
38
|
+
client.on('connected', () => console.log('Connected to broker'));
|
|
43
39
|
client.on('message', (topic, data) => console.log(`[${topic}] ${data}`));
|
|
44
|
-
client.on('
|
|
40
|
+
client.on('error', (error) => console.error('Error:', error));
|
|
45
41
|
|
|
46
|
-
// Connect and use
|
|
47
42
|
async function main() {
|
|
48
43
|
await client.connect();
|
|
49
|
-
|
|
44
|
+
|
|
50
45
|
client.subscribe('chat.general');
|
|
51
46
|
client.publish('chat.general', 'Hello, Jolt!');
|
|
52
47
|
client.ping();
|
|
53
|
-
|
|
54
|
-
// Keep running...
|
|
48
|
+
|
|
55
49
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
56
|
-
|
|
57
50
|
client.close();
|
|
58
51
|
}
|
|
59
52
|
|
|
60
53
|
main();
|
|
61
54
|
```
|
|
62
55
|
|
|
63
|
-
## API
|
|
56
|
+
## API Summary
|
|
64
57
|
|
|
65
58
|
### Constructor
|
|
66
59
|
|
|
@@ -68,134 +61,99 @@ main();
|
|
|
68
61
|
const client = new JoltClient(config);
|
|
69
62
|
```
|
|
70
63
|
|
|
71
|
-
|
|
72
|
-
- `host` (string): Broker host (default: '127.0.0.1')
|
|
73
|
-
- `port` (number): Broker port (default: 8080)
|
|
64
|
+
Configuration options:
|
|
74
65
|
|
|
75
|
-
|
|
66
|
+
* **host**: Broker hostname (default: `127.0.0.1`)
|
|
67
|
+
* **port**: Broker port (default: `8080`)
|
|
76
68
|
|
|
77
|
-
|
|
78
|
-
- `connect()` → Promise<void> - Connect to broker
|
|
79
|
-
- `close()` → void - Close connection
|
|
80
|
-
- `isConnected()` → boolean - Check connection status
|
|
69
|
+
### Connection Methods
|
|
81
70
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
- `unsubscribe(topic)` → void - Unsubscribe from topic
|
|
86
|
-
- `publish(topic, data)` → void - Publish message
|
|
87
|
-
- `ping()` → void - Send ping
|
|
71
|
+
* **connect()** – Establishes a connection to the broker.
|
|
72
|
+
* **close()** – Closes the client connection.
|
|
73
|
+
* **isConnected()** – Returns connection state.
|
|
88
74
|
|
|
89
|
-
###
|
|
75
|
+
### Messaging Methods
|
|
90
76
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
client.on('disconnected', () => {})
|
|
97
|
-
client.on('socketError', (err) => {})
|
|
98
|
-
client.on('parseError', (err, line) => {})
|
|
99
|
-
client.on('unknown', (data, line) => {})
|
|
100
|
-
```
|
|
77
|
+
* **auth(username, password)** – Performs broker authentication.
|
|
78
|
+
* **subscribe(topic)** – Subscribes to a topic.
|
|
79
|
+
* **unsubscribe(topic)** – Removes an existing subscription.
|
|
80
|
+
* **publish(topic, data)** – Publishes a message to a topic.
|
|
81
|
+
* **ping()** – Issues a protocol-level health check.
|
|
101
82
|
|
|
102
|
-
|
|
83
|
+
### Event Interface
|
|
103
84
|
|
|
104
|
-
|
|
85
|
+
* **connected**
|
|
86
|
+
* **ok**
|
|
87
|
+
* **error**
|
|
88
|
+
* **message**
|
|
89
|
+
* **disconnected**
|
|
90
|
+
* **socketError**
|
|
91
|
+
* **parseError**
|
|
92
|
+
* **unknown**
|
|
105
93
|
|
|
106
|
-
|
|
107
|
-
const JoltClient = require('jolt-js-api');
|
|
94
|
+
These events provide full visibility into the broker communication, parsing results, socket behavior, and message routing.
|
|
108
95
|
|
|
109
|
-
|
|
96
|
+
## Additional Examples
|
|
110
97
|
|
|
111
|
-
|
|
112
|
-
console.log(`[${topic}] ${data}`);
|
|
113
|
-
});
|
|
98
|
+
### Simple Pub/Sub
|
|
114
99
|
|
|
100
|
+
```javascript
|
|
115
101
|
await client.connect();
|
|
116
102
|
client.subscribe('chat.room1');
|
|
117
|
-
client.publish('chat.room1', 'Hello
|
|
103
|
+
client.publish('chat.room1', 'Hello');
|
|
118
104
|
```
|
|
119
105
|
|
|
120
106
|
### Multiple Topics
|
|
121
107
|
|
|
122
108
|
```javascript
|
|
123
|
-
|
|
109
|
+
['news', 'sports', 'weather']
|
|
110
|
+
.forEach(t => client.subscribe(t));
|
|
124
111
|
|
|
125
|
-
|
|
126
|
-
topics.forEach(topic => client.subscribe(topic));
|
|
127
|
-
|
|
128
|
-
// Publish to each
|
|
129
|
-
client.publish('news', 'Breaking news!');
|
|
130
|
-
client.publish('sports', 'Score: 3-2');
|
|
131
|
-
client.publish('weather', 'Sunny, 25°C');
|
|
112
|
+
client.publish('news', 'Latest headline');
|
|
132
113
|
```
|
|
133
114
|
|
|
134
|
-
### Promise-Based
|
|
115
|
+
### Promise-Based Wrapper Usage
|
|
135
116
|
|
|
136
117
|
```javascript
|
|
137
|
-
const JoltClientWrapper = require('./examples/advanced-usage');
|
|
138
|
-
|
|
139
|
-
const client = new JoltClientWrapper({ host: '127.0.0.1', port: 8080 });
|
|
140
|
-
|
|
141
118
|
await client.connect();
|
|
142
119
|
await client.subscribeAsync('chat.general');
|
|
143
|
-
await client.publishAsync('chat.general', 'Hello
|
|
120
|
+
await client.publishAsync('chat.general', 'Hello');
|
|
144
121
|
```
|
|
145
122
|
|
|
146
|
-
### Error Handling
|
|
123
|
+
### Error Handling Pattern
|
|
147
124
|
|
|
148
125
|
```javascript
|
|
149
|
-
client.on('error', (
|
|
150
|
-
|
|
151
|
-
console.error('Authentication failed!');
|
|
152
|
-
} else if (error.includes('unknown_topic')) {
|
|
153
|
-
console.error('Topic does not exist!');
|
|
154
|
-
} else {
|
|
155
|
-
console.error('Error:', error);
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
client.on('socketError', (err) => {
|
|
160
|
-
console.error('Socket error:', err);
|
|
161
|
-
// Implement reconnection logic
|
|
126
|
+
client.on('error', (err) => {
|
|
127
|
+
console.error(err);
|
|
162
128
|
});
|
|
163
129
|
```
|
|
164
130
|
|
|
165
131
|
## Testing
|
|
166
132
|
|
|
167
133
|
```bash
|
|
168
|
-
# Run tests (broker must be running)
|
|
169
134
|
npm test
|
|
170
|
-
|
|
171
|
-
# Watch mode
|
|
172
135
|
npm run test:watch
|
|
173
|
-
|
|
174
|
-
# Run examples
|
|
175
136
|
npm run example
|
|
176
137
|
npm run example:advanced
|
|
177
138
|
```
|
|
178
139
|
|
|
179
|
-
|
|
140
|
+
A running Jolt broker instance is required for full test execution.
|
|
141
|
+
|
|
142
|
+
## Protocol Notes
|
|
143
|
+
|
|
144
|
+
Communication uses newline-delimited JSON over TCP.
|
|
180
145
|
|
|
181
|
-
|
|
146
|
+
Example request frames:
|
|
182
147
|
|
|
183
|
-
### Commands
|
|
184
148
|
```json
|
|
185
149
|
{"op": "auth", "user": "username", "pass": "password"}
|
|
186
|
-
{"op": "sub", "topic": "channel"}
|
|
187
|
-
{"op": "unsub", "topic": "channel"}
|
|
188
150
|
{"op": "pub", "topic": "channel", "data": "message"}
|
|
189
|
-
{"op": "
|
|
151
|
+
{"op": "sub", "topic": "channel"}
|
|
190
152
|
```
|
|
191
153
|
|
|
192
|
-
|
|
154
|
+
Example response frames:
|
|
155
|
+
|
|
193
156
|
```json
|
|
194
157
|
{"ok": true}
|
|
195
|
-
{"ok": false, "error": "error_message"}
|
|
196
158
|
{"topic": "channel", "data": "message"}
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
## License
|
|
200
|
-
|
|
201
|
-
MIT License - see LICENSE file for details
|
|
159
|
+
```
|
package/package.json
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jolt-js-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "JavaScript & Node.js client for the Jolt in-memory messaging broker",
|
|
5
5
|
"main": "src/JoltClient.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"example": "node examples/simple-chat.js",
|
|
10
|
-
"example:advanced": "node examples/advanced-usage.js"
|
|
7
|
+
"example": "node examples/simple-chat.js",
|
|
8
|
+
"example:advanced": "node examples/advanced-usage.js"
|
|
11
9
|
},
|
|
12
10
|
"keywords": [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
"jolt",
|
|
12
|
+
"messaging",
|
|
13
|
+
"broker",
|
|
14
|
+
"pubsub",
|
|
15
|
+
"real-time",
|
|
16
|
+
"tcp",
|
|
17
|
+
"ndjson"
|
|
20
18
|
],
|
|
21
19
|
"author": "DevArqf",
|
|
22
20
|
"license": "MIT",
|
|
23
21
|
"repository": {
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git://github.com/Jolt-Database/jolt-js-api"
|
|
26
24
|
},
|
|
27
|
-
"
|
|
28
|
-
|
|
25
|
+
"homepage": "https://github.com/Jolt-Database/jolt-js-api#readme",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/Jolt-Database/jolt-js-api/issues"
|
|
29
28
|
},
|
|
30
29
|
"engines": {
|
|
31
|
-
|
|
30
|
+
"node": ">=14.0.0"
|
|
32
31
|
}
|
|
33
|
-
|
|
32
|
+
}
|