@bangstack/protocol
v1.0.0
Published
Mesh Protocol specification and JSON schemas for event-driven communication
Maintainers
Readme
@bangstack/protocol
Mesh Protocol specification and JSON schemas for event-driven communication.
Installation
npm install @bangstack/protocolQuick Start
import {
Operations,
ErrorCodes,
createEvent,
createMessage,
validateEventType,
matchesPattern
} from '@bangstack/protocol';
// Create a protocol-compliant event
const event = createEvent('user:session:started', { userId: '123' });
// Create a protocol message
const message = createMessage(Operations.EMIT, { type: event.type, data: event.data });
// Validate event types
validateEventType('user:session:started'); // true
validateEventType('invalid'); // throws
// Pattern matching for subscriptions
matchesPattern('user:session:started', 'user:*'); // true
matchesPattern('user:session:started', 'order:*'); // falseProtocol Operations
| Operation | Description |
|-----------|-------------|
| CONNECT | Client connects to server |
| CONNECTED | Server acknowledges connection |
| SUBSCRIBE | Subscribe to event patterns |
| UNSUBSCRIBE | Remove subscription |
| EMIT | Emit event to mesh |
| EVENT | Server pushes event to subscriber |
| QUERY | Query historical events |
| ACK | Acknowledge message |
| ERROR | Error response |
JSON Schemas
Protocol includes JSON schemas for validation:
import { eventSchema, messageSchema, querySchema } from '@bangstack/protocol';See PROTOCOL.md for the full specification.
License
MIT
