chore(form): T2 review — orphan --strict, @deprecated tag, magic string

This commit is contained in:
ssw committed 2026-07-28 15:55:51 +08:00
1 parent 81e1f77c1a
commit 472f310b64
3 files changed
+15 -6

No files matched your search

@@ -177,6 +177,9 @@ export async function completeRelationFormFields(
* 现 (webapi hardening) 合并为统一规则: relationForm 控件必须 3 字段齐全, 走
* `validateStrictSchema` 一处定义. 旧 API 保留为薄壳, 内部 delegate, 避免上游
* (form/update + tests/unit/form_update_fields.test.ts) 出现"两套校验" 漂移.
*
* @deprecated since v0.23 — use `validateStrictSchema` from `./_schema_normalize.ts`.
* Retained only for backward compatibility with `tests/unit/form_update_fields.test.ts`.
*/
export function validateRelationFormFields(fields: any[]): { ok: boolean; errors: string[] } {
return validateStrictSchema(fields as any)
+4 -2
View File
@@ -23,6 +23,8 @@ const CONFIG_KEYS = [
] as const
const CONFIG_KEY_SET = new Set<string>(CONFIG_KEYS)
const RELATION_FORM_KEYS = ['modelId', 'propsValue', 'relationField', 'showField', 'relationTable']
/** 控件 jnpfKey 标识: 关联表单 (web formGenerator `relationForm` 控件). */
export const RELATION_FORM_JNPF_KEY = 'relationForm'
/** relationForm 控件必填字段 (web 渲染需 modelId + propsValue + relationField 才能下拉选择). */
const RELATION_FORM_REQUIRED = ['modelId', 'propsValue', 'relationField']
/** 控件禁止 required 的集合 — mirrors web component capability matrix
@@ -72,7 +74,7 @@ export function applyNormalizedPatch(existing: FormField[], patches: Record<stri
current.__config__ = { ...current.__config__, ...normalized.__config__ }
if (previousJnpfKey === 'relationForm' && nextJnpfKey && nextJnpfKey !== previousJnpfKey) {
if (previousJnpfKey === RELATION_FORM_JNPF_KEY && nextJnpfKey && nextJnpfKey !== previousJnpfKey) {
for (const key of RELATION_FORM_KEYS) delete current.__config__[key]
}
@@ -98,7 +100,7 @@ export function validateStrictSchema(fields: FormField[]): StrictValidation {
const config = field.__config__ || {}
if (!config.jnpfKey) {
errors.push(`field ${field.__vModel__}: missing __config__.jnpfKey`)
} else if (config.jnpfKey === 'relationForm') {
} else if (config.jnpfKey === RELATION_FORM_JNPF_KEY) {
for (const k of RELATION_FORM_REQUIRED) {
if (!config[k]) errors.push(`field ${field.__vModel__}: relationForm missing ${k}`)
}
+8 -4
View File
@@ -38,7 +38,7 @@ interface Opts {
expectedState?: string
/** dirty check: 跳过校验, 强制覆盖 */
force?: boolean
/** v2.4+ (2026-07-24): strict 校验, relationForm 4 字段必填. 默认 ON, --no-strict 跳过 */
/** deprecated since v0.23 (webapi hardening): strict 校验已无条件执行, 此选项保留仅为向后兼容, 不再生效 */
strict?: boolean
json?: boolean
/** v2.1+ (2026-07-21): --verbose, addOutputOptions 注入 */
@@ -89,7 +89,11 @@ export function mergeFormFieldUpdates(existing: unknown[], updates: unknown[]):
*
* 现委托到 `_relationform_completeness.validateRelationFormFields` (合并为单一定义, 避免双套规则).
* 保留本导出仅为向后兼容 (tests/unit/form_update_fields.test.ts 已 import 此符号).
*
* @deprecated since v0.23 — use `validateStrictSchema` from `./_schema_normalize.ts`.
* This re-export exists only for backward compatibility.
*/
/** @deprecated since v0.23 use validateStrictSchema from ./_schema_normalize.ts */
export { validateRelationFormFields } from './_relationform_completeness.ts'
export function buildFormUpdateCommand(): Command {
@@ -116,8 +120,8 @@ export function buildFormUpdateCommand(): Command {
.option('--expected-enCode <e>', '期望的 enCode (与 getInfo 对比, 防止覆盖外部修改)')
.option('--expected-state <s>', '期望的 state (0/1/2, 防止覆盖外部修改)')
.option('--force', '跳过 dirty check, 强制覆盖 (慎用!)', false)
.option('--strict', 'v2.4+: 严格校验 relationForm 4 字段 (jnpfKey/modelId/propsValue/relationField) 必填. 默认 ON, --no-strict 跳过', true)
.option('--no-strict', 'v2.4+: 跳过 strict 校验 (兼容老用法, 不推荐)')
.option('--strict', 'deprecated since v0.23: strict 永远跑, 此选项保留仅为向后兼容, 不再生效 (统一走 validateStrictSchema)', true)
.option('--no-strict', 'deprecated since v0.23: 已 no-op, strict 永远跑. 仅作为迁移诊断选项保留')
addOutputOptions(cmd)
.action(async (opts: Opts) => {
setupOutputFilter(opts)
@@ -433,7 +437,7 @@ export function buildFormUpdateCommand(): Command {
'PUT 语义, 未传字段保留原值',
'自动 BS-49 enCode 唯一性检测 + BS-53 自动重新发布',
'--fields 增量合并, 按 vmodel 去重 (新增追加, 重复替换)',
'v2.4+ (2026-07-24): --strict (默认 ON) 校验 relationForm 4 字段必填. 缺字段时用 `dacli form relation-form-complete --id=<id>` 自动补',
'v0.23+ (webapi hardening): strict 校验已无条件执行 (validateStrictSchema 统一一处). --strict / --no-strict 已 deprecated, 保留仅为向后兼容. 缺字段时用 `dacli form relation-form-complete --id=<id>` 自动补',
],
})
return cmd