feat(spec): field runtime value-shape contract — ADR-0104 phase 1 (D1)#3429
Merged
Conversation
Spec now owns the runtime value shape of every field type
(data/field-value.zod.ts): semantic type classes, the shared
isMultiValueField, and valueSchemaFor(field, 'stored' | 'expanded').
Consumers converged (each loses its private hand-copied type lists):
- objectql record-validator: derives from spec; previously-opaque types
(single references, file-likes, location/address/composite/repeater/
record/vector) get warn-first shape checks (strict via
OS_DATA_VALUE_SHAPE_STRICT_ENABLED=1); update path no longer clones
field defs so the per-def schema cache hits.
- rest import-coerce: six local sets → spec-derived.
- driver-sql: JSON_COLUMN_TYPES / NUMERIC_SCALAR_TYPES membership now
spec-derived (+ driver-internal aliases).
- qa/dogfood: field-zoo MATRIX extracted to field-zoo.matrix.ts; new
field-zoo-value-shape.test.ts pins contract ⇔ oracle (45 vectors).
Deprecated (removal rides next spec major; FROM→TO in changeset):
CurrencyValueSchema (currency IS a bare number), LocationCoordinatesSchema
(stored shape is {lat, lng} → LocationValueSchema). AddressSchema adopted
as the enforced address value contract.
Tests: spec 6834, objectql 1039, rest 331, driver-sql 284, dogfood
value-shape 45 — all green.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SHpGw3GBA9aFpfwVArRWfd
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 5 package(s): 111 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SHpGw3GBA9aFpfwVArRWfd
…orts 24 additive exports (semantic type classes, isMultiValueField, valueSchemaFor, value schemas), 0 breaking. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SHpGw3GBA9aFpfwVArRWfd
os-zhuang
marked this pull request as ready for review
July 24, 2026 11:53
This was referenced Jul 24, 2026
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
实施 ADR-0104(#3412 已合并)的 D4 阶段 1(D1):spec 拥有字段运行时值形状契约,四个消费方收敛,契约与 field-zoo oracle 互锁。
改动
新增:
packages/spec/src/data/field-value.zod.ts(经@objectstack/spec/data导出)STRING_VALUE_TYPES/NUMERIC_VALUE_TYPES/BOOLEAN_VALUE_TYPES/CALENDAR_DATE_TYPES/INSTANT_TYPES/CLOCK_TIME_TYPES/SINGLE_OPTION_TYPES/MULTI_OPTION_TYPES/REFERENCE_VALUE_TYPES/FILE_REFERENCE_TYPES/STRUCTURED_JSON_TYPES/COMPUTED_VALUE_TYPES,以及共享的MULTI_CAPABLE_TYPES+isMultiValueField(此前在 record-validator 和 import-coerce 各有一份手工拷贝)。valueSchemaFor(field, 'stored' | 'expanded'):纯推导函数,给出每个字段类型的运行时值 Zod schema;stored/expanded双形态把 lookup 的$expand原地替换多态显式命名。json等开放类型是显式决定的开放,不再是没人检查的偶然。「现实优先」处理三个死值 schema
CurrencyValueSchema@deprecated:currency 值在验证器、SQL 驱动、导入、field-zoo 全链路都是裸 number,{value,currency}从未被消费。下个 spec major 移除。LocationCoordinatesSchema@deprecated → 新LocationValueSchema({lat,lng},即实际存储形态)。AddressSchema正名采纳为address的值契约(AddressValueSchema)。四个消费方收敛(各自删掉私有类型清单)
record-validator.ts:集合与isMultiValueField改从 spec 导入;此前完全不校验的类型(单值 lookup/master_detail/user/tree、file 系、location/address/composite/repeater/record/vector)按契约做形状检查——warn-first(ADR-0104 R1/R2:违规仅告警放行,OS_DATA_VALUE_SHAPE_STRICT_ENABLED=1提前开强制,后续 minor 再翻默认);update 路径去掉字段定义克隆,使按定义身份键控的 schema 缓存(WeakMap)能命中。import-coerce.ts:六个本地集合全部改为 spec 派生(reference作为非 authorable 的遗留别名保留为本地补充)。JSON_COLUMN_TYPES/NUMERIC_SCALAR_TYPES成员改由 spec 类集合派生 + 驱动内部别名(object/array/integer/int/float)。逐项核对与原清单成员完全一致,零行为变化。field-zoo.matrix.ts伴生模块(沿用 authz-conformance 先例);新增field-zoo-value-shape.test.ts—— 45 个写入向量必须能被valueSchemaFor(stored)解析,契约与 oracle 从此互锁,单元级、不启动 stack。测试
备注
🤖 Generated with Claude Code
https://claude.ai/code/session_01SHpGw3GBA9aFpfwVArRWfd
Generated by Claude Code