@motiadev/stream-client-node 0.5.2-beta.104-330172 → 0.5.3-beta.105
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 +9 -12
- package/dist/cjs/index.js +9 -0
- package/dist/cjs/src/stream-adapter.js +32 -0
- package/dist/cjs/src/stream.js +11 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/src/stream-adapter.d.ts +13 -0
- package/dist/esm/src/stream.d.ts +4 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/src/stream-adapter.d.ts +13 -0
- package/dist/types/src/stream.d.ts +4 -0
- package/package.json +18 -5
- package/scripts/build.sh +14 -0
- package/index.ts +0 -2
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{src → cjs/src}/stream-adapter.d.ts +0 -0
- /package/dist/{src → cjs/src}/stream.d.ts +0 -0
- /package/dist/{index.js → esm/index.d.ts} +0 -0
- /package/dist/{src → esm/src}/stream-adapter.js +0 -0
- /package/dist/{src → esm/src}/stream.js +0 -0
package/README.md
CHANGED
|
@@ -27,9 +27,7 @@ npm install @motiadev/stream-client-node
|
|
|
27
27
|
```typescript
|
|
28
28
|
import { Stream } from '@motiadev/stream-client-node'
|
|
29
29
|
|
|
30
|
-
const stream = new Stream('wss://your-stream-server'
|
|
31
|
-
console.log('WebSocket connection established!')
|
|
32
|
-
})
|
|
30
|
+
const stream = new Stream('wss://your-stream-server')
|
|
33
31
|
```
|
|
34
32
|
|
|
35
33
|
### 2. Subscribing to an Item Stream
|
|
@@ -163,18 +161,17 @@ All types are exported from `stream.types.ts` for advanced usage and type safety
|
|
|
163
161
|
```typescript
|
|
164
162
|
import { Stream } from '@motiadev/stream-client-node'
|
|
165
163
|
|
|
166
|
-
const stream = new Stream('wss://example.com'
|
|
167
|
-
|
|
164
|
+
const stream = new Stream('wss://example.com')
|
|
165
|
+
const userSub = stream.subscribeItem<{ id: string; name: string }>('users', 'user-1')
|
|
168
166
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
userSub.addChangeListener((user) => {
|
|
168
|
+
// React to user changes
|
|
169
|
+
})
|
|
172
170
|
|
|
173
|
-
|
|
171
|
+
const groupSub = stream.subscribeGroup<{ id: string; name: string }>('users', 'group-1')
|
|
174
172
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
})
|
|
173
|
+
groupSub.addChangeListener((users) => {
|
|
174
|
+
// React to group changes
|
|
178
175
|
})
|
|
179
176
|
```
|
|
180
177
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamSubscription = exports.StreamGroupSubscription = exports.StreamItemSubscription = exports.Stream = void 0;
|
|
4
|
+
var stream_1 = require("./src/stream");
|
|
5
|
+
Object.defineProperty(exports, "Stream", { enumerable: true, get: function () { return stream_1.Stream; } });
|
|
6
|
+
var stream_client_1 = require("@motiadev/stream-client");
|
|
7
|
+
Object.defineProperty(exports, "StreamItemSubscription", { enumerable: true, get: function () { return stream_client_1.StreamItemSubscription; } });
|
|
8
|
+
Object.defineProperty(exports, "StreamGroupSubscription", { enumerable: true, get: function () { return stream_client_1.StreamGroupSubscription; } });
|
|
9
|
+
Object.defineProperty(exports, "StreamSubscription", { enumerable: true, get: function () { return stream_client_1.StreamSubscription; } });
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamSocketAdapter = void 0;
|
|
4
|
+
const ws_1 = require("ws");
|
|
5
|
+
class StreamSocketAdapter {
|
|
6
|
+
constructor(address) {
|
|
7
|
+
this.address = address;
|
|
8
|
+
this.ws = new ws_1.WebSocket(this.address);
|
|
9
|
+
}
|
|
10
|
+
connect() { }
|
|
11
|
+
send(message) {
|
|
12
|
+
this.ws.send(message);
|
|
13
|
+
}
|
|
14
|
+
onMessage(callback) {
|
|
15
|
+
const listener = (message) => callback(message.data.toString());
|
|
16
|
+
this.ws.addEventListener('message', listener);
|
|
17
|
+
}
|
|
18
|
+
onOpen(callback) {
|
|
19
|
+
this.ws.addEventListener('open', callback);
|
|
20
|
+
}
|
|
21
|
+
onClose(callback) {
|
|
22
|
+
this.ws.addEventListener('close', callback);
|
|
23
|
+
}
|
|
24
|
+
close() {
|
|
25
|
+
this.ws.close();
|
|
26
|
+
this.ws.removeAllListeners();
|
|
27
|
+
}
|
|
28
|
+
isOpen() {
|
|
29
|
+
return this.ws.readyState === ws_1.WebSocket.OPEN;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.StreamSocketAdapter = StreamSocketAdapter;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Stream = void 0;
|
|
4
|
+
const stream_client_1 = require("@motiadev/stream-client");
|
|
5
|
+
const stream_adapter_1 = require("./stream-adapter");
|
|
6
|
+
class Stream extends stream_client_1.Stream {
|
|
7
|
+
constructor(address) {
|
|
8
|
+
super(() => new stream_adapter_1.StreamSocketAdapter(address));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.Stream = Stream;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SocketAdapter } from '@motiadev/stream-client';
|
|
2
|
+
export declare class StreamSocketAdapter implements SocketAdapter {
|
|
3
|
+
private address;
|
|
4
|
+
private ws;
|
|
5
|
+
constructor(address: string);
|
|
6
|
+
connect(): void;
|
|
7
|
+
send(message: string): void;
|
|
8
|
+
onMessage(callback: (message: string) => void): void;
|
|
9
|
+
onOpen(callback: () => void): void;
|
|
10
|
+
onClose(callback: () => void): void;
|
|
11
|
+
close(): void;
|
|
12
|
+
isOpen(): boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SocketAdapter } from '@motiadev/stream-client';
|
|
2
|
+
export declare class StreamSocketAdapter implements SocketAdapter {
|
|
3
|
+
private address;
|
|
4
|
+
private ws;
|
|
5
|
+
constructor(address: string);
|
|
6
|
+
connect(): void;
|
|
7
|
+
send(message: string): void;
|
|
8
|
+
onMessage(callback: (message: string) => void): void;
|
|
9
|
+
onOpen(callback: () => void): void;
|
|
10
|
+
onClose(callback: () => void): void;
|
|
11
|
+
close(): void;
|
|
12
|
+
isOpen(): boolean;
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@motiadev/stream-client-node",
|
|
3
3
|
"description": "Motia Stream Client Package – Responsible for managing streams of data.",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.3-beta.105",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"
|
|
6
|
+
"main": "dist/cjs/index.js",
|
|
7
|
+
"module": "dist/esm/index.js",
|
|
8
|
+
"types": "dist/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"require": "./dist/cjs/index.js",
|
|
12
|
+
"import": "./dist/esm/index.js",
|
|
13
|
+
"types": "./dist/types/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./workbench": {
|
|
16
|
+
"require": "./dist/cjs/workbench.js",
|
|
17
|
+
"import": "./dist/esm/workbench.js",
|
|
18
|
+
"types": "./dist/types/workbench.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
8
21
|
"dependencies": {
|
|
9
22
|
"uuid": "^11.1.0",
|
|
10
23
|
"ws": "^8.18.2",
|
|
11
|
-
"@motiadev/stream-client": "0.5.
|
|
24
|
+
"@motiadev/stream-client": "0.5.3-beta.105"
|
|
12
25
|
},
|
|
13
26
|
"devDependencies": {
|
|
14
27
|
"@types/jest": "^29.5.14",
|
|
@@ -18,7 +31,7 @@
|
|
|
18
31
|
"typescript": "^5.7.2"
|
|
19
32
|
},
|
|
20
33
|
"scripts": {
|
|
21
|
-
"build": "
|
|
34
|
+
"build": "sh scripts/build.sh",
|
|
22
35
|
"lint": "eslint --config ../../eslint.config.js"
|
|
23
36
|
}
|
|
24
37
|
}
|
package/scripts/build.sh
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
rm -rf dist
|
|
4
|
+
|
|
5
|
+
echo "Building CommonJS version..."
|
|
6
|
+
npx tsc --project tsconfig.json --outDir dist/cjs --module CommonJS
|
|
7
|
+
|
|
8
|
+
echo "Building ESM version..."
|
|
9
|
+
npx tsc --project tsconfig.json --outDir dist/esm --module ES2020
|
|
10
|
+
|
|
11
|
+
echo "Building type declarations..."
|
|
12
|
+
npx tsc --emitDeclarationOnly --declaration --outDir dist/types
|
|
13
|
+
|
|
14
|
+
echo "Build completed successfully!"
|
package/index.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|