@decafhub/decaf-client-extras 0.0.5 → 0.1.1

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 (52) hide show
  1. package/.github/workflows/release-please.yml +6 -2
  2. package/.github/workflows/test.yml +6 -2
  3. package/.release-please-manifest.json +1 -1
  4. package/CHANGELOG.md +22 -0
  5. package/commons/-currency.d.ts +22 -6
  6. package/commons/-currency.js +12 -6
  7. package/commons/{-date-type.d.ts → -datetype.d.ts} +1 -1
  8. package/commons/{-date-type.js → -datetype.js} +2 -2
  9. package/commons/-id.d.ts +109 -17
  10. package/commons/-id.js +73 -0
  11. package/commons/index.d.ts +4 -1
  12. package/commons/index.js +17 -1
  13. package/es/commons/-currency.d.ts +22 -6
  14. package/es/commons/-currency.js +12 -6
  15. package/es/commons/{-date-type.d.ts → -datetype.d.ts} +1 -1
  16. package/es/commons/{-date-type.js → -datetype.js} +1 -1
  17. package/es/commons/-id.d.ts +109 -17
  18. package/es/commons/-id.js +70 -1
  19. package/es/commons/index.d.ts +4 -1
  20. package/es/commons/index.js +4 -1
  21. package/es/reports/valuation/-remote-valuation-report-portfolio.d.ts +15 -15
  22. package/es/reports/valuation/-remote-valuation-report-portfolio.js +32 -32
  23. package/es/reports/valuation/-remote-valuation-report-shared.d.ts +4 -4
  24. package/es/reports/valuation/-remote-valuation-report-shared.js +29 -26
  25. package/es/reports/valuation/-valuation-report-holdings-tree/-machinery.js +1 -3
  26. package/es/reports/valuation/-valuation-report-portfolio.d.ts +14 -14
  27. package/es/reports/valuation/-valuation-report-shared.d.ts +6 -6
  28. package/nix/default.nix +59 -0
  29. package/nix/sources.json +14 -0
  30. package/nix/sources.nix +194 -0
  31. package/package.json +21 -21
  32. package/reports/valuation/-remote-valuation-report-portfolio.d.ts +15 -15
  33. package/reports/valuation/-remote-valuation-report-portfolio.js +31 -31
  34. package/reports/valuation/-remote-valuation-report-shared.d.ts +4 -4
  35. package/reports/valuation/-remote-valuation-report-shared.js +28 -25
  36. package/reports/valuation/-valuation-report-holdings-tree/-machinery.js +7 -9
  37. package/reports/valuation/-valuation-report-portfolio.d.ts +14 -14
  38. package/reports/valuation/-valuation-report-shared.d.ts +6 -6
  39. package/shell.nix +5 -20
  40. package/src/commons/-currency.test.ts +27 -0
  41. package/src/commons/-currency.ts +24 -9
  42. package/src/commons/-datetype.test.ts +10 -0
  43. package/src/commons/{-date-type.ts → -datetype.ts} +1 -1
  44. package/src/commons/-id.test.ts +27 -0
  45. package/src/commons/-id.ts +112 -17
  46. package/src/commons/index.ts +4 -1
  47. package/src/index.test.ts +5 -5
  48. package/src/reports/valuation/-remote-valuation-report-portfolio.ts +54 -54
  49. package/src/reports/valuation/-remote-valuation-report-shared.ts +34 -31
  50. package/src/reports/valuation/-valuation-report-holdings-tree/-machinery.ts +5 -7
  51. package/src/reports/valuation/-valuation-report-portfolio.ts +20 -20
  52. package/src/reports/valuation/-valuation-report-shared.ts +13 -6
