-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Add WebSocket and real-time collaboration protocol specifications #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| "graphql", | ||
| "odata", | ||
| "realtime", | ||
| "router" | ||
| "router", | ||
| "websocket" | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; | ||
| 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` | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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., butpackages/spec/src/api/websocket.zod.tsexportsFilterOperator,EditOperationType,WebSocketMessageType, etc. (noSchemasuffix). Update the example to match actual exports to prevent copy/paste errors.