You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7411f9b
Browse filesBrowse the repository at this point in the historyBrowse files
feat(spec, platform-objects): the standard unit table and the organization unit object sys_unit (ADR-0158 U1-U3) (#35581)
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgEpYDjddvdg2ymktFMmNiYa)_Fixes#35488
Refs #35465
Refs #35466
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 管理员在设置的「配置」下多一个「计量单位」页,可以登记本组织自己的单位(比如编码“BOX_12”、名称“12
只装箱”),所有成员都能看到它的名称;平台同时内置一张约四十个国际标准单位的表(公斤、米、升、小时、件、箱等),目前还没有任何字段使用它们。
-
这是“计量单位”第一期的地基,后面的数量字段声明单位、保存时校验单位、按单位显示等卡片都会用到它;同时定下了单位表收哪些单位、新对象归哪个包、以及删除后的单位编码能不能重新启用这三个待决问题。
-
只有组织管理员能新增或修改单位,成员只能查看;单位不能真正删除,只能停用,停用后不能恢复,同一编码也不能再建一次,以免旧数据的含义被改掉;这个改动可以直接撤回,因为还没有地方读取这些数据。
- 需要你做的:无。“停用后不能恢复、编码不能重新启用”这条规则由席位在合同评审中裁决。
## 席位核对 (seat check)
- **Ruled, executed as ruled.** U1 closed constant, not a
`ValueDomainSchema` member (pinned: it keeps 3 members). U2 piece `H87`;
`C62` and `EA` absent from the table and refused as org codes. U3
`sys_unit` org-owned, `organization_id` injected (census reach `in`,
tenant field `organization_id`; the integration test reads it stamped),
zero shipped rows (pinned on the manifest), org codes at least 4
characters or containing `_`. Members read it. L1: ratio written only by
an org admin or owner, field history on every column, code and dimension
refused on change. L2: one `label` column. U6/L4/OI10: `decimal_places`
(0 to 12) on the row.
- **One reading the seat should confirm.** L1 says "delete allowed" and
OI2 says "delete: org admin"; the brief's OI11 recommendation and its
example mechanism ("a soft-retire flag instead of a hard delete") are
how this PR spells that delete: an org admin retires the row (`retired`,
one way). There is no hard delete through the data API or Setup. If the
seat reads L1 as requiring a physical delete, OI11 as recommended cannot
hold and this needs a ruling.
- **Settled here (ADR-0158 amended, dated notes).** OI1 membership: 41
codes over mass, length, area, volume, time, count and package, each
ratio an exact decimal string with scale at most 12 and a named source.
OI2: owner `platform-objects`, field list, grants. OI11: a deleted code
stays retired; mechanism and pins listed in the ADR note.
- **One file beyond the first claim (amended 7015603132).**
`packages/cli/test/connect-agent-both-halves-wire.pin.test.ts`: Test
Core 1/10 went red on `298bbb987` because that pin counts the Setup tree
at 31, and the new `nav_units_of_measure` entry makes it 32. `c890bf191`
sets both counts to 32 and asserts the entry is present.
- **Fences held.** No `unitConfig`, no field key, no write-path
membership check, no renderer, no #35498 setting.
- **Deviation from the brief's wording.** The brief lists the dimension
as "piece"; the table names it `count` (base `H87`, with `PR` and `DZN`
as multiples), because a pair and a dozen are counts, not pieces. The
reasoning is in the ADR OI1 note.
## What changes
- `@objectstack/spec` (`@objectstack/spec/data`): `STANDARD_UNITS` (41
UN/ECE Rec 20 codes), `UNIT_DIMENSIONS`, `UNIT_DIMENSION_BASE_CODES`
(`KGM`, `MTR`, `MTK`, `MTQ`, `SEC`, `H87`),
`ORGANIZATION_UNIT_CODE_PATTERN`; `sys_unit` joins
`PLATFORM_OBJECTS_BY_PACKAGE['platform-objects']`. The api-surface and
export-origins files are regenerated.
- `@objectstack/platform-objects`: `sys_unit` (code, label, dimension,
ratio scale 12, decimal_places, retired), its rules (namespace format;
code, dimension and retired one way; ratio required except on `package`
and refused on `package`), the org-scoped unique key on `code`,
`apiMethods` `get list create update bulk`, Setup → Configuration →
Units of Measure, and the translation bundles (zh-CN translated; the
other locales take the generator's English fill).
- `@objectstack/plugin-security`: `member_default` reads `sys_unit` (no
create, edit or delete).
- `@objectstack/cli`: the organization-ownership inventory lists
`sys_unit` as attributed.
- `scripts/platform-object-tenancy-census.json` is regenerated (104
registered, 53 in reach).
First files to read, by risk:
1. `packages/platform-objects/src/system/sys-unit.object.ts`, the
`validations` block and `enable.apiMethods`: these carry L1 and OI11.
2.
`packages/plugins/plugin-security/src/objects/default-permission-sets.ts`,
the `sys_unit` row in `member_default`.
3. `packages/spec/src/data/standard-units.ts`, the ratio table.
Two-minute check: `pnpm --filter @objectstack/plugin-security exec
vitest run --maxWorkers=2
src/default-permission-sets.unit-of-measure.integration.test.ts` should
print 14 passed. It boots a real stack and shows a member reading but
refused writes, an admin writing, refused codes, immutability refusals,
and re-creating a retired code refused with 409.
## Tests
All tests below ran on head `298bbb987`, with the tree byte-identical to
the commit.
<details><summary>Package suites (under the verify lock, `set
-e`)</summary>
- `@objectstack/spec`: `src/data/standard-units.test.ts`,
`src/data/api-methods-batch-conformance.test.ts`,
`platform-object-names`, `platform-tool-names` and `value-domain`: Test
Files 5 passed (5), Tests 67 passed (67).
- `@objectstack/platform-objects` full suite: Test Files 125 passed
(125), Tests 2092 passed (2092).
- `@objectstack/cli` unit layer, inventory tests: Test Files 1 passed
(1), Tests 26 passed (26). The integration layer is left to CI because
the diff does not touch it.
- `@objectstack/plugin-security` full suite: Test Files 282 passed
(282), Tests 7050 passed, 45 skipped (7095). This includes the new
`default-permission-sets.unit-of-measure.integration.test.ts` (14).
- Typecheck: `spec`, `platform-objects` and `plugin-security` gave
VERDICT command-exit 0. `cli` gave VERDICT command-exit 0.
</details>
## Acceptance notes
- **Engine-level delete is not refused.** `apiMethods` closes the data
API, and Setup offers no Delete, but a delete issued to the engine below
the REST door is not refused. No platform path issues one, and whether
an automation could is not measured. This is recorded in the ADR OI11
note.
- **`bulk` is granted.** The apiMethods batch conformance ratchet
requires it wherever single-record writes are granted. A batch admits
only granted child verbs, so a batched delete is still refused; this is
pinned in `sys-unit.object.test.ts`.
- **Locale fill.** Only zh-CN carries translated `sys_unit` strings. The
other nine locales carry the generator's English fill (nav labels are
translated in all eleven).
- **Un-retire is refused.** This is a rule, not a grant, so an
organization that retires a code by mistake cannot bring it back; it
names a new code. This is the open question to the seat.
## Verification
All readings below are on head `298bbb987`.
<details><summary>Derived gate families (110) and the --ran
reconciliation</summary>
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 110 families from the tree at
`298bbb987`. Each family was run, and the exit code was captured before
any pipe: 110 exited 0, none exited non-zero. This includes
`check:dual-build-cjs-loads` (124 entry points across 72 packages load)
and `check:i18n-coverage` ("14 config(s), 423 baselined untranslated
string(s), none new").
- `--ran` printed: "Run reconciliation — 110 derived, 110 run, 0
NOT-MEASURED, 0 UNRUN."
</details>
<details><summary>Overlap check</summary>
- `node scripts/pm/overlap-check.mjs` against origin/main `cf6bb70e2d`
merges cleanly, and so do PRs #35510 and #34223, which share files:
"VERDICT clean exit 0".
</details>
<details><summary>Not measured locally</summary>
- `check:dev-prereqs` (a local-only family) exits 1 with "The workspace
is not built — 1 unmet precondition": 35 of 108 workspace packages, all
in the UI tree, have no `dist/`. This is the container's build state,
not this diff. It is recorded as NOT MEASURED.
- The CLI `integration` layer, `test:repo`, and the repo-wide lint are
left to CI.
- Dogfood: n/a. The title has no `!`, and Clause-② is a widening.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CajiB6BSQKWowy6YLB)_
<!-- signed: repo:objectstack#5 · os-bill ·
session_01Utp6CajiB6BSQKWowy6YLB -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
feat(spec, platform-objects): the standard unit table and the organization unit object `sys_unit` (ADR-0158 U1–U3)
9
+
10
+
Clause-②: yes (widening)
11
+
Metadata-protocol: none
12
+
13
+
Units of measure, first release (ADR-0158 U7 R1). Nothing reads these tables yet: the unit declaration on a `number` field, the write-time membership check and the display of a quantity with its unit ship with their own cards. No field key ships here.
14
+
15
+
-**`@objectstack/spec`** (`@objectstack/spec/data`) exports `STANDARD_UNITS`, a closed table of 41 UN/ECE Recommendation 20 codes. Each code carries its dimension (`UNIT_DIMENSIONS`: `mass`, `length`, `area`, `volume`, `time`, `count`, `package`) and its ratio to the dimension's base unit (`UNIT_DIMENSION_BASE_CODES`: `KGM`, `MTR`, `MTK`, `MTQ`, `SEC`, `H87`), as an exact decimal string: `1 CODE = ratio × BASE`. Package codes (`XBX`, `XCT`, `XPX`, …) carry no ratio. The piece is `H87`; `C62` and `EA` are not members. `ORGANIZATION_UNIT_CODE_PATTERN` is the namespace of an organization's own codes (uppercase letters, digits and underscores, at least 4 characters or containing an underscore), which no standard code can match. `PLATFORM_OBJECTS_BY_PACKAGE['platform-objects']` gains `sys_unit`. The table is not a value domain: `ValueDomainSchema` keeps its three members.
16
+
-**`@objectstack/platform-objects`** registers `sys_unit` (Setup → Configuration → Units of Measure), an organization's own units: `code`, `label`, `dimension`, `ratio` (scale 12; required on every dimension but `package`, refused on `package`), `decimal_places` (a display default) and `retired`. It is organization-owned behind the tenant wall and ships no rows. A code outside the organization namespace is refused, the code is unique within the organization, and the code and dimension cannot change after create. A unit is retired instead of deleted, and retiring cannot be undone, so a code is never created again with another meaning; the data API serves no delete on it. Every column carries field history.
17
+
-**`@objectstack/plugin-security`**: `member_default` reads `sys_unit`, so a unit's label displays to every member; organization administrators write it through their existing grant.
18
+
-**`@objectstack/cli`**: the organization-ownership inventory lists `sys_unit` as attributed to its organization.
// Exchange rates (`@objectstack/platform-objects`, #27185): an organization's
852
852
// administrators author its own rate table; no parent row anchors a rate.
853
853
{object: 'sys_exchange_rate',census: PMAIN,fate: 'attribution',citation: `${CENSUS_MAIN} (in reach, added since the first census); ${D10_SINGLE}`,anchors: []},
854
+
// Units of measure (`@objectstack/platform-objects`, ADR-0158 U3): an
855
+
// organization's administrators author its own units; the platform ships no
856
+
// row, and no parent row anchors a unit.
857
+
{object: 'sys_unit',census: PMAIN,fate: 'attribution',citation: `${CENSUS_MAIN} (in reach, added since the first census); ${D10_SINGLE}`,anchors: []},
854
858
// The recycle bin (`@objectstack/platform-objects`, ADR-0148, #30237): the
855
859
// engine writes each entry with the organization of the record it holds,
856
860
// else the deleting context's. A NULL row comes only from a delete with
0 commit comments