@fintekkers/ledger-models 1.1.20 → 1.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/hierarchy.json +19 -2
  2. package/node/wrappers/models/errors.d.ts +30 -0
  3. package/node/wrappers/models/errors.js +39 -1
  4. package/node/wrappers/models/errors.js.map +1 -1
  5. package/node/wrappers/models/errors.ts +44 -0
  6. package/node/wrappers/models/security/TreasuryFrnFixings.js +5 -0
  7. package/node/wrappers/models/security/TreasuryFrnFixings.js.map +1 -1
  8. package/node/wrappers/models/security/TreasuryFrnFixings.ts +5 -0
  9. package/node/wrappers/models/security/product_input_builders.test.d.ts +1 -0
  10. package/node/wrappers/models/security/product_input_builders.test.js +192 -0
  11. package/node/wrappers/models/security/product_input_builders.test.js.map +1 -0
  12. package/node/wrappers/models/security/product_input_builders.test.ts +192 -0
  13. package/node/wrappers/models/security/product_inputs.d.ts +79 -0
  14. package/node/wrappers/models/security/product_inputs.js +290 -0
  15. package/node/wrappers/models/security/product_inputs.js.map +1 -0
  16. package/node/wrappers/models/security/product_inputs.test.d.ts +1 -0
  17. package/node/wrappers/models/security/product_inputs.test.js +144 -0
  18. package/node/wrappers/models/security/product_inputs.test.js.map +1 -0
  19. package/node/wrappers/models/security/product_inputs.test.ts +141 -0
  20. package/node/wrappers/models/security/product_inputs.ts +308 -0
  21. package/node/wrappers/requests/valuation/ValuationRequests.d.ts +21 -0
  22. package/node/wrappers/requests/valuation/ValuationRequests.js +33 -0
  23. package/node/wrappers/requests/valuation/ValuationRequests.js.map +1 -0
  24. package/node/wrappers/requests/valuation/ValuationRequests.ts +37 -0
  25. package/node/wrappers/util/object-types.test.js +6 -1
  26. package/node/wrappers/util/object-types.test.js.map +1 -1
  27. package/node/wrappers/util/object-types.test.ts +9 -1
  28. package/package.json +1 -1