@@ -1,58 +1,150 @@
1
- import { NewTypeWithPhantom } from '@telostat/prelude';
2
1
  /**
3
- * Type definition for identifiers with value spaces discriminated over the
4
- * given phantom type.
2
+ * This module provides a collection of DECAF record identifier type
3
+ * definitions. It is not exhaustive and it will be improved on an ongoing
4
+ * basis.
5
+ *
6
+ * Typically, a DECAF record identifier is either number or string. Some DECAF
7
+ * API endoints can consume string values even though a number is expected. We
8
+ * are sticking here to the original type: No `number | string` definitions.
9
+ *
10
+ * Methodologically, we are using a type trick to emulate newtypes in this
11
+ * module: For example, DECAF artifact identifier type is defined as:
12
+ *
13
+ * ```ts
14
+ * export type DecafArtifactId = number & { readonly __tag: unique symbol };
15
+ * ```
16
+ *
17
+ * In runtime, there is only a number. The `& { readonly __tag: unique symbol }`
18
+ * is provided to the compiler to distinguish in between `number` identifier
19
+ * values which are representing different DECAF record types.
20
+ *
21
+ * The construction and deconstruction of DECAF record identifiers are done via,
22
+ * respecively, `mkDecafRecordId` and `unDecafRecordId`:
23
+ *
24
+ * ```ts
25
+ * const exampleDecafArtifactIdValue: number = unDecafRecordId(exampleDecafArtifactId);
26
+ * const exampleDecafArtifactId: DecafArtifactId = mkDecafRecordId(42);
27
+ * expect(exampleDecafArtifactIdValue).toBe(42);
28
+ *
29
+ * const exampleDecafActionId: DecafActionId = mkDecafRecordId(42);
30
+ * const exampleDecafActionIdValue: number = unDecafRecordId(exampleDecafActionId);
31
+ * expect(exampleDecafActionIdValue).toBe(42);
32
+ *
33
+ * const exampleDecafArtifactTypeId: DecafArtifactTypeId = mkDecafRecordId('CCY');
34
+ * const exampleDecafArtifactTypeIdValue: string = unDecafRecordId(exampleDecafArtifactTypeId);
35
+ * expect(exampleDecafArtifactTypeIdValue).toBe('CCY');
36
+ * ```
37
+ *
38
+ * To re-iterate, the runtime representation is not affected by how DECAF record
39
+ * identifier types are defined:
40
+ *
41
+ * ```ts
42
+ * interface DecafArtifact {
43
+ * id: DecafArtifactId;
44
+ * type: DecafArtifactTypeId;
45
+ * }
46
+ *
47
+ * const exampleDecafArtifact: DecafArtifact = { id: mkDecafRecordId(10), type: mkDecafRecordId('CCY') };
48
+ * expect(exampleDecafArtifact).toStrictEqual({ id: 10, type: 'CCY' });
49
+ * ```
50
+ *
51
+ * @module
5
52
  */
6
- export type Id<P, V> = NewTypeWithPhantom<P, V>;
53
+ /**
54
+ * Type definition covering all possible DECAF record identifiers based on
55
+ * `number` values.
56
+ *
57
+ * This type definition must be extended whenever there is a new DECAF record
58
+ * identifier is defined in this module.
59
+ */
60
+ export type _DecafRecordIdFromNumber = DecafArtifactId | DecafActionId;
61
+ /**
62
+ * Type definition covering all possible DECAF record identifiers based on
63
+ * `string` values.
64
+ *
65
+ * This type definition must be extended whenever there is a new DECAF record
66
+ * identifier is defined in this module.
67
+ */
68
+ export type _DecafRecordIdFromString = DecafArtifactTypeId;
69
+ export declare function mkDecafRecordId<T extends _DecafRecordIdFromNumber>(x: number): T;
70
+ export declare function mkDecafRecordId<T extends _DecafRecordIdFromString>(x: string): T;
71
+ export declare function unDecafRecordId<T extends _DecafRecordIdFromNumber>(x: T): number;
72
+ export declare function unDecafRecordId<K extends _DecafRecordIdFromString>(x: K): string;
7
73
  /**
8
74
  * Type definition for DECAF artifact identifiers.
9
75
  */
10
- export type ArtifactId = NewTypeWithPhantom<'DecafArtifact', string | number>;
76
+ export type DecafArtifactId = number & {
77
+ readonly __tag: unique symbol;
78
+ };
11
79
  /**
12
80
  * Type definition for DECAF artifact type identifiers.
13
81
  */
14
- export type ArtifactTypeId = NewTypeWithPhantom<'DecafArtifactType', string>;
82
+ export type DecafArtifactTypeId = string & {
83
+ readonly __tag: unique symbol;
84
+ };
15
85
  /**
16
86
  * Type definition for DECAF share class identifiers.
17
87
  */
18
- export type ShareClassId = NewTypeWithPhantom<'DecafShareClass', string | number>;
88
+ export type DecafShareClassId = number & {
89
+ readonly __tag: unique symbol;
90
+ };
19
91
  /**
20
92
  * Type definition for DECAF principal identifiers.
21
93
  */
22
- export type PrincipalId = NewTypeWithPhantom<'DecafPrincipal', string | number>;
94
+ export type DecafPrincipalId = number & {
95
+ readonly __tag: unique symbol;
96
+ };
23
97
  /**
24
98
  * Type definition for DECAF institution identifiers.
25
99
  */
26
- export type InstitutionId = NewTypeWithPhantom<'DecafInstitution', string | number>;
100
+ export type DecafInstitutionId = number & {
101
+ readonly __tag: unique symbol;
102
+ };
27
103
  /**
28
104
  * Type definition for DECAF team identifiers.
29
105
  */
30
- export type TeamId = NewTypeWithPhantom<'DecafTeam', string | number>;
106
+ export type DecafTeamId = number & {
107
+ readonly __tag: unique symbol;
108
+ };
31
109
  /**
32
110
  * Type definition for DECAF portfolio identifiers.
33
111
  */
34
- export type PortfolioId = NewTypeWithPhantom<'DecafPortfolio', string | number>;
112
+ export type DecafPortfolioId = number & {
113
+ readonly __tag: unique symbol;
114
+ };
35
115
  /**
36
116
  * Type definition for DECAF portfolio group identifiers.
37
117
  */
38
- export type PortfolioGroupId = NewTypeWithPhantom<'DecafPortfolioGroup', string | number>;
118
+ export type DecafPortfolioGroupId = number & {
119
+ readonly __tag: unique symbol;
120
+ };
39
121
  /**
40
122
  * Type definition for DECAF account identifiers.
41
123
  */
42
- export type AccountId = NewTypeWithPhantom<'DecafAccount', string | number>;
124
+ export type DecafAccountId = number & {
125
+ readonly __tag: unique symbol;
126
+ };
43
127
  /**
44
128
  * Type definition for DECAF OHLC series identifiers.
45
129
  */
46
- export type OhlcSeriesId = NewTypeWithPhantom<'DecafOhlcSeries', string | number>;
130
+ export type DecafOhlcSeriesId = number & {
131
+ readonly __tag: unique symbol;
132
+ };
47
133
  /**
48
134
  * Type definition for DECAF share class fee schedule identifiers.
49
135
  */
50
- export type ShareClassFeeScheduleId = NewTypeWithPhantom<'DecafShareClassFeeSchedule', string | number>;
136
+ export type DecafShareClassFeeScheduleId = number & {
137
+ readonly __tag: unique symbol;
138
+ };
51
139
  /**
52
140
  * Type definition for DECAF action identifiers.
53
141
  */
54
- export type ActionId = NewTypeWithPhantom<'DecafAction', string | number>;
142
+ export type DecafActionId = number & {
143
+ readonly __tag: unique symbol;
144
+ };
55
145
  /**
56
146
  * Type definition for DECAF external valuation identifiers.
57
147
  */
58
- export type ExternalValuationId = NewTypeWithPhantom<'DecafExternalValuation', string | number>;
148
+ export type DecafExternalValuationId = number & {
149
+ readonly __tag: unique symbol;
150
+ };
package/es/commons/-id.js CHANGED
@@ -1 +1,70 @@
1
- export {};
1
+ /**
2
+ * This module provides a collection of DECAF record identifier type
3
+ * definitions. It is not exhaustive and it will be improved on an ongoing
4
+ * basis.
5
+ *
6
+ * Typically, a DECAF record identifier is either number or string. Some DECAF
7
+ * API endoints can consume string values even though a number is expected. We
8
+ * are sticking here to the original type: No `number | string` definitions.
9
+ *
10
+ * Methodologically, we are using a type trick to emulate newtypes in this
11
+ * module: For example, DECAF artifact identifier type is defined as:
12
+ *
13
+ * ```ts
14
+ * export type DecafArtifactId = number & { readonly __tag: unique symbol };
15
+ * ```
16
+ *
17
+ * In runtime, there is only a number. The `& { readonly __tag: unique symbol }`
18
+ * is provided to the compiler to distinguish in between `number` identifier
19
+ * values which are representing different DECAF record types.
20
+ *
21
+ * The construction and deconstruction of DECAF record identifiers are done via,
22
+ * respecively, `mkDecafRecordId` and `unDecafRecordId`:
23
+ *
24
+ * ```ts
25
+ * const exampleDecafArtifactIdValue: number = unDecafRecordId(exampleDecafArtifactId);
26
+ * const exampleDecafArtifactId: DecafArtifactId = mkDecafRecordId(42);
27
+ * expect(exampleDecafArtifactIdValue).toBe(42);
28
+ *
29
+ * const exampleDecafActionId: DecafActionId = mkDecafRecordId(42);
30
+ * const exampleDecafActionIdValue: number = unDecafRecordId(exampleDecafActionId);
31
+ * expect(exampleDecafActionIdValue).toBe(42);
32
+ *
33
+ * const exampleDecafArtifactTypeId: DecafArtifactTypeId = mkDecafRecordId('CCY');
34
+ * const exampleDecafArtifactTypeIdValue: string = unDecafRecordId(exampleDecafArtifactTypeId);
35
+ * expect(exampleDecafArtifactTypeIdValue).toBe('CCY');
36
+ * ```
37
+ *
38
+ * To re-iterate, the runtime representation is not affected by how DECAF record
39
+ * identifier types are defined:
40
+ *
41
+ * ```ts
42
+ * interface DecafArtifact {
43
+ * id: DecafArtifactId;
44
+ * type: DecafArtifactTypeId;
45
+ * }
46
+ *
47
+ * const exampleDecafArtifact: DecafArtifact = { id: mkDecafRecordId(10), type: mkDecafRecordId('CCY') };
48
+ * expect(exampleDecafArtifact).toStrictEqual({ id: 10, type: 'CCY' });
49
+ * ```
50
+ *
51
+ * @module
52
+ */
53
+ /**
54
+ * Constructor for DECAF record identifiers.
55
+ *
56
+ * @param x Value to create DECAF record identifier from.
57
+ * @returns DECAF record identifier of type deduced from call-site usage.
58
+ */
59
+ export function mkDecafRecordId(x) {
60
+ return x;
61
+ }
62
+ /**
63
+ * Deconstructor for DECAF record identifiers.
64
+ *
65
+ * @param x DECAF record identifier.
66
+ * @returns Value of the DECAF record identifier (deduced from call-site usage).
67
+ */
68
+ export function unDecafRecordId(x) {
69
+ return x;
70
+ }
@@ -1,3 +1,6 @@
1
1
  export * from './-currency';
2
- export * from './-date-type';
2
+ export * as currency from './-currency';
3
+ export * from './-datetype';
4
+ export * as datetype from './-datetype';
3
5
  export * from './-id';
6
+ export * as id from './-id';
@@ -1,3 +1,6 @@
1
1
  export * from './-currency';
2
- export * from './-date-type';
2
+ export * as currency from './-currency';
3
+ export * from './-datetype';
4
+ export * as datetype from './-datetype';
3
5
  export * from './-id';
6
+ export * as id from './-id';
@@ -1,6 +1,6 @@
1
1
  import { DecafClient } from '@decafhub/decaf-client';
2
2
  import { CustomError, Either, SDate, SDateTime } from '@telostat/prelude';
3
- import { ActionId, CurrencyCode, DateType, ExternalValuationId, OhlcSeriesId, PortfolioId, PrincipalId, ShareClassFeeScheduleId, ShareClassId } from '../../commons';
3
+ import { CurrencyCode, DateType, DecafActionId, DecafExternalValuationId, DecafOhlcSeriesId, DecafPortfolioId, DecafPrincipalId, DecafShareClassFeeScheduleId, DecafShareClassId } from '../../commons';
4
4
  import { RemoteBaseValuationReport } from './-remote-valuation-report-shared';
5
5
  import { PortfolioValuationReport, PortfolioValuationReportShareClassValue } from './-valuation-report-portfolio';
6
6
  import { ValuationReportPortfolio } from './-valuation-report-shared';
@@ -23,7 +23,7 @@ export interface PortfolioValuationReportQuery {
23
23
  /**
24
24
  * Portfolio the valuation report is requested for.
25
25
  */
26
- portfolio: PortfolioId;
26
+ portfolio: DecafPortfolioId;
27
27
  }
28
28
  /**
29
29
  * Type definition for the remote (raw) portfolio valuation report data.
@@ -58,13 +58,13 @@ export interface RemoteValuationShareClassValue {
58
58
  * Type definition for share class on the remote portfolio valuation report.
59
59
  */
60
60
  export interface RemoteValuationShareClass {
61
- id: ShareClassId;
61
+ id: DecafShareClassId;
62
62
  created: SDateTime;
63
- creator: PrincipalId;
63
+ creator: DecafPrincipalId;
64
64
  updated: SDateTime;
65
- updater: PrincipalId;
65
+ updater: DecafPrincipalId;
66
66
  guid: string;
67
- portfolio: PortfolioId;
67
+ portfolio: DecafPortfolioId;
68
68
  name: string;
69
69
  currency: CurrencyCode;
70
70
  isin?: string;
@@ -76,11 +76,11 @@ export interface RemoteValuationShareClass {
76
76
  subredperiod?: string;
77
77
  freqmngt?: number;
78
78
  freqperf?: number;
79
- benchmark?: OhlcSeriesId;
79
+ benchmark?: DecafOhlcSeriesId;
80
80
  description?: string;
81
- feeschedules: ShareClassFeeScheduleId[];
82
- effectivefeeschedule?: ShareClassFeeScheduleId;
83
- subscriptions: ActionId[];
81
+ feeschedules: DecafShareClassFeeScheduleId[];
82
+ effectivefeeschedule?: DecafShareClassFeeScheduleId;
83
+ subscriptions: DecafActionId[];
84
84
  outstanding?: number;
85
85
  }
86
86
  /**
@@ -88,14 +88,14 @@ export interface RemoteValuationShareClass {
88
88
  * report.
89
89
  */
90
90
  export interface RemoteValuationExternalValue {
91
- id: ExternalValuationId;
91
+ id: DecafExternalValuationId;
92
92
  created: SDateTime;
93
- creator: PrincipalId;
93
+ creator: DecafPrincipalId;
94
94
  updated: SDateTime;
95
- updater: PrincipalId;
95
+ updater: DecafPrincipalId;
96
96
  guid: string;
97
- portfolio: PortfolioId;
98
- shareclass?: ShareClassId;
97
+ portfolio: DecafPortfolioId;
98
+ shareclass?: DecafShareClassId;
99
99
  date: SDate;
100
100
  ccy: CurrencyCode;
101
101
  shares?: number;
@@ -1,4 +1,4 @@
1
- import { asDecimal, customError, Left, Maybe, maybeDecimal, Right, sanitizedNonEmptyText, zero, } from '@telostat/prelude';
1
+ import { customError, decimalFromNullable, Left, Maybe, Right, sanitizedNonEmptyText, unsafeDecimal, zero, } from '@telostat/prelude';
2
2
  import { recompileBaseValuationReport } from './-remote-valuation-report-shared';
3
3
  /**
4
4
  * Attempts to retrieve remote portfolio valuation report.
@@ -52,7 +52,7 @@ export function toShareClassValue(x) {
52
52
  feeScheduleIds: x.shareclass.feeschedules,
53
53
  effectiveFeeScheduleId: Maybe.fromNullable(x.shareclass.effectivefeeschedule),
54
54
  subscriptionIds: x.shareclass.subscriptions,
55
- outstanding: maybeDecimal(x.shareclass.outstanding),
55
+ outstanding: decimalFromNullable(x.shareclass.outstanding),
56
56
  },
57
57
  external: Maybe.fromNullable(x.external).map((ev) => ({
58
58
  id: ev.id,
@@ -65,36 +65,36 @@ export function toShareClassValue(x) {
65
65
  shareclass: Maybe.fromNullable(ev.shareclass),
66
66
  date: ev.date,
67
67
  ccy: ev.ccy,
68
- shares: maybeDecimal(ev.shares),
69
- price: maybeDecimal(ev.price),
70
- nav: maybeDecimal(ev.nav),
71
- aum: maybeDecimal(ev.aum),
72
- hedgepnl: maybeDecimal(ev.hedgepnl),
73
- feemngt: maybeDecimal(ev.feemngt),
74
- feeperf: maybeDecimal(ev.feeperf),
75
- otheraccrued: maybeDecimal(ev.otheraccrued),
76
- totalaccrued: maybeDecimal(ev.totalaccrued),
77
- subred: maybeDecimal(ev.subred),
78
- perfdaily: maybeDecimal(ev.perfdaily),
79
- perfweekly: maybeDecimal(ev.perfweekly),
80
- perfmonthly: maybeDecimal(ev.perfmonthly),
81
- perfytd: maybeDecimal(ev.perfytd),
82
- perfstart: maybeDecimal(ev.perfstart),
83
- coefficient: maybeDecimal(ev.coefficient),
68
+ shares: decimalFromNullable(ev.shares),
69
+ price: decimalFromNullable(ev.price),
70
+ nav: decimalFromNullable(ev.nav),
71
+ aum: decimalFromNullable(ev.aum),
72
+ hedgepnl: decimalFromNullable(ev.hedgepnl),
73
+ feemngt: decimalFromNullable(ev.feemngt),
74
+ feeperf: decimalFromNullable(ev.feeperf),
75
+ otheraccrued: decimalFromNullable(ev.otheraccrued),
76
+ totalaccrued: decimalFromNullable(ev.totalaccrued),
77
+ subred: decimalFromNullable(ev.subred),
78
+ perfdaily: decimalFromNullable(ev.perfdaily),
79
+ perfweekly: decimalFromNullable(ev.perfweekly),
80
+ perfmonthly: decimalFromNullable(ev.perfmonthly),
81
+ perfytd: decimalFromNullable(ev.perfytd),
82
+ perfstart: decimalFromNullable(ev.perfstart),
83
+ coefficient: decimalFromNullable(ev.coefficient),
84
84
  })),
85
- nav: asDecimal(x.nav),
86
- navAdjusted: asDecimal(x.nav_adjusted),
87
- navAdjustedTotal: asDecimal(x.nav_adjusted_total),
88
- coefficient: asDecimal(x.coefficient),
89
- gavRefccy: asDecimal(x.gav_refccy),
90
- gavClsccy: asDecimal(x.gav_clsccy),
91
- sharecountPrev: asDecimal(x.sharecount_prev),
92
- sharecountCurr: asDecimal(x.sharecount_curr),
93
- sharecountDiff: asDecimal(x.sharecount_diff),
94
- pxRefCcy: maybeDecimal(x.px_refccy),
95
- pxClsCcy: maybeDecimal(x.px_clsccy),
96
- ytdExt: maybeDecimal(x.ytdext),
97
- ytdInt: maybeDecimal(x.ytdint),
85
+ nav: unsafeDecimal(x.nav),
86
+ navAdjusted: unsafeDecimal(x.nav_adjusted),
87
+ navAdjustedTotal: unsafeDecimal(x.nav_adjusted_total),
88
+ coefficient: unsafeDecimal(x.coefficient),
89
+ gavRefccy: unsafeDecimal(x.gav_refccy),
90
+ gavClsccy: unsafeDecimal(x.gav_clsccy),
91
+ sharecountPrev: unsafeDecimal(x.sharecount_prev),
92
+ sharecountCurr: unsafeDecimal(x.sharecount_curr),
93
+ sharecountDiff: unsafeDecimal(x.sharecount_diff),
94
+ pxRefCcy: decimalFromNullable(x.px_refccy),
95
+ pxClsCcy: decimalFromNullable(x.px_clsccy),
96
+ ytdExt: decimalFromNullable(x.ytdext),
97
+ ytdInt: decimalFromNullable(x.ytdint),
98
98
  };
99
99
  }
100
100
  /**
@@ -113,7 +113,7 @@ export function recompilePortfolioValuationReport(x) {
113
113
  return {
114
114
  ...report,
115
115
  portfolio: x.portfolio,
116
- subscriptions: maybeDecimal(x.subscriptions).orDefault(zero),
116
+ subscriptions: decimalFromNullable(x.subscriptions).orDefault(zero),
117
117
  shareClassValues: x.scvals.map(toShareClassValue),
118
118
  };
119
119
  });
@@ -1,5 +1,5 @@
1
1
  import { CustomError, Decimal, Either, Maybe, SDate, SDateTime } from '@telostat/prelude';
2
- import { ArtifactId, ArtifactTypeId, CurrencyCode, DateType } from '../../commons';
2
+ import { CurrencyCode, DateType, DecafArtifactId, DecafArtifactTypeId } from '../../commons';
3
3
  import { BaseValuationReport, BaseValuationReportHolding, ValuationReportAccount, ValuationReportAccounts, ValuationReportAccrual, ValuationReportArtifact, ValuationReportFigureOrgRef, ValuationReportHolding } from './-valuation-report-shared';
4
4
  export interface RemoteBaseValuationReport {
5
5
  reported: SDateTime;
@@ -161,10 +161,10 @@ export interface RemoteValuationReportChildHolding {
161
161
  * Valuation artifact.
162
162
  */
163
163
  export interface RemoteValuationReportArtifact {
164
- id: ArtifactId;
164
+ id: DecafArtifactId;
165
165
  guid: string;
166
166
  type: {
167
- id: ArtifactTypeId;
167
+ id: DecafArtifactTypeId;
168
168
  name: string;
169
169
  order: number;
170
170
  };
@@ -181,7 +181,7 @@ export interface RemoteValuationReportArtifact {
181
181
  isin?: string;
182
182
  figi?: string;
183
183
  expiry?: SDate;
184
- underlying_id?: ArtifactId;
184
+ underlying_id?: DecafArtifactId;
185
185
  }
186
186
  /**
187
187
  * Valuation accrual.
@@ -1,4 +1,4 @@
1
- import { asDecimal, Just, Maybe, maybeDecimal, Right, safeDiv, sanitizedNonEmptyText, zero, } from '@telostat/prelude';
1
+ import { decimalFromNullable, Just, Maybe, Right, safeDiv, sanitizedNonEmptyText, unsafeDecimal, zero, } from '@telostat/prelude';
2
2
  export function toArtifact(x) {
3
3
  return {
4
4
  id: x.id,
@@ -8,7 +8,7 @@ export function toArtifact(x) {
8
8
  symbol: x.symbol,
9
9
  name: sanitizedNonEmptyText(x.name),
10
10
  ccy: Maybe.fromNullable(x.ccy),
11
- quantity: asDecimal(x.quantity),
11
+ quantity: unsafeDecimal(x.quantity),
12
12
  country: sanitizedNonEmptyText(x.country),
13
13
  issuer: sanitizedNonEmptyText(x.issuer),
14
14
  sector: sanitizedNonEmptyText(x.sector),
@@ -23,31 +23,34 @@ export function toArtifact(x) {
23
23
  export function toAccrual(x) {
24
24
  return {
25
25
  name: x.name,
26
- value: asDecimal(x.value),
26
+ value: unsafeDecimal(x.value),
27
27
  accounts: x.accounts.map((y) => ({
28
28
  account: y.account,
29
- value: asDecimal(y.value),
29
+ value: unsafeDecimal(y.value),
30
30
  accruals: y.accruals.map((z) => ({
31
31
  artifact: toArtifact(z.artifact),
32
32
  ccy: z.ccy,
33
- value: { org: asDecimal(z.value.org || 0), ref: asDecimal(z.value.ref || 0) },
33
+ value: {
34
+ org: decimalFromNullable(z.value.org).orDefault(zero),
35
+ ref: decimalFromNullable(z.value.ref).orDefault(zero),
36
+ },
34
37
  })),
35
38
  })),
36
39
  };
37
40
  }
38
41
  export function toOrgRef(x) {
39
42
  return {
40
- org: maybeDecimal(x.org).orDefault(zero),
41
- ref: maybeDecimal(x.ref).orDefault(zero),
43
+ org: decimalFromNullable(x.org).orDefault(zero),
44
+ ref: decimalFromNullable(x.ref).orDefault(zero),
42
45
  };
43
46
  }
44
47
  export function toMaybeOrgRef(x) {
45
- return Maybe.fromNullable(x).chain(({ org, ref }) => maybeDecimal(org).chain((o) => maybeDecimal(ref).chain((r) => Just({ org: o, ref: r }))));
48
+ return Maybe.fromNullable(x).chain(({ org, ref }) => decimalFromNullable(org).chain((o) => decimalFromNullable(ref).chain((r) => Just({ org: o, ref: r }))));
46
49
  }
47
50
  export function toBaseHolding(nav, x) {
48
51
  return {
49
52
  artifact: toArtifact(x.artifact),
50
- quantity: asDecimal(x.quantity),
53
+ quantity: unsafeDecimal(x.quantity),
51
54
  investment: {
52
55
  px: toOrgRef(x.investment.px),
53
56
  txncosts: toMaybeOrgRef(x.investment.txncosts),
@@ -66,12 +69,12 @@ export function toBaseHolding(nav, x) {
66
69
  abs: toOrgRef(x.valuation.exposure.abs),
67
70
  },
68
71
  },
69
- valuePercentage: safeDiv(maybeDecimal(x.valuation.value.net.ref).orDefault(zero), nav),
70
- netExposurePercentage: safeDiv(maybeDecimal(x.valuation.exposure.net.ref).orDefault(zero), nav),
71
- absExposurePercentage: safeDiv(maybeDecimal(x.valuation.exposure.abs.ref).orDefault(zero), nav),
72
- change: maybeDecimal(x.change),
73
- pnl: maybeDecimal(x.pnl).orDefault(zero),
74
- pnlToInvestment: maybeDecimal(x.pnl_to_investment),
72
+ valuePercentage: safeDiv(decimalFromNullable(x.valuation.value.net.ref).orDefault(zero), nav),
73
+ netExposurePercentage: safeDiv(decimalFromNullable(x.valuation.exposure.net.ref).orDefault(zero), nav),
74
+ absExposurePercentage: safeDiv(decimalFromNullable(x.valuation.exposure.abs.ref).orDefault(zero), nav),
75
+ change: decimalFromNullable(x.change),
76
+ pnl: decimalFromNullable(x.pnl).orDefault(zero),
77
+ pnlToInvestment: decimalFromNullable(x.pnl_to_investment),
75
78
  opendate: x.opendate,
76
79
  lastdate: x.lastdate,
77
80
  };
@@ -98,7 +101,7 @@ export function toHolding(nav, x) {
98
101
  * report.
99
102
  */
100
103
  export function recompileBaseValuationReport(x) {
101
- const nav = maybeDecimal(x.nav).orDefault(zero);
104
+ const nav = decimalFromNullable(x.nav).orDefault(zero);
102
105
  const report = {
103
106
  asof: x.reported,
104
107
  date: x.asof,
@@ -107,20 +110,20 @@ export function recompileBaseValuationReport(x) {
107
110
  accounts: x.accounts,
108
111
  holdings: x.holdings.map((rh) => toHolding(nav, rh)),
109
112
  accruals: x.accruals.map(toAccrual),
110
- fxRates: x.fxrates.map((r) => ({ ccy1: r.ccy1, ccy2: r.ccy2, value: asDecimal(r.value), asof: r.asof })),
113
+ fxRates: x.fxrates.map((r) => ({ ccy1: r.ccy1, ccy2: r.ccy2, value: unsafeDecimal(r.value), asof: r.asof })),
111
114
  figures: {
112
- investment: maybeDecimal(x.investment).orDefault(zero),
115
+ investment: decimalFromNullable(x.investment).orDefault(zero),
113
116
  valuation: {
114
- net: maybeDecimal(x.valuation_net).orDefault(zero),
115
- abs: maybeDecimal(x.valuation_abs).orDefault(zero),
117
+ net: decimalFromNullable(x.valuation_net).orDefault(zero),
118
+ abs: decimalFromNullable(x.valuation_abs).orDefault(zero),
116
119
  },
117
- accrued: maybeDecimal(x.accrued).orDefault(zero),
118
- liabilities: maybeDecimal(x.liabilities).orDefault(zero),
119
- gav: maybeDecimal(x.gav).orDefault(zero),
120
+ accrued: decimalFromNullable(x.accrued).orDefault(zero),
121
+ liabilities: decimalFromNullable(x.liabilities).orDefault(zero),
122
+ gav: decimalFromNullable(x.gav).orDefault(zero),
120
123
  nav,
121
- aum: maybeDecimal(x.aum).orDefault(zero),
122
- pnl: maybeDecimal(x.pnl).orDefault(zero),
123
- pnlToInvestment: maybeDecimal(x.pnl_to_investment),
124
+ aum: decimalFromNullable(x.aum).orDefault(zero),
125
+ pnl: decimalFromNullable(x.pnl).orDefault(zero),
126
+ pnlToInvestment: decimalFromNullable(x.pnl_to_investment),
124
127
  },
125
128
  };
126
129
  return Right(report);
@@ -1,6 +1,4 @@
1
- import { safeDiv, sumDecimals, Tuple, zero } from '@telostat/prelude';
2
- import { Just, Maybe, Nothing } from 'purify-ts';
3
- import { List } from 'purify-ts/List';
1
+ import { Just, List, Maybe, Nothing, safeDiv, sumDecimals, Tuple, zero } from '@telostat/prelude';
4
2
  import { compareStringArrays } from './-utils';
5
3
  export function makeValuationReportHoldingsTreeNodeValue() {
6
4
  return {
@@ -1,5 +1,5 @@
1
1
  import { Decimal, Maybe, SDate, SDateTime } from '@telostat/prelude';
2
- import { ActionId, CurrencyCode, ExternalValuationId, OhlcSeriesId, PortfolioId, PrincipalId, ShareClassFeeScheduleId, ShareClassId } from '../../commons';
2
+ import { DecafActionId, CurrencyCode, DecafExternalValuationId, DecafOhlcSeriesId, DecafPortfolioId, DecafPrincipalId, DecafShareClassFeeScheduleId, DecafShareClassId } from '../../commons';
3
3
  import { BaseValuationReport, ValuationReportPortfolio } from './-valuation-report-shared';
4
4
  export interface PortfolioValuationReport extends BaseValuationReport {
5
5
  portfolio: ValuationReportPortfolio;
@@ -24,13 +24,13 @@ export interface PortfolioValuationReportShareClassValue {
24
24
  ytdInt: Maybe<Decimal>;
25
25
  }
26
26
  export interface PortfolioValuationReportShareClass {
27
- id: ShareClassId;
27
+ id: DecafShareClassId;
28
28
  created: SDateTime;
29
- creator: Maybe<PrincipalId>;
29
+ creator: Maybe<DecafPrincipalId>;
30
30
  updated: SDateTime;
31
- updater: Maybe<PrincipalId>;
31
+ updater: Maybe<DecafPrincipalId>;
32
32
  guid: string;
33
- portfolio: PortfolioId;
33
+ portfolio: DecafPortfolioId;
34
34
  name: string;
35
35
  currency: CurrencyCode;
36
36
  isin: Maybe<string>;
@@ -42,22 +42,22 @@ export interface PortfolioValuationReportShareClass {
42
42
  subscriptionRedemptionPeriod: Maybe<string>;
43
43
  managementFeeFrequency: Maybe<number>;
44
44
  performanceFeeFrequency: Maybe<number>;
45
- benchmark: Maybe<OhlcSeriesId>;
45
+ benchmark: Maybe<DecafOhlcSeriesId>;
46
46
  description: Maybe<string>;
47
- feeScheduleIds: ShareClassFeeScheduleId[];
48
- effectiveFeeScheduleId: Maybe<ShareClassFeeScheduleId>;
49
- subscriptionIds: ActionId[];
47
+ feeScheduleIds: DecafShareClassFeeScheduleId[];
48
+ effectiveFeeScheduleId: Maybe<DecafShareClassFeeScheduleId>;
49
+ subscriptionIds: DecafActionId[];
50
50
  outstanding: Maybe<Decimal>;
51
51
  }
52
52
  export interface PortfolioValuationReportExternalValue {
53
- id: ExternalValuationId;
53
+ id: DecafExternalValuationId;
54
54
  created: SDateTime;
55
- creator: Maybe<PrincipalId>;
55
+ creator: Maybe<DecafPrincipalId>;
56
56
  updated: SDateTime;
57
- updater: Maybe<PrincipalId>;
57
+ updater: Maybe<DecafPrincipalId>;
58
58
  guid: string;
59
- portfolio: PortfolioId;
60
- shareclass: Maybe<ShareClassId>;
59
+ portfolio: DecafPortfolioId;
60
+ shareclass: Maybe<DecafShareClassId>;
61
61
  date: SDate;
62
62
  ccy: CurrencyCode;
63
63
  shares: Maybe<Decimal>;