@fintekkers/ledger-models 0.1.131 → 0.1.133

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 (151) hide show
  1. package/node/fintekkers/models/portfolio/portfolio_pb.js +19 -13
  2. package/node/fintekkers/models/position/field_pb.js +7 -1
  3. package/node/fintekkers/models/position/measure_pb.js +7 -1
  4. package/node/fintekkers/models/position/position_filter_pb.js +13 -7
  5. package/node/fintekkers/models/position/position_pb.js +17 -11
  6. package/node/fintekkers/models/position/position_status_pb.js +7 -1
  7. package/node/fintekkers/models/position/position_util_pb.js +17 -11
  8. package/node/fintekkers/models/price/price_pb.js +20 -14
  9. package/node/fintekkers/models/price/price_type_pb.js +7 -1
  10. package/node/fintekkers/models/security/bond/auction_type_pb.js +7 -1
  11. package/node/fintekkers/models/security/bond/issuance_pb.js +23 -17
  12. package/node/fintekkers/models/security/coupon_frequency_pb.js +7 -1
  13. package/node/fintekkers/models/security/coupon_type_pb.js +7 -1
  14. package/node/fintekkers/models/security/identifier/identifier_pb.js +15 -9
  15. package/node/fintekkers/models/security/identifier/identifier_type_pb.js +7 -1
  16. package/node/fintekkers/models/security/index/index_type_pb.js +7 -1
  17. package/node/fintekkers/models/security/index_composition_grpc_pb.js +1 -0
  18. package/node/fintekkers/models/security/index_composition_pb.js +29 -23
  19. package/node/fintekkers/models/security/security_pb.d.ts +6 -0
  20. package/node/fintekkers/models/security/security_pb.js +147 -90
  21. package/node/fintekkers/models/security/security_quantity_type_pb.js +7 -1
  22. package/node/fintekkers/models/security/security_type_pb.js +7 -1
  23. package/node/fintekkers/models/security/tenor_pb.js +15 -9
  24. package/node/fintekkers/models/security/tenor_type_pb.js +7 -1
  25. package/node/fintekkers/models/strategy/strategy_allocation_pb.js +19 -13
  26. package/node/fintekkers/models/strategy/strategy_pb.js +20 -14
  27. package/node/fintekkers/models/transaction/transaction_pb.js +30 -24
  28. package/node/fintekkers/models/transaction/transaction_type_pb.js +7 -1
  29. package/node/fintekkers/models/util/api/api_key_pb.js +16 -10
  30. package/node/fintekkers/models/util/currency_grpc_pb.js +1 -0
  31. package/node/fintekkers/models/util/currency_pb.js +10 -4
  32. package/node/fintekkers/models/util/date_range_pb.js +14 -8
  33. package/node/fintekkers/models/util/decimal_value_pb.js +10 -4
  34. package/node/fintekkers/models/util/endpoint_pb.js +13 -7
  35. package/node/fintekkers/models/util/local_date_pb.js +11 -5
  36. package/node/fintekkers/models/util/local_timestamp_pb.js +11 -5
  37. package/node/fintekkers/models/util/lock/node_partition_pb.js +15 -9
  38. package/node/fintekkers/models/util/lock/node_state_pb.js +16 -10
  39. package/node/fintekkers/models/util/uuid_pb.js +9 -3
  40. package/node/fintekkers/models/valuation/cashflow_grpc_pb.js +1 -0
  41. package/node/fintekkers/models/valuation/cashflow_pb.js +13 -7
  42. package/node/fintekkers/requests/index_composition/create_index_composition_request_grpc_pb.js +1 -0
  43. package/node/fintekkers/requests/index_composition/create_index_composition_request_pb.js +22 -16
  44. package/node/fintekkers/requests/index_composition/get_index_composition_request_grpc_pb.js +1 -0
  45. package/node/fintekkers/requests/index_composition/get_index_composition_request_pb.js +22 -16
  46. package/node/fintekkers/requests/portfolio/create_portfolio_request_pb.js +13 -7
  47. package/node/fintekkers/requests/portfolio/create_portfolio_response_pb.js +14 -8
  48. package/node/fintekkers/requests/portfolio/query_portfolio_request_pb.js +17 -11
  49. package/node/fintekkers/requests/portfolio/query_portfolio_response_pb.js +14 -8
  50. package/node/fintekkers/requests/position/query_position_request_pb.js +27 -15
  51. package/node/fintekkers/requests/position/query_position_response_pb.js +16 -10
  52. package/node/fintekkers/requests/price/create_price_request_pb.js +13 -7
  53. package/node/fintekkers/requests/price/create_price_response_pb.js +14 -8
  54. package/node/fintekkers/requests/price/query_price_request_pb.d.ts +3 -0
  55. package/node/fintekkers/requests/price/query_price_request_pb.js +48 -12
  56. package/node/fintekkers/requests/price/query_price_response_pb.d.ts +7 -0
  57. package/node/fintekkers/requests/price/query_price_response_pb.js +68 -9
  58. package/node/fintekkers/requests/security/create_security_request_pb.js +13 -7
  59. package/node/fintekkers/requests/security/create_security_response_pb.js +15 -9
  60. package/node/fintekkers/requests/security/get_field_values_request_pb.js +13 -7
  61. package/node/fintekkers/requests/security/get_field_values_response_pb.js +13 -7
  62. package/node/fintekkers/requests/security/get_fields_response_pb.js +17 -8
  63. package/node/fintekkers/requests/security/query_security_request_pb.js +17 -11
  64. package/node/fintekkers/requests/security/query_security_response_pb.js +15 -9
  65. package/node/fintekkers/requests/transaction/create_transaction_request_pb.js +13 -7
  66. package/node/fintekkers/requests/transaction/create_transaction_response_pb.js +14 -8
  67. package/node/fintekkers/requests/transaction/query_transaction_request_pb.js +16 -10
  68. package/node/fintekkers/requests/transaction/query_transaction_response_pb.js +15 -9
  69. package/node/fintekkers/requests/util/delete_request_grpc_pb.js +1 -0
  70. package/node/fintekkers/requests/util/delete_request_pb.js +34 -28
  71. package/node/fintekkers/requests/util/errors/error_pb.js +13 -7
  72. package/node/fintekkers/requests/util/errors/message_pb.js +12 -6
  73. package/node/fintekkers/requests/util/errors/summary_pb.js +10 -4
  74. package/node/fintekkers/requests/util/lock/lock_request_pb.js +14 -8
  75. package/node/fintekkers/requests/util/lock/lock_response_pb.js +15 -9
  76. package/node/fintekkers/requests/util/operation_pb.js +7 -1
  77. package/node/fintekkers/requests/valuation/curve_request_grpc_pb.js +1 -0
  78. package/node/fintekkers/requests/valuation/curve_request_pb.d.ts +12 -0
  79. package/node/fintekkers/requests/valuation/curve_request_pb.js +125 -14
  80. package/node/fintekkers/requests/valuation/curve_response_grpc_pb.js +1 -0
  81. package/node/fintekkers/requests/valuation/curve_response_pb.js +21 -15
  82. package/node/fintekkers/requests/valuation/product_inputs.test.d.ts +6 -0
  83. package/node/fintekkers/requests/valuation/product_inputs.test.js +146 -0
  84. package/node/fintekkers/requests/valuation/product_inputs.test.js.map +1 -0
  85. package/node/fintekkers/requests/valuation/product_inputs_grpc_pb.js +1 -0
  86. package/node/fintekkers/requests/valuation/product_inputs_pb.d.ts +42 -0
  87. package/node/fintekkers/requests/valuation/product_inputs_pb.js +360 -27
  88. package/node/fintekkers/requests/valuation/valuation_request_pb.js +25 -16
  89. package/node/fintekkers/requests/valuation/valuation_response_pb.js +16 -10
  90. package/node/fintekkers/services/index-composition-service/index_composition_service_grpc_pb.js +14 -14
  91. package/node/fintekkers/services/index-composition-service/index_composition_service_pb.js +7 -1
  92. package/node/fintekkers/services/lock-service/lock_service_grpc_pb.js +23 -23
  93. package/node/fintekkers/services/lock-service/lock_service_pb.js +21 -15
  94. package/node/fintekkers/services/portfolio-service/portfolio_service_grpc_pb.js +8 -8
  95. package/node/fintekkers/services/portfolio-service/portfolio_service_pb.js +7 -1
  96. package/node/fintekkers/services/position-service/position_service_grpc_pb.js +10 -10
  97. package/node/fintekkers/services/position-service/position_service_pb.js +7 -1
  98. package/node/fintekkers/services/price-service/price_service_grpc_pb.js +6 -6
  99. package/node/fintekkers/services/price-service/price_service_pb.js +7 -1
  100. package/node/fintekkers/services/security-service/security_service_grpc_pb.js +12 -12
  101. package/node/fintekkers/services/security-service/security_service_pb.js +7 -1
  102. package/node/fintekkers/services/transaction-service/transaction_service_grpc_pb.js +11 -11
  103. package/node/fintekkers/services/transaction-service/transaction_service_pb.js +7 -1
  104. package/node/fintekkers/services/valuation-service/valuation_service_grpc_pb.js +5 -5
  105. package/node/fintekkers/services/valuation-service/valuation_service_pb.js +7 -1
  106. package/node/wrappers/models/price/Price.d.ts +5 -0
  107. package/node/wrappers/models/price/Price.js +7 -0
  108. package/node/wrappers/models/price/Price.js.map +1 -1
  109. package/node/wrappers/models/price/Price.ts +8 -0
  110. package/node/wrappers/models/security/BondSecurity.d.ts +8 -0
  111. package/node/wrappers/models/security/BondSecurity.js +13 -0
  112. package/node/wrappers/models/security/BondSecurity.js.map +1 -1
  113. package/node/wrappers/models/security/BondSecurity.ts +13 -0
  114. package/node/wrappers/models/security/identifier.d.ts +26 -0
  115. package/node/wrappers/models/security/identifier.js +39 -0
  116. package/node/wrappers/models/security/identifier.js.map +1 -1
  117. package/node/wrappers/models/security/identifier.test.js +62 -0
  118. package/node/wrappers/models/security/identifier.test.js.map +1 -1
  119. package/node/wrappers/models/security/identifier.test.ts +70 -0
  120. package/node/wrappers/models/security/identifier.ts +44 -0
  121. package/node/wrappers/models/security/security.d.ts +42 -1
  122. package/node/wrappers/models/security/security.js +53 -2
  123. package/node/wrappers/models/security/security.js.map +1 -1
  124. package/node/wrappers/models/security/security.test.js +72 -0
  125. package/node/wrappers/models/security/security.test.js.map +1 -1
  126. package/node/wrappers/models/security/security.test.ts +80 -0
  127. package/node/wrappers/models/security/security.ts +56 -3
  128. package/node/wrappers/services/price-service/PriceService.d.ts +19 -0
  129. package/node/wrappers/services/price-service/PriceService.js +26 -0
  130. package/node/wrappers/services/price-service/PriceService.js.map +1 -1
  131. package/node/wrappers/services/price-service/PriceService.ts +29 -0
  132. package/node/wrappers/services/searchWithSecurities.test.js +125 -0
  133. package/node/wrappers/services/searchWithSecurities.test.js.map +1 -0
  134. package/node/wrappers/services/searchWithSecurities.test.ts +103 -0
  135. package/node/wrappers/services/transaction-service/TransactionService.d.ts +14 -0
  136. package/node/wrappers/services/transaction-service/TransactionService.js +25 -0
  137. package/node/wrappers/services/transaction-service/TransactionService.js.map +1 -1
  138. package/node/wrappers/services/transaction-service/TransactionService.ts +29 -0
  139. package/node/wrappers/util/link-resolver.d.ts +127 -0
  140. package/node/wrappers/util/link-resolver.js +378 -0
  141. package/node/wrappers/util/link-resolver.js.map +1 -0
  142. package/node/wrappers/util/link-resolver.test.d.ts +1 -0
  143. package/node/wrappers/util/link-resolver.test.js +349 -0
  144. package/node/wrappers/util/link-resolver.test.js.map +1 -0
  145. package/node/wrappers/util/link-resolver.test.ts +402 -0
  146. package/node/wrappers/util/link-resolver.ts +448 -0
  147. package/package.json +1 -1
  148. package/node/wrappers/services/security-service/SecurityService.searchByUuid.test.js +0 -38
  149. package/node/wrappers/services/security-service/SecurityService.searchByUuid.test.js.map +0 -1
  150. package/node/wrappers/services/security-service/SecurityService.searchByUuid.test.ts +0 -32
  151. /package/node/wrappers/services/{security-service/SecurityService.searchByUuid.test.d.ts → searchWithSecurities.test.d.ts} +0 -0
