Skip to content

Commit 2930942

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-g1qmlm
2 parents 962e384 + 0cd578f commit 2930942

26 files changed

Lines changed: 573 additions & 42 deletions
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/formula': minor
4+
'@objectstack/platform-objects': minor
5+
---
6+
7+
fix(spec)!: a `fixed` currency config needs its code — `currencyConfig.defaultCurrency` loses its `'CNY'` default, and a `dynamic` config parses with no code
8+
9+
Clause-②: no (narrowing)
10+
Metadata-protocol: narrowed
11+
12+
<!-- adr-0087: registered currency-config-fixed-default-currency-required, currency-config-dynamic-default-currency-removed -->
13+
14+
**BREAKING** for one shape: a `currencyConfig` with `currencyMode: 'fixed'` and no `defaultCurrency`, on a currency field or on a formula field whose `returnType` is `currency`. Ruling X on #27119: an amount whose currency is not known takes the tenant default, and nothing guesses.
15+
16+
- **Before.** `defaultCurrency` was `.default('CNY')`. `{ currencyMode: 'fixed' }` parsed to `{ currencyMode: 'fixed', defaultCurrency: 'CNY' }`, so the field silently became a yuan field and showed `¥` in a dollar or euro app. Every `dynamic` config's parse output carried that `'CNY'` too, though nothing reads a `dynamic` config's code.
17+
- **Now.** A `fixed` config without a code is refused at every door that parses a field (`defineStack`, `os validate`, the object save door), with one `custom` issue at `currencyConfig.defaultCurrency`: "`currencyConfig.currencyMode: 'fixed'` needs `defaultCurrency`, the field's one currency: give its ISO 4217 code (e.g. `defaultCurrency: 'USD'`), or use `currencyMode: 'dynamic'` to display amounts in the tenant default currency (the `localization.currency` setting)." A `dynamic` config (and an empty one) parses to `{ currencyMode: 'dynamic' }`: no code is materialized. An authored code under `dynamic` is still accepted and still unread.
18+
- **FROM → TO.** `currencyConfig: { currencyMode: 'fixed' }` → `currencyConfig: { currencyMode: 'fixed', defaultCurrency: 'USD' }` (the code the field is in; until now it displayed CNY), or `currencyMode: 'dynamic'` / no `currencyConfig` for the tenant default currency.
19+
- **The one-line fix.** Write the code next to `currencyMode: 'fixed'`.
20+
- **Stored rows and built artifacts (ADR-0087).** A built artifact holds the parsed stack, so its `fixed` configs carry the code the old parse filled in and keep it. A `sys_metadata` object row is stored as authored, so a row saved as `{ currencyMode: 'fixed' }` (Studio's Fixed mode with the code left blank, or a `/meta` write) has no code, and nothing converts one in: guessing `'CNY'` is what the ruling forbids. Such a row still loads and is registered unchanged; boot counts it `invalid` and prints `[metadata_spec_invalid] stored object/NAME fails the current spec schema even after conversion (fields.FIELD.currencyConfig.defaultCurrency: …)`, and the next save of that object is refused (422 `INVALID_METADATA` at `fields.FIELD.currencyConfig.defaultCurrency`) until the code is written. Its display does not change: the registry already held the row as stored, and the console reads a `fixed` code only when there is one, so it showed the tenant default before and still does. `@objectstack/formula` now reads a formula over that field as an unproven currency instead of fixed CNY. The D2 conversion `currency-config-dynamic-default-currency-removed` strips the unread code from `dynamic` configs (and configs with no mode) on stored-row rehydration and inside a built artifact's declared-floor window, on objects and object extensions; no display changes. It is retired from the load path, so an authored source is never rewritten. The upgrade guide entry is `currency-config-fixed-default-currency-required`.
21+
- **Readers.** None changes what it displays. The console's `resolveFieldCurrency` and the analytics field-currency relay already read the code only under `fixed`. `@objectstack/formula`'s return-type inference reads a field's currency through `CurrencyConfigSchema`; a `fixed` config without a code no longer parses there, so it reads as an unproven currency instead of CNY.
22+
- **`@objectstack/platform-objects`.** The field form's `defaultCurrency` help text says the code is required in fixed mode instead of "Defaults to CNY", in en, zh-CN, ja-JP and es-ES.
23+
24+
Survey at the change: 11 `fixed` currency configs across `examples/**`, `packages/platform-objects/**`, `packages/qa/**`, seeds and fixtures, none without a code.

‎content/docs/data-modeling/field-types.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ code lives in `currencyConfig`, never in the value.
215215
| `min` | `number` | — | Minimum value |
216216
| `max` | `number` | — | Maximum value |
217217
| `currencyConfig.currencyMode` | `'dynamic' \| 'fixed'` | `'dynamic'` | Whether the column is pinned to `defaultCurrency` (`fixed`) or displays in the tenant default currency, the `localization.currency` setting (`dynamic`); the value is a bare number either way |
218-
| `currencyConfig.defaultCurrency` | `string` | `'CNY'` | The column's currency code under `fixed`; not the displayed currency under `dynamic` |
218+
| `currencyConfig.defaultCurrency` | `string` | — | The column's currency code under `fixed`, where it is required; not the displayed currency under `dynamic` |
219219

220220
```typescript
221221
{ name: 'price', label: 'Price', type: 'currency', currencyConfig: { currencyMode: 'fixed', defaultCurrency: 'USD' } }

‎content/docs/data-modeling/validation-rules.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ These properties apply to **all** field types and are validated by the base `Fie
153153
| `min` | `number` | — | Minimum monetary value |
154154
| `max` | `number` | — | Maximum monetary value |
155155
| `currencyConfig.currencyMode` | `enum` | `dynamic` | `fixed` pins the field to `defaultCurrency`; `dynamic` displays the tenant default currency (the `localization.currency` setting). Not a per-record choice |
156-
| `currencyConfig.defaultCurrency` | `string` | `CNY` | 3-character currency code (ISO 4217 or crypto): the field's currency under `fixed`; not the displayed currency under `dynamic` |
156+
| `currencyConfig.defaultCurrency` | `string` | — | 3-character currency code (ISO 4217 or crypto): the field's currency under `fixed`, where it is required (a `fixed` config without one is refused); not the displayed currency under `dynamic` |
157157

158158
**Default constraints:** Stored as a **bare number** (a finite numeric scalar — `valueSchemaFor` routes `currency` to `z.number().finite()`); there is no `{ value, currency }` envelope on the value path. The currency **code** is never stored per record: it is field configuration, carried by `currencyConfig` above. Decimal places are the currency's ISO 4217 minor unit (2 for USD, 0 for JPY, 3 for KWD) and are declared nowhere — `currencyConfig` has no decimal-places key (`currencyConfig.precision` is refused, with a prescription to delete it), and the field-level `precision` is the total digit count, never compared with the currency.
159159

‎packages/formula/src/formula-return.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ const FIELDS: Readonly<Record<string, FormulaSourceField>> = {
3838
weighted: { type: 'formula', returnType: 'currency', currencyConfig: USD },
3939
count_formula: { type: 'formula', returnType: 'number' },
4040
broken: { type: 'currency', currencyConfig: { currencyMode: 'fixed', defaultCurrency: 'US' } },
41+
// `fixed` with no code: the spec refuses it rather than filling in CNY (#27157).
42+
fixed_no_code: { type: 'currency', currencyConfig: { currencyMode: 'fixed' } },
4143
};
4244

4345
const NAMES = Object.keys(FIELDS);
@@ -127,6 +129,8 @@ describe('CONTROL — a numeric formula stays `number`', () => {
127129
'record.flag ? record.amount : record.fee_eur',
128130
// A source whose currency does not parse names no currency.
129131
'record.broken * 2',
132+
// Nor does a fixed source with no code: it is never read as CNY (#27157).
133+
'record.fixed_no_code * 2',
130134
// A roll-up's unit is its child field's, not readable here.
131135
'record.rollup * 2',
132136
'record.amount % 3',

‎packages/formula/src/formula-return.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,16 @@ function sameCurrency(a: MoneyCurrency, b: MoneyCurrency): boolean {
129129
return a.code === b.code;
130130
}
131131

132-
/** A field's currency, read through the schema a currency field is parsed with — or `null` when it does not parse. */
132+
/**
133+
* A field's currency, read through the schema a currency field is parsed with — or `null` when it does not parse.
134+
* A `fixed` config with no code does not parse (the schema refuses it rather than filling in a code), so the
135+
* `defaultCurrency` guard below only narrows the type the refinement already guarantees.
136+
*/
133137
function currencyOf(config: unknown): MoneyCurrency | null {
134138
const parsed = CurrencyConfigSchema.safeParse(config ?? {});
135139
if (!parsed.success) return null;
136-
return parsed.data.currencyMode === 'fixed'
137-
? { mode: 'fixed', code: parsed.data.defaultCurrency }
138-
: { mode: 'dynamic' };
140+
if (parsed.data.currencyMode !== 'fixed') return { mode: 'dynamic' };
141+
return parsed.data.defaultCurrency === undefined ? null : { mode: 'fixed', code: parsed.data.defaultCurrency };
139142
}
140143

141144
/** Is `d` a number that is not an amount (a quantity or a constant)? */

‎packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ export const enMetadataForms: NonNullable<TranslationData['metadataForms']> = {
618618
},
619619
"currencyConfig.defaultCurrency": {
620620
label: "Default Currency",
621-
helpText: "The one currency of a fixed-mode field, as a three-character ISO 4217 code (e.g. USD, EUR). Defaults to CNY. Not read in dynamic mode."
621+
helpText: "The one currency of a fixed-mode field, as a three-character ISO 4217 code (e.g. USD, EUR). Required in fixed mode; nothing fills one in. Not read in dynamic mode."
622622
},
623623
step: {
624624
label: "Step",

‎packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ export const esESMetadataForms: NonNullable<TranslationData['metadataForms']> =
618618
},
619619
"currencyConfig.defaultCurrency": {
620620
label: "Moneda predeterminada",
621-
helpText: "La única moneda de un campo en modo fixed, como código ISO 4217 de tres caracteres (p. ej., USD, EUR). Por defecto, CNY. No se lee en modo dynamic."
621+
helpText: "La única moneda de un campo en modo fixed, como código ISO 4217 de tres caracteres (p. ej., USD, EUR). Obligatorio en modo fixed; no se rellena automáticamente. No se lee en modo dynamic."
622622
},
623623
step: {
624624
label: "Incremento",

‎packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ export const jaJPMetadataForms: NonNullable<TranslationData['metadataForms']> =
618618
},
619619
"currencyConfig.defaultCurrency": {
620620
label: "既定の通貨",
621-
helpText: "fixed モードのフィールドの通貨。3 文字の ISO 4217 コード(例:USD、EUR)で指定します。既定は CNY です。dynamic モードでは参照されません。"
621+
helpText: "fixed モードのフィールドの通貨。3 文字の ISO 4217 コード(例:USD、EUR)で指定します。fixed モードでは必須で、自動では補われません。dynamic モードでは参照されません。"
622622
},
623623
step: {
624624
label: "ステップ値",

‎packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ export const zhCNMetadataForms: NonNullable<TranslationData['metadataForms']> =
618618
},
619619
"currencyConfig.defaultCurrency": {
620620
label: "默认货币",
621-
helpText: "fixed 模式字段的唯一货币,使用三个字符的 ISO 4217 代码(例如 USD、EUR)。默认为 CNY。dynamic 模式下不读取。"
621+
helpText: "fixed 模式字段的唯一货币,使用三个字符的 ISO 4217 代码(例如 USD、EUR)。fixed 模式下必填,不会自动填入。dynamic 模式下不读取。"
622622
},
623623
step: {
624624
label: "步进值",

‎packages/spec/authorable-defaults/data.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"data/CrossFieldValidation:severity = \"error\"",
1313
"data/Cube:public = true",
1414
"data/CurrencyConfig:currencyMode = \"dynamic\"",
15-
"data/CurrencyConfig:defaultCurrency = \"CNY\"",
1615
"data/DataEngineDeleteOptions:multi = false",
1716
"data/DataEngineInsertOptions:returning = true",
1817
"data/DataEngineUpdateOptions:multi = false",

0 commit comments

Comments
 (0)