Registry / database / liwi-resources-websocket-client

liwi-resources-websocket-client

JSON →
library12.0.0jsnpmunverified

WebSocket client implementation for the liwi real-time query and subscription system. Version 12.0.0 requires Node 18.12+. Provides a client for connecting to liwi-resources backends over WebSocket, enabling live queries, resource subscriptions, and mutations. Key differentiator: integrates seamlessly with the liwi ecosystem (liwi-resources-server, liwi-resources-optimistic), supporting offline resilience, optimistic updates, and automatic reconnection. Released as ESM-only, with bundled TypeScript types.

npm install liwi-resources-websocket-client
INSTALL
IMPORT
SIG · LIWI-RESOURCES-WEB
L
liwi-resources-websocket-client
databasejavascriptv12.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

WebSocketClient
import { WebSocketClient } from 'liwi-resources-websocket-client'
const WebSocketClient = require('liwi-resources-websocket-client')
ESM-only package; require() will throw ERR_REQUIRE_ESM
WebSocketClientOptions
import type { WebSocketClientOptions } from 'liwi-resources-websocket-client'
import { WebSocketClientOptions } from 'liwi-resources-websocket-client'
TypeScript type; use import type to avoid runtime emission
createWebSocketClient
import { createWebSocketClient } from 'liwi-resources-websocket-client'
Factory function to easily create a WebSocketClient instance

Creates a WebSocket client, subscribes to a resource query, performs a mutation, and unsubscribes.

import { createWebSocketClient } from 'liwi-resources-websocket-client'; const client = createWebSocketClient({ url: 'ws://localhost:4000', token: process.env.AUTH_TOKEN ?? '' }); // Subscribe to a resource const subscription = client.subscribe('todos', { status: 'pending' }).subscribe({ next: (data) => console.log('Received:', data), error: (err) => console.error('Error:', err), complete: () => console.log('Subscription closed') }); // Perform a mutation client.mutate('todos', { action: 'create', data: { title: 'New task' } }) .then(result => console.log('Mutation result:', result)) .catch(err => console.error('Mutation failed:', err)); // Later: unsubscribe subscription.unsubscribe();
Debug
Known issues
breakingVersion 12.0.0 drops CommonJS support; only ESM is available.
fix
Use dynamic import() or change to ESM project (type: module in package.json).
affects: >=12
breakingMinimum Node.js version is now 18.12.0.
fix
Upgrade Node.js to >=18.12.0
affects: >=12
deprecatedThe 'autoReconnect' option is deprecated and will be removed in v13; use 'reconnect' instead.
fix
Replace autoReconnect with reconnect in client options.
affects: >=11 <=12
gotchaWebSocket connection will fail if AUTH_TOKEN is missing or invalid; no fallback.
fix
Ensure a valid token is passed in the client options, or handle connection errors.
affects: >=12
gotchaImporting from subpaths (e.g., 'liwi-resources-websocket-client/foo') is not supported; only main entry is exported.
fix
Always import from 'liwi-resources-websocket-client'.
affects: >=12
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/liwi-resources-websocket-client/index.js from not supported.
Package is ESM-only, but you are using require() in a CommonJS file.
fix
Convert your file to ESM (use import/export, add type: module to package.json) or use dynamic import().
TypeError: (intermediate value).subscribe is not a function
Calling subscribe on a non-observable response, likely a mutation result which returns a Promise.
fix
Use .then/.catch on mutation results, not .subscribe.
WebSocket connection to 'ws://localhost:4000' failed: Unexpected server response: 401
Authentication token is missing or invalid.
fix
Provide a valid token via the options.token field.
Upgrade
Version history
12.0.0latest on npm
Audit
Dependencies
liwi-resourcesrequiredCore liwi resources types and base classes
wsoptionalWebSocket client for Node.js environments
Agent activity
3 hits · last 30 days
node
2
Amazon
1
Resources
liwi-resources-websocket-client — npm install liwi-resources-websocket-client · libregistry