Initial commit with Advoware proxy

This commit is contained in:
root
2025-10-19 14:57:07 +00:00
commit 273aa8b549
45771 changed files with 5534555 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Motia
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,182 @@
# @motiadev/stream-client-node
Motia Stream Client Package Responsible for managing real-time [Motia](https://motia.dev) streams of data in node environments. This package provides a simple, type-safe interface for subscribing to item and group streams over WebSockets, handling live updates, and managing stream state in your web applications.
## Features
- **WebSocket-based streaming** for real-time data updates
- **Item and group subscriptions** with automatic state management
- **Change listeners** for reactive UI updates
- **Custom event handling** for extensibility
- **TypeScript support** for strong typing and autocompletion
---
## Installation
```bash
npm install @motiadev/stream-client-node
```
---
## Usage
### 1. Creating a Stream Connection
```typescript
import { Stream } from '@motiadev/stream-client-node'
const stream = new Stream('wss://your-stream-server')
```
### 2. Subscribing to an Item Stream
```typescript
const itemSubscription = stream.subscribeItem<{ id: string; name: string }>('users', 'user-123')
itemSubscription.addChangeListener((user) => {
console.log('User updated:', user)
})
// Listen for custom events
itemSubscription.onEvent('custom-event', (data) => {
console.log('Received custom event:', data)
})
```
### 3. Subscribing to a Group Stream
```typescript
const groupSubscription = stream.subscribeGroup<{ id: string; name: string }>('users', 'group-abc')
groupSubscription.addChangeListener((users) => {
console.log('Group users updated:', users)
})
```
### 4. Cleaning Up
```typescript
itemSubscription.close()
groupSubscription.close()
stream.close()
```
---
## API Reference
### `Stream`
- **constructor(address: string, onReady: () => void)**
- Establishes a WebSocket connection to the given address.
- Calls `onReady` when the connection is open.
- **subscribeItem<T>(streamName: string, id: string): StreamItemSubscription<T>**
- Subscribes to a single item in a stream.
- Returns a `StreamItemSubscription` instance.
- **subscribeGroup<T>(streamName: string, groupId: string): StreamGroupSubscription<T>**
- Subscribes to a group of items in a stream.
- Returns a `StreamGroupSubscription` instance.
- **close()**
- Closes the WebSocket connection.
---
### `StreamItemSubscription<T>`
- **addChangeListener(listener: (item: T | null) => void)**
- Registers a callback for when the item changes.
- **removeChangeListener(listener)**
- Unregisters a change listener.
- **onEvent(type: string, listener: (event: any) => void)**
- Registers a custom event listener.
- **offEvent(type: string, listener)**
- Unregisters a custom event listener.
- **getState(): T | null**
- Returns the current state of the item.
- **close()**
- Unsubscribes from the item stream and cleans up listeners.
---
### `StreamGroupSubscription<T>`
- **addChangeListener(listener: (items: T[]) => void)**
- Registers a callback for when the group changes.
- **removeChangeListener(listener)**
- Unregisters a change listener.
- **onEvent(type: string, listener: (event: any) => void)**
- Registers a custom event listener.
- **offEvent(type: string, listener: (event: any) => void)**
- Unregisters a custom event listener.
- **getState(): T[]**
- Returns the current state of the group.
- **close()**
- Unsubscribes from the group stream and cleans up listeners.
---
### `StreamSubscription` (Base Class)
- **onEvent(type: string, listener: (event: any) => void)**
- **offEvent(type: string, listener: (event: any) => void)**
---
## Types
All types are exported from `stream.types.ts` for advanced usage and type safety.
---
## Example
```typescript
import { Stream } from '@motiadev/stream-client-node'
const stream = new Stream('wss://example.com')
const userSub = stream.subscribeItem<{ id: string; name: string }>('users', 'user-1')
userSub.addChangeListener((user) => {
// React to user changes
})
const groupSub = stream.subscribeGroup<{ id: string; name: string }>('users', 'group-1')
groupSub.addChangeListener((users) => {
// React to group changes
})
```
---
## License
MIT

View File

@@ -0,0 +1,2 @@
export { Stream } from './src/stream';
export { StreamItemSubscription, StreamGroupSubscription, StreamSubscription } from '@motiadev/stream-client';

View File

@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StreamSubscription = exports.StreamGroupSubscription = exports.StreamItemSubscription = exports.Stream = void 0;
var stream_1 = require("./src/stream");
Object.defineProperty(exports, "Stream", { enumerable: true, get: function () { return stream_1.Stream; } });
var stream_client_1 = require("@motiadev/stream-client");
Object.defineProperty(exports, "StreamItemSubscription", { enumerable: true, get: function () { return stream_client_1.StreamItemSubscription; } });
Object.defineProperty(exports, "StreamGroupSubscription", { enumerable: true, get: function () { return stream_client_1.StreamGroupSubscription; } });
Object.defineProperty(exports, "StreamSubscription", { enumerable: true, get: function () { return stream_client_1.StreamSubscription; } });

View File

@@ -0,0 +1,13 @@
import type { SocketAdapter } from '@motiadev/stream-client';
export declare class StreamSocketAdapter implements SocketAdapter {
private address;
private ws;
constructor(address: string);
connect(): void;
send(message: string): void;
onMessage(callback: (message: string) => void): void;
onOpen(callback: () => void): void;
onClose(callback: () => void): void;
close(): void;
isOpen(): boolean;
}

View File

@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StreamSocketAdapter = void 0;
const ws_1 = require("ws");
class StreamSocketAdapter {
constructor(address) {
this.address = address;
this.ws = new ws_1.WebSocket(this.address);
}
connect() { }
send(message) {
this.ws.send(message);
}
onMessage(callback) {
const listener = (message) => callback(message.data.toString());
this.ws.addEventListener('message', listener);
}
onOpen(callback) {
this.ws.addEventListener('open', callback);
}
onClose(callback) {
this.ws.addEventListener('close', callback);
}
close() {
this.ws.close();
this.ws.removeAllListeners();
}
isOpen() {
return this.ws.readyState === ws_1.WebSocket.OPEN;
}
}
exports.StreamSocketAdapter = StreamSocketAdapter;

View File

@@ -0,0 +1,4 @@
import { Stream as StreamClient } from '@motiadev/stream-client';
export declare class Stream extends StreamClient {
constructor(address: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Stream = void 0;
const stream_client_1 = require("@motiadev/stream-client");
const stream_adapter_1 = require("./stream-adapter");
class Stream extends stream_client_1.Stream {
constructor(address) {
super(() => new stream_adapter_1.StreamSocketAdapter(address));
}
}
exports.Stream = Stream;

View File

@@ -0,0 +1,2 @@
export { Stream } from './src/stream';
export { StreamItemSubscription, StreamGroupSubscription, StreamSubscription } from '@motiadev/stream-client';

View File

@@ -0,0 +1,2 @@
export { Stream } from './src/stream';
export { StreamItemSubscription, StreamGroupSubscription, StreamSubscription } from '@motiadev/stream-client';

View File

@@ -0,0 +1,13 @@
import type { SocketAdapter } from '@motiadev/stream-client';
export declare class StreamSocketAdapter implements SocketAdapter {
private address;
private ws;
constructor(address: string);
connect(): void;
send(message: string): void;
onMessage(callback: (message: string) => void): void;
onOpen(callback: () => void): void;
onClose(callback: () => void): void;
close(): void;
isOpen(): boolean;
}

View File

@@ -0,0 +1,28 @@
import { WebSocket } from 'ws';
export class StreamSocketAdapter {
constructor(address) {
this.address = address;
this.ws = new WebSocket(this.address);
}
connect() { }
send(message) {
this.ws.send(message);
}
onMessage(callback) {
const listener = (message) => callback(message.data.toString());
this.ws.addEventListener('message', listener);
}
onOpen(callback) {
this.ws.addEventListener('open', callback);
}
onClose(callback) {
this.ws.addEventListener('close', callback);
}
close() {
this.ws.close();
this.ws.removeAllListeners();
}
isOpen() {
return this.ws.readyState === WebSocket.OPEN;
}
}

View File

@@ -0,0 +1,4 @@
import { Stream as StreamClient } from '@motiadev/stream-client';
export declare class Stream extends StreamClient {
constructor(address: string);
}

View File

@@ -0,0 +1,7 @@
import { Stream as StreamClient } from '@motiadev/stream-client';
import { StreamSocketAdapter } from './stream-adapter';
export class Stream extends StreamClient {
constructor(address) {
super(() => new StreamSocketAdapter(address));
}
}

View File

@@ -0,0 +1,2 @@
export { Stream } from './src/stream';
export { StreamItemSubscription, StreamGroupSubscription, StreamSubscription } from '@motiadev/stream-client';

View File

@@ -0,0 +1,13 @@
import type { SocketAdapter } from '@motiadev/stream-client';
export declare class StreamSocketAdapter implements SocketAdapter {
private address;
private ws;
constructor(address: string);
connect(): void;
send(message: string): void;
onMessage(callback: (message: string) => void): void;
onOpen(callback: () => void): void;
onClose(callback: () => void): void;
close(): void;
isOpen(): boolean;
}

View File

@@ -0,0 +1,4 @@
import { Stream as StreamClient } from '@motiadev/stream-client';
export declare class Stream extends StreamClient {
constructor(address: string);
}

View File

@@ -0,0 +1,37 @@
{
"name": "@motiadev/stream-client-node",
"description": "Motia Stream Client Package Responsible for managing streams of data.",
"version": "0.8.2-beta.139",
"license": "MIT",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"exports": {
".": {
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts"
},
"./workbench": {
"require": "./dist/cjs/workbench.js",
"import": "./dist/esm/workbench.js",
"types": "./dist/types/workbench.d.ts"
}
},
"dependencies": {
"uuid": "^11.1.0",
"ws": "^8.18.2",
"@motiadev/stream-client": "0.8.2-beta.139"
},
"devDependencies": {
"@types/jest": "^29.5.14",
"@types/ws": "^8.18.1",
"jest": "^29.7.0",
"ts-jest": "^29.3.2",
"typescript": "^5.7.2"
},
"scripts": {
"build": "sh scripts/build.sh",
"lint": "eslint --config ../../eslint.config.js"
}
}

View File

@@ -0,0 +1,14 @@
#!/bin/bash
rm -rf dist
echo "Building CommonJS version..."
npx tsc --project tsconfig.json --outDir dist/cjs --module CommonJS
echo "Building ESM version..."
npx tsc --project tsconfig.json --outDir dist/esm --module ES2020
echo "Building type declarations..."
npx tsc --emitDeclarationOnly --declaration --outDir dist/types
echo "Build completed successfully!"