Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

fix(data-objectstack): queryDataset 返回的 fields 元素改用 spec 的 AnalyticsResult.fields[] 类型 (#3752) - #3817

Merged
yinlianghui merged 1 commit into
mainfrom
claude/issue-3752-querydataset-fields-type
Aug 8, 2026
Merged

yinlianghui merged 1 commit into
mainfrom
claude/issue-3752-querydataset-fields-type

Conversation

@yinlianghui

Copy link
Copy Markdown
Contributor

Fixes #3752

做了什么

ObjectStackAdapter.queryDataset 返回类型里 fields 的元素形状,由手写的五键改成 spec 拥有的那一个类型:

// before —— packages/data-objectstack/src/index.ts
fields: Array< { name: string; type: string; label?: string; format?: string; currency?: string } >;

// after
import type { AnalyticsResult, DatasetSelection } from '@objectstack/spec/contracts';
fields: Array< AnalyticsResult['fields'][number] >;

JSDoc 一并改写:原来那段逐项列举("a display label…, and a measure's numeral format + declared currency")本身就是第二方言的载体 —— 它和被删的类型犯的是同一个错,停在了写它那天的 spec 上。新注释指向 spec、不再复述键名,只留下"为什么只有这一项派生"的理由。

为什么漏项不是纸面问题

实装 @objectstack/spec@17.0.0-rc.5 的 AnalyticsResult.fields[] 除那五项外还有 percentScale?: PercentScale,spec 注释写明「renderers that receive it must scale by it instead of guessing from the value (objectui#3136)」。仓内三个消费端(plugin-dashboard / plugin-report / DatasetPreview)靠 @object-ui/core 的本地 DatasetResultField 读到它,所以今天不红;而按 adapter 声明的返回类型取值的外部作者会拿到 Property 'percentScale' does not exist —— 声明在把作者推回 #3136 明令禁止的"按数值大小猜刻度"。

取向:守 B,不升 A(实读 framework 路由后的结论)

派单允许在"实证服务端回全 AnalyticsResult"时升级为 A(整体交叉类型)。实读后结论相反,且证据在本仓自己这边:

  • framework(objectstack @ ea1d9165d)packages/rest/src/rest-server.ts 的 POST /analytics/dataset/query 是 res.json(result),原样下发 svc.queryDataset(...) 的结果;packages/services/service-analytics/src/analytics-service.ts:614 声明返回 Promise< AnalyticsResult >,并在 :745 起把 ADR-0021 D2 的钻取旁路(object / dimensionFields / drillRawRows / drillRawTotals / drillRanges)通过 AnalyticsResultWithDrill 加在 AnalyticsResult 之上。也就是说线上信封确实是「AnalyticsResult + 增量」。
  • 但 adapter 并不返回它收到的东西:packages/data-objectstack/src/index.ts:3355 是 return { rows, fields, object, dimensionFields, drillRawRows, totals }; —— 逐项挑键,从不拷贝 sql。所以哪怕路由回全,声明成 AnalyticsResult & { … } 也会向调用方广告一个本方法结构上永远不会给出的键(sql?: string 虽是可选,但"可能有"本身就是假声明)。

因此 A 的前提在本仓一侧就不成立,和路由回不回 sql 无关。信封其余字段保持本地声明,并把这个事实钉成测试(_NoSql),下一个读者不必再重查一遍。

类型钉子与 sabotage 自证

packages/data-objectstack/src/queryDataset.test.ts 追加一段(沿用本包 #3613 那节的 Assert / Equal 范式;本包 tsconfig 编译自己的测试树,所以这些钉子由 tsc --noEmit 承载):

  • _IsTheSpecField —— 与 spec 元素结构相等(用 Equal 而非 extends:窄化的手抄件在漂移方向上仍然可赋值)。
  • _HasPercentScale / _PercentScaleIsTheSpecUnion / _PercentScaleIsNotString —— 点名那一个漏键,并钉住它是 'fraction' | 'whole' 而不是被放宽的 string。
  • _NotTheFiveKeyCopy —— 负向钉子:把手写五键放回去就红,sabotage 方向写进测试而不是只写进 commit message。
  • _NoSql / _HasDrillObject / _HasDimensionFields / _HasDrillRawRows —— 钉住"信封不是 AnalyticsResult"这个取向。
  • 一个运行时测试:服务端回包里带 percentScale: 'fraction' 的列,经声明类型读出来仍是 'fraction'(修前这一行根本不编译)。

sabotage(临时把五键手写形状放回 index.ts,未入 commit)。预判方向:vitest 只做类型擦除、不会变红,红信号必须来自 tsc --noEmit —— 实测如此:

src/queryDataset.test.ts(282,35): error TS2344: Type 'false' does not satisfy the constraint 'true'.
src/queryDataset.test.ts(286,36): error TS2344: Type 'false' does not satisfy the constraint 'true'.
src/queryDataset.test.ts(288,25): error TS2339: Property 'percentScale' does not exist on type '{ name: string; type: string; label?: string | undefined; format?: string | undefined; currency?: string | undefined; }'.
src/queryDataset.test.ts(293,7): error TS2344: Type 'false' does not satisfy the constraint 'true'.
src/queryDataset.test.ts(293,31): error TS2339: Property 'percentScale' does not exist on type '{ … }'.
src/queryDataset.test.ts(300,7): error TS2344: Type 'false' does not satisfy the constraint 'true'.
src/queryDataset.test.ts(345,20): error TS2339: Property 'percentScale' does not exist on type '{ … }'.
src/queryDataset.test.ts(347,19): error TS2339: Property 'percentScale' does not exist on type '{ … }'.
 ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  @object-ui/data-objectstack@17.3.0 type-check: `tsc --noEmit` Exit status 2

:345 那两条正是 issue 描述的外部作者现场:读一列的 percentScale 编译不过。还原后 tsc --noEmit 无输出(绿)。

验证

  • pnpm vitest run packages/data-objectstack --maxWorkers=2 —— 24 files / 359 tests passed(含新增的 3 个断言块)。
  • pnpm --filter @object-ui/data-objectstack type-check —— 绿(钉子在这里生效)。
  • pnpm --filter @object-ui/data-objectstack lint —— 0 errors(330 个既有 no-explicit-any warning,与本改动无关)。
  • 消费半径:plugin-dashboard / plugin-report / app-shell 三个读 percentScale 的包 type-check 全绿、零改动 —— 与预期一致,它们走 @object-ui/core 的本地类型,而本改动对它们是加性的(多一个可选键)。
  • node scripts/check-control-bytes.mjs —— OK(3733 个文件);改动文件另做 grep -naP '[\x00-\x08\x0b\x0c\x0e-\x1f]' 自扫,零命中。

Changeset

.changeset/dataset-result-fields-spec-type-3752.md,@object-ui/data-objectstack: patch —— 类型面修正、对既有消费者加性,与同族的 #3753(dataset-selection-spec-type-3613.md)同档。

顺手核对与越界发现(均已单开,本 PR 不修)


Generated by Claude Code

…alyticsResult element (#3752)

The return-value half of the drift #3613/#3753 fixed on the parameter side. The
adapter hand-listed five keys for a result column (name/type/label/format/
currency) and, like every restatement, stopped at the contract of the day it was
written: it never grew percentScale, which @objectstack/spec@17.0.0-rc.5 carries
on AnalyticsResult.fields[] and documents as mandatory reading — "renderers that
receive it must scale by it instead of guessing from the value" (#3136).

Three in-repo consumers (plugin-dashboard, plugin-report, DatasetPreview) read
the key through @object-ui/core's local DatasetResultField, so nothing was red
here; but an author reading columns through the adapter's DECLARED return type
got "Property 'percentScale' does not exist" — the declaration steering them
back to the guess-by-magnitude #3136 banned.

fields is now the spec element by reference, additively for existing consumers.
The rest of the envelope stays locally declared on purpose: the route adds
ADR-0021 D2 drill metadata on top of AnalyticsResult, and this method rebuilds
its own object without copying sql (index.ts:3355), so an intersection with
AnalyticsResult would advertise a key the adapter structurally cannot return.

queryDataset.test.ts pins structural identity with the spec element, pins
percentScale as the 'fraction' | 'whole' union rather than a widened string,
keeps a negative pin against the five-key shape, pins the envelope as NOT an
AnalyticsResult, and reads percentScale off a column through the declared type
at runtime.
@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
objectui Ignored Ignored Aug 8, 2026 5:27pm

Request Review

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

✅ Console Performance Budget

Metric Value Budget
Main entry (gzip) 28.1 KB 350 KB
Entry file index-D3crvStP.js —
Status PASS —

📦 Bundle Size Report

Package Size Gzipped
app-shell (index.js) 8.66KB 3.13KB
app-shell (runtime-config.js) 7.42KB 2.32KB
app-shell (types.js) 0.01KB 0.04KB
app-shell (urlParams.js) 7.57KB 2.97KB
auth (AuthContext.js) 0.31KB 0.24KB
auth (AuthGuard.js) 1.17KB 0.53KB
auth (AuthProvider.js) 22.10KB 4.37KB
auth (AuthShell.js) 3.49KB 1.40KB
auth (ForgotPasswordForm.js) 12.21KB 3.45KB
auth (LoginForm.js) 18.13KB 5.39KB
auth (PreviewBanner.js) 0.90KB 0.50KB
auth (RegisterForm.js) 6.64KB 2.21KB
auth (SocialSignInButtons.js) 9.60KB 3.89KB
auth (UserMenu.js) 3.40KB 1.22KB
auth (auth-gate-events.js) 1.29KB 0.66KB
auth (authStyles.js) 5.04KB 1.72KB
auth (createAuthClient.js) 35.76KB 9.11KB
auth (createAuthenticatedFetch.js) 4.37KB 1.69KB
auth (index.js) 2.35KB 1.07KB
auth (org-roles.js) 6.66KB 2.78KB
auth (phone-identifier.js) 1.11KB 0.66KB
auth (types.js) 0.59KB 0.35KB
auth (useAuth.js) 4.91KB 0.87KB
auth (useIsWorkspaceAdmin.js) 1.61KB 0.85KB
collaboration (CommentThread.js) 26.07KB 7.56KB
collaboration (LiveCursors.js) 3.17KB 1.27KB
collaboration (PresenceAvatars.js) 6.49KB 2.64KB
collaboration (PresenceProvider.js) 2.79KB 1.13KB
collaboration (index.js) 1.65KB 0.73KB
collaboration (useCollaborationTranslation.js) 6.05KB 2.52KB
collaboration (useCommentSearch.js) 1.98KB 0.88KB
collaboration (useConflictResolution.js) 7.75KB 1.86KB
collaboration (useMentionNotifications.js) 1.81KB 0.68KB
collaboration (usePresence.js) 6.33KB 1.84KB
collaboration (useRealtimeSubscription.js) 7.91KB 2.01KB
components (index.js) 481.69KB 106.04KB
core (index.js) 2.96KB 1.13KB
create-plugin (index.js) 9.85KB 3.18KB
data-objectstack (index.js) 139.51KB 35.97KB
fields (index.js) 230.82KB 56.70KB
i18n (LocalizationContext.js) 1.76KB 0.96KB
i18n (currency.js) 1.22KB 0.64KB
i18n (i18n.js) 4.32KB 1.77KB
i18n (index.js) 2.65KB 1.06KB
i18n (pickLocalized.js) 1.70KB 0.83KB
i18n (provider.js) 9.48KB 3.27KB
i18n (useObjectLabel.js) 27.59KB 6.63KB
i18n (useSafeTranslation.js) 4.52KB 1.96KB
layout (index.js) 38.53KB 10.71KB
mobile (MobileProvider.js) 0.92KB 0.49KB
mobile (ResponsiveContainer.js) 0.94KB 0.38KB
mobile (breakpoints.js) 1.51KB 0.70KB
mobile (createOfflineDataSource.js) 5.61KB 1.74KB
mobile (index.js) 1.50KB 0.62KB
mobile (offlineQueue.js) 3.91KB 1.35KB
mobile (pwa.js) 0.97KB 0.49KB
mobile (serviceWorker.js) 1.48KB 0.62KB
mobile (serviceWorkerSource.js) 3.41KB 1.48KB
mobile (useBreakpoint.js) 1.54KB 0.65KB
mobile (useGesture.js) 6.96KB 1.98KB
mobile (useOfflineSync.js) 1.99KB 0.72KB
mobile (usePullToRefresh.js) 2.53KB 0.85KB
mobile (useResponsive.js) 0.71KB 0.42KB
mobile (useResponsiveConfig.js) 1.36KB 0.63KB
mobile (useSpecGesture.js) 4.32KB 1.64KB
mobile (useTouchTarget.js) 1.01KB 0.54KB
permissions (MePermissionsProvider.js) 8.75KB 3.06KB
permissions (PermissionContext.js) 0.31KB 0.25KB
permissions (PermissionGuard.js) 0.89KB 0.45KB
permissions (PermissionProvider.js) 3.67KB 1.12KB
permissions (evaluator.js) 4.41KB 1.44KB
permissions (index.js) 0.91KB 0.41KB
permissions (store.js) 0.91KB 0.42KB
permissions (useFieldPermissions.js) 1.28KB 0.52KB
permissions (usePermissions.js) 1.55KB 0.71KB
plugin-ai (index.js) 15.71KB 3.79KB
plugin-calendar (index.js) 44.98KB 12.37KB
plugin-charts (index.js) 61.04KB 17.31KB
plugin-chatbot (index.js) 180.33KB 42.79KB
plugin-dashboard (index.js) 117.21KB 30.27KB
plugin-designer (index.js) 210.51KB 42.51KB
plugin-detail (index.js) 232.99KB 57.58KB
plugin-editor (index.js) 2.46KB 1.10KB
plugin-form (index.js) 112.10KB 27.10KB
plugin-gantt (index.js) 162.55KB 39.57KB
plugin-grid (index.js) 187.71KB 49.68KB
plugin-kanban (index.js) 48.30KB 13.28KB
plugin-list (index.js) 105.12KB 25.48KB
plugin-map (index.js) 16.81KB 5.24KB
plugin-markdown (index.js) 13.72KB 4.69KB
plugin-report (index.js) 40.58KB 10.58KB
plugin-timeline (index.js) 25.76KB 7.33KB
plugin-tree (index.js) 8.50KB 2.88KB
plugin-view (index.js) 84.03KB 20.55KB
providers (DataSourceProvider.js) 0.75KB 0.39KB
providers (MetadataProvider.js) 1.37KB 0.59KB
providers (ThemeProvider.js) 1.90KB 0.85KB
providers (UploadProvider.js) 11.71KB 3.53KB
providers (index.js) 0.44KB 0.22KB
providers (types.js) 0.01KB 0.04KB
react-runtime (index.js) 5.67KB 2.37KB
react (LazyPluginLoader.js) 3.77KB 1.33KB
react (SchemaRenderer.js) 19.28KB 6.38KB
react (data-invalidation.js) 5.05KB 2.08KB
react (index.js) 1.02KB 0.55KB
react (spec-input.js) 0.20KB 0.18KB
sdui-parser (codegen.js) 4.09KB 1.74KB
sdui-parser (index.js) 4.47KB 2.03KB
sdui-parser (parse.js) 10.04KB 2.82KB
sdui-parser (types.js) 0.29KB 0.24KB
sdui-parser (validate.js) 4.69KB 1.48KB
types (ai.js) 0.20KB 0.17KB
types (api-types.js) 0.20KB 0.18KB
types (app.js) 2.87KB 0.99KB
types (base.js) 0.20KB 0.18KB
types (blocks.js) 0.20KB 0.18KB
types (complex.js) 0.20KB 0.18KB
types (crud.js) 0.20KB 0.18KB
types (data-display.js) 0.20KB 0.18KB
types (data-protocol.js) 0.20KB 0.19KB
types (data.js) 0.20KB 0.18KB
types (designer.js) 1.87KB 0.85KB
types (disclosure.js) 0.20KB 0.18KB
types (error-code.js) 1.54KB 0.88KB
types (feedback.js) 0.20KB 0.18KB
types (field-types.js) 0.20KB 0.18KB
types (form.js) 0.20KB 0.18KB
types (http-retry.js) 4.32KB 2.02KB
types (index.js) 2.71KB 1.34KB
types (layout.js) 0.20KB 0.18KB
types (managed-by.js) 0.19KB 0.18KB
types (mobile.js) 2.59KB 1.31KB
types (navigation.js) 0.20KB 0.18KB
types (objectql.js) 0.20KB 0.18KB
types (overlay.js) 0.20KB 0.18KB
types (permissions.js) 0.20KB 0.18KB
types (plugin-scope.js) 0.20KB 0.18KB
types (record-components.js) 0.20KB 0.19KB
types (record-semantics.js) 1.28KB 0.67KB
types (registry.js) 0.20KB 0.18KB
types (reports.js) 0.20KB 0.18KB
types (spec-report.js) 5.05KB 1.93KB
types (system-fields.js) 3.33KB 1.54KB
types (theme.js) 0.20KB 0.18KB
types (ui-action.js) 3.40KB 1.71KB
types (views.js) 0.20KB 0.18KB
types (widget.js) 0.20KB 0.18KB

Size Limits

  • ✅ Core packages should be < 50KB gzipped
  • ✅ Component packages should be < 100KB gzipped
  • ⚠️ Plugin packages should be < 150KB gzipped

Copy link
Copy Markdown
Contributor Author

✅ 验收通过(objectui 分片 PM,session_01GTRjn8xBqp75dk7kFupVRt)—— undraft + auto-merge。

方向裁定采纳:守 B 不升 A 的论证质量高 —— A 的前提失效点不在服务端(路由确实回全 AnalyticsResult,已实读 file:line)而在本仓 adapter 侧(index.ts:3355 逐项挑键、从不返回 sql,交叉类型会广告结构上不存在的键),并把该事实钉成 _NoSql 测试而非替服务端下断言 —— 这是比派发词更精确的 B 依据。

核验:净 diff 3 文件(PM 前跳已核);sabotage 方向先判后跑(红信号在 tsc 非 vitest,8 条错误含 issue 描述的外部作者现场两处);消费半径三包 type-check 零变化(预期=实测);19 项 CI 全绿含承载类型钉子的 Type Check。changeset patch 同族先例。dev 的 curl 假绿自曝(GH_TOKEN 空 + 无 check_runs 键读成 PENDING 0)为该失败类第五例,结论全部改由鉴权通道 —— 处置正确。衍生:#3813(adapter 丢 drillRanges,日期分桶钻取恒不可用)另行判级;#3815(core 侧 DatasetResultField 休眠漂移面)finding 在案。


Generated by Claude Code

@yinlianghui
yinlianghui marked this pull request as ready for review August 8, 2026 17:36
@yinlianghui
yinlianghui added this pull request to the merge queue Aug 8, 2026
Merged via the queue into main with commit d83f6b3 Aug 8, 2026
19 checks passed
@yinlianghui
yinlianghui deleted the claude/issue-3752-querydataset-fields-type branch August 8, 2026 17:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

data-objectstack 的 queryDataset 返回类型漏掉 fields[].percentScale,而 #3136 明令渲染端必须按它缩放

2 participants