@@ -0,0 +1,141 @@
1
+ /**
2
+ * LM-409: valuation_arms in hierarchy.json, resolved by armFor /
3
+ * requiredMarketData.
4
+ *
5
+ * The shared cases live in ledger-models-protos/fixtures/valuation_arms_cases.json,
6
+ * read by the Java, Python and Rust tests too.
7
+ */
8
+ import * as fs from 'fs';
9
+ import * as path from 'path';
10
+
11
+ import { armFor, parseValuationArms, requiredMarketData, shippedValuationArms } from './product_inputs';
12
+ import { descendantsOf } from './product_hierarchy';
13
+ import { UnmappedProductTypeError } from '../errors';
14
+ import { CouponTypeProto } from '../../../fintekkers/models/security/coupon_type_pb';
15
+ import { ProductTypeProto } from '../../../fintekkers/models/security/product_type_pb';
16
+ import { BondDetailsProto, SecurityProto } from '../../../fintekkers/models/security/security_pb';
17
+
18
+ const PROTOS = path.resolve(__dirname, '../../../../../ledger-models-protos');
19
+ const BUNDLED = path.resolve(__dirname, '../../../../hierarchy.json');
20
+
21
+ interface Case {
22
+ product_type: string;
23
+ coupon_type: string;
24
+ arm?: string;
25
+ requires?: string[];
26
+ error?: string;
27
+ }
28
+
29
+ const cases: Case[] = JSON.parse(
30
+ fs.readFileSync(path.join(PROTOS, 'fixtures/valuation_arms_cases.json'), 'utf-8'),
31
+ ).cases;
32
+
33
+ function sourceSection(): any {
34
+ return JSON.parse(fs.readFileSync(path.join(PROTOS, 'hierarchy.json'), 'utf-8')).valuation_arms;
35
+ }
36
+
37
+ function hasEnumValue(productType: string): boolean {
38
+ return Object.prototype.hasOwnProperty.call(ProductTypeProto, productType);
39
+ }
40
+
41
+ function security(productType: string, couponType: string): SecurityProto {
42
+ const details = new BondDetailsProto();
43
+ details.setCouponType(CouponTypeProto[couponType as keyof typeof CouponTypeProto]);
44
+ const s = new SecurityProto();
45
+ s.setProductType(ProductTypeProto[productType as keyof typeof ProductTypeProto]);
46
+ s.setBondDetails(details);
47
+ return s;
48
+ }
49
+
50
+ /** [arm, requires] through a real proto when the type has an enum value; planned leaves by name. */
51
+ function resolve(productType: string, couponType: string): [string, string[]] {
52
+ if (!hasEnumValue(productType)) {
53
+ const a = shippedValuationArms().require(productType, couponType);
54
+ return [a.arm, [...a.requires]];
55
+ }
56
+ const s = security(productType, couponType);
57
+ return [armFor(s), requiredMarketData(s)];
58
+ }
59
+
60
+ function catchUnmapped(fn: () => unknown): UnmappedProductTypeError {
61
+ try {
62
+ fn();
63
+ } catch (e) {
64
+ if (e instanceof UnmappedProductTypeError) return e;
65
+ throw e;
66
+ }
67
+ throw new Error('expected UnmappedProductTypeError');
68
+ }
69
+
70
+ describe('valuation_arms shared fixture (metric 1)', () => {
71
+ test('has the required cases', () => {
72
+ expect(cases.length).toBeGreaterThanOrEqual(5);
73
+ const seen = cases.map(c => `${c.product_type}/${c.coupon_type}`);
74
+ expect(seen).toEqual(expect.arrayContaining([
75
+ 'TBILL/ZERO', 'TIPS/FIXED', 'CORP_BOND/FLOAT', 'TREASURY_NOTE/FLOAT', 'FX_SPOT/UNKNOWN_COUPON_TYPE',
76
+ ]));
77
+ });
78
+
79
+ test.each(cases.map(c => [`${c.product_type}/${c.coupon_type}`, c] as [string, Case]))('%s', (_, c) => {
80
+ if (c.error !== undefined) {
81
+ expect(c.error).toBe('UnmappedProductTypeError');
82
+ const e = catchUnmapped(() => resolve(c.product_type, c.coupon_type));
83
+ expect([e.productType, e.couponType]).toEqual([c.product_type, c.coupon_type]);
84
+ } else {
85
+ expect(resolve(c.product_type, c.coupon_type)).toEqual([c.arm, c.requires]);
86
+ }
87
+ });
88
+ });
89
+
90
+ describe('unmapped types raise (metric 2)', () => {
91
+ const unmapped = new Set(['FX_SPOT']);
92
+ for (const root of ['INDEX', 'CRYPTO', 'COMMODITY_SPOT']) {
93
+ for (const n of descendantsOf(root)) if (descendantsOf(n).length === 0) unmapped.add(n);
94
+ }
95
+
96
+ test('the set comes from the registry', () => {
97
+ expect([...unmapped]).toEqual(expect.arrayContaining([
98
+ 'FX_SPOT', 'COMMODITY_INDEX', 'PLATINUM', 'PALLADIUM', 'CRYPTOCURRENCY', 'GOLD',
99
+ ]));
100
+ });
101
+
102
+ test.each([...unmapped].sort())('%s', pt => {
103
+ const e = catchUnmapped(() => resolve(pt, 'UNKNOWN_COUPON_TYPE'));
104
+ expect(e.message).toContain(pt);
105
+ expect(e.message).toContain('UNKNOWN_COUPON_TYPE');
106
+ });
107
+
108
+ test('message names product and coupon type', () => {
109
+ const gold = security('GOLD', 'FLOAT');
110
+ const e = catchUnmapped(() => armFor(gold));
111
+ expect(e.message).toContain('GOLD');
112
+ expect(e.message).toContain('FLOAT');
113
+ expect(() => requiredMarketData(gold)).toThrow(UnmappedProductTypeError);
114
+ });
115
+
116
+ test('unset bond_details reads as UNKNOWN_COUPON_TYPE', () => {
117
+ const corp = new SecurityProto();
118
+ corp.setProductType(ProductTypeProto.CORP_BOND);
119
+ expect(armFor(corp)).toBe('bond');
120
+ const fx = new SecurityProto();
121
+ fx.setProductType(ProductTypeProto.FX_SPOT);
122
+ expect(catchUnmapped(() => armFor(fx)).couponType).toBe('UNKNOWN_COUPON_TYPE');
123
+ });
124
+ });
125
+
126
+ test('bundled valuation_arms equals the source (metric 4)', () => {
127
+ expect(fs.existsSync(BUNDLED)).toBe(true);
128
+ const bundled = JSON.parse(fs.readFileSync(BUNDLED, 'utf-8'));
129
+ expect(bundled.valuation_arms).toBeDefined();
130
+ expect(bundled.valuation_arms).toEqual(sourceSection());
131
+ });
132
+
133
+ test('parse rejects a requires value outside the vocabulary (metric 5)', () => {
134
+ const section = sourceSection();
135
+ section.entries[0].requires.push('FX_RATE');
136
+ expect(() => parseValuationArms(section)).toThrow(/FX_RATE/);
137
+ });
138
+
139
+ test('every leaf is covered (metric 3)', () => {
140
+ expect(shippedValuationArms().uncoveredLeaves()).toEqual([]);
141
+ });
@@ -0,0 +1,308 @@
1
+ /**
2
+ * Which ProductInput arm values a security, and which market data that arm
3
+ * needs. Backed by the valuation_arms section of
4
+ * ledger-models-protos/hierarchy.json; there is no mapping table in code.
5
+ * Same rule in Java / Rust / Python / JS-TS. See docs/adr/valuation_arms.md.
6
+ *
7
+ * Resolution walks from the security's product_type up its parent chain. At
8
+ * each node a coupon_types entry matching bond_details.coupon_type wins, then
9
+ * the node's plain entry, then an unpriced listing. The first node with any
10
+ * match decides. No match, or an unpriced match, throws
11
+ * UnmappedProductTypeError: there is no default arm. A broken section throws
12
+ * a plain Error at load, like product_hierarchy.
13
+ *
14
+ * forSecurity builds the ProductInput for that arm from a security, its price
15
+ * and its market data; checkProductInput checks a ProductInput against the
16
+ * same rule (LM-410). See docs/adr/product_input_builders.md.
17
+ */
18
+
19
+ import hierarchy from '../../../../hierarchy.json';
20
+ import { CouponTypeProto } from '../../../fintekkers/models/security/coupon_type_pb';
21
+ import { ProductTypeProto } from '../../../fintekkers/models/security/product_type_pb';
22
+ import { PriceProto } from '../../../fintekkers/models/price/price_pb';
23
+ import { SecurityProto } from '../../../fintekkers/models/security/security_pb';
24
+ import {
25
+ BondInput, CashInput, EquityInput, FrnInput, InflationIndexInput, MbsInput, ProductInput,
26
+ ReferenceRateFixingProto, TipsInput, YieldCurveInput,
27
+ } from '../../../fintekkers/requests/valuation/product_inputs_pb';
28
+ import { MissingMarketDataError, ModelValidationError, UnmappedProductTypeError, violation } from '../errors';
29
+ import { UUID } from '../utils/uuid';
30
+ import { allProductTypes, descendantsOf, parentOf } from './product_hierarchy';
31
+
32
+ /** The closed requires vocabulary: market data an arm needs beyond the price. */
33
+ export type MarketDataKind = 'CPI_U' | 'FRN_FIXINGS' | 'FRN_CURVE';
34
+
35
+ const MARKET_DATA_KINDS: ReadonlyArray<string> = ['CPI_U', 'FRN_FIXINGS', 'FRN_CURVE'];
36
+
37
+ /** Map key for a node's entry with no coupon_types. */
38
+ const ANY_COUPON = '';
39
+
40
+ interface Arm {
41
+ arm: string;
42
+ requires: ReadonlyArray<MarketDataKind>;
43
+ }
44
+
45
+ function hasOwn(o: object, key: string): boolean {
46
+ return Object.prototype.hasOwnProperty.call(o, key);
47
+ }
48
+
49
+ function enumName(e: object, value: number): string {
50
+ for (const [k, v] of Object.entries(e)) {
51
+ if (v === value) return k;
52
+ }
53
+ return String(value);
54
+ }
55
+
56
+ /** A parsed, checked valuation_arms section. */
57
+ export class ValuationArms {
58
+ /** @param entries node -> coupon type name (or '' for the plain entry) -> arm */
59
+ constructor(
60
+ private readonly entries: Map<string, Map<string, Arm>>,
61
+ private readonly unpriced: ReadonlySet<string>,
62
+ ) {}
63
+
64
+ /** The deepest matching node's arm, or null when unmapped or unpriced. */
65
+ resolve(productType: string, couponType: string): Arm | null {
66
+ for (let node: string | null = productType; node !== null; node = parentOf(node)) {
67
+ const byCoupon = this.entries.get(node);
68
+ const arm = byCoupon?.get(couponType) ?? byCoupon?.get(ANY_COUPON);
69
+ if (arm) return arm;
70
+ if (this.unpriced.has(node)) return null;
71
+ }
72
+ return null;
73
+ }
74
+
75
+ require(productType: string, couponType: string): Arm {
76
+ const arm = this.resolve(productType, couponType);
77
+ if (!arm) throw new UnmappedProductTypeError(productType, couponType);
78
+ return arm;
79
+ }
80
+
81
+ /** Leaf product types (active and planned) with neither an entry nor an unpriced listing. */
82
+ uncoveredLeaves(): string[] {
83
+ return allProductTypes().filter(n => descendantsOf(n).length === 0 && !this.covers(n));
84
+ }
85
+
86
+ private covers(productType: string): boolean {
87
+ for (let node: string | null = productType; node !== null; node = parentOf(node)) {
88
+ if (this.entries.has(node) || this.unpriced.has(node)) return true;
89
+ }
90
+ return false;
91
+ }
92
+ }
93
+
94
+ function bad(detail: string): Error {
95
+ return new Error(`hierarchy.json valuation_arms: ${detail}`);
96
+ }
97
+
98
+ function stringOf(body: Record<string, unknown>, key: string): string {
99
+ const v = body[key];
100
+ if (typeof v !== 'string') throw bad(`'${key}' must be a string in ${JSON.stringify(body)}`);
101
+ return v;
102
+ }
103
+
104
+ function stringsOf(body: Record<string, unknown>, key: string): string[] {
105
+ const v = body[key];
106
+ if (!Array.isArray(v) || !v.every(x => typeof x === 'string')) {
107
+ throw bad(`'${key}' must be a list of strings in ${JSON.stringify(body)}`);
108
+ }
109
+ return v as string[];
110
+ }
111
+
112
+ /**
113
+ * Parses and checks a valuation_arms section against the shipped
114
+ * product_types tree, the ProductInput oneof and the CouponTypeProto /
115
+ * MarketDataKind vocabularies. Throws on any failure. Exported for tests.
116
+ */
117
+ export function parseValuationArms(section: unknown): ValuationArms {
118
+ if (typeof section !== 'object' || section === null || Array.isArray(section)) {
119
+ throw bad('section must be an object');
120
+ }
121
+ const s = section as Record<string, unknown>;
122
+ const productTypes = new Set(allProductTypes());
123
+ const arms = new Set(Object.keys(ProductInput.InputCase)
124
+ .filter(k => k !== 'INPUT_NOT_SET')
125
+ .map(k => k.toLowerCase()));
126
+
127
+ if (!Array.isArray(s.entries)) throw bad("'entries' must be a list");
128
+ const entries = new Map<string, Map<string, Arm>>();
129
+ for (const raw of s.entries as unknown[]) {
130
+ if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
131
+ throw bad(`entry must be an object, got ${JSON.stringify(raw)}`);
132
+ }
133
+ const body = raw as Record<string, unknown>;
134
+ const node = stringOf(body, 'node');
135
+ if (!productTypes.has(node)) throw bad(`node '${node}' is not in product_types`);
136
+ const arm = stringOf(body, 'arm');
137
+ if (!arms.has(arm)) throw bad(`arm '${arm}' is not a ProductInput.input field`);
138
+ const requires = stringsOf(body, 'requires').map(r => {
139
+ if (!MARKET_DATA_KINDS.includes(r)) {
140
+ throw bad(`requires value '${r}' is not one of CPI_U, FRN_FIXINGS, FRN_CURVE`);
141
+ }
142
+ return r as MarketDataKind;
143
+ });
144
+ let coupons = [ANY_COUPON];
145
+ if (hasOwn(body, 'coupon_types')) {
146
+ coupons = stringsOf(body, 'coupon_types');
147
+ for (const c of coupons) {
148
+ if (!hasOwn(CouponTypeProto, c)) throw bad(`coupon_types value '${c}' is not a CouponTypeProto name`);
149
+ }
150
+ }
151
+ let byCoupon = entries.get(node);
152
+ if (!byCoupon) {
153
+ byCoupon = new Map();
154
+ entries.set(node, byCoupon);
155
+ }
156
+ const value: Arm = Object.freeze({ arm, requires: Object.freeze(requires) });
157
+ for (const c of coupons) {
158
+ if (byCoupon.has(c)) throw bad(`duplicate entry for node ${node}${c ? `, coupon_type ${c}` : ''}`);
159
+ byCoupon.set(c, value);
160
+ }
161
+ }
162
+
163
+ const unpriced = new Set<string>();
164
+ for (const node of stringsOf(s, 'unpriced')) {
165
+ if (!productTypes.has(node)) throw bad(`node '${node}' is not in product_types`);
166
+ if (entries.has(node)) throw bad(`node ${node} is both mapped and unpriced`);
167
+ unpriced.add(node);
168
+ }
169
+ return new ValuationArms(entries, unpriced);
170
+ }
171
+
172
+ let shippedArms: ValuationArms | undefined;
173
+
174
+ /** The shipped valuation_arms section, parsed and checked on first use. Exported for tests. */
175
+ export function shippedValuationArms(): ValuationArms {
176
+ if (!shippedArms) {
177
+ const section = (hierarchy as Record<string, unknown>).valuation_arms;
178
+ if (section === undefined) throw bad('section missing from hierarchy.json');
179
+ shippedArms = parseValuationArms(section);
180
+ }
181
+ return shippedArms;
182
+ }
183
+
184
+ function productTypeOf(security: SecurityProto): string {
185
+ return enumName(ProductTypeProto, security.getProductType());
186
+ }
187
+
188
+ /** Read from the proto field only; unset bond_details reads as UNKNOWN_COUPON_TYPE. */
189
+ function couponTypeOf(security: SecurityProto): string {
190
+ const details = security.getBondDetails();
191
+ return details ? enumName(CouponTypeProto, details.getCouponType()) : 'UNKNOWN_COUPON_TYPE';
192
+ }
193
+
194
+ /** Name of the ProductInput.input oneof field that values `security`, e.g. 'tips'. */
195
+ export function armFor(security: SecurityProto): string {
196
+ return shippedValuationArms().require(productTypeOf(security), couponTypeOf(security)).arm;
197
+ }
198
+
199
+ /** Market data the security's arm needs, in file order. A fresh array; empty when none. */
200
+ export function requiredMarketData(security: SecurityProto): MarketDataKind[] {
201
+ return [...shippedValuationArms().require(productTypeOf(security), couponTypeOf(security)).requires];
202
+ }
203
+
204
+ /**
205
+ * Market data for forSecurity, one field per MarketDataKind: CPI_U is `cpi`,
206
+ * FRN_FIXINGS is `fixings`, FRN_CURVE is `curve`. Each is copied to the arm
207
+ * field of the same name (TipsInput.cpi, FrnInput.fixings, FrnInput.curve)
208
+ * when the arm has one; the others are ignored.
209
+ */
210
+ export interface MarketData {
211
+ cpi?: InflationIndexInput;
212
+ fixings?: ReferenceRateFixingProto[];
213
+ curve?: YieldCurveInput;
214
+ }
215
+
216
+ /**
217
+ * The ProductInput for `security`, in the arm armFor picks.
218
+ *
219
+ * Sets the arm's security and copies price.price as is into clean_price
220
+ * (bond, tips, frn, mbs) or unit_price (equity, cash). Never sets
221
+ * cost_basis. Throws UnmappedProductTypeError when the type has no arm and
222
+ * MissingMarketDataError when `marketData` lacks a kind the arm requires.
223
+ * The caller's protos are set as they are, not copied or stamped (LM-322).
224
+ */
225
+ export function forSecurity(security: SecurityProto, price: PriceProto, marketData?: MarketData | null): ProductInput {
226
+ const md = marketData ?? {};
227
+ const arm = armFor(security);
228
+ const p = price.getPrice();
229
+ const out = new ProductInput();
230
+ switch (arm) {
231
+ case 'bond':
232
+ out.setBond(new BondInput().setSecurity(security).setCleanPrice(p));
233
+ break;
234
+ case 'tips':
235
+ out.setTips(new TipsInput().setSecurity(security).setCleanPrice(p).setCpi(md.cpi));
236
+ break;
237
+ case 'frn':
238
+ out.setFrn(new FrnInput().setSecurity(security).setCleanPrice(p).setCurve(md.curve)
239
+ .setFixingsList([...(md.fixings ?? [])]));
240
+ break;
241
+ case 'mbs':
242
+ out.setMbs(new MbsInput().setSecurity(security).setCleanPrice(p));
243
+ break;
244
+ case 'equity':
245
+ out.setEquity(new EquityInput().setSecurity(security).setUnitPrice(p));
246
+ break;
247
+ case 'cash':
248
+ out.setCash(new CashInput().setSecurity(security).setUnitPrice(p));
249
+ break;
250
+ default:
251
+ throw new Error(`forSecurity has no builder for arm ${arm}`);
252
+ }
253
+ checkProductInput(out);
254
+ return out;
255
+ }
256
+
257
+ /**
258
+ * Checks `productInput` is the arm armFor picks for its security, and holds
259
+ * every market-data kind that arm requires. Throws ModelValidationError (no
260
+ * arm, or the wrong arm), UnmappedProductTypeError or MissingMarketDataError.
261
+ */
262
+ export function checkProductInput(productInput: ProductInput): void {
263
+ const [arm, body] = armOf(productInput);
264
+ if (!body) throw new ModelValidationError([violation('product_input', undefined, 'no ProductInput arm is set')]);
265
+ const security = body.getSecurity() ?? new SecurityProto();
266
+ const productType = productTypeOf(security);
267
+ const resolved = shippedValuationArms().require(productType, couponTypeOf(security));
268
+ if (resolved.arm !== arm) {
269
+ throw new ModelValidationError([violation(`product_input.${arm}`, uuidOf(security),
270
+ `arm ${arm} does not match arm ${resolved.arm} for product_type ${productType}`)]);
271
+ }
272
+ for (const kind of resolved.requires) {
273
+ if (!has(productInput, kind)) throw new MissingMarketDataError(arm, kind, `${arm}.${FIELD_OF[kind]}`, uuidOf(security));
274
+ }
275
+ }
276
+
277
+ /** The set arm's name and message, or [undefined, undefined] when none is set. */
278
+ function armOf(input: ProductInput): [string, { getSecurity(): SecurityProto | undefined }] | [undefined, undefined] {
279
+ switch (input.getInputCase()) {
280
+ case ProductInput.InputCase.BOND: return ['bond', input.getBond()!];
281
+ case ProductInput.InputCase.TIPS: return ['tips', input.getTips()!];
282
+ case ProductInput.InputCase.FRN: return ['frn', input.getFrn()!];
283
+ case ProductInput.InputCase.MBS: return ['mbs', input.getMbs()!];
284
+ case ProductInput.InputCase.EQUITY: return ['equity', input.getEquity()!];
285
+ case ProductInput.InputCase.CASH: return ['cash', input.getCash()!];
286
+ default: return [undefined, undefined];
287
+ }
288
+ }
289
+
290
+ /** The ProductInput arm field (and MarketData field) that holds each kind. */
291
+ const FIELD_OF: Readonly<Record<MarketDataKind, string>> = { CPI_U: 'cpi', FRN_FIXINGS: 'fixings', FRN_CURVE: 'curve' };
292
+
293
+ /** Whether `input` holds `kind`. A cpi with neither readings nor reference_cpi does not count. */
294
+ function has(input: ProductInput, kind: MarketDataKind): boolean {
295
+ switch (kind) {
296
+ case 'CPI_U': {
297
+ const cpi = input.getTips()?.getCpi();
298
+ return cpi !== undefined && cpi.getCpiCase() !== InflationIndexInput.CpiCase.CPI_NOT_SET;
299
+ }
300
+ case 'FRN_FIXINGS': return (input.getFrn()?.getFixingsList().length ?? 0) > 0;
301
+ case 'FRN_CURVE': return input.getFrn()?.hasCurve() ?? false;
302
+ }
303
+ }
304
+
305
+ function uuidOf(security: SecurityProto): UUID | undefined {
306
+ const raw = security.getUuid()?.getRawUuid_asU8();
307
+ return raw && raw.length === 16 ? UUID.fromU8Array(raw) : undefined;
308
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Typed valuation requests (LM-410). Same rule in Java / Rust / Python /
3
+ * JS-TS. See docs/adr/product_input_builders.md.
4
+ */
5
+ import { MeasureProto } from '../../../fintekkers/models/position/measure_pb';
6
+ import { PositionProto } from '../../../fintekkers/models/position/position_pb';
7
+ import { LocalTimestampProto } from '../../../fintekkers/models/util/local_timestamp_pb';
8
+ import { ProductInput } from '../../../fintekkers/requests/valuation/product_inputs_pb';
9
+ import { ValuationRequestProto } from '../../../fintekkers/requests/valuation/valuation_request_pb';
10
+ export declare class ValuationRequests {
11
+ /**
12
+ * A ValuationRequestProto valued from `productInput` alone.
13
+ *
14
+ * Sets asof_datetime (23), measures (30), position_input (21) and
15
+ * product_input (70). Never sets security_input (20) or price_input (22).
16
+ * `productInput` is checked with checkProductInput first, so a tips input
17
+ * with no cpi throws MissingMarketDataError here too. The caller's protos
18
+ * are set as they are, not stamped (LM-322).
19
+ */
20
+ static typed(asof: LocalTimestampProto | undefined, productInput: ProductInput, position: PositionProto | undefined, measures: MeasureProto[]): ValuationRequestProto;
21
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValuationRequests = void 0;
4
+ const valuation_request_pb_1 = require("../../../fintekkers/requests/valuation/valuation_request_pb");
5
+ const errors_1 = require("../../models/errors");
6
+ const product_inputs_1 = require("../../models/security/product_inputs");
7
+ const object_types_1 = require("../../util/object-types");
8
+ class ValuationRequests {
9
+ /**
10
+ * A ValuationRequestProto valued from `productInput` alone.
11
+ *
12
+ * Sets asof_datetime (23), measures (30), position_input (21) and
13
+ * product_input (70). Never sets security_input (20) or price_input (22).
14
+ * `productInput` is checked with checkProductInput first, so a tips input
15
+ * with no cpi throws MissingMarketDataError here too. The caller's protos
16
+ * are set as they are, not stamped (LM-322).
17
+ */
18
+ static typed(asof, productInput, position, measures) {
19
+ const missing = [['asof_datetime', asof], ['position_input', position]]
20
+ .filter(([, value]) => value === undefined || value === null)
21
+ .map(([field]) => (0, errors_1.violation)(field, undefined, `${field} is required`));
22
+ if (missing.length > 0)
23
+ throw new errors_1.ModelValidationError(missing);
24
+ (0, product_inputs_1.checkProductInput)(productInput);
25
+ return (0, object_types_1.stampOwn)(new valuation_request_pb_1.ValuationRequestProto())
26
+ .setMeasuresList([...measures])
27
+ .setAsofDatetime(asof)
28
+ .setPositionInput(position)
29
+ .setProductInput(productInput);
30
+ }
31
+ }
32
+ exports.ValuationRequests = ValuationRequests;
33
+ //# sourceMappingURL=ValuationRequests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValuationRequests.js","sourceRoot":"","sources":["ValuationRequests.ts"],"names":[],"mappings":";;;AAQA,sGAAoG;AACpG,gDAAsE;AACtE,yEAAyE;AACzE,0DAAmD;AAEnD,MAAa,iBAAiB;IAC5B;;;;;;;;OAQG;IACH,MAAM,CAAC,KAAK,CAAC,IAAqC,EAAE,YAA0B,EAC5E,QAAmC,EAAE,QAAwB;QAC7D,MAAM,OAAO,GAAI,CAAC,CAAC,eAAe,EAAE,IAAI,CAAC,EAAE,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAW;aAC/E,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;aAC5D,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,IAAA,kBAAS,EAAC,KAAK,EAAE,SAAS,EAAE,GAAG,KAAK,cAAc,CAAC,CAAC,CAAC;QACzE,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;YAAE,MAAM,IAAI,6BAAoB,CAAC,OAAO,CAAC,CAAC;QAChE,IAAA,kCAAiB,EAAC,YAAY,CAAC,CAAC;QAChC,OAAO,IAAA,uBAAQ,EAAC,IAAI,4CAAqB,EAAE,CAAC;aACzC,eAAe,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC;aAC9B,eAAe,CAAC,IAAI,CAAC;aACrB,gBAAgB,CAAC,QAAQ,CAAC;aAC1B,eAAe,CAAC,YAAY,CAAC,CAAC;IACnC,CAAC;CACF;AAvBD,8CAuBC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Typed valuation requests (LM-410). Same rule in Java / Rust / Python /
3
+ * JS-TS. See docs/adr/product_input_builders.md.
4
+ */
5
+ import { MeasureProto } from '../../../fintekkers/models/position/measure_pb';
6
+ import { PositionProto } from '../../../fintekkers/models/position/position_pb';
7
+ import { LocalTimestampProto } from '../../../fintekkers/models/util/local_timestamp_pb';
8
+ import { ProductInput } from '../../../fintekkers/requests/valuation/product_inputs_pb';
9
+ import { ValuationRequestProto } from '../../../fintekkers/requests/valuation/valuation_request_pb';
10
+ import { ModelValidationError, violation } from '../../models/errors';
11
+ import { checkProductInput } from '../../models/security/product_inputs';
12
+ import { stampOwn } from '../../util/object-types';
13
+
14
+ export class ValuationRequests {
15
+ /**
16
+ * A ValuationRequestProto valued from `productInput` alone.
17
+ *
18
+ * Sets asof_datetime (23), measures (30), position_input (21) and
19
+ * product_input (70). Never sets security_input (20) or price_input (22).
20
+ * `productInput` is checked with checkProductInput first, so a tips input
21
+ * with no cpi throws MissingMarketDataError here too. The caller's protos
22
+ * are set as they are, not stamped (LM-322).
23
+ */
24
+ static typed(asof: LocalTimestampProto | undefined, productInput: ProductInput,
25
+ position: PositionProto | undefined, measures: MeasureProto[]): ValuationRequestProto {
26
+ const missing = ([['asof_datetime', asof], ['position_input', position]] as const)
27
+ .filter(([, value]) => value === undefined || value === null)
28
+ .map(([field]) => violation(field, undefined, `${field} is required`));
29
+ if (missing.length > 0) throw new ModelValidationError(missing);
30
+ checkProductInput(productInput);
31
+ return stampOwn(new ValuationRequestProto())
32
+ .setMeasuresList([...measures])
33
+ .setAsofDatetime(asof)
34
+ .setPositionInput(position)
35
+ .setProductInput(productInput);
36
+ }
37
+ }
@@ -49,6 +49,7 @@ const transaction_pb_1 = require("../../fintekkers/models/transaction/transactio
49
49
  const portfolio_pb_1 = require("../../fintekkers/models/portfolio/portfolio_pb");
50
50
  const transaction_type_pb_1 = require("../../fintekkers/models/transaction/transaction_type_pb");
51
51
  const position_pb_1 = require("../../fintekkers/models/position/position_pb");
52
+ const measure_pb_1 = require("../../fintekkers/models/position/measure_pb");
52
53
  const query_security_response_pb_1 = require("../../fintekkers/requests/security/query_security_response_pb");
53
54
  const query_portfolio_response_pb_1 = require("../../fintekkers/requests/portfolio/query_portfolio_response_pb");
54
55
  const query_transaction_response_pb_1 = require("../../fintekkers/requests/transaction/query_transaction_response_pb");
@@ -77,6 +78,8 @@ const transaction_1 = __importDefault(require("../models/transaction/transaction
77
78
  const transaction_type_1 = require("../models/transaction/transaction_type");
78
79
  const positionfilter_1 = require("../models/position/positionfilter");
79
80
  const QueryPositionRequest_1 = require("../requests/position/QueryPositionRequest");
81
+ const ValuationRequests_1 = require("../requests/valuation/ValuationRequests");
82
+ const product_inputs_1 = require("../models/security/product_inputs");
80
83
  const uuid_1 = require("../models/utils/uuid");
81
84
  const datetime_1 = require("../models/utils/datetime");
82
85
  const PriceService_1 = require("../services/price-service/PriceService");
@@ -259,6 +262,8 @@ const BUILDERS = [
259
262
  B('LinkResolver.getTransaction', T.OBJECT_TYPE_QUERY_TRANSACTION_REQUEST, () => resolverRequest((r) => r.getTransaction(linkUuid()))),
260
263
  B('LinkResolver.resolveSecurities', T.OBJECT_TYPE_QUERY_SECURITY_REQUEST, (c) => resolverRequest((r) => r.resolveSecurities([linkedPrice(c)]))),
261
264
  B('LinkResolver.resolvePortfolios', T.OBJECT_TYPE_QUERY_PORTFOLIO_REQUEST, (c) => resolverRequest((r) => r.resolvePortfolios([linkedTransaction(c)]))),
265
+ // LM-410: the request is the builder's; the product input's security and the position are the caller's.
266
+ B('ValuationRequests.typed', T.OBJECT_TYPE_VALUATION_REQUEST, (c) => ValuationRequests_1.ValuationRequests.typed(asOf, (0, product_inputs_1.forSecurity)(bond(c).proto, new price_pb_1.PriceProto()), c(new position_pb_1.PositionProto()), [measure_pb_1.MeasureProto.MARKET_VALUE])),
262
267
  ];
263
268
  /** The messages a builder returned: wrappers are read through `proto`, arrays item by item. */
264
269
  function messagesOf(built) {
@@ -531,7 +536,7 @@ const WRAPS_CALLER = "wraps the caller's proto (pass-through ruling)";
531
536
  const SERIALIZES = "converts values to untyped messages (dates, UUIDs, decimals) or returns the caller's Identifier proto as is";
532
537
  const DESERIALIZES = 'decodes protos the caller or server sent into wrappers; builds no message';
533
538
  /** Public callables the scan flags that build no message to stamp, each with its reason. */
534
- const EXCLUSIONS = Object.assign(Object.assign({ 'object-types.stamp': 'the stamping helper itself (tested above)', 'object-types.stampOwn': 'the stamping helper itself (tested above)', 'price_rules.validate': 'local stand-in for null input; never returned or sent', 'price_rules.requireValid': 'local stand-in for null input; never returned or sent', 'Security.create': "picks the wrapper class for the caller's proto (pass-through ruling)", 'Position.fromJSON': DESERIALIZES, 'ProtoSerializationUtil.deserialize': DESERIALIZES, 'serialization.util.unpack': DESERIALIZES, 'LocalDate.toDate': DESERIALIZES, 'ProtoSerializationUtil.serialize': SERIALIZES, 'serialization.util.pack': SERIALIZES, 'PositionFilter.addFilter': SERIALIZES, 'PositionFilter.addEqualsFilter': SERIALIZES, 'PositionFilter.addEqualsStringFilter': SERIALIZES, 'PositionFilter.addObjectFilter': SERIALIZES, 'Security.hydrate': 'swaps in the proto LinkResolver.getSecurity fetched (that request is tested)', 'Portfolio.hydrate': 'swaps in the proto LinkResolver.getPortfolio fetched (that request is tested)', 'Transaction.hydrate': 'swaps in the proto LinkResolver.getTransaction fetched (that request is tested)', 'TreasuryFrnFixings.select': "builds a ReferenceRateFixingProto, which has no object_type; flagged only for reading the caller's issuances" }, Object.fromEntries([
539
+ const EXCLUSIONS = Object.assign(Object.assign({ 'object-types.stamp': 'the stamping helper itself (tested above)', 'object-types.stampOwn': 'the stamping helper itself (tested above)', 'price_rules.validate': 'local stand-in for null input; never returned or sent', 'price_rules.requireValid': 'local stand-in for null input; never returned or sent', 'product_inputs.checkProductInput': 'local stand-in SecurityProto for an arm with no security; never returned or sent', 'product_inputs.forSecurity': "builds a ProductInput, which has no object_type, around the caller's security; flagged only for calling checkProductInput", 'Security.create': "picks the wrapper class for the caller's proto (pass-through ruling)", 'Position.fromJSON': DESERIALIZES, 'ProtoSerializationUtil.deserialize': DESERIALIZES, 'serialization.util.unpack': DESERIALIZES, 'LocalDate.toDate': DESERIALIZES, 'ProtoSerializationUtil.serialize': SERIALIZES, 'serialization.util.pack': SERIALIZES, 'PositionFilter.addFilter': SERIALIZES, 'PositionFilter.addEqualsFilter': SERIALIZES, 'PositionFilter.addEqualsStringFilter': SERIALIZES, 'PositionFilter.addObjectFilter': SERIALIZES, 'Security.hydrate': 'swaps in the proto LinkResolver.getSecurity fetched (that request is tested)', 'Portfolio.hydrate': 'swaps in the proto LinkResolver.getPortfolio fetched (that request is tested)', 'Transaction.hydrate': 'swaps in the proto LinkResolver.getTransaction fetched (that request is tested)', 'TreasuryFrnFixings.select': "builds a ReferenceRateFixingProto, which has no object_type; flagged only for reading the caller's issuances" }, Object.fromEntries([
535
540
  'BondSecurity.constructor', 'FloatingRateNote.constructor', 'Identifier.constructor', 'IndexSecurity.constructor',
536
541
  'Issuance.constructor', 'MortgageBackedSecurity.constructor', 'Portfolio.constructor', 'Position.constructor',
537
542
  'Price.constructor', 'Security.constructor', 'TIPSBond.constructor',