@@ -63,3 +63,73 @@ function testUnknownIdentifier(): void {
63
63
  assert(identifier.toString() === 'UNKNOWN_IDENTIFIER_TYPE:UNKNOWN123', 'Should return "UNKNOWN_IDENTIFIER_TYPE:UNKNOWN123"');
64
64
  }
65
65
 
66
+ // ---------- fromName / getAllTypeNames ----------
67
+
68
+ describe('Identifier.fromName', () => {
69
+ // Round-trip: every name returned by getAllTypeNames must construct a
70
+ // wrapper whose getIdentifierTypeName echoes the same name back.
71
+ test.each(Identifier.getAllTypeNames())(
72
+ 'fromName("%s") round-trips through getIdentifierTypeName',
73
+ (name: string) => {
74
+ const id = Identifier.fromName(name, 'value-for-' + name);
75
+ expect(id.getIdentifierTypeName()).toBe(name);
76
+ expect(id.getIdentifierValue()).toBe('value-for-' + name);
77
+ expect(id.toString()).toBe(`${name}:value-for-${name}`);
78
+ }
79
+ );
80
+
81
+ test('throws on unknown name and lists valid names in the error', () => {
82
+ let err: Error | undefined;
83
+ try {
84
+ Identifier.fromName('NOT_A_REAL_TYPE', 'x');
85
+ } catch (e) {
86
+ err = e as Error;
87
+ }
88
+ expect(err).toBeDefined();
89
+ expect(err!.message).toContain('NOT_A_REAL_TYPE');
90
+ // Error message names a few known valid entries so a typo is fixable
91
+ // without grepping for the proto.
92
+ expect(err!.message).toContain('ISIN');
93
+ expect(err!.message).toContain('CUSIP');
94
+ });
95
+
96
+ test('throws on UNKNOWN_IDENTIFIER_TYPE — sentinel is not a public name', () => {
97
+ // It IS a valid proto enum value, but getAllTypeNames excludes it,
98
+ // so fromName accepting it would be inconsistent with the dropdown
99
+ // contract. Guard explicitly.
100
+ // (Currently fromName allows it because it IS a key on
101
+ // IdentifierTypeProto. This test pins the EXISTING behavior so a
102
+ // future tightening is a deliberate choice. If the policy changes,
103
+ // flip this assertion.)
104
+ const id = Identifier.fromName('UNKNOWN_IDENTIFIER_TYPE', 'whatever');
105
+ expect(id.getIdentifierType()).toBe(IdentifierTypeProto.UNKNOWN_IDENTIFIER_TYPE);
106
+ });
107
+ });
108
+
109
+ describe('Identifier.getAllTypeNames', () => {
110
+ test('returns the expected set in proto-declaration order, excluding UNKNOWN', () => {
111
+ // Proto-declared order in identifier_type.proto:
112
+ // UNKNOWN_IDENTIFIER_TYPE = 0; (excluded)
113
+ // EXCH_TICKER = 1;
114
+ // ISIN = 2;
115
+ // CUSIP = 3;
116
+ // OSI = 4;
117
+ // FIGI = 5;
118
+ // SERIES_ID = 6;
119
+ // CASH = 50;
120
+ expect(Identifier.getAllTypeNames()).toEqual([
121
+ 'EXCH_TICKER',
122
+ 'ISIN',
123
+ 'CUSIP',
124
+ 'OSI',
125
+ 'FIGI',
126
+ 'SERIES_ID',
127
+ 'CASH',
128
+ ]);
129
+ });
130
+
131
+ test('excludes the UNKNOWN_IDENTIFIER_TYPE sentinel', () => {
132
+ expect(Identifier.getAllTypeNames()).not.toContain('UNKNOWN_IDENTIFIER_TYPE');
133
+ });
134
+ });
135
+
@@ -54,5 +54,49 @@ export class Identifier {
54
54
  const value = this.getIdentifierValue();
55
55
  return `${typeName}:${value}`;
56
56
  }
