Registry / http-networking / tgrid
library1.2.1jsnpmunverified

TGrid is a robust TypeScript framework designed for building grid computing applications and facilitating real-time network communication across various environments. It provides abstractions for Remote Procedure Call (RPC), Remote Function Call (RFC), and Remote Object Call (ROC), enabling developers to create distributed systems that leverage WebSockets, Web Workers, Shared Workers, and integrate seamlessly with NestJS. The current stable version is 1.2.1, with a release cadence that focuses on incremental improvements, bug fixes, and documentation enhancements, rather than frequent major breaking changes. Its key differentiators include comprehensive TypeScript type safety, unified API for diverse communication protocols, and a strong emphasis on simplifying complex network paradigms into an intuitive Object-Oriented Network (OON) model. TGrid aims to reduce boilerplate and complexity associated with developing high-performance, distributed applications.

npm install tgrid
INSTALL
IMPORT
SIG · TGRID
T
tgrid
http-networkingjavascriptv1.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Driver
import { Driver } from 'tgrid'
const { Driver } = require('tgrid')
TGrid is primarily designed for ESM; while CommonJS might work with transpilation, direct require is not recommended.
WebSocketConnector
import { WebSocketConnector } from 'tgrid'
const WebSocketConnector = require('tgrid').WebSocketConnector
This is a named export. Ensure proper named import syntax, especially for TypeScript projects.
WorkerConnector
import { WorkerConnector } from 'tgrid'
import WorkerConnector from 'tgrid/WorkerConnector'
Access Worker-related connectors directly from the main 'tgrid' package, not sub-paths.
Communicator
import { Communicator } from 'tgrid'
import { ICommunicator } from 'tgrid'
Communicator is a class, not an interface. Interfaces typically start with 'I' by convention.

This quickstart demonstrates how to establish a WebSocket connection with a TGrid server and perform remote procedure calls (RPC) using a type-safe interface. It connects to a hypothetical 'calculator' service and invokes arithmetic operations.

import { Driver, WebSocketConnector } from "tgrid"; interface ICalculator { plus(a: number, b: number): number; minus(a: number, b: number): number; multiply(a: number, b: number): number; divide(a: number, b: number): number; } export const webSocketClientMain = async () => { // CONNECT TO WEBSOCKET SERVER // Assume a TGrid server is running at ws://127.0.0.1:37000/composite const connector: WebSocketConnector<null, null, ICalculator> = new WebSocketConnector( null, // header: data sent during connection, null for this example null // provider: local functions/objects to expose to the remote server, null here ); try { await connector.connect("ws://127.0.0.1:37000/composite"); console.log("Connected to WebSocket server."); // CALL REMOTE FUNCTIONS const remote: Driver<ICalculator> = connector.getDriver(); console.log( "10 + 20 =", await remote.plus(10, 20), // Expected: 30 "7 - 3 =", await remote.minus(7, 3), // Expected: 4 "3 * 4 =", await remote.multiply(3, 4), // Expected: 12 "5 / 2 =", await remote.divide(5, 2) // Expected: 2.5 ); } catch (error) { console.error("WebSocket connection or RPC failed:", error.message); } finally { await connector.close(); console.log("Connection closed."); } }; // To run this, you would typically have a server-side TGrid setup like: // import { WebSocketAcceptor } from "tgrid"; // class CalculatorProvider implements ICalculator { // plus(a: number, b: number): number { return a + b; } // minus(a: number, b: number): number { return a - b; } // multiply(a: number, b: number): number { return a * b; } // divide(a: number, b: number): number { return a / b; } // } // const acceptor = new WebSocketAcceptor(); // acceptor.on("/composite", async (connector) => { // await connector.accept(new CalculatorProvider()); // }); // acceptor.open(37000); // console.log("WebSocket server listening on port 37000"); webSocketClientMain();
Debug
Known issues
breakingVersion 1.0.0 introduced significant breaking changes by refactoring the names of WebSocket-related classes. Code written for pre-1.0.0 versions using `WebSocket` components will require updates.
fix
Review the TGrid v1.0.0 changelog and documentation to adapt to the new class names and API structures for WebSocket interactions.
affects: >=1.0.0 <1.0.1
breakingThe error patterns were unified in version 1.0.2. If your application relied on the specific structure or properties of error objects thrown by TGrid prior to this version, your error handling logic may need adjustments.
fix
Test error handling paths and update catch blocks or error inspection logic to conform to the new uniform error pattern introduced in v1.0.2.
affects: >=1.0.2
gotchaIn v1.1.0, `Communicator.on()` was enhanced to include message with event types. While an improvement, developers who extended or heavily customized `Communicator` behavior might need to verify compatibility with the new event typing.
fix
Check custom `Communicator` implementations or usages of `on()` to ensure they align with the updated method signature and event type handling, especially if type inference or custom event objects are involved.
affects: >=1.1.0
gotchaUnderstanding worker context and paths, especially with the `WorkerConnector.IConnectOptions.cwd` introduced in v1.2.0, can be a source of confusion. Incorrect relative paths for worker scripts are common.
fix
When using `WorkerConnector`, explicitly define `cwd` if your worker script is not in the default working directory, or ensure paths are absolute for clarity. Pay close attention to how your bundler or runtime resolves worker script paths.
affects: >=1.2.0
Errors
Common errors & fixes
Error: connect ECONNREFUSED 127.0.0.1:XXXX
The TGrid server (WebSocket or Worker) is not running, or it's listening on a different IP address or port than the client is trying to connect to.
fix
Ensure the TGrid server process is active and verify that the client's connection URL/parameters (e.g., 'ws://127.0.0.1:37000/composite') precisely match the server's configured listening address and port.
TypeError: (remote.someMethod is not a function)
The remote provider object on the server/worker side does not implement or expose the specific method that the client is attempting to call, or it was not correctly registered with the `Communicator`.
fix
Review the interface (`ICalculator` in the quickstart) and the actual provider object instantiated on the server/worker side. Ensure the method (`someMethod`) is correctly implemented and passed to `connector.accept()`.
Cannot find module 'tgrid' or its corresponding type declarations.
The 'tgrid' package has not been installed, or the TypeScript configuration (`tsconfig.json`) is not correctly set up to resolve modules or type definitions.
fix
Run `npm install tgrid` to install the package. For TypeScript, ensure `compilerOptions.esModuleInterop` is set to `true` and that `compilerOptions.moduleResolution` is appropriate (e.g., `NodeNext` or `Node`).
WebSocket connection to 'ws://...' failed: Error during WebSocket handshake: Unexpected response code: 404
The WebSocket endpoint path specified by the client is incorrect, or the TGrid server is not configured to handle WebSocket connections at that particular route.
fix
Verify that the WebSocket URL path (e.g., `/composite` in the quickstart) precisely matches the path configured on the `WebSocketAcceptor` or equivalent server-side setup.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
tgrid — npm install tgrid · libregistry