This commit is contained in:
2026-03-06 08:19:15 +07:00
parent 1b86a9252d
commit aa7cdbd36f
31 changed files with 89 additions and 89 deletions

View File

@@ -47,9 +47,9 @@ NATSBridge enables seamless communication across multiple platforms through NATS
| Platform | Implementation | Features | | Platform | Implementation | Features |
|----------|----------------|----------| |----------|----------------|----------|
| **Julia** | [`src/NATSBridge.jl`](src/NATSBridge.jl) | Full feature set, Arrow IPC, multiple dispatch | | **Julia** | [`src/NATSBridge.jl`](src/NATSBridge.jl) | Full feature set, Arrow IPC, multiple dispatch |
| **JavaScript** | [`src/natbridge.js`](src/natbridge.js) | Node.js & browser, async/await | | **JavaScript** | [`src/natsbridge.js`](src/natsbridge.js) | Node.js & browser, async/await |
| **Python** | [`src/natbridge.py`](src/natbridge.py) | Desktop Python, asyncio, type hints | | **Python** | [`src/natsbridge.py`](src/natsbridge.py) | Desktop Python, asyncio, type hints |
| **MicroPython** | [`src/natbridge_mpy.py`](src/natbridge_mpy.py) | Memory-constrained, synchronous API | | **MicroPython** | [`src/natsbridge_mpy.py`](src/natsbridge_mpy.py) | Memory-constrained, synchronous API |
### Platform Comparison ### Platform Comparison
@@ -332,7 +332,7 @@ env, env_json_str = NATSBridge.smartsend(
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
const [env, env_json_str] = await NATSBridge.smartsend( const [env, env_json_str] = await NATSBridge.smartsend(
subject, subject,
@@ -361,7 +361,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
env, env_json_str = await NATSBridge.smartsend( env, env_json_str = await NATSBridge.smartsend(
subject: str, subject: str,
@@ -388,7 +388,7 @@ env, env_json_str = await NATSBridge.smartsend(
#### MicroPython #### MicroPython
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
# Limited to direct transport (< 100KB threshold) # Limited to direct transport (< 100KB threshold)
env, env_json_str = NATSBridge.smartsend( env, env_json_str = NATSBridge.smartsend(
@@ -551,7 +551,7 @@ env, env_json_str = NATSBridge.smartsend("/chat/room1", data; fileserver_url="ht
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
const data = [ const data = [
["message_text", "Hello!", "text"], ["message_text", "Hello!", "text"],
@@ -569,7 +569,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
data = [ data = [
("message_text", "Hello!", "text"), ("message_text", "Hello!", "text"),
@@ -606,7 +606,7 @@ env, env_json_str = NATSBridge.smartsend("/device/config", data)
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
const config = { const config = {
wifi_ssid: "MyNetwork", wifi_ssid: "MyNetwork",
@@ -623,7 +623,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
config = { config = {
"wifi_ssid": "MyNetwork", "wifi_ssid": "MyNetwork",
@@ -658,7 +658,7 @@ env, env_json_str = NATSBridge.smartsend("/data/analysis", data)
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
const df = [ const df = [
{ id: 1, name: "Alice", score: 95 }, { id: 1, name: "Alice", score: 95 },
@@ -675,7 +675,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
import pandas as pd import pandas as pd
df = pd.DataFrame({ df = pd.DataFrame({
@@ -735,7 +735,7 @@ end
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
// Requester // Requester
const [env, env_json_str] = await NATSBridge.smartsend( const [env, env_json_str] = await NATSBridge.smartsend(
@@ -748,7 +748,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
```javascript ```javascript
// Responder // Responder
const nats = require('nats'); const nats = require('nats');
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
async function testResponder() { async function testResponder() {
const conn = await nats.connect('nats://localhost:4222'); const conn = await nats.connect('nats://localhost:4222');
@@ -782,7 +782,7 @@ async function testResponder() {
#### Python #### Python
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
# Requester # Requester
env, env_json_str = await NATSBridge.smartsend( env, env_json_str = await NATSBridge.smartsend(
@@ -795,7 +795,7 @@ env, env_json_str = await NATSBridge.smartsend(
```python ```python
# Responder # Responder
from natbridge import NATSBridge from natsbridge import NATSBridge
import asyncio import asyncio
import nats import nats

View File

@@ -82,7 +82,7 @@ env = smartreceive(msg; fileserver_download_handler=_fetch_with_backoff)
**JavaScript:** **JavaScript:**
```javascript ```javascript
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
// Send // Send
const [env, env_json_str] = await NATSBridge.smartsend( const [env, env_json_str] = await NATSBridge.smartsend(
@@ -104,7 +104,7 @@ const env = await NATSBridge.smartreceive(msg, {
**Python:** **Python:**
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
# Send # Send
env, env_json_str = NATSBridge.smartsend( env, env_json_str = NATSBridge.smartsend(
@@ -124,7 +124,7 @@ env = NATSBridge.smartreceive(
**MicroPython:** **MicroPython:**
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
# Send (limited to direct transport due to memory constraints) # Send (limited to direct transport due to memory constraints)
env, env_json_str = NATSBridge.smartsend( env, env_json_str = NATSBridge.smartsend(

View File

@@ -16,9 +16,9 @@ This document describes the implementation of the high-performance, bi-direction
| Language | Implementation File | Description | | Language | Implementation File | Description |
|----------|---------------------|-------------| |----------|---------------------|-------------|
| **Julia** | [`src/NATSBridge.jl`](../src/NATSBridge.jl) | Full Julia implementation with Arrow IPC support | | **Julia** | [`src/NATSBridge.jl`](../src/NATSBridge.jl) | Full Julia implementation with Arrow IPC support |
| **JavaScript** | `src/natbridge.js` | Node.js/browser implementation | | **JavaScript** | `src/natsbridge.js` | Node.js/browser implementation |
| **Python** | `src/natbridge.py` | Desktop Python implementation | | **Python** | `src/natsbridge.py` | Desktop Python implementation |
| **MicroPython** | `src/natbridge_mpy.py` | MicroPython implementation (limited features) | | **MicroPython** | `src/natsbridge_mpy.py` | MicroPython implementation (limited features) |
--- ---
@@ -228,7 +228,7 @@ end
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('natbridge'); const NATSBridge = require('natsbridge');
// Single payload // Single payload
const [env, env_json_str] = await NATSBridge.smartsend( const [env, env_json_str] = await NATSBridge.smartsend(
@@ -275,7 +275,7 @@ for (const [dataname, data, type] of env.payloads) {
#### Python #### Python
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
# Single payload # Single payload
env, env_json_str = await NATSBridge.smartsend( env, env_json_str = await NATSBridge.smartsend(
@@ -317,7 +317,7 @@ for dataname, data, type_ in env["payloads"]:
#### MicroPython #### MicroPython
```python ```python
from natbridge import NATSBridge from natsbridge import NATSBridge
# Limited to text and binary (no tables due to memory constraints) # Limited to text and binary (no tables due to memory constraints)
env, env_json_str = NATSBridge.smartsend( env, env_json_str = NATSBridge.smartsend(
@@ -929,7 +929,7 @@ end
#### Module Structure #### Module Structure
```javascript ```javascript
// natbridge.js // natsbridge.js
const nats = require('nats'); const nats = require('nats');
const { v4: uuidv4 } = require('uuid'); const { v4: uuidv4 } = require('uuid');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
@@ -1272,7 +1272,7 @@ async function plikOneshotUpload(file_server_url, dataname, data) {
#### Module Structure #### Module Structure
```python ```python
# natbridge.py # natsbridge.py
import asyncio import asyncio
import base64 import base64
import json import json
@@ -1690,7 +1690,7 @@ MicroPython has significant constraints compared to desktop implementations:
### MicroPython Module Structure ### MicroPython Module Structure
```python ```python
# natbridge_mpy.py (MicroPython) # natsbridge_mpy.py (MicroPython)
import network import network
import time import time
import json import json

View File

@@ -134,7 +134,7 @@ env, env_json_str = smartsend("/chat/room1", data, broker_url="nats://localhost:
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
// Send a text message // Send a text message
const data = [["message", "Hello World", "text"]]; const data = [["message", "Hello World", "text"]];
@@ -158,7 +158,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import smartsend from natsbridge import smartsend
# Send a text message # Send a text message
data = [("message", "Hello World", "text")] data = [("message", "Hello World", "text")]
@@ -185,7 +185,7 @@ env, env_json_str = await smartsend(
#### MicroPython #### MicroPython
```python ```python
from natbridge_mpy import NATSBridge from natsbridge_mpy import NATSBridge
bridge = NATSBridge() bridge = NATSBridge()
@@ -218,7 +218,7 @@ end
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
// Receive and process message // Receive and process message
const env = await NATSBridge.smartreceive(msg, { const env = await NATSBridge.smartreceive(msg, {
@@ -233,7 +233,7 @@ for (const [dataname, data, type] of env.payloads) {
#### Python #### Python
```python ```python
from natbridge import smartreceive, fetch_with_backoff from natsbridge import smartreceive, fetch_with_backoff
# Receive and process message # Receive and process message
env = await smartreceive( env = await smartreceive(
@@ -269,7 +269,7 @@ env, env_json_str = smartsend("/device/config", data, broker_url="nats://localho
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
const config = { const config = {
wifi_ssid: "MyNetwork", wifi_ssid: "MyNetwork",
@@ -288,7 +288,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import smartsend from natsbridge import smartsend
config = { config = {
"wifi_ssid": "MyNetwork", "wifi_ssid": "MyNetwork",
@@ -307,7 +307,7 @@ env, env_json_str = await smartsend(
#### MicroPython #### MicroPython
```python ```python
from natbridge_mpy import NATSBridge from natsbridge_mpy import NATSBridge
bridge = NATSBridge() bridge = NATSBridge()
@@ -342,7 +342,7 @@ env, env_json_str = smartsend("/chat/image", data, broker_url="nats://localhost:
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
const fs = require('fs'); const fs = require('fs');
// Read image file // Read image file
@@ -359,7 +359,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import smartsend from natsbridge import smartsend
# Read image file # Read image file
with open("image.png", "rb") as f: with open("image.png", "rb") as f:
@@ -376,7 +376,7 @@ env, env_json_str = await smartsend(
#### MicroPython #### MicroPython
```python ```python
from natbridge_mpy import NATSBridge from natsbridge_mpy import NATSBridge
bridge = NATSBridge() bridge = NATSBridge()
@@ -413,7 +413,7 @@ env, env_json_str = smartsend(
#### JavaScript (Requester) #### JavaScript (Requester)
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
// Send command with reply-to // Send command with reply-to
const data = [["command", { action: "read_sensor" }, "dictionary"]]; const data = [["command", { action: "read_sensor" }, "dictionary"]];
@@ -431,7 +431,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python (Requester) #### Python (Requester)
```python ```python
from natbridge import smartsend from natsbridge import smartsend
# Send command with reply-to # Send command with reply-to
data = [("command", {"action": "read_sensor"}, "dictionary")] data = [("command", {"action": "read_sensor"}, "dictionary")]
@@ -506,7 +506,7 @@ println("File uploaded to: $(env.payloads[1].data)")
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
// Create large data (> 1MB) // Create large data (> 1MB)
const large_data = Buffer.alloc(2_000_000); const large_data = Buffer.alloc(2_000_000);
@@ -530,7 +530,7 @@ console.log("File uploaded to:", env.payloads[0].data);
#### Python #### Python
```python ```python
from natbridge import smartsend from natsbridge import smartsend
# Create large data (> 1MB) # Create large data (> 1MB)
import os import os
@@ -552,7 +552,7 @@ print(f"File uploaded to: {env['payloads'][0]['data']}")
MicroPython enforces a hard limit of 50KB per payload: MicroPython enforces a hard limit of 50KB per payload:
```python ```python
from natbridge_mpy import NATSBridge from natsbridge_mpy import NATSBridge
bridge = NATSBridge() bridge = NATSBridge()
@@ -590,7 +590,7 @@ env, env_json_str = smartsend("/chat/mixed", data, broker_url="nats://localhost:
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
const fs = require('fs'); const fs = require('fs');
const image_data = fs.readFileSync('avatar.png'); const image_data = fs.readFileSync('avatar.png');
@@ -610,7 +610,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import smartsend from natsbridge import smartsend
with open("avatar.png", "rb") as f: with open("avatar.png", "rb") as f:
image_data = f.read() image_data = f.read()
@@ -652,7 +652,7 @@ env, env_json_str = smartsend("/data/students", data, broker_url="nats://localho
#### JavaScript #### JavaScript
```javascript ```javascript
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
// Create table data (array of objects) // Create table data (array of objects)
const table_data = [ const table_data = [
@@ -672,7 +672,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
#### Python #### Python
```python ```python
from natbridge import smartsend from natsbridge import smartsend
import pandas as pd import pandas as pd
# Create DataFrame # Create DataFrame

View File

@@ -177,7 +177,7 @@ end
```javascript ```javascript
// src/chat_ui.js // src/chat_ui.js
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
class ChatUI { class ChatUI {
constructor() { constructor() {
@@ -333,7 +333,7 @@ end
```javascript ```javascript
// src/chat_handler.js // src/chat_handler.js
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
const nats = require('nats'); const nats = require('nats');
class ChatHandler { class ChatHandler {
@@ -393,7 +393,7 @@ module.exports = ChatHandler;
# src/chat_handler.py # src/chat_handler.py
import asyncio import asyncio
from typing import Optional from typing import Optional
from natbridge import smartreceive, fetch_with_backoff from natsbridge import smartreceive, fetch_with_backoff
class ChatHandler: class ChatHandler:
def __init__(self, nats_connection): def __init__(self, nats_connection):
@@ -526,7 +526,7 @@ end
```javascript ```javascript
// src/file_upload_service.js // src/file_upload_service.js
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
const fs = require('fs'); const fs = require('fs');
class FileUploadService { class FileUploadService {
@@ -580,7 +580,7 @@ module.exports = FileUploadService;
```python ```python
# src/file_upload_service.py # src/file_upload_service.py
from natbridge import smartsend from natsbridge import smartsend
import os import os
class FileUploadService: class FileUploadService:
@@ -659,7 +659,7 @@ end
```javascript ```javascript
// src/file_download_service.js // src/file_download_service.js
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
const fs = require('fs'); const fs = require('fs');
class FileDownloadService { class FileDownloadService {
@@ -690,7 +690,7 @@ module.exports = FileDownloadService;
```python ```python
# src/file_download_service.py # src/file_download_service.py
from natbridge import smartreceive, fetch_with_backoff from natsbridge import smartreceive, fetch_with_backoff
import os import os
class FileDownloadService: class FileDownloadService:
@@ -832,7 +832,7 @@ end
```javascript ```javascript
// src/sensor_data.js // src/sensor_data.js
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
class SensorReading { class SensorReading {
constructor(sensorId, value, unit, metadata = {}) { constructor(sensorId, value, unit, metadata = {}) {
@@ -985,7 +985,7 @@ end
```javascript ```javascript
// src/sensor_sender.js // src/sensor_sender.js
const NATSBridge = require('./src/natbridge.js'); const NATSBridge = require('./src/natsbridge.js');
const { SensorReading, SensorBatch } = require('./sensor_data.js'); const { SensorReading, SensorBatch } = require('./sensor_data.js');
class SensorSender { class SensorSender {
@@ -1069,7 +1069,7 @@ module.exports = SensorSender;
```python ```python
# src/sensor_sender.py # src/sensor_sender.py
from natbridge import smartsend from natsbridge import smartsend
from sensor_data import SensorReading, SensorBatch from sensor_data import SensorReading, SensorBatch
class SensorSender: class SensorSender:
@@ -1282,7 +1282,7 @@ end
# Cache file server responses # Cache file server responses
import asyncio import asyncio
import threading import threading
from natbridge import fetch_with_backoff from natsbridge import fetch_with_backoff
file_cache = {} file_cache = {}
cache_lock = threading.Lock() cache_lock = threading.Lock()

View File

@@ -6,7 +6,7 @@ This module provides functionality for sending and receiving data across network
using NATS as the message bus, with support for both direct payload transport and using NATS as the message bus, with support for both direct payload transport and
URL-based transport for larger payloads. URL-based transport for larger payloads.
@package natbridge @package natsbridge
""" """
import asyncio import asyncio

View File

@@ -3,7 +3,7 @@
* Tests the smartreceive function with binary/image/audio/video payloads * Tests the smartreceive function with binary/image/audio/video payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080'; const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080';

View File

@@ -3,7 +3,7 @@
* Tests the smartsend function with binary/image/audio/video payloads * Tests the smartsend function with binary/image/audio/video payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const TEST_SUBJECT = '/test/binary'; const TEST_SUBJECT = '/test/binary';
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';

View File

@@ -3,7 +3,7 @@
* Tests the smartreceive function with dictionary payloads * Tests the smartreceive function with dictionary payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080'; const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080';

View File

@@ -3,7 +3,7 @@
* Tests the smartsend function with dictionary payloads * Tests the smartsend function with dictionary payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const TEST_SUBJECT = '/test/dictionary'; const TEST_SUBJECT = '/test/dictionary';
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';

View File

@@ -3,7 +3,7 @@
* Tests the smartsend function with mixed payload types * Tests the smartsend function with mixed payload types
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const TEST_SUBJECT = '/test/mix'; const TEST_SUBJECT = '/test/mix';
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';

View File

@@ -3,7 +3,7 @@
* Tests the smartreceive function with table (Arrow IPC) payloads * Tests the smartreceive function with table (Arrow IPC) payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080'; const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080';

View File

@@ -3,7 +3,7 @@
* Tests the smartsend function with table (Arrow IPC) payloads * Tests the smartsend function with table (Arrow IPC) payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const TEST_SUBJECT = '/test/table'; const TEST_SUBJECT = '/test/table';
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';

View File

@@ -3,7 +3,7 @@
* Tests the smartreceive function with text payloads * Tests the smartreceive function with text payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080'; const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080';

View File

@@ -3,7 +3,7 @@
* Tests the smartsend function with text payloads * Tests the smartsend function with text payloads
*/ */
const NATSBridge = require('../src/natbridge.js'); const NATSBridge = require('../src/natsbridge.js');
const TEST_SUBJECT = '/test/text'; const TEST_SUBJECT = '/test/text';
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222'; const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';

View File

@@ -14,7 +14,7 @@ import base64
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080') TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
@@ -23,7 +23,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
def run_test(): def run_test():
print('=== MicroPython Binary Receiver Test ===\n') print('=== MicroPython Binary Receiver Test ===\n')
from natbridge_mpy import _generate_uuid from natsbridge_mpy import _generate_uuid
# Create mock NATS message with binary payloads # Create mock NATS message with binary payloads
image_data = bytes([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]) # PNG header image_data = bytes([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]) # PNG header

View File

@@ -13,7 +13,7 @@ import base64
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE from natsbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE
TEST_SUBJECT = '/test/binary' TEST_SUBJECT = '/test/binary'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
@@ -23,7 +23,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
def run_test(): def run_test():
print('=== MicroPython Binary Sender Test ===\n') print('=== MicroPython Binary Sender Test ===\n')
from natbridge_mpy import _generate_uuid from natsbridge_mpy import _generate_uuid
correlation_id = 'mpy-binary-test-' + _generate_uuid() correlation_id = 'mpy-binary-test-' + _generate_uuid()
print(f'Correlation ID: {correlation_id}') print(f'Correlation ID: {correlation_id}')
print(f'Subject: {TEST_SUBJECT}') print(f'Subject: {TEST_SUBJECT}')

View File

@@ -13,7 +13,7 @@ import json
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080') TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
@@ -22,7 +22,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
def run_test(): def run_test():
print('=== MicroPython Dictionary Receiver Test ===\n') print('=== MicroPython Dictionary Receiver Test ===\n')
from natbridge_mpy import _generate_uuid from natsbridge_mpy import _generate_uuid
# Create a mock NATS message with dictionary payloads # Create a mock NATS message with dictionary payloads
import base64 import base64

View File

@@ -13,7 +13,7 @@ import json
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE from natsbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE
TEST_SUBJECT = '/test/dictionary' TEST_SUBJECT = '/test/dictionary'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
@@ -23,7 +23,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
def run_test(): def run_test():
print('=== MicroPython Dictionary Sender Test ===\n') print('=== MicroPython Dictionary Sender Test ===\n')
from natbridge_mpy import _generate_uuid from natsbridge_mpy import _generate_uuid
correlation_id = 'mpy-dict-test-' + _generate_uuid() correlation_id = 'mpy-dict-test-' + _generate_uuid()
print(f'Correlation ID: {correlation_id}') print(f'Correlation ID: {correlation_id}')
print(f'Subject: {TEST_SUBJECT}') print(f'Subject: {TEST_SUBJECT}')

View File

@@ -13,7 +13,7 @@ import json
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080') TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
@@ -22,7 +22,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
def run_test(): def run_test():
print('=== MicroPython Text Receiver Test ===\n') print('=== MicroPython Text Receiver Test ===\n')
from natbridge_mpy import _generate_uuid from natsbridge_mpy import _generate_uuid
# Create a mock NATS message with text payload # Create a mock NATS message with text payload
test_text = 'Hello, NATSBridge! This is a test message.' test_text = 'Hello, NATSBridge! This is a test message.'

View File

@@ -12,7 +12,7 @@ import os
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE from natsbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE
TEST_SUBJECT = '/test/text' TEST_SUBJECT = '/test/text'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
@@ -22,7 +22,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
def run_test(): def run_test():
print('=== MicroPython Text Sender Test ===\n') print('=== MicroPython Text Sender Test ===\n')
from natbridge_mpy import _generate_uuid from natsbridge_mpy import _generate_uuid
correlation_id = 'mpy-text-test-' + _generate_uuid() correlation_id = 'mpy-text-test-' + _generate_uuid()
print(f'Correlation ID: {correlation_id}') print(f'Correlation ID: {correlation_id}')
print(f'Subject: {TEST_SUBJECT}') print(f'Subject: {TEST_SUBJECT}')

View File

@@ -12,7 +12,7 @@ import base64
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080') TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')

View File

@@ -11,7 +11,7 @@ import base64
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_SUBJECT = '/test/binary' TEST_SUBJECT = '/test/binary'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')

View File

@@ -11,7 +11,7 @@ import json
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080') TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')

View File

@@ -11,7 +11,7 @@ import json
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_SUBJECT = '/test/dictionary' TEST_SUBJECT = '/test/dictionary'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')

View File

@@ -11,7 +11,7 @@ import base64
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_SUBJECT = '/test/mix' TEST_SUBJECT = '/test/mix'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')

View File

@@ -10,7 +10,7 @@ import os
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_SUBJECT = '/test/table' TEST_SUBJECT = '/test/table'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')

View File

@@ -11,7 +11,7 @@ import json
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080') TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')

View File

@@ -10,7 +10,7 @@ import os
# Add parent directory to path # Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from natbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL from natsbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
TEST_SUBJECT = '/test/text' TEST_SUBJECT = '/test/text'
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222') TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')