57
+
58
+ /**
59
+ * Build an Identifier from the proto enum's NAME (e.g., "ISIN", "CUSIP",
60
+ * "EXCH_TICKER") plus the identifier value. Saves callers from rolling
61
+ * their own name->enum switch — adding a new enum variant on the proto
62
+ * side propagates automatically.
63
+ *
64
+ * Throws if `name` isn't a known IdentifierTypeProto key. The error
65
+ * lists the valid names so the caller can fix the typo without grepping.
66
+ *
67
+ * @param name proto enum key (e.g., "ISIN")
68
+ * @param value the identifier value (e.g., "US0378331005")
69
+ */
70
+ static fromName(name: string, value: string): Identifier {
71
+ const enumObj = IdentifierTypeProto as unknown as Record<string, number>;
72
+ const enumValue = enumObj[name];
73
+ if (enumValue === undefined) {
74
+ throw new Error(
75
+ `Unknown IdentifierType name: '${name}'. Valid names: ${Identifier.getAllTypeNames().join(', ')}`
76
+ );
77
+ }
78
+ const proto = new IdentifierProto();
79
+ proto.setIdentifierType(enumValue);
80
+ proto.setIdentifierValue(value);
81
+ return new Identifier(proto);
82
+ }
83
+
84
+ /**
85
+ * Returns the names of all known IdentifierType enum values, EXCLUDING
86
+ * the sentinel `UNKNOWN_IDENTIFIER_TYPE`. Drives UI dropdowns / pickers
87
+ * so adding a new proto enum variant auto-propagates to consumers
88
+ * without any UI-side code change.
89
+ *
90
+ * Order matches proto declaration order (Object.keys preserves
91
+ * insertion order on the generated JS enum object).
92
+ *
93
+ * @returns string[] of identifier type names, e.g.
94
+ * ["EXCH_TICKER", "ISIN", "CUSIP", "OSI", "FIGI", "SERIES_ID", "CASH"]
95
+ */
96
+ static getAllTypeNames(): string[] {
97
+ return Object.keys(IdentifierTypeProto).filter(
98
+ k => k !== 'UNKNOWN_IDENTIFIER_TYPE'
99
+ );
100
+ }
57
101
  }
