Skip to content

[WIP] Add SysUserPreference system object to plugin-auth#1104

Merged
hotlong merged 2 commits intomainfrom
claude/add-sysuserpreference-object
Apr 10, 2026
Merged

[WIP] Add SysUserPreference system object to plugin-auth#1104
hotlong merged 2 commits intomainfrom
claude/add-sysuserpreference-object

Conversation

@Claude
Copy link
Copy Markdown
Contributor

@Claude Claude AI commented Apr 10, 2026

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.


This section details on the original issue you should resolve

<issue_title>在 plugin-auth 中添加 SysUserPreference 系统对象,支持用户偏好存储</issue_title>
<issue_description>## 背景

框架当前缺少用户偏好(theme、locale、timezone、sidebar 状态等)的持久化能力。Config Resolution 文档(content/docs/protocol/objectos/config-resolution.mdx)已定义了 User Preferences 作为配置分层体系的第 2 层(Runtime > User Preferences > Tenant > Env),但代码层面尚未落地对应的 object schema。

方案

直接将 user_preference 作为系统对象放入 plugin-auth——与 SysUserSysSession 等同属 identity 领域,遵循已有的 sys namespace 规范。
export const SysUserPreference = ObjectSchema.create({
namespace: 'sys',
name: 'user_preference',
label: 'User Preference',
pluralLabel: 'User Preferences',
icon: 'settings',
isSystem: true,
description: 'Per-user key-value preferences (theme, locale, etc.)',
titleFormat: '{key}',
compactLayout: ['user_id', 'key'],

fields: {
id: Field.text({
label: 'Preference 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,
  maxLength: 255,
  description: 'Owner user of this preference',
}),

key: Field.text({
  label: 'Key',
  required: true,
  maxLength: 255,
  description: 'Preference key (e.g., theme, locale, plugin.ai.auto_save)',
}),

value: Field.json({
  label: 'Value',
  description: 'Preference value (any JSON-serializable type)',
}),

},

indexes: [
{ fields: ['user_id', 'key'], unique: true },
{ fields: ['user_id'] },
],

enable: {
trackHistory: false,
searchable: false,
apiEnabled: true,
apiMethods: ['get', 'list', 'create', 'update', 'delete'],
trash: false,
mru: false,
},
});

客户端使用方式

import { SystemObjectName } from '@objectstack/spec/system';

// 读取偏好
const theme = await engine.findOne(SystemObjectName.USER_PREFERENCE, {
  where: { user_id: currentUserId, key: 'theme' },
});

// 写入偏好
await engine.upsert(SystemObjectName.USER_PREFERENCE, {
  user_id: currentUserId,
  key: 'theme',
  value: JSON.stringify('dark'),
});

// 批量读取某用户所有偏好
const allPrefs = await engine.find(SystemObjectName.USER_PREFERENCE, {
  where: { user_id: currentUserId },
});

</issue_description>

Comments on the Issue (you are @claude[agent] in this section)

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectstack-play Ready Ready Preview, Comment Apr 10, 2026 4:14am
spec Ready Ready Preview, Comment Apr 10, 2026 4:14am

Request Review

- Create sys-user-preference.object.ts with complete schema definition
- Add USER_PREFERENCE constant to SystemObjectName in spec
- Register SysUserPreference in AuthPlugin with other auth objects
- Update tests to validate new USER_PREFERENCE constant
- Support user preferences layer in Config Resolution hierarchy

Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/9ec9dd2d-4fd7-4b98-9840-031868eb27d4

Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new system object for per-user preference persistence in the auth/identity domain, aligning code with the documented Config Resolution “User Preferences” layer by introducing a canonical system name and registering the object in plugin-auth.

Changes:

  • Added SystemObjectName.USER_PREFERENCE constant (sys_user_preference) and updated its unit tests.
  • Introduced SysUserPreference system object schema (sys.user_preference) with fields and indexes suitable for key/value preference storage.
  • Registered/exported SysUserPreference via plugin-auth object exports and manifest registration.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/spec/src/system/constants/system-names.ts Adds canonical system object name constant for user preferences.
packages/spec/src/system/constants/system-names.test.ts Extends coverage to assert the new USER_PREFERENCE constant is present/correct.
packages/plugins/plugin-auth/src/objects/sys-user-preference.object.ts Defines the SysUserPreference system object schema (fields/indexes/capabilities).
packages/plugins/plugin-auth/src/objects/index.ts Exports SysUserPreference from the auth objects barrel.
packages/plugins/plugin-auth/src/auth-plugin.ts Registers SysUserPreference in the system manifest objects list.

@hotlong hotlong merged commit 86b56ea into main Apr 10, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

在 plugin-auth 中添加 SysUserPreference 系统对象,支持用户偏好存储

4 participants