/** * The `money()` field descriptor — a branded schema-layer descriptor, a * sibling of `i18nText()` / `dictKey()`. It owns currency, scale, and * rounding policy for a field; the pure arithmetic lives in * {@link ./fixed-point} and default scale resolution in * {@link ./iso4217}. * * Two modes: * - **fixed** `money({ currency: 'EUR' })` — one currency for the * field; the value stores a bare scaled-integer string. * - **multi** `money({ currencies: 'any' | [...] })` — currency travels * per record; the value stores `{ amount, currency }`. * * `currency` and `currencies` are mutually exclusive. */ import type { RoundingMode } from './fixed-point.js'; import { NoydbError } from '../../kernel/errors.js'; export interface MoneyOptionsFixed { currency: string; /** Override the ISO-4217 default scale (required for unlisted codes). */ scale?: number; rounding?: RoundingMode; } export interface MoneyOptionsMulti { currencies: 'any' | readonly string[]; /** Per-currency scale overrides (required for unlisted codes). */ scaleOverrides?: Record; rounding?: RoundingMode; } export type MoneyOptions = MoneyOptionsFixed | MoneyOptionsMulti; export interface MoneyDescriptor { readonly _noydbMoney: true; /** Via port brand marker — lets a `MoneyDescriptor` satisfy the kernel's opaque `ViaDescriptor`. */ readonly _viaBrand: 'money'; readonly mode: 'fixed' | 'multi'; readonly options: MoneyOptions; readonly rounding: RoundingMode | undefined; /** The currency for fixed mode; `undefined` in multi mode. */ readonly fixedCurrency: string | undefined; /** Resolve the scale for a currency, throwing if not allowed / unknown. */ scaleFor(currency: string): number; /** Whether this descriptor permits the given currency. */ allows(currency: string): boolean; /** * The single currency this descriptor implies, if any — fixed mode, or * multi mode with exactly one allow-listed currency. Lets a multi field * accept a bare amount unambiguously. `undefined` otherwise. */ soleCurrency(): string | undefined; } /** Raised when a written value carries more precision than `scale` allows. */ export declare class MoneyPrecisionError extends NoydbError { readonly field: string; readonly value: unknown; readonly scale: number; constructor(field: string, value: unknown, scale: number); } /** Raised when a currency is disallowed or has no resolvable scale. */ export declare class MoneyCurrencyError extends NoydbError { readonly currency: string; readonly reason: 'not-allowed' | 'unknown-scale'; readonly field?: string | undefined; constructor(currency: string, reason: 'not-allowed' | 'unknown-scale', field?: string | undefined); } /** Raised when an aggregate operation is not supported on a money field. */ export declare class MoneyUnsupportedError extends NoydbError { readonly field: string; constructor(field: string, message?: string); } /** Create a {@link MoneyDescriptor}. */ export declare function money(options: MoneyOptions): MoneyDescriptor; /** Runtime predicate for detecting a {@link MoneyDescriptor}. */ export declare function isMoneyDescriptor(x: unknown): x is MoneyDescriptor;