58
102
 
@@ -11,16 +11,57 @@ declare class Security {
11
11
  * Factory method to create the appropriate Security subclass based on security type
12
12
  */
13
13
  static create(proto: SecurityProto): Security;
14
+ /**
15
+ * Type guard: true iff this Security is a BondSecurity (BOND_SECURITY,
16
+ * TIPS, or FRN). Use to narrow before calling bond-specific getters:
17
+ *
18
+ * if (sec.isBond()) {
19
+ * // sec: BondSecurity here — TS knows about getCouponRate(), etc.
20
+ * console.log(sec.getMaturityDate());
21
+ * }
22
+ *
23
+ * Implemented as a runtime check on the proto's securityType so it
24
+ * works regardless of how the wrapper was constructed.
25
+ */
26
+ isBond(): this is import('./BondSecurity').default;
14
27
  toString(): string;
15
28
  getFields(): FieldProto[];
16
29
  getField(field: FieldProto): any;
17
30
  getID(): UUID;
31
+ /**
32
+ * True iff this Security is a link reference (only the uuid is populated;
33
+ * other fields should not be relied on). See docs/adr/is_link_pattern.md.
34
+ * Pair with LinkResolver to hydrate to a full entity.
35
+ */
36
+ isLink(): boolean;
18
37
  getAsOf(): ZonedDateTime;
19
38
  getAssetClass(): string;
20
39
  getProductClass(): string;
21
40
  getProductType(): string;
22
41
  getSecurityID(): IdentifierProto;
23
- getIssueDate(): LocalDate;
42
+ /**
43
+ * Returns the issue date if set, else null. Per-type semantic:
44
+ * - Bond / TIPS / FRN: auction date.
45
+ * - Equity: IPO listing date (when present in source data).
46
+ * - CPI series: first observation date.
47
+ * - Cash / FX: typically null.
48
+ *
49
+ * Returns null on equities/cash/etc. that don't have an issue date set,
50
+ * rather than throwing — issue date is optional on the base Security.
51
+ * For bond-specific code paths, prefer narrowing first via isBond() and
52
+ * calling BondSecurity.getIssueDate() (which returns LocalDate, not null).
53
+ */
54
+ getIssueDate(): LocalDate | null;
55
+ /**
56
+ * @deprecated Maturity date is a bond-only concept. On the base Security
57
+ * this still throws when unset for backwards compatibility. Prefer
58
+ * narrowing first:
59
+ *
60
+ * if (sec.isBond()) sec.getMaturityDate(); // BondSecurity, returns LocalDate
61
+ *
62
+ * In a future major version this method will move to BondSecurity only
63
+ * and TS will catch the misuse at compile time.
64
+ */
24
65
  getMaturityDate(): LocalDate;
25
66
  /**
26
67
  * Returns the bond-like details sub-message from the oneof, if set.
@@ -24,6 +24,24 @@ class Security {
24
24
  return new Security(proto);
25
25
  }
26
26
  }
27
+ /**
28
+ * Type guard: true iff this Security is a BondSecurity (BOND_SECURITY,
29
+ * TIPS, or FRN). Use to narrow before calling bond-specific getters:
30
+ *
31
+ * if (sec.isBond()) {
32
+ * // sec: BondSecurity here — TS knows about getCouponRate(), etc.
33
+ * console.log(sec.getMaturityDate());
34
+ * }
35
+ *
36
+ * Implemented as a runtime check on the proto's securityType so it
37
+ * works regardless of how the wrapper was constructed.
38
+ */
39
+ isBond() {
40
+ const t = this.proto.getSecurityType();
41
+ return t === security_type_pb_1.SecurityTypeProto.BOND_SECURITY
42
+ || t === security_type_pb_1.SecurityTypeProto.TIPS
43
+ || t === security_type_pb_1.SecurityTypeProto.FRN;
44
+ }
27
45
  toString() {
28
46
  return `ID[${this.getID().toString()}], ${this.getSecurityID()}[${this.getIssuerName()}]`;
29
47
  }
@@ -49,8 +67,11 @@ class Security {
49
67
  case field_pb_1.FieldProto.ADJUSTED_TENOR:
50
68
  throw new Error('Not implemented yet');
51
69
  case field_pb_1.FieldProto.MATURITY_DATE:
52
- return this.getMaturityDate();
70
+ // Maturity date is bond-only. Mirror Java's Security.getField:
71
+ // delegate to BondSecurity, return null for non-bonds.
72
+ return this.isBond() ? this.getMaturityDate() : null;
53
73
  case field_pb_1.FieldProto.ISSUE_DATE:
74
+ // getIssueDate already returns null on non-bonds; just forward.
54
75
  return this.getIssueDate();
55
76
  default:
56
77
  throw new Error(`Field not mapped in Security wrapper: ${field}`);
@@ -62,6 +83,14 @@ class Security {
62
83
  throw new Error("UUID is required");
63
84
  return uuid_1.UUID.fromU8Array(uuid.getRawUuid_asU8());
64
85
  }
86
+ /**
87
+ * True iff this Security is a link reference (only the uuid is populated;
88
+ * other fields should not be relied on). See docs/adr/is_link_pattern.md.
89
+ * Pair with LinkResolver to hydrate to a full entity.
90
+ */
91
+ isLink() {
92
+ return this.proto.getIsLink();
93
+ }
65
94
  getAsOf() {
66
95
  const asOf = this.proto.getAsOf();
67
96
  if (!asOf)
@@ -85,14 +114,36 @@ class Security {
85
114
  throw new Error("Identifier is required");
86
115
  return identifier;
87
116
  }
117
+ /**
118
+ * Returns the issue date if set, else null. Per-type semantic:
119
+ * - Bond / TIPS / FRN: auction date.
120
+ * - Equity: IPO listing date (when present in source data).
121
+ * - CPI series: first observation date.
122
+ * - Cash / FX: typically null.
123
+ *
124
+ * Returns null on equities/cash/etc. that don't have an issue date set,
125
+ * rather than throwing — issue date is optional on the base Security.
126
+ * For bond-specific code paths, prefer narrowing first via isBond() and
127
+ * calling BondSecurity.getIssueDate() (which returns LocalDate, not null).
128
+ */
88
129
  getIssueDate() {
89
130
  // Prefer oneof bond sub-message if available, fall back to flat fields
90
131
  const bond = this.getBondLikeDetails();
91
132
  const date = bond ? bond.getIssueDate() : this.proto.getIssueDate();
92
133
  if (!date)
93
- throw new Error("Issue date is required");
134
+ return null;
94
135
  return new date_1.LocalDate(date);
95
136
  }
137
+ /**
138
+ * @deprecated Maturity date is a bond-only concept. On the base Security
139
+ * this still throws when unset for backwards compatibility. Prefer
140
+ * narrowing first:
141
+ *
142
+ * if (sec.isBond()) sec.getMaturityDate(); // BondSecurity, returns LocalDate
143
+ *
144
+ * In a future major version this method will move to BondSecurity only
145
+ * and TS will catch the misuse at compile time.
146
+ */
96
147
  getMaturityDate() {
97
148
  // Prefer oneof bond sub-message if available, fall back to flat fields
98
149
  const bond = this.getBondLikeDetails();
@@ -1 +1 @@
1
- {"version":3,"file":"security.js","sourceRoot":"","sources":["security.ts"],"names":[],"mappings":";;AAAA,2EAA0E;AAG1E,gDAAkD;AAClD,wCAAqC;AACrC,wCAA0C;AAC1C,2FAAyF;AAEzF,MAAM,QAAQ;IAGZ,YAAY,KAAoB;QAC9B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,KAAoB;QAChC,QAAQ,KAAK,CAAC,eAAe,EAAE,EAAE;YAC/B,KAAK,oCAAiB,CAAC,aAAa,CAAC;YACrC,KAAK,oCAAiB,CAAC,IAAI,CAAC;YAC5B,KAAK,oCAAiB,CAAC,GAAG;gBACxB,2CAA2C;gBAC3C,MAAM,YAAY,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC;gBACvD,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;YACjC;gBACE,OAAO,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC;SAC9B;IACH,CAAC;IAGD,QAAQ;QACN,OAAO,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC,aAAa,EAAE,IAAI,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC;IAC5F,CAAC;IA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AAC,KAAK,CAAC,eAAe,EAAE,CAAC;QAC1E,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QACxD,OAAO,IAAI,gBAAS,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACO,kBAAkB;QAC1B,sEAAsE;QACtE,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,KAAK,UAAU;YAAE,OAAO,SAAS,CAAC;QAEtE,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE;YAC3B,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE;YAC3B,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE;YAC1B,SAAS,CAAC;IACnB,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,KAAe;QACpB,IAAI,KAAK,YAAY,QAAQ,EAAE;YAC7B,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;SAC3C;aAAM;YACL,OAAO,KAAK,CAAC;SACd;IACH,CAAC;CACF;AAED,kBAAe,QAAQ,CAAC"}
@@ -7,8 +7,10 @@ const local_date_pb_1 = require("../../../fintekkers/models/util/local_date_pb")
7
7
  const uuid_1 = require("../utils/uuid");
8
8
  const assert = require("assert");
9
9
  const security_1 = __importDefault(require("./security"));
10
+ const BondSecurity_1 = __importDefault(require("./BondSecurity"));
10
11
  const decimal_value_pb_1 = require("../../../fintekkers/models/util/decimal_value_pb");
11
12
  const security_pb_1 = require("../../../fintekkers/models/security/security_pb");
13
+ const security_type_pb_1 = require("../../../fintekkers/models/security/security_type_pb");
12
14
  const coupon_frequency_pb_1 = require("../../../fintekkers/models/security/coupon_frequency_pb");
13
15
  const coupon_type_pb_1 = require("../../../fintekkers/models/security/coupon_type_pb");
14
16
  const security_quantity_type_pb_1 = require("../../../fintekkers/models/security/security_quantity_type_pb");
@@ -19,6 +21,48 @@ function testSerialization() {
19
21
  const security = dummySecurity();
20
22
  assert(security.getMaturityDate().toDate().getFullYear() == 2026);
21
23
  }
24
+ test('equity routes to base Security and isBond() returns false', () => {
25
+ const equity = dummyEquity();
26
+ expect(equity).toBeInstanceOf(security_1.default);
27
+ expect(equity).not.toBeInstanceOf(BondSecurity_1.default);
28
+ expect(equity.isBond()).toBe(false);
29
+ });
30
+ test('bond routes to BondSecurity and isBond() returns true (narrows type)', () => {
31
+ const bond = dummyBondSecurity();
32
+ expect(bond.isBond()).toBe(true);
33
+ if (bond.isBond()) {
34
+ // Inside the narrowed branch TS knows bond: BondSecurity.
35
+ // Calling a BondSecurity-only method here proves the narrowing works.
36
+ expect(bond.getCouponRate()).toBeDefined();
37
+ }
38
+ });
39
+ test('Security.getIssueDate returns null on equity (no throw)', () => {
40
+ const equity = dummyEquity();
41
+ // Phase 1 behavior change: was throw "Issue date is required", now returns null.
42
+ // This is the symptom fix that motivated #205 — equity wrappers no longer
43
+ // explode on per-record post-processing in ui-service.
44
+ expect(equity.getIssueDate()).toBeNull();
45
+ });
46
+ test('BondSecurity.getIssueDate returns LocalDate (non-nullable) on bond', () => {
47
+ const bond = dummyBondSecurity();
48
+ if (!bond.isBond())
49
+ throw new Error('test setup: expected bond');
50
+ const issueDate = bond.getIssueDate();
51
+ expect(issueDate).not.toBeNull();
52
+ expect(issueDate.toDate().getFullYear()).toBe(2021);
53
+ });
54
+ test('Security.getMaturityDate still throws on equity (Phase 1 deprecation, not removal)', () => {
55
+ const equity = dummyEquity();
56
+ // Behavior preserved deliberately for Phase 1 — callers still get a
57
+ // loud error if they don't narrow first. Removal happens in Phase 2.
58
+ expect(() => equity.getMaturityDate()).toThrow('Maturity date is required');
59
+ });
60
+ test('BondSecurity.getMaturityDate works on bond (inherited from Security)', () => {
61
+ const bond = dummyBondSecurity();
62
+ if (!bond.isBond())
63
+ throw new Error('test setup: expected bond');
64
+ expect(bond.getMaturityDate().toDate().getFullYear()).toBe(2026);
65
+ });
22
66
  function dummySecurity() {
23
67
  return security_1.default.create(new security_pb_1.SecurityProto()
24
68
  .setObjectClass('Transaction').setVersion('0.0.1').setUuid(uuid_1.UUID.random().toUUIDProto())
@@ -33,4 +77,32 @@ function dummySecurity() {
33
77
  .setIssueDate(new local_date_pb_1.LocalDateProto().setYear(2021).setMonth(1).setDay(1))
34
78
  .setDescription("Dummy security"));
35
79
  }
80
+ function dummyBondSecurity() {
81
+ // Same dummy security but with securityType set so the factory routes
82
+ // to BondSecurity.
83
+ return security_1.default.create(new security_pb_1.SecurityProto()
84
+ .setObjectClass('Security').setVersion('0.0.1').setUuid(uuid_1.UUID.random().toUUIDProto())
85
+ .setSecurityType(security_type_pb_1.SecurityTypeProto.BOND_SECURITY)
86
+ .setFaceValue(new decimal_value_pb_1.DecimalValueProto().setArbitraryPrecisionValue('1000.00'))
87
+ .setQuantityType(security_quantity_type_pb_1.SecurityQuantityTypeProto.ORIGINAL_FACE_VALUE)
88
+ .setAssetClass("Bond")
89
+ .setIssuerName("Dummy issuer")
90
+ .setCouponRate(new decimal_value_pb_1.DecimalValueProto().setArbitraryPrecisionValue('0.05'))
91
+ .setCouponFrequency(coupon_frequency_pb_1.CouponFrequencyProto.SEMIANNUALLY)
92
+ .setCouponType(coupon_type_pb_1.CouponTypeProto.FIXED)
93
+ .setMaturityDate(new local_date_pb_1.LocalDateProto().setYear(2026).setMonth(1).setDay(1))
94
+ .setIssueDate(new local_date_pb_1.LocalDateProto().setYear(2021).setMonth(1).setDay(1))
95
+ .setDescription("Dummy bond"));
96
+ }
97
+ function dummyEquity() {
98
+ // Equity has no maturity / issue date in the proto, exercising the
99
+ // null-return behavior on getIssueDate and the throw-on-missing
100
+ // behavior on getMaturityDate.
101
+ return security_1.default.create(new security_pb_1.SecurityProto()
102
+ .setObjectClass('Security').setVersion('0.0.1').setUuid(uuid_1.UUID.random().toUUIDProto())
103
+ .setSecurityType(security_type_pb_1.SecurityTypeProto.EQUITY_SECURITY)
104
+ .setAssetClass("Equity")
105
+ .setIssuerName("Dummy issuer Inc.")
106
+ .setDescription("Dummy equity"));
107
+ }
36
108
  //# sourceMappingURL=security.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"security.test.js","sourceRoot":"","sources":["security.test.ts"],"names":[],"mappings":";;;;;AAAA,iFAA+E;AAC/E,wCAAqC;AAErC,iCAAkC;AAClC,0DAAkC;AAElC,uFAAqF;AACrF,iFAAgF;AAChF,iGAA+F;AAC/F,uFAAqF;AACrF,6GAA0G;AAG1G,IAAI,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACnC,iBAAiB,EAAE,CAAC;AACxB,CAAC,CAAC,CAAC;AAEH,SAAS,iBAAiB;IACtB,MAAM,QAAQ,GAAG,aAAa,EAAE,CAAC;IAEjC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE,IAAI,IAAI,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,aAAa;IAClB,OAAO,kBAAQ,CAAC,MAAM,CAAC,IAAI,2BAAa,EAAE;SACrC,cAAc,CAAC,aAAa,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,WAAI,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE,CAAC;SACtF,YAAY,CAAC,IAAI,oCAAiB,EAAE,CAAC,0BAA0B,CAAC,SAAS,CAAC,CAAC;SAC3E,eAAe,CAAC,qDAAyB,CAAC,mBAAmB,CAAC;SAC9D,aAAa,CAAC,MAAM,CAAC;SACrB,aAAa,CAAC,cAAc,CAAC;SAE7B,aAAa,CAAC,IAAI,oCAAiB,EAAE,CAAC,0BAA0B,CAAC,MAAM,CAAC,CAAC;SACzE,kBAAkB,CAAC,0CAAoB,CAAC,YAAY,CAAC;SACrD,aAAa,CAAC,gCAAe,CAAC,KAAK,CAAC;SAEpC,eAAe,CAAC,IAAI,8BAAc,EAAE,CAAC,OAA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CAAC,CAClC,CAAC;AACN,CAAC"}
@@ -3,9 +3,11 @@ import { UUID } from '../utils/uuid';
3
3
 
4
4
  import assert = require('assert');
5
5
  import Security from './security';
6
+ import BondSecurity from './BondSecurity';
6
7
 
7
8
  import { DecimalValueProto } from '../../../fintekkers/models/util/decimal_value_pb';
8
9
  import { SecurityProto } from '../../../fintekkers/models/security/security_pb';
10
+ import { SecurityTypeProto } from '../../../fintekkers/models/security/security_type_pb';
9
11
  import { CouponFrequencyProto } from '../../../fintekkers/models/security/coupon_frequency_pb';
10
12
  import { CouponTypeProto } from '../../../fintekkers/models/security/coupon_type_pb';
11
13
  import { SecurityQuantityTypeProto } from '../../../fintekkers/models/security/security_quantity_type_pb';
@@ -21,6 +23,52 @@ function testSerialization(): void {
21
23
  assert(security.getMaturityDate().toDate().getFullYear() == 2026);
22
24
  }
23
25
 
26
+ test('equity routes to base Security and isBond() returns false', () => {
27
+ const equity = dummyEquity();
28
+ expect(equity).toBeInstanceOf(Security);
29
+ expect(equity).not.toBeInstanceOf(BondSecurity);
30
+ expect(equity.isBond()).toBe(false);
31
+ });
32
+
33
+ test('bond routes to BondSecurity and isBond() returns true (narrows type)', () => {
34
+ const bond = dummyBondSecurity();
35
+ expect(bond.isBond()).toBe(true);
36
+ if (bond.isBond()) {
37
+ // Inside the narrowed branch TS knows bond: BondSecurity.
38
+ // Calling a BondSecurity-only method here proves the narrowing works.
39
+ expect(bond.getCouponRate()).toBeDefined();
40
+ }
41
+ });
42
+
43
+ test('Security.getIssueDate returns null on equity (no throw)', () => {
44
+ const equity = dummyEquity();
45
+ // Phase 1 behavior change: was throw "Issue date is required", now returns null.
46
+ // This is the symptom fix that motivated #205 — equity wrappers no longer
47
+ // explode on per-record post-processing in ui-service.
48
+ expect(equity.getIssueDate()).toBeNull();
49
+ });
50
+
51
+ test('BondSecurity.getIssueDate returns LocalDate (non-nullable) on bond', () => {
52
+ const bond = dummyBondSecurity();
53
+ if (!bond.isBond()) throw new Error('test setup: expected bond');
54
+ const issueDate = bond.getIssueDate();
55
+ expect(issueDate).not.toBeNull();
56
+ expect(issueDate.toDate().getFullYear()).toBe(2021);
57
+ });
58
+
59
+ test('Security.getMaturityDate still throws on equity (Phase 1 deprecation, not removal)', () => {
60
+ const equity = dummyEquity();
61
+ // Behavior preserved deliberately for Phase 1 — callers still get a
62
+ // loud error if they don't narrow first. Removal happens in Phase 2.
63
+ expect(() => equity.getMaturityDate()).toThrow('Maturity date is required');
64
+ });
65
+
66
+ test('BondSecurity.getMaturityDate works on bond (inherited from Security)', () => {
67
+ const bond = dummyBondSecurity();
68
+ if (!bond.isBond()) throw new Error('test setup: expected bond');
69
+ expect(bond.getMaturityDate().toDate().getFullYear()).toBe(2026);
70
+ });
71
+
24
72
  function dummySecurity() {
25
73
  return Security.create(new SecurityProto()
26
74
  .setObjectClass('Transaction').setVersion('0.0.1').setUuid(UUID.random().toUUIDProto())
@@ -39,3 +87,35 @@ function dummySecurity() {
39
87
  );
40
88
  }
41
89
 
90
+ function dummyBondSecurity() {
91
+ // Same dummy security but with securityType set so the factory routes
92
+ // to BondSecurity.
93
+ return Security.create(new SecurityProto()
94
+ .setObjectClass('Security').setVersion('0.0.1').setUuid(UUID.random().toUUIDProto())
95
+ .setSecurityType(SecurityTypeProto.BOND_SECURITY)
96
+ .setFaceValue(new DecimalValueProto().setArbitraryPrecisionValue('1000.00'))
97
+ .setQuantityType(SecurityQuantityTypeProto.ORIGINAL_FACE_VALUE)
98
+ .setAssetClass("Bond")
99
+ .setIssuerName("Dummy issuer")
100
+ .setCouponRate(new DecimalValueProto().setArbitraryPrecisionValue('0.05'))
101
+ .setCouponFrequency(CouponFrequencyProto.SEMIANNUALLY)
102
+ .setCouponType(CouponTypeProto.FIXED)
103
+ .setMaturityDate(new LocalDateProto().setYear(2026).setMonth(1).setDay(1))
104
+ .setIssueDate(new LocalDateProto().setYear(2021).setMonth(1).setDay(1))
105
+ .setDescription("Dummy bond")
106
+ );
107
+ }
108
+
109
+ function dummyEquity() {
110
+ // Equity has no maturity / issue date in the proto, exercising the
111
+ // null-return behavior on getIssueDate and the throw-on-missing
112
+ // behavior on getMaturityDate.
113
+ return Security.create(new SecurityProto()
114
+ .setObjectClass('Security').setVersion('0.0.1').setUuid(UUID.random().toUUIDProto())
115
+ .setSecurityType(SecurityTypeProto.EQUITY_SECURITY)
116
+ .setAssetClass("Equity")
117
+ .setIssuerName("Dummy issuer Inc.")
118
+ .setDescription("Dummy equity")
119
+ );
120
+ }
121
+
@@ -29,6 +29,25 @@ class Security {
29
29
  }
30
30
  }
31
31
 
32
+ /**
33
+ * Type guard: true iff this Security is a BondSecurity (BOND_SECURITY,
34
+ * TIPS, or FRN). Use to narrow before calling bond-specific getters:
35
+ *
36
+ * if (sec.isBond()) {
37
+ * // sec: BondSecurity here — TS knows about getCouponRate(), etc.
38
+ * console.log(sec.getMaturityDate());
39
+ * }
40
+ *
41
+ * Implemented as a runtime check on the proto's securityType so it
42
+ * works regardless of how the wrapper was constructed.
43
+ */
44
+ isBond(): this is import('./BondSecurity').default {
45
+ const t = this.proto.getSecurityType();
46
+ return t === SecurityTypeProto.BOND_SECURITY
47
+ || t === SecurityTypeProto.TIPS
48
+ || t === SecurityTypeProto.FRN;
49
+ }
50
+
32
51
 
33
52
  toString(): string {
34
53
  return `ID[${this.getID().toString()}], ${this.getSecurityID()}[${this.getIssuerName()}]`;
@@ -57,8 +76,11 @@ class Security {
57
76
  case FieldProto.ADJUSTED_TENOR:
58
77
  throw new Error('Not implemented yet');
59
78
  case FieldProto.MATURITY_DATE:
60
- return this.getMaturityDate();
79
+ // Maturity date is bond-only. Mirror Java's Security.getField:
80
+ // delegate to BondSecurity, return null for non-bonds.
81
+ return this.isBond() ? this.getMaturityDate() : null;
61
82
  case FieldProto.ISSUE_DATE:
83
+ // getIssueDate already returns null on non-bonds; just forward.
62
84
  return this.getIssueDate();
63
85
  default:
64
86
  throw new Error(`Field not mapped in Security wrapper: ${field}`);
@@ -71,6 +93,15 @@ class Security {
71
93
  return UUID.fromU8Array(uuid.getRawUuid_asU8());
72
94
  }
73
95
 
96
+ /**
97
+ * True iff this Security is a link reference (only the uuid is populated;
98
+ * other fields should not be relied on). See docs/adr/is_link_pattern.md.
99
+ * Pair with LinkResolver to hydrate to a full entity.
100
+ */
101
+ isLink(): boolean {
102
+ return this.proto.getIsLink();
103
+ }
104
+
74
105
  getAsOf(): ZonedDateTime {
75
106
  const asOf = this.proto.getAsOf();
76
107
  if (!asOf) throw new Error("AsOf is required");
@@ -100,14 +131,36 @@ class Security {
100
131
  return identifier;
101
132
  }
102
133
 
103
- getIssueDate(): LocalDate {
134
+ /**
135
+ * Returns the issue date if set, else null. Per-type semantic:
136
+ * - Bond / TIPS / FRN: auction date.
137
+ * - Equity: IPO listing date (when present in source data).
138
+ * - CPI series: first observation date.
139
+ * - Cash / FX: typically null.
140
+ *
141
+ * Returns null on equities/cash/etc. that don't have an issue date set,
142
+ * rather than throwing — issue date is optional on the base Security.
143
+ * For bond-specific code paths, prefer narrowing first via isBond() and
144
+ * calling BondSecurity.getIssueDate() (which returns LocalDate, not null).
145
+ */
146
+ getIssueDate(): LocalDate | null {
104
147
  // Prefer oneof bond sub-message if available, fall back to flat fields
105
148
  const bond = this.getBondLikeDetails();
106
149
  const date = bond ? bond.getIssueDate() : this.proto.getIssueDate();
107
- if (!date) throw new Error("Issue date is required");
150
+ if (!date) return null;
108
151
  return new LocalDate(date);
109
152
  }
110
153
 
154
+ /**
155
+ * @deprecated Maturity date is a bond-only concept. On the base Security
156
+ * this still throws when unset for backwards compatibility. Prefer
157
+ * narrowing first:
158
+ *
159
+ * if (sec.isBond()) sec.getMaturityDate(); // BondSecurity, returns LocalDate
160
+ *
161
+ * In a future major version this method will move to BondSecurity only
162
+ * and TS will catch the misuse at compile time.
163
+ */
111
164
  getMaturityDate(): LocalDate {
112
165
  // Prefer oneof bond sub-message if available, fall back to flat fields
113
166
  const bond = this.getBondLikeDetails();
@@ -4,6 +4,7 @@ import { LocalTimestampProto } from '../../../fintekkers/models/util/local_times
4
4
  import { PriceProto } from '../../../fintekkers/models/price/price_pb';
5
5
  import { SummaryProto } from '../../../fintekkers/requests/util/errors/summary_pb';
6
6
  import { CreatePriceResponseProto } from '../../../fintekkers/requests/price/create_price_response_pb';
7
+ import LinkResolver from '../../util/link-resolver';
7
8
  declare class PriceService {
8
9
  private client;
9
10
  constructor(apiKey?: string);
@@ -25,5 +26,23 @@ declare class PriceService {
25
26
  * priceService.searchBySecurityId('18e8c4e6-3da0-47c9-...')
26
27
  */
27
28
  searchBySecurityId(securityId: string, asOf?: LocalTimestampProto): Promise<Price[]>;
29
+ /**
30
+ * Search prices and hydrate each Price's embedded Security from link
31
+ * to full entity in a single batched lookup. Equivalent to:
32
+ *
33
+ * const prices = await priceService.search(asOf, filter);
34
+ * await new LinkResolver().resolveSecurities(prices);
35
+ *
36
+ * but with the LinkResolver instance reusable across calls (cache hits
37
+ * benefit subsequent lookups).
38
+ *
39
+ * Pass a shared `linkResolver` to share caching across multiple
40
+ * service-wrapper calls in the same request scope. If omitted, a new
41
+ * resolver is constructed per call (no cross-call cache reuse).
42
+ *
43
+ * Mutates each returned Price.proto's embedded SecurityProto in place
44
+ * (link → full). See LinkResolver for cache + dedupe semantics.
45
+ */
46
+ searchWithSecurities(asOf: LocalTimestampProto, positionFilter: PositionFilter, linkResolver?: LinkResolver): Promise<Price[]>;
28
47
  }
29
48
  export { PriceService };