From 07b8feb4cd7656ec084f69996d9f96df9b39f02c Mon Sep 17 00:00:00 2001 From: Jack Zhuang <277994282+os-zhuang@users.noreply.github.com> Date: Tue, 2 Jun 2026 04:50:05 +0800 Subject: [PATCH] fix(platform-objects): drop unenforceable sys_user email_unique validation (#1485 regression) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #1485 trimmed the `unique`/`async`/`custom` validation-rule types from the union, but sys_user still declared `email_unique` with type: 'unique', so ObjectSchema.create threw a ZodError at load and platform-objects.test.ts (and main CI) went red. The rule was redundant — sys_user already has a unique index on email and better-auth enforces it on the managed user table — so it's removed rather than migrated. No other object uses a trimmed type. Verified: platform-objects.test.ts 52/52 pass. Co-Authored-By: Claude Opus 4.8 --- .changeset/fix-sys-user-unique-validation.md | 17 +++++++++++++++++ .../src/identity/sys-user.object.ts | 14 ++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 .changeset/fix-sys-user-unique-validation.md diff --git a/.changeset/fix-sys-user-unique-validation.md b/.changeset/fix-sys-user-unique-validation.md new file mode 100644 index 000000000..610b7ce0b --- /dev/null +++ b/.changeset/fix-sys-user-unique-validation.md @@ -0,0 +1,17 @@ +--- +'@objectstack/platform-objects': patch +--- + +Fix `sys_user` load failure after the validation-rule type trim (#1485) + +#1485 trimmed the unenforceable validation-rule types (`unique`, `async`, +`custom`) from the `ValidationRuleSchema` discriminated union, but `sys_user` +still declared an `email_unique` rule with `type: 'unique'`. Loading the object +then threw a `ZodError` ("Invalid discriminator value … at validations[0].type"), +failing `platform-objects.test.ts` and turning `main` red. + +The rule was redundant: `sys_user` already declares a unique index on `email` +(`indexes: [{ fields: ['email'], unique: true }]`), and the user table is +managed by better-auth which enforces email uniqueness at the source. Removed +the unenforceable validation rule; uniqueness remains enforced by the index. +No other object uses a trimmed validation type. diff --git a/packages/platform-objects/src/identity/sys-user.object.ts b/packages/platform-objects/src/identity/sys-user.object.ts index 380318876..1cdb327f3 100644 --- a/packages/platform-objects/src/identity/sys-user.object.ts +++ b/packages/platform-objects/src/identity/sys-user.object.ts @@ -439,14 +439,8 @@ export const SysUser = ObjectSchema.create({ mru: true, }, - validations: [ - { - name: 'email_unique', - type: 'unique', - severity: 'error', - message: 'Email must be unique', - fields: ['email'], - caseSensitive: false, - }, - ], + // Email uniqueness is enforced by the unique index above (and better-auth's + // managed user table). A declarative `unique` validation rule is intentionally + // not used — uniqueness needs a DB lookup, not a synchronous validation, so it + // is not one of the declarable validation-rule types. });