-
Notifications
You must be signed in to change notification settings - Fork 1
Add sys_presence system object to service-realtime package #1020
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 3 commits
Commits
Show all changes
4 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
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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. | ||
|
|
||
| /** | ||
| * Realtime Service — System Object Definitions (sys namespace) | ||
| * | ||
| * Canonical ObjectSchema definitions for realtime-related system objects. | ||
| */ | ||
|
|
||
| export { SysPresence } from './sys-presence.object.js'; |
73 changes: 73 additions & 0 deletions
73
packages/services/service-realtime/src/objects/sys-presence.object.test.ts
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,73 @@ | ||
| // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. | ||
|
|
||
| import { describe, it, expect } from 'vitest'; | ||
| import { SysPresence } from './sys-presence.object'; | ||
|
|
||
| describe('SysPresence object definition', () => { | ||
| it('should have correct namespace and name', () => { | ||
| expect(SysPresence.namespace).toBe('sys'); | ||
| expect(SysPresence.name).toBe('presence'); | ||
| }); | ||
|
|
||
| it('should auto-derive tableName as sys_presence', () => { | ||
| expect(SysPresence.tableName).toBe('sys_presence'); | ||
| }); | ||
|
|
||
| it('should be a system object', () => { | ||
| expect(SysPresence.isSystem).toBe(true); | ||
| }); | ||
|
|
||
| it('should have label and pluralLabel', () => { | ||
| expect(SysPresence.label).toBe('Presence'); | ||
| expect(SysPresence.pluralLabel).toBe('Presences'); | ||
| }); | ||
|
|
||
| it('should define all presence protocol fields', () => { | ||
| const fieldKeys = Object.keys(SysPresence.fields); | ||
| expect(fieldKeys).toContain('id'); | ||
| expect(fieldKeys).toContain('created_at'); | ||
| expect(fieldKeys).toContain('updated_at'); | ||
| expect(fieldKeys).toContain('user_id'); | ||
| expect(fieldKeys).toContain('session_id'); | ||
| expect(fieldKeys).toContain('status'); | ||
| expect(fieldKeys).toContain('last_seen'); | ||
| expect(fieldKeys).toContain('current_location'); | ||
| expect(fieldKeys).toContain('device'); | ||
| expect(fieldKeys).toContain('custom_status'); | ||
| expect(fieldKeys).toContain('metadata'); | ||
| }); | ||
|
|
||
| it('should have status field with correct options', () => { | ||
| const statusField = SysPresence.fields.status; | ||
| expect(statusField.type).toBe('select'); | ||
| expect(statusField.options).toEqual([ | ||
| { value: 'online', label: 'Online' }, | ||
| { value: 'away', label: 'Away' }, | ||
| { value: 'busy', label: 'Busy' }, | ||
| { value: 'offline', label: 'Offline' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should have device field with correct options', () => { | ||
| const deviceField = SysPresence.fields.device; | ||
| expect(deviceField.type).toBe('select'); | ||
| expect(deviceField.options).toEqual([ | ||
| { value: 'desktop', label: 'Desktop' }, | ||
| { value: 'mobile', label: 'Mobile' }, | ||
| { value: 'tablet', label: 'Tablet' }, | ||
| { value: 'other', label: 'Other' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should have indexes on user_id, session_id, and status', () => { | ||
| expect(SysPresence.indexes).toEqual([ | ||
| { fields: ['user_id'], unique: false, type: 'btree' }, | ||
| { fields: ['session_id'], unique: true, type: 'btree' }, | ||
| { fields: ['status'], unique: false, type: 'btree' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should have API enabled', () => { | ||
| expect(SysPresence.enable?.apiEnabled).toBe(true); | ||
| }); | ||
| }); |
119 changes: 119 additions & 0 deletions
119
packages/services/service-realtime/src/objects/sys-presence.object.ts
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,119 @@ | ||
| // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. | ||
|
|
||
| import { ObjectSchema, Field } from '@objectstack/spec/data'; | ||
|
|
||
| /** | ||
| * sys_presence — System Presence Object | ||
| * | ||
| * Tracks real-time user presence and activity across the platform. | ||
| * Fields align with the PresenceStateSchema protocol definition | ||
| * from `@objectstack/spec/api` (websocket.zod.ts). | ||
| * | ||
| * Owned by `service-realtime` as the canonical Presence domain object. | ||
| * | ||
| * @namespace sys | ||
| * @see PresenceStateSchema in packages/spec/src/api/websocket.zod.ts | ||
| */ | ||
| export const SysPresence = ObjectSchema.create({ | ||
| namespace: 'sys', | ||
| name: 'presence', | ||
| label: 'Presence', | ||
| pluralLabel: 'Presences', | ||
| icon: 'wifi', | ||
| isSystem: true, | ||
| description: 'Real-time user presence and activity tracking', | ||
| titleFormat: '{user_id} ({status})', | ||
| compactLayout: ['user_id', 'status', 'last_seen'], | ||
|
|
||
| fields: { | ||
| id: Field.text({ | ||
| label: 'Presence ID', | ||
| required: true, | ||
| readonly: true, | ||
| }), | ||
|
|
||
| created_at: Field.datetime({ | ||
| label: 'Created At', | ||
| defaultValue: 'NOW()', | ||
| readonly: true, | ||
| }), | ||
|
|
||
| updated_at: Field.datetime({ | ||
| label: 'Updated At', | ||
| defaultValue: 'NOW()', | ||
| readonly: true, | ||
| }), | ||
|
|
||
| user_id: Field.text({ | ||
| label: 'User ID', | ||
| required: true, | ||
| searchable: true, | ||
| }), | ||
|
|
||
| session_id: Field.text({ | ||
| label: 'Session ID', | ||
| required: true, | ||
| }), | ||
|
|
||
| status: Field.select({ | ||
| label: 'Status', | ||
| required: true, | ||
| defaultValue: 'online', | ||
| options: [ | ||
| { value: 'online', label: 'Online' }, | ||
| { value: 'away', label: 'Away' }, | ||
| { value: 'busy', label: 'Busy' }, | ||
| { value: 'offline', label: 'Offline' }, | ||
| ], | ||
| }), | ||
|
|
||
| last_seen: Field.datetime({ | ||
| label: 'Last Seen', | ||
| required: true, | ||
| defaultValue: 'NOW()', | ||
| }), | ||
|
|
||
| current_location: Field.text({ | ||
| label: 'Current Location', | ||
| required: false, | ||
| maxLength: 500, | ||
| }), | ||
|
|
||
| device: Field.select({ | ||
| label: 'Device', | ||
| required: false, | ||
| options: [ | ||
| { value: 'desktop', label: 'Desktop' }, | ||
| { value: 'mobile', label: 'Mobile' }, | ||
| { value: 'tablet', label: 'Tablet' }, | ||
| { value: 'other', label: 'Other' }, | ||
| ], | ||
| }), | ||
|
|
||
| custom_status: Field.text({ | ||
| label: 'Custom Status', | ||
| required: false, | ||
| maxLength: 255, | ||
| }), | ||
|
|
||
| metadata: Field.textarea({ | ||
| label: 'Metadata', | ||
| required: false, | ||
| }), | ||
| }, | ||
|
|
||
| indexes: [ | ||
| { fields: ['user_id'], unique: false }, | ||
| { fields: ['session_id'], unique: true }, | ||
| { fields: ['status'], unique: false }, | ||
| ], | ||
|
|
||
| enable: { | ||
| trackHistory: false, | ||
| searchable: false, | ||
| apiEnabled: true, | ||
| apiMethods: ['get', 'list', 'create', 'update', 'delete'], | ||
| trash: false, | ||
| mru: false, | ||
| }, | ||
| }); | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.