Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions content/docs/references/api/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ This section contains all protocol schemas for the api layer of ObjectStack.
<Card href="./odata" title="Odata" description="Source: packages/spec/src/api/odata.zod.ts" />
<Card href="./realtime" title="Realtime" description="Source: packages/spec/src/api/realtime.zod.ts" />
<Card href="./router" title="Router" description="Source: packages/spec/src/api/router.zod.ts" />
<Card href="./websocket" title="Websocket" description="Source: packages/spec/src/api/websocket.zod.ts" />
</Cards>

3 changes: 2 additions & 1 deletion content/docs/references/api/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"graphql",
"odata",
"realtime",
"router"
"router",
"websocket"
]
}
374 changes: 374 additions & 0 deletions content/docs/references/api/websocket.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,374 @@
---
title: Websocket
description: Websocket protocol schemas
---

# Websocket

<Callout type="info">
**Source:** `packages/spec/src/api/websocket.zod.ts`
</Callout>

## TypeScript Usage

```typescript
import { AckMessageSchema, CursorMessageSchema, CursorPositionSchema, DocumentStateSchema, EditMessageSchema, EditOperationSchema, EditOperationTypeSchema, ErrorMessageSchema, EventFilterSchema, EventFilterConditionSchema, EventMessageSchema, EventPatternSchema, EventSubscriptionSchema, FilterOperatorSchema, PingMessageSchema, PongMessageSchema, PresenceMessageSchema, PresenceStateSchema, PresenceUpdateSchema, SubscribeMessageSchema, UnsubscribeMessageSchema, UnsubscribeRequestSchema, WebSocketConfigSchema, WebSocketMessageSchema, WebSocketMessageTypeSchema, WebSocketPresenceStatusSchema } from '@objectstack/spec/api';
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TypeScript import example references schema exports like FilterOperatorSchema, EditOperationTypeSchema, WebSocketMessageTypeSchema, etc., but packages/spec/src/api/websocket.zod.ts exports FilterOperator, EditOperationType, WebSocketMessageType, etc. (no Schema suffix). Update the example to match actual exports to prevent copy/paste errors.

Suggested change
import { AckMessageSchema, CursorMessageSchema, CursorPositionSchema, DocumentStateSchema, EditMessageSchema, EditOperationSchema, EditOperationTypeSchema, ErrorMessageSchema, EventFilterSchema, EventFilterConditionSchema, EventMessageSchema, EventPatternSchema, EventSubscriptionSchema, FilterOperatorSchema, PingMessageSchema, PongMessageSchema, PresenceMessageSchema, PresenceStateSchema, PresenceUpdateSchema, SubscribeMessageSchema, UnsubscribeMessageSchema, UnsubscribeRequestSchema, WebSocketConfigSchema, WebSocketMessageSchema, WebSocketMessageTypeSchema, WebSocketPresenceStatusSchema } from '@objectstack/spec/api';
import { AckMessageSchema, CursorMessageSchema, CursorPositionSchema, DocumentStateSchema, EditMessageSchema, EditOperationSchema, EditOperationType, ErrorMessageSchema, EventFilterSchema, EventFilterConditionSchema, EventMessageSchema, EventPatternSchema, EventSubscriptionSchema, FilterOperator, PingMessageSchema, PongMessageSchema, PresenceMessageSchema, PresenceStateSchema, PresenceUpdateSchema, SubscribeMessageSchema, UnsubscribeMessageSchema, UnsubscribeRequestSchema, WebSocketConfigSchema, WebSocketMessageSchema, WebSocketMessageType, WebSocketPresenceStatus } from '@objectstack/spec/api';

Copilot uses AI. Check for mistakes.
import type { AckMessage, CursorMessage, CursorPosition, DocumentState, EditMessage, EditOperation, EditOperationType, ErrorMessage, EventFilter, EventFilterCondition, EventMessage, EventPattern, EventSubscription, FilterOperator, PingMessage, PongMessage, PresenceMessage, PresenceState, PresenceUpdate, SubscribeMessage, UnsubscribeMessage, UnsubscribeRequest, WebSocketConfig, WebSocketMessage, WebSocketMessageType, WebSocketPresenceStatus } from '@objectstack/spec/api';

// Validate data
const result = AckMessageSchema.parse(data);
```

---

## AckMessage

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **messageId** | `string` | ✅ | Unique message identifier |
| **type** | `string` | ✅ | |
| **timestamp** | `string` | ✅ | ISO 8601 datetime when message was sent |
| **ackMessageId** | `string` | ✅ | ID of the message being acknowledged |
| **success** | `boolean` | ✅ | Whether the operation was successful |
| **error** | `string` | optional | Error message if operation failed |

---

## CursorMessage

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **messageId** | `string` | ✅ | Unique message identifier |
| **type** | `string` | ✅ | |
| **timestamp** | `string` | ✅ | ISO 8601 datetime when message was sent |
| **cursor** | `object` | ✅ | Cursor position |

---

## CursorPosition

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **userId** | `string` | ✅ | User identifier |
| **sessionId** | `string` | ✅ | Session identifier |
| **documentId** | `string` | ✅ | Document identifier being edited |
| **position** | `object` | optional | Cursor position in document |
| **selection** | `object` | optional | Selection range (if text is selected) |
| **color** | `string` | optional | Cursor color for visual representation |
| **userName** | `string` | optional | Display name of user |
| **lastUpdate** | `string` | ✅ | ISO 8601 datetime of last cursor update |

---

## DocumentState

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **documentId** | `string` | ✅ | Document identifier |
| **version** | `integer` | ✅ | Current document version |
| **content** | `string` | ✅ | Current document content |
| **lastModified** | `string` | ✅ | ISO 8601 datetime of last modification |
| **activeSessions** | `string[]` | ✅ | Active editing session IDs |
| **checksum** | `string` | optional | Content checksum for integrity verification |

---

## EditMessage

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **messageId** | `string` | ✅ | Unique message identifier |
| **type** | `string` | ✅ | |
| **timestamp** | `string` | ✅ | ISO 8601 datetime when message was sent |
| **operation** | `object` | ✅ | Edit operation |

---

## EditOperation

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **operationId** | `string` | ✅ | Unique operation identifier |
| **documentId** | `string` | ✅ | Document identifier |
| **userId** | `string` | ✅ | User who performed the edit |
| **sessionId** | `string` | ✅ | Session identifier |
| **type** | `Enum<'insert' \| 'delete' \| 'replace'>` | ✅ | Type of edit operation |
| **position** | `object` | ✅ | Starting position of the operation |
| **endPosition** | `object` | optional | Ending position (for delete/replace operations) |
| **content** | `string` | optional | Content to insert/replace |
| **version** | `integer` | ✅ | Document version before this operation |
| **timestamp** | `string` | ✅ | ISO 8601 datetime when operation was created |
| **baseOperationId** | `string` | optional | Previous operation ID this builds upon (for OT) |

---

## EditOperationType

### Allowed Values

* `insert`
* `delete`
* `replace`

---

## ErrorMessage

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **messageId** | `string` | ✅ | Unique message identifier |
| **type** | `string` | ✅ | |
| **timestamp** | `string` | ✅ | ISO 8601 datetime when message was sent |
| **code** | `string` | ✅ | Error code |
| **message** | `string` | ✅ | Error message |
| **details** | `any` | optional | Additional error details |

---

## EventFilter

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **conditions** | `object[]` | optional | Array of filter conditions |
| **and** | `any[]` | optional | AND logical combination of filters |
| **or** | `any[]` | optional | OR logical combination of filters |
| **not** | `any` | optional | NOT logical negation of filter |

---

## EventFilterCondition

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **field** | `string` | ✅ | Field path to filter on (supports dot notation, e.g., "user.email") |
| **operator** | `Enum<'eq' \| 'ne' \| 'gt' \| 'gte' \| 'lt' \| 'lte' \| 'in' \| 'nin' \| 'contains' \| 'startsWith' \| 'endsWith' \| 'exists' \| 'regex'>` | ✅ | Comparison operator |
| **value** | `any` | optional | Value to compare against (not needed for "exists" operator) |

---

## EventMessage

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **messageId** | `string` | ✅ | Unique message identifier |
| **type** | `string` | ✅ | |
| **timestamp** | `string` | ✅ | ISO 8601 datetime when message was sent |
| **subscriptionId** | `string` | ✅ | Subscription ID this event belongs to |
| **eventName** | `string` | ✅ | Event name |
| **object** | `string` | optional | Object name the event relates to |
| **payload** | `any` | optional | Event payload data |
| **userId** | `string` | optional | User who triggered the event |

---

## EventPattern

Event pattern (supports wildcards like "record.*" or "*.created")

---

## EventSubscription

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **subscriptionId** | `string` | ✅ | Unique subscription identifier |
| **events** | `string[]` | ✅ | Event patterns to subscribe to (supports wildcards, e.g., "record.*", "user.created") |
| **objects** | `string[]` | optional | Object names to filter events by (e.g., ["account", "contact"]) |
| **filters** | `object` | optional | Advanced filter conditions for event payloads |
| **channels** | `string[]` | optional | Channel names for scoped subscriptions |

---

## FilterOperator

### Allowed Values

* `eq`
* `ne`
* `gt`
* `gte`
* `lt`
* `lte`
* `in`
* `nin`
* `contains`
* `startsWith`
* `endsWith`
* `exists`
* `regex`

---

## PingMessage

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **messageId** | `string` | ✅ | Unique message identifier |
| **type** | `string` | ✅ | |
| **timestamp** | `string` | ✅ | ISO 8601 datetime when message was sent |

---

## PongMessage

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **messageId** | `string` | ✅ | Unique message identifier |
| **type** | `string` | ✅ | |
| **timestamp** | `string` | ✅ | ISO 8601 datetime when message was sent |
| **pingMessageId** | `string` | optional | ID of ping message being responded to |

---

## PresenceMessage

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **messageId** | `string` | ✅ | Unique message identifier |
| **type** | `string` | ✅ | |
| **timestamp** | `string` | ✅ | ISO 8601 datetime when message was sent |
| **presence** | `object` | ✅ | Presence state |

---

## PresenceState

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **userId** | `string` | ✅ | User identifier |
| **sessionId** | `string` | ✅ | Unique session identifier |
| **status** | `Enum<'online' \| 'away' \| 'busy' \| 'offline'>` | ✅ | Current presence status |
| **lastSeen** | `string` | ✅ | ISO 8601 datetime of last activity |
| **currentLocation** | `string` | optional | Current page/route user is viewing |
| **device** | `Enum<'desktop' \| 'mobile' \| 'tablet' \| 'other'>` | optional | Device type |
| **customStatus** | `string` | optional | Custom user status message |
| **metadata** | `Record<string, any>` | optional | Additional custom presence data |

---

## PresenceUpdate

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **status** | `Enum<'online' \| 'away' \| 'busy' \| 'offline'>` | optional | Updated presence status |
| **currentLocation** | `string` | optional | Updated current location |
| **customStatus** | `string` | optional | Updated custom status message |
| **metadata** | `Record<string, any>` | optional | Updated metadata |

---

## SubscribeMessage

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **messageId** | `string` | ✅ | Unique message identifier |
| **type** | `string` | ✅ | |
| **timestamp** | `string` | ✅ | ISO 8601 datetime when message was sent |
| **subscription** | `object` | ✅ | Subscription configuration |

---

## UnsubscribeMessage

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **messageId** | `string` | ✅ | Unique message identifier |
| **type** | `string` | ✅ | |
| **timestamp** | `string` | ✅ | ISO 8601 datetime when message was sent |
| **request** | `object` | ✅ | Unsubscribe request |

---

## UnsubscribeRequest

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **subscriptionId** | `string` | ✅ | Subscription ID to unsubscribe from |

---

## WebSocketConfig

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **url** | `string` | ✅ | WebSocket server URL |
| **protocols** | `string[]` | optional | WebSocket sub-protocols |
| **reconnect** | `boolean` | optional | Enable automatic reconnection |
| **reconnectInterval** | `integer` | optional | Reconnection interval in milliseconds |
| **maxReconnectAttempts** | `integer` | optional | Maximum reconnection attempts |
| **pingInterval** | `integer` | optional | Ping interval in milliseconds |
| **timeout** | `integer` | optional | Message timeout in milliseconds |
| **headers** | `Record<string, string>` | optional | Custom headers for WebSocket handshake |

---

## WebSocketMessage

---

## WebSocketMessageType

### Allowed Values

* `subscribe`
* `unsubscribe`
* `event`
* `ping`
* `pong`
* `ack`
* `error`
* `presence`
* `cursor`
* `edit`

---

## WebSocketPresenceStatus

### Allowed Values

* `online`
* `away`
* `busy`
* `offline`

Loading
Loading