@decafhub/decaf-client-extras 0.0.5 → 0.1.0

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 (50) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +15 -0
  3. package/commons/-currency.d.ts +22 -6
  4. package/commons/-currency.js +12 -6
  5. package/commons/{-date-type.d.ts → -datetype.d.ts} +1 -1
  6. package/commons/{-date-type.js → -datetype.js} +2 -2
  7. package/commons/-id.d.ts +109 -17
  8. package/commons/-id.js +73 -0
  9. package/commons/index.d.ts +4 -1
  10. package/commons/index.js +17 -1
  11. package/es/commons/-currency.d.ts +22 -6
  12. package/es/commons/-currency.js +12 -6
  13. package/es/commons/{-date-type.d.ts → -datetype.d.ts} +1 -1
  14. package/es/commons/{-date-type.js → -datetype.js} +1 -1
  15. package/es/commons/-id.d.ts +109 -17
  16. package/es/commons/-id.js +70 -1
  17. package/es/commons/index.d.ts +4 -1
  18. package/es/commons/index.js +4 -1
  19. package/es/reports/valuation/-remote-valuation-report-portfolio.d.ts +15 -15
  20. package/es/reports/valuation/-remote-valuation-report-portfolio.js +32 -32
  21. package/es/reports/valuation/-remote-valuation-report-shared.d.ts +4 -4
  22. package/es/reports/valuation/-remote-valuation-report-shared.js +29 -26
  23. package/es/reports/valuation/-valuation-report-holdings-tree/-machinery.js +1 -3
  24. package/es/reports/valuation/-valuation-report-portfolio.d.ts +14 -14
  25. package/es/reports/valuation/-valuation-report-shared.d.ts +6 -6
  26. package/nix/default.nix +59 -0
  27. package/nix/sources.json +14 -0
  28. package/nix/sources.nix +194 -0
  29. package/package.json +2 -2
  30. package/reports/valuation/-remote-valuation-report-portfolio.d.ts +15 -15
  31. package/reports/valuation/-remote-valuation-report-portfolio.js +31 -31
  32. package/reports/valuation/-remote-valuation-report-shared.d.ts +4 -4
  33. package/reports/valuation/-remote-valuation-report-shared.js +28 -25
  34. package/reports/valuation/-valuation-report-holdings-tree/-machinery.js +7 -9
  35. package/reports/valuation/-valuation-report-portfolio.d.ts +14 -14
  36. package/reports/valuation/-valuation-report-shared.d.ts +6 -6
  37. package/shell.nix +5 -20
  38. package/src/commons/-currency.test.ts +27 -0
  39. package/src/commons/-currency.ts +24 -9
  40. package/src/commons/-datetype.test.ts +10 -0
  41. package/src/commons/{-date-type.ts → -datetype.ts} +1 -1
  42. package/src/commons/-id.test.ts +27 -0
  43. package/src/commons/-id.ts +112 -17
  44. package/src/commons/index.ts +4 -1
  45. package/src/index.test.ts +5 -5
  46. package/src/reports/valuation/-remote-valuation-report-portfolio.ts +54 -54
  47. package/src/reports/valuation/-remote-valuation-report-shared.ts +34 -31
  48. package/src/reports/valuation/-valuation-report-holdings-tree/-machinery.ts +5 -7
  49. package/src/reports/valuation/-valuation-report-portfolio.ts +20 -20
  50. package/src/reports/valuation/-valuation-report-shared.ts +13 -6
@@ -38,13 +38,11 @@ var __values = (this && this.__values) || function(o) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.makeValuationReportHoldingsTree = exports.addValuationReportHoldingToTree = exports.makeValuationReportHoldingsTreeNode = exports.retreatTree = exports.resortChildren = exports.updateTotals = exports.makeValuationReportHoldingsTreeNodeValue = void 0;
40
40
  var prelude_1 = require("@telostat/prelude");
41
- var purify_ts_1 = require("purify-ts");
42
- var List_1 = require("purify-ts/List");
43
41
  var _utils_1 = require("./-utils");
44
42
  function makeValuationReportHoldingsTreeNodeValue() {
45
43
  return {
46
44
  investment: prelude_1.zero,
47
- accrued: purify_ts_1.Nothing,
45
+ accrued: prelude_1.Nothing,
48
46
  netValue: prelude_1.zero,
49
47
  netValueRatio: prelude_1.zero,
50
48
  absValue: prelude_1.zero,
@@ -73,10 +71,10 @@ function updateTotals(nav, investment, tree) {
73
71
  var pnl = (0, prelude_1.sumDecimals)(holdings.map(function (x) { return x.pnl; })).add((0, prelude_1.sumDecimals)(children.map(function (x) { return x.totals.pnl; })));
74
72
  var accruedsHoldings = holdings.map(function (x) { return x.investment.accrued.map(function (x) { return x.ref; }); });
75
73
  var accruedsChildren = children.map(function (x) { return x.totals.accrued; });
76
- var accrueds = purify_ts_1.Maybe.catMaybes(__spreadArray(__spreadArray([], __read(accruedsHoldings), false), __read(accruedsChildren), false));
74
+ var accrueds = prelude_1.Maybe.catMaybes(__spreadArray(__spreadArray([], __read(accruedsHoldings), false), __read(accruedsChildren), false));
77
75
  return {
78
76
  investment: (0, prelude_1.sumDecimals)(holdings.map(function (x) { return x.investment.value.ref; })).add((0, prelude_1.sumDecimals)(children.map(function (x) { return x.totals.investment; }))),
79
- accrued: accrueds.length === 0 ? purify_ts_1.Nothing : (0, purify_ts_1.Just)((0, prelude_1.sumDecimals)(accrueds)),
77
+ accrued: accrueds.length === 0 ? prelude_1.Nothing : (0, prelude_1.Just)((0, prelude_1.sumDecimals)(accrueds)),
80
78
  netValue: netValue,
81
79
  netValueRatio: (0, prelude_1.safeDiv)(netValue, nav).orDefault(prelude_1.zero),
82
80
  absValue: absValue,
@@ -93,11 +91,11 @@ exports.updateTotals = updateTotals;
93
91
  function resortChildren(node) {
94
92
  return node.children.sort(function (t1, t2) {
95
93
  // Get current address segments:
96
- var segment1 = List_1.List.last(t1.address);
97
- var segment2 = List_1.List.last(t2.address);
94
+ var segment1 = prelude_1.List.last(t1.address);
95
+ var segment2 = prelude_1.List.last(t2.address);
98
96
  // Compare and return:
99
97
  return segment1
100
- .chain(function (s1) { return segment2.chain(function (s2) { return (0, purify_ts_1.Just)((0, prelude_1.Tuple)(s1, s2)); }); })
98
+ .chain(function (s1) { return segment2.chain(function (s2) { return (0, prelude_1.Just)((0, prelude_1.Tuple)(s1, s2)); }); })
101
99
  .map(function (x) { return x.toArray(); })
102
100
  .map(function (_a) {
103
101
  var _b = __read(_a, 2), x = _b[0], y = _b[1];
@@ -118,7 +116,7 @@ function retreatTree(nav, investment, tree) {
118
116
  exports.retreatTree = retreatTree;
119
117
  function makeValuationReportHoldingsTreeNode(address) {
120
118
  return {
121
- name: List_1.List.last(address)
119
+ name: prelude_1.List.last(address)
122
120
  .map(function (x) { return x.name; })
123
121
  .orDefault(''),
124
122
  address: address,
@@ -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>;
@@ -1,5 +1,5 @@
1
1
  import { Decimal, Maybe, SDate, SDateTime } from '@telostat/prelude';
2
- import { AccountId, ArtifactId, ArtifactTypeId, CurrencyCode, DateType, PortfolioId } from '../../commons';
2
+ import { CurrencyCode, DateType, DecafAccountId, DecafArtifactId, DecafArtifactTypeId, DecafPortfolioId } from '../../commons';
3
3
  /**
4
4
  * Type definition for base valuation report.
5
5
  */
@@ -31,7 +31,7 @@ export interface BaseValuationReport {
31
31
  * Type definition for account reference in valuation reports.
32
32
  */
33
33
  export interface ValuationReportAccount {
34
- id: AccountId;
34
+ id: DecafAccountId;
35
35
  guid: string;
36
36
  name: string;
37
37
  }
@@ -39,7 +39,7 @@ export interface ValuationReportAccount {
39
39
  * Type definition for portfolio reference in valuation reports.
40
40
  */
41
41
  export interface ValuationReportPortfolio {
42
- id: PortfolioId;
42
+ id: DecafPortfolioId;
43
43
  guid: string;
44
44
  name: string;
45
45
  }
@@ -155,7 +155,7 @@ export interface ValuationReportAccrualByCurrency {
155
155
  * Type definition of the FINREA artifact type.
156
156
  */
157
157
  export interface ValuationReportArtifactType {
158
- id: ArtifactTypeId;
158
+ id: DecafArtifactTypeId;
159
159
  name: string;
160
160
  order: number;
161
161
  }
@@ -163,7 +163,7 @@ export interface ValuationReportArtifactType {
163
163
  * Type definition for the artifact as reported in the valuation.
164
164
  */
165
165
  export interface ValuationReportArtifact {
166
- id: ArtifactId;
166
+ id: DecafArtifactId;
167
167
  guid: string;
168
168
  type: ValuationReportArtifactType;
169
169
  stype: Maybe<string>;
@@ -179,7 +179,7 @@ export interface ValuationReportArtifact {
179
179
  isin: Maybe<string>;
180
180
  figi: Maybe<string>;
181
181
  expiry: Maybe<SDate>;
182
- underlyingId: Maybe<ArtifactId>;
182
+ underlyingId: Maybe<DecafArtifactId>;
183
183
  }
184
184
  export interface ValuationReportFxRate {
185
185
  ccy1: CurrencyCode;
package/shell.nix CHANGED
@@ -1,21 +1,6 @@
1
- with import (fetchTarball https://github.com/NixOS/nixpkgs/archive/22.05.tar.gz) { };
1
+ { ... }:
2
2
 
3
- stdenv.mkDerivation {
4
- name = "decaf-client-javascript-extras";
5
-
6
- buildInputs = with pkgs; [
7
- git
8
- nodejs-16_x
9
- yarn
10
-
11
- figlet
12
- lolcat
13
- ];
14
-
15
- shellHook = ''
16
- ## Greet:
17
- figlet -w 999 -f standard "DECAF CLIENT EXTRAS DEV SHELL" | lolcat -S 179
18
- '';
19
-
20
- DECAF_JS_SKIP_POSTINSTALL = "TRUE";
21
- }
3
+ let
4
+ nix = import ./nix { };
5
+ in
6
+ nix.shell
@@ -0,0 +1,27 @@
1
+ import { Just, Nothing } from '@telostat/prelude';
2
+ import { CurrencyCode, mkCurrencyCode, mkCurrencyCodeError, unCurrencyCode } from './-currency';
3
+
4
+ describe('currency code tests', () => {
5
+ const inputInvalid = ['', ' ', '\n', '\r', '\t', ' \n\r\t ', ' USD', 'USD ', ' USD ', 'U SD'];
6
+ const inputValid = ['U', 'US', 'USD', 'USd'];
7
+
8
+ test('invalid strings are rejected by the smart constructor', () => {
9
+ inputInvalid.forEach((x) => expect(mkCurrencyCode(x)).toBe(Nothing));
10
+ });
11
+
12
+ test('invalid strings throw errors by the unsafe constructor', () => {
13
+ inputInvalid.forEach((x) => expect(() => mkCurrencyCodeError(x)).toThrow(/^Invalid currency code: /));
14
+ });
15
+
16
+ test('valid strings are accepted by the smart constructor', () => {
17
+ inputValid.forEach((x) => expect(mkCurrencyCode(x)).toStrictEqual(Just(x as CurrencyCode)));
18
+ });
19
+
20
+ test('valid strings are accepted by the unsafe constructor', () => {
21
+ inputValid.forEach((x) => expect(mkCurrencyCodeError(x)).toStrictEqual(x as CurrencyCode));
22
+ });
23
+
24
+ test('currency codes can be converted back to string', () => {
25
+ inputValid.forEach((x) => expect(unCurrencyCode(mkCurrencyCodeError(x))).toStrictEqual(x));
26
+ });
27
+ });
@@ -4,27 +4,40 @@
4
4
  * @module
5
5
  */
6
6
 
7
- import { Just, Maybe, mkPhantom, NewTypeWithPhantom, Nothing, unPhantom } from '@telostat/prelude';
7
+ import { Just, Maybe, Nothing } from '@telostat/prelude';
8
8
 
9
9
  /**
10
- * Type encoding for currency code values.
10
+ * Type definition for currency code values.
11
11
  *
12
- * A currency code is (typically) defined as all-uppercase, three letters.
12
+ * A currency code is (typically) defined as all-uppercase, three-letter
13
+ * `string`. In this library, we are particularly using the regular expression
14
+ * {@link REGEXP_CURRENCY_CODE} which allows any uppercase letter followed by
15
+ * uppercase or lowercase letters.
16
+ *
17
+ * As for the type definition: We are using a (not-so-elegant) trick called
18
+ * "tagged-type" to annotate the plain-vanilla `string` type to be the
19
+ * `CurrencyCode` (_poor man's newtype_). Note that during the runtime, all
20
+ * `CurrencyCode` values are simply a `string` values.
13
21
  */
14
- export type CurrencyCode = NewTypeWithPhantom<'CurrencyCode', string>;
22
+ export type CurrencyCode = string & { readonly __tag: unique symbol };
23
+
24
+ /**
25
+ * Regular expression for currency codes in our concept.
26
+ */
27
+ export const REGEXP_CURRENCY_CODE = /^[A-Z][a-zA-Z]*$/;
15
28
 
16
29
  /**
17
30
  * Attempts to create a {@link CurrencyCode} value with the given currency code.
18
31
  *
19
- * This function returns a `Maybe` value. For the version that throws an
20
- * error, see {@link mkCurrencyCodeError}.
32
+ * This function returns a `Maybe` value. For the
33
+ * version that throws an error, see {@link mkCurrencyCodeError}.
21
34
  *
22
35
  * @param x A currency code represented as string.
23
36
  * @returns If the argument has leading or trailing spaces OR it is empty,
24
37
  * `Nothing` is retured, `Just` {@link CurrencyCode} otherwise.
25
38
  */
26
39
  export function mkCurrencyCode(x: string): Maybe<CurrencyCode> {
27
- return x !== x.trim() || x === '' ? Nothing : Just(mkPhantom(x));
40
+ return REGEXP_CURRENCY_CODE.test(x) ? Just(x as CurrencyCode) : Nothing;
28
41
  }
29
42
 
30
43
  /**
@@ -40,16 +53,18 @@ export function mkCurrencyCode(x: string): Maybe<CurrencyCode> {
40
53
  */
41
54
  export function mkCurrencyCodeError(x: string): CurrencyCode {
42
55
  return mkCurrencyCode(x).orDefaultLazy(() => {
43
- throw new Error(`Invalid currency code: "${x}"`);
56
+ throw new Error(`Invalid currency code: ${x}`);
44
57
  });
45
58
  }
46
59
 
47
60
  /**
48
61
  * Return the currency code as a string value.
49
62
  *
63
+ * In runtime, this is effectively the identity function.
64
+ *
50
65
  * @param x {@link CurrencyCode} to be extracted string from.
51
66
  * @returns Currency code as a string.
52
67
  */
53
68
  export function unCurrencyCode(x: CurrencyCode): string {
54
- return unPhantom(x);
69
+ return x as string;
55
70
  }
@@ -0,0 +1,10 @@
1
+ import { DATE_TYPES } from './-datetype';
2
+
3
+ describe('date-type tests', () => {
4
+ test('we maintain the catalogue of date-type tests', () => {
5
+ expect(DATE_TYPES).toStrictEqual([
6
+ { label: 'Trade Date', value: 'commitment' },
7
+ { label: 'Value Date', value: 'settlement' },
8
+ ]);
9
+ });
10
+ });
@@ -6,7 +6,7 @@ export type DateType = 'commitment' | 'settlement';
6
6
  /**
7
7
  * Translation table for DECAF FINREA action date types.
8
8
  */
9
- export const dateTypes: { label: string; value: DateType }[] = [
9
+ export const DATE_TYPES: { label: string; value: DateType }[] = [
10
10
  { label: 'Trade Date', value: 'commitment' },
11
11
  { label: 'Value Date', value: 'settlement' },
12
12
  ];
@@ -0,0 +1,27 @@
1
+ import { DecafActionId, DecafArtifactId, DecafArtifactTypeId, mkDecafRecordId, unDecafRecordId } from './-id';
2
+
3
+ describe('DECAF record identifier tests', () => {
4
+ test('types are aligned and inferred correctly', () => {
5
+ const exampleDecafArtifactId: DecafArtifactId = mkDecafRecordId(42);
6
+ const exampleDecafArtifactIdValue: number = unDecafRecordId(exampleDecafArtifactId);
7
+ expect(exampleDecafArtifactIdValue).toBe(42);
8
+
9
+ const exampleDecafActionId: DecafActionId = mkDecafRecordId(42);
10
+ const exampleDecafActionIdValue: number = unDecafRecordId(exampleDecafActionId);
11
+ expect(exampleDecafActionIdValue).toBe(42);
12
+
13
+ const exampleDecafArtifactTypeId: DecafArtifactTypeId = mkDecafRecordId('CCY');
14
+ const exampleDecafArtifactTypeIdValue: string = unDecafRecordId(exampleDecafArtifactTypeId);
15
+ expect(exampleDecafArtifactTypeIdValue).toBe('CCY');
16
+ });
17
+
18
+ test('type erasure works as expected', () => {
19
+ interface DecafArtifact {
20
+ id: DecafArtifactId;
21
+ type: DecafArtifactTypeId;
22
+ }
23
+
24
+ const exampleDecafArtifact: DecafArtifact = { id: mkDecafRecordId(10), type: mkDecafRecordId('CCY') };
25
+ expect(exampleDecafArtifact).toStrictEqual({ id: 10, type: 'CCY' });
26
+ });
27
+ });
@@ -1,72 +1,167 @@
1
- import { NewTypeWithPhantom } from '@telostat/prelude';
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
+ /**
55
+ * Type definition covering all possible DECAF record identifiers based on
56
+ * `number` values.
57
+ *
58
+ * This type definition must be extended whenever there is a new DECAF record
59
+ * identifier is defined in this module.
60
+ */
61
+ export type _DecafRecordIdFromNumber = DecafArtifactId | DecafActionId;
62
+
63
+ /**
64
+ * Type definition covering all possible DECAF record identifiers based on
65
+ * `string` values.
66
+ *
67
+ * This type definition must be extended whenever there is a new DECAF record
68
+ * identifier is defined in this module.
69
+ */
70
+ export type _DecafRecordIdFromString = DecafArtifactTypeId;
71
+
72
+ /* Signature for overloaded `mkDecafRecordId` function consuming a `number`. */
73
+ export function mkDecafRecordId<T extends _DecafRecordIdFromNumber>(x: number): T;
74
+
75
+ /* Signature for overloaded `mkDecafRecordId` function consuming a `string`. */
76
+ export function mkDecafRecordId<T extends _DecafRecordIdFromString>(x: string): T;
77
+
78
+ /**
79
+ * Constructor for DECAF record identifiers.
80
+ *
81
+ * @param x Value to create DECAF record identifier from.
82
+ * @returns DECAF record identifier of type deduced from call-site usage.
83
+ */
84
+ export function mkDecafRecordId<T>(x: any): T {
85
+ return x as T;
86
+ }
87
+
88
+ /* Signature for overloaded `unDecafRecordId` function producing a `number`. */
89
+ export function unDecafRecordId<T extends _DecafRecordIdFromNumber>(x: T): number;
90
+
91
+ /* Signature for overloaded `unDecafRecordId` function producing a `string`. */
92
+ export function unDecafRecordId<K extends _DecafRecordIdFromString>(x: K): string;
2
93
 
3
94
  /**
4
- * Type definition for identifiers with value spaces discriminated over the
5
- * given phantom type.
95
+ * Deconstructor for DECAF record identifiers.
96
+ *
97
+ * @param x DECAF record identifier.
98
+ * @returns Value of the DECAF record identifier (deduced from call-site usage).
6
99
  */
7
- export type Id<P, V> = NewTypeWithPhantom<P, V>;
100
+ export function unDecafRecordId<T>(x: T): any {
101
+ return x as unknown;
102
+ }
8
103
 
9
104
  /**
10
105
  * Type definition for DECAF artifact identifiers.
11
106
  */
12
- export type ArtifactId = NewTypeWithPhantom<'DecafArtifact', string | number>;
107
+ export type DecafArtifactId = number & { readonly __tag: unique symbol };
13
108
 
14
109
  /**
15
110
  * Type definition for DECAF artifact type identifiers.
16
111
  */
17
- export type ArtifactTypeId = NewTypeWithPhantom<'DecafArtifactType', string>;
112
+ export type DecafArtifactTypeId = string & { readonly __tag: unique symbol };
18
113
 
19
114
  /**
20
115
  * Type definition for DECAF share class identifiers.
21
116
  */
22
- export type ShareClassId = NewTypeWithPhantom<'DecafShareClass', string | number>;
117
+ export type DecafShareClassId = number & { readonly __tag: unique symbol };
23
118
 
24
119
  /**
25
120
  * Type definition for DECAF principal identifiers.
26
121
  */
27
- export type PrincipalId = NewTypeWithPhantom<'DecafPrincipal', string | number>;
122
+ export type DecafPrincipalId = number & { readonly __tag: unique symbol };
28
123
 
29
124
  /**
30
125
  * Type definition for DECAF institution identifiers.
31
126
  */
32
- export type InstitutionId = NewTypeWithPhantom<'DecafInstitution', string | number>;
127
+ export type DecafInstitutionId = number & { readonly __tag: unique symbol };
33
128
 
34
129
  /**
35
130
  * Type definition for DECAF team identifiers.
36
131
  */
37
- export type TeamId = NewTypeWithPhantom<'DecafTeam', string | number>;
132
+ export type DecafTeamId = number & { readonly __tag: unique symbol };
38
133
 
39
134
  /**
40
135
  * Type definition for DECAF portfolio identifiers.
41
136
  */
42
- export type PortfolioId = NewTypeWithPhantom<'DecafPortfolio', string | number>;
137
+ export type DecafPortfolioId = number & { readonly __tag: unique symbol };
43
138
 
44
139
  /**
45
140
  * Type definition for DECAF portfolio group identifiers.
46
141
  */
47
- export type PortfolioGroupId = NewTypeWithPhantom<'DecafPortfolioGroup', string | number>;
142
+ export type DecafPortfolioGroupId = number & { readonly __tag: unique symbol };
48
143
 
49
144
  /**
50
145
  * Type definition for DECAF account identifiers.
51
146
  */
52
- export type AccountId = NewTypeWithPhantom<'DecafAccount', string | number>;
147
+ export type DecafAccountId = number & { readonly __tag: unique symbol };
53
148
 
54
149
  /**
55
150
  * Type definition for DECAF OHLC series identifiers.
56
151
  */
57
- export type OhlcSeriesId = NewTypeWithPhantom<'DecafOhlcSeries', string | number>;
152
+ export type DecafOhlcSeriesId = number & { readonly __tag: unique symbol };
58
153
 
59
154
  /**
60
155
  * Type definition for DECAF share class fee schedule identifiers.
61
156
  */
62
- export type ShareClassFeeScheduleId = NewTypeWithPhantom<'DecafShareClassFeeSchedule', string | number>;
157
+ export type DecafShareClassFeeScheduleId = number & { readonly __tag: unique symbol };
63
158
 
64
159
  /**
65
160
  * Type definition for DECAF action identifiers.
66
161
  */
67
- export type ActionId = NewTypeWithPhantom<'DecafAction', string | number>;
162
+ export type DecafActionId = number & { readonly __tag: unique symbol };
68
163
 
69
164
  /**
70
165
  * Type definition for DECAF external valuation identifiers.
71
166
  */
72
- export type ExternalValuationId = NewTypeWithPhantom<'DecafExternalValuation', string | number>;
167
+ export type DecafExternalValuationId = number & { readonly __tag: unique symbol };
@@ -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';
package/src/index.test.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { buildDecafClient, DecafClient, gql } from '@decafhub/decaf-client';
2
- import { mk, PDateTime, safeDiv, zero } from '@telostat/prelude';
2
+ import { PDateTime, safeDiv, zero } from '@telostat/prelude';
3
3
  import { fail } from 'assert';
4
- import { PortfolioId } from './commons';
4
+ import { DecafPortfolioId, mkCurrencyCodeError } from './commons';
5
5
  import { makeValuationReportHoldingsTree } from './reports/valuation/';
6
6
  import {
7
7
  fetchPortfolioValuationReport,
@@ -23,7 +23,7 @@ const FIRST_PORTFOLIO_QUERY = gql`
23
23
 
24
24
  describe('Main', () => {
25
25
  let client: DecafClient;
26
- let portfolioId: PortfolioId;
26
+ let portfolioId: DecafPortfolioId;
27
27
 
28
28
  beforeAll(() => {
29
29
  jest.resetModules();
@@ -56,7 +56,7 @@ describe('Main', () => {
56
56
  portfolio: portfolioId,
57
57
  date: PDateTime(new Date()).format('YYYY-MM-DD'),
58
58
  dateType: 'settlement',
59
- currency: mk('EUR'),
59
+ currency: mkCurrencyCodeError('EUR'),
60
60
  });
61
61
  eValue.caseOf({
62
62
  Left: (e) => fail('Error while fetching the remote portfolio report: ' + e.msg),
@@ -74,7 +74,7 @@ describe('Main', () => {
74
74
  portfolio: portfolioId,
75
75
  date: PDateTime(new Date()).format('YYYY-MM-DD'),
76
76
  dateType: 'settlement',
77
- currency: mk('EUR'),
77
+ currency: mkCurrencyCodeError('EUR'),
78
78
  });
79
79
  eValue.caseOf({
80
80
  Left: (e) => fail('Error while fetching the remote portfolio report: ' + e.msg),