Skip to content
Merged
18 changes: 18 additions & 0 deletions .changeset/35488-standard-unit-table-sys-unit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@objectstack/spec': patch
'@objectstack/platform-objects': patch
'@objectstack/plugin-security': patch
'@objectstack/cli': patch
---

feat(spec, platform-objects): the standard unit table and the organization unit object `sys_unit` (ADR-0158 U1–U3)

Clause-②: yes (widening)
Metadata-protocol: none

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.

- **`@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.
- **`@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.
- **`@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.
- **`@objectstack/cli`**: the organization-ownership inventory lists `sys_unit` as attributed to its organization.
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ U7 is the ruled plan; this table restates it and adds nothing.
first, and only an organization admin edits a ratio, audited.
- **A unit row's code and dimension cannot change after create** (L1, settled by the seat). A deleted code can be
created again with another dimension; what that does to resting rows is [Open item](#open-items) 11.
*Note (2026-11-19):* Open item 11 is settled: a deleted code stays retired, and the retired row keeps its code, so it
is never created again.
- **A deleted org unit leaves its rows readable** (L1, settled by the seat): they keep their code and stored
conversion and show the code without a label, and a new save with that code is refused. Which writes count as such
a save is [Open item](#open-items) 9.
Expand Down Expand Up @@ -469,11 +471,63 @@ amended with each answer, the way ADR-0144's open items were.

1. **U1's membership.** Which Rec 20 common codes the curated subset holds, each one's dimension and ratio, and which
package codes it lists. U2 fixes one code (`H87`) and refuses two (`C62`, `EA`).
*Note (2026-11-19):* settled on the `sys_unit` card
([#35488](https://github.com/objectstack-ai/objectstack/issues/35488)), under the owning seat's contract review; the
table is `packages/spec/src/data/standard-units.ts#STANDARD_UNITS`, 41 codes. Seven dimensions, the closed
vocabulary `UNIT_DIMENSIONS`; each ratio dimension has a base unit (`UNIT_DIMENSION_BASE_CODES`), whose ratio is
`1`. The ratio reads `1 CODE = ratio × BASE`, so a quantity converts to the base unit by multiplying it by the
ratio. Every ratio is a decimal string of at most 12 places, exact by definition:

| Dimension | Base | Members, with ratio |
|:--|:--|:--|
| `mass` | `KGM` | `GRM` 0.001, `MGM` 0.000001, `TNE` 1000, `LBR` 0.45359237, `ONZ` 0.028349523125 |
| `length` | `MTR` | `MMT` 0.001, `CMT` 0.01, `KMT` 1000, `INH` 0.0254, `FOT` 0.3048, `YRD` 0.9144 |
| `area` | `MTK` | `CMK` 0.0001, `MMK` 0.000001, `FTK` 0.09290304 |
| `volume` | `MTQ` | `LTR` 0.001, `MLT` 0.000001, `GLL` 0.003785411784 |
| `time` | `SEC` | `MIN` 60, `HUR` 3600, `DAY` 86400, `WEE` 604800 |
| `count` | `H87` | `PR` 2, `DZN` 12 |
| `package` | none | `XBG`, `XBE`, `XBO`, `XBX`, `XCT`, `XCS`, `XCR`, `XDR`, `XPK`, `XPX`, `XRO`, `XSA`; no ratio |

Sources: the SI prefixes (`GRM`, `MGM`, `MMT`, `CMT`, `KMT`, `CMK`, `MMK`, `MLT`) and the units accepted for use with
the SI (`TNE`, `LTR`, `MIN`, `HUR`, `DAY`), SI Brochure 9th edition, Tables 7 and 8; the international yard and
pound of 1959 (`LBR`, `ONZ` as 1/16 lb, `INH`, `FOT`, `YRD`, `FTK`); the United States gallon of 231 cubic inches
(`GLL`); Recommendation 20's own factor (`WEE`, `PR`, `DZN`). Recommendation 20 prints `ONZ` and `GLL` rounded
(2.834 952 × 10⁻² kg, 3.785 412 × 10⁻³ m³); the table holds the exact values. Left out: hectare (`HAR`), which
Recommendation 20 marks deprecated; month (`MON`) and year (`ANN`), whose Recommendation 20 factors rest on a
365.25-day year that no calendar month or year equals; and every affine unit (U7 R2). The dimension is named
`count`, not `piece`: a pair and a dozen are counts measured in pieces, as a gram is a mass measured in kilograms.
Codes, names, statuses and factors were read from the Recommendation 20 annex (the `datasets/unece-units-of-measure`
mirror, data package 17.0) and the package codes from the Peppol BIS Billing 3.0 list `UNECERec20` ("including
Recommendation 21 codes - prefixed with X", Revision 11e). The organization namespace of U3 is the same file's
`ORGANIZATION_UNIT_CODE_PATTERN`: uppercase letters, digits and underscores, starting with a letter or a digit, at
most 32 characters, at least 4 long or containing an underscore. The table widens only by an amendment of this
record.
2. **`sys_unit`'s owning package, its fields and its write grants.** Its fields beyond what U3, U6, U7 R2, L1 and L2
name, against [ADR-0029](./0029-kernel-object-ownership-and-platform-objects-decomposition.md) D1, D3 and D6.
ADR-0144 D3 left `sys_exchange_rate`'s owner to its card the same way. Its write grants: who creates, relabels and
deletes an org unit. The seat's L1 settlement names only who edits a ratio, and a delete is the act L1 attaches
refusals to.
*Note (2026-11-19):* settled on the `sys_unit` card
([#35488](https://github.com/objectstack-ai/objectstack/issues/35488)), under the owning seat's contract review,
answering [#35465](https://github.com/objectstack-ai/objectstack/issues/35465).
- **Owner: `@objectstack/platform-objects`**
(`packages/platform-objects/src/system/sys-unit.object.ts#SysUnit`), registered in its first manifest beside
`sys_exchange_rate`. ADR-0029 D3 asks for one owner per object, and this is the only one. Its readers are the
engine's write-time membership check (U5) and the display of a quantity with its unit, present in every
composition that can write or read a record, so it has no on/off boundary of its own (D2) and no capability plugin
(D1) would own it; it joins the per-organization reference table ADR-0144's Open item 11 settled into the same
package. D6's decomposition, when it comes, moves both together.
- **Fields:** `code` (text, at most 32, required, unique per organization, in U3's namespace, immutable after
create); `label` (text, at most 80, required: L2's one org-written label); `dimension` (select over U1's closed
vocabulary, required, immutable after create); `ratio` (number, scale 12, precision 24, at least 10⁻¹², required
on every dimension but `package` and refused on `package`, U1's shape; editable, an edit affecting later writes
only, L1); `decimal_places` (whole number 0 to 12, optional, the display default of U6, never a storage rule, L4);
`retired` (boolean, default false, Open item 11). `organization_id` is injected (U3). Every authored column
carries field history.
- **Grants:** every member reads (`member_default` names `sys_unit`, read only; the seat's first U3 note). An
organization owner or administrator creates, relabels, edits a ratio and retires a unit, through
`organization_admin`'s wildcard grant, the way `sys_exchange_rate` is written; no member holds a write bit. No one
deletes: retiring is the delete (Open item 11).
3. **The codes of the new refusals**: U5's membership refusal, U7 R1's aggregate refusal, U7 R2's refusal of a write
with no ratio and no factor, and the refusal of a new save with a deleted org unit's code (L1, settled by the
seat). [ADR-0112](./0112-error-code-vocabulary-and-ledger.md) sets their codes and envelope.
Expand Down Expand Up @@ -539,6 +593,23 @@ amended with each answer, the way ADR-0144's open items were.
record declines a lock for the ratio only, and L1 rules out scanning for "used", so a use check cannot close it.
For the `sys_unit` card: either a deleted code stays retired, or re-creation is admitted and its consequence is
stated. Not settled here.
*Note (2026-11-19):* settled on the `sys_unit` card
([#35488](https://github.com/objectstack-ai/objectstack/issues/35488)), under the owning seat's contract review,
answering [#35466](https://github.com/objectstack-ai/objectstack/issues/35466): **a deleted code stays retired.**
L1's delete is spelled as a one-way `retired` flag on the row. The row is never removed, so it keeps holding the
organization-scoped unique key on `code`, and the same code can never be created again with another dimension,
ratio or label; the hazard above cannot arise. The mechanism, each part pinned: the data API serves no delete on
`sys_unit`, single or batched (`enable.apiMethods` is `get`, `list`, `create`, `update`, `bulk`, and a batch admits
only a granted verb), Setup offers no Delete
(`userActions.delete: false`), and a rule refuses clearing `retired` once set. Rows resting on a retired unit keep
their code and stored conversion, as L1 states for a deleted unit. Two consequences are left to their cards: the
membership card (U5, [Open item](#open-items) 9) refuses a new save with a retired code, as L1's delete bullet
requires; and the display card says whether a resting row shows the retired unit's label, which stays on file, or
the bare code that L1 wrote for a deleted unit. Re-creation was not admitted: no measured reason favoured it, and
an organization that needs the code's old meaning back has the retired row's history, while one that needs a new
meaning names a new code. Not closed by this mechanism: `apiMethods` governs the data API, so a delete issued to the
engine directly, below that door, is not refused by it; no platform path issues one, and whether an automation
could is not measured here.
12. **R1's backfill and its raw aggregates.** The backfill mirrors `os migrate record-currency-codes` loosely. That
door writes one code, the operator's, into the rows whose code is blank
(`packages/objectql/src/record-currency-backfill.ts#backfillRecordCurrencyCodes`); the unit door rewrites free
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/utils/organization-ownership-inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,10 @@ export const ORGANIZATION_OWNERSHIP_INVENTORY: readonly InventoryEntry[] = [
// Exchange rates (`@objectstack/platform-objects`, #27185): an organization's
// administrators author its own rate table; no parent row anchors a rate.
{ object: 'sys_exchange_rate', census: PMAIN, fate: 'attribution', citation: `${CENSUS_MAIN} (in reach, added since the first census); ${D10_SINGLE}`, anchors: [] },
// Units of measure (`@objectstack/platform-objects`, ADR-0158 U3): an
// organization's administrators author its own units; the platform ships no
// row, and no parent row anchors a unit.
{ object: 'sys_unit', census: PMAIN, fate: 'attribution', citation: `${CENSUS_MAIN} (in reach, added since the first census); ${D10_SINGLE}`, anchors: [] },
// The recycle bin (`@objectstack/platform-objects`, ADR-0148, #30237): the
// engine writes each entry with the organization of the record it holds,
// else the deleting context's. A NULL row comes only from a delete with
Expand Down
11 changes: 7 additions & 4 deletions packages/cli/test/connect-agent-both-halves-wire.pin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,19 @@ describe('#17647 — Connect-an-Agent visibility: BOTH halves, over the wire', (
// Configuration; 32 until the recycle bin entry, `nav_recycle_bin`,
// joined Configuration (#30239); 33 until objectstack#34724 retired
// the Packaged Actions entry, `nav_packaged_actions`, the one entry
// `group_apps` held here, so that group collapses too.)
// `group_apps` held here, so that group collapses too; 31 until the
// Units of Measure entry, `nav_units_of_measure`, joined Configuration
// (#35488).)
// `nav_settings_branding` is not among them, and not because of a
// tenancy wall (this harness boots none): since #24766 it is
// contributed by `@objectstack/service-settings` together with the
// `branding` namespace, offered only where no organization wall stands,
// and this harness composes platform-objects and the MCP bundle alone.
expect(allowedIds).toHaveLength(31);
expect(allowedIds).toHaveLength(32);
expect(allowedIds).not.toContain('nav_packaged_actions');
expect(allowedIds).toContain('nav_settings_access_policy');
expect(allowedIds).toContain('nav_recycle_bin');
expect(allowedIds).toContain('nav_units_of_measure');
expect(allowedIds).not.toContain('nav_settings_branding');
// The two per-user stores are reached from the User record page, not
// from Setup's menu (#23803).
Expand All @@ -306,8 +309,8 @@ describe('#17647 — Connect-an-Agent visibility: BOTH halves, over the wire', (
expect(withAccountHalf.statusCode).toBe(200);
expect(withoutAccountHalf.statusCode).toBe(200);
expect(navIds(withAccountHalf.body?.item)).toEqual(navIds(withoutAccountHalf.body?.item));
// 31: the composition the count in the test above states.
expect(navIds(withAccountHalf.body?.item)).toHaveLength(31);
// 32: the composition the count in the test above states.
expect(navIds(withAccountHalf.body?.item)).toHaveLength(32);

// The mechanism behind the invariance, asserted rather than assumed:
// the bundle aims exactly one contribution at `setup` and one at
Expand Down
2 changes: 2 additions & 0 deletions packages/platform-objects/scripts/i18n-extract.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ import {
SysPlatformSettingAudit,
SysMigration,
SysExchangeRate,
SysUnit,
} from '../src/system/index.js';

// ── Existing Setup app + dashboards + translations ────────────────────────
Expand Down Expand Up @@ -360,6 +361,7 @@ const config: ObjectStackDefinition = defineStack({
SysPlatformSettingAudit,
SysMigration,
SysExchangeRate,
SysUnit,
] as any,

apps: [SETUP_APP, STUDIO_APP, ACCOUNT_APP] as any,
Expand Down
5 changes: 5 additions & 0 deletions packages/platform-objects/src/apps/setup-nav.contributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ export const SETUP_NAV_CONTRIBUTIONS: NavigationContribution[] = [
// `requiredPermissions`: the object grant decides who reads and writes
// (organization admins), and Setup itself already needs `setup.access`.
{ id: 'nav_exchange_rates', type: 'object', label: 'Exchange Rates', objectName: 'sys_exchange_rate', viewName: 'all_rates', icon: 'arrow-right-left' },
// [ADR-0158 U3] The organization's own units of measure, beside the
// exchange rates as the other per-organization reference table. No
// `requiredPermissions`: the object grant decides (every member reads,
// organization admins write), and Setup itself already needs `setup.access`.
{ id: 'nav_units_of_measure', type: 'object', label: 'Units of Measure', objectName: 'sys_unit', viewName: 'all_units', icon: 'ruler' },
{ id: 'nav_settings_company', type: 'url', label: 'Company', url: '/apps/setup/system/settings/company', icon: 'building-2' },
// `nav_settings_branding` is contributed by `@objectstack/service-settings`
// with the `branding` namespace, which is offered only where no
Expand Down
Loading
Loading