sigmasockets-types
v1.0.16
Published
Shared TypeScript type definitions for SigmaSockets
Maintainers
Readme
@sigmasockets/types
Shared TypeScript type definitions for the SigmaSockets WebSocket system.
Installation
npm install @sigmasockets/typesUsage
Import All Types
import type {
ConnectionStatus,
Message,
SigmaSocketClient,
SigmaSocketServer,
SigmaSocketError,
} from '@sigmasockets/types';Import Specific Type Categories
// Common types
import type { ConnectionStatus, Message } from '@sigmasockets/types/common';
// Client types
import type { SigmaSocketClient, ClientEvents } from '@sigmasockets/types/client';
// Server types
import type { SigmaSocketServer, ServerEvents } from '@sigmasockets/types/server';Type Categories
Common Types (/common)
Core types shared between client and server:
ConnectionStatus- Connection state enumerationMessage- WebSocket message typesClientSession- Client session informationConnectionConfig- Connection configurationServerConfig- Server configurationSigmaSocketError- Custom error classErrorCode- Error code enumeration
Client Types (/client)
Client-specific types:
SigmaSocketClient- Main client interfaceSigmaSocketClientConfig- Client configurationClientEvents- Client event typesClientPlugin- Plugin interfaceClientMiddleware- Middleware interfaceClientBuilder- Builder pattern interface
Server Types (/server)
Server-specific types:
SigmaSocketServer- Main server interfaceSigmaSocketServerConfig- Server configurationServerEvents- Server event typesServerPlugin- Plugin interfaceServerMiddleware- Middleware interfaceServerBuilder- Builder pattern interface
Examples
Client Usage
import type { SigmaSocketClient, ConnectionStatus } from '@sigmasockets/types';
const client: SigmaSocketClient = new SigmaSocketClient({
url: 'ws://localhost:8080',
reconnectInterval: 1000,
maxReconnectAttempts: 10,
});
client.on('connection', (status: ConnectionStatus) => {
console.log('Connection status:', status);
});Server Usage
import type { SigmaSocketServer, Message } from '@sigmasockets/types';
const server: SigmaSocketServer = new SigmaSocketServer({
port: 8080,
heartbeatInterval: 30000,
});
server.on('message', (clientId: string, message: Message) => {
console.log('Received message from', clientId, ':', message);
});Error Handling
import type { SigmaSocketError, ErrorCode } from '@sigmasockets/types';
try {
// Some SigmaSockets operation
} catch (error) {
if (error instanceof SigmaSocketError) {
switch (error.code) {
case ErrorCode.ConnectionFailed:
console.error('Connection failed:', error.message);
break;
case ErrorCode.AuthenticationFailed:
console.error('Authentication failed:', error.message);
break;
default:
console.error('SigmaSocket error:', error.message);
}
}
}Type Safety Features
Strict Type Checking
All types are designed with strict TypeScript in mind:
- No
anytypes in public APIs - Comprehensive error handling types
- Immutable interfaces where appropriate
- Proper generic constraints
IntelliSense Support
Full IntelliSense support for:
- Method signatures
- Property types
- Event callbacks
- Configuration options
- Error codes and messages
Compile-Time Validation
Type definitions provide compile-time validation for:
- Configuration objects
- Event handlers
- Message structures
- Error handling
- Plugin interfaces
Version Compatibility
This package follows semantic versioning:
- Major version: Breaking changes to type definitions
- Minor version: New types or non-breaking additions
- Patch version: Bug fixes and documentation updates
Contributing
When adding new types:
- Follow the existing naming conventions
- Add comprehensive JSDoc comments
- Include examples in documentation
- Update this README if needed
- Ensure backward compatibility
License
MIT
