@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
@@ -6,7 +6,11 @@ on:
6
6
  name: release-please
7
7
  jobs:
8
8
  release-please:
9
- runs-on: ubuntu-latest
9
+ runs-on: ${{ matrix.os }}
10
+ strategy:
11
+ matrix:
12
+ node: [16]
13
+ os: [ubuntu-latest]
10
14
  steps:
11
15
  - uses: google-github-actions/release-please-action@v3
12
16
  id: release
@@ -18,7 +22,7 @@ jobs:
18
22
 
19
23
  - uses: actions/setup-node@v3
20
24
  with:
21
- node-version: 16.x
25
+ node-version: ${{ matrix.node }}
22
26
  registry-url: 'https://registry.npmjs.org'
23
27
  cache: 'yarn'
24
28
  if: ${{ steps.release.outputs.release_created }}
@@ -5,13 +5,17 @@ on:
5
5
 
6
6
  jobs:
7
7
  test:
8
- runs-on: ubuntu-latest
8
+ runs-on: ${{ matrix.os }}
9
+ strategy:
10
+ matrix:
11
+ node: [14, 16, 18]
12
+ os: [ubuntu-latest]
9
13
  steps:
10
14
  - uses: actions/checkout@v3
11
15
 
12
16
  - uses: actions/setup-node@v3
13
17
  with:
14
- node-version: 16.x
18
+ node-version: ${{ matrix.node }}
15
19
  registry-url: 'https://registry.npmjs.org'
16
20
  cache: 'yarn'
17
21
 
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "0.0.5"
2
+ ".": "0.1.1"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.1](https://github.com/teloscube/decaf-client-javascript-extras/compare/v0.1.0...v0.1.1) (2023-04-02)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * release 0.1.1 ([e5aedf7](https://github.com/teloscube/decaf-client-javascript-extras/commit/e5aedf7ac6f802da1afdafbe2e040fb455d28c82))
9
+
10
+ ## [0.1.0](https://github.com/teloscube/decaf-client-javascript-extras/compare/v0.0.5...v0.1.0) (2023-01-31)
11
+
12
+
13
+ ### ⚠ BREAKING CHANGES
14
+
15
+ * The underlying types of DECAF record identifiers have been changed to a simpler, tagged type definitions. Call-sites should use `mkDecafRecordId` constructor and `unDecafRecordId` de-constructor OR direct type casting when producing and consuming such values.
16
+ * We are now adopting the convention that constants are defined via all-uppercase, snake-case symbols.
17
+ * The underlying type of CurrencyCode has been changed to a simpler, tagged type definition. Call-sites should use either of:
18
+
19
+ ### Code Refactoring
20
+
21
+ * change type of CurrencyCode, use regexp for validation ([b4915aa](https://github.com/teloscube/decaf-client-javascript-extras/commit/b4915aace037ce9e56be9161ea730529a7d31536))
22
+ * change type of DECAF record identifiers ([a2f48c0](https://github.com/teloscube/decaf-client-javascript-extras/commit/a2f48c00525714ffa20ecdca2900b842581ede43))
23
+ * rename constant dateTypes to DATE_TYPES ([7801283](https://github.com/teloscube/decaf-client-javascript-extras/commit/7801283bdc72463bbb243f03c5bb10ef77c5dd7a))
24
+
3
25
  ## [0.0.5](https://github.com/teloscube/decaf-client-javascript-extras/compare/v0.0.4...v0.0.5) (2022-12-28)
4
26
 
5
27
 
@@ -3,18 +3,32 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { Maybe, NewTypeWithPhantom } from '@telostat/prelude';
6
+ import { Maybe } from '@telostat/prelude';
7
7
  /**
8
- * Type encoding for currency code values.
8
+ * Type definition for currency code values.
9
9
  *
10
- * A currency code is (typically) defined as all-uppercase, three letters.
10
+ * A currency code is (typically) defined as all-uppercase, three-letter
11
+ * `string`. In this library, we are particularly using the regular expression
12
+ * {@link REGEXP_CURRENCY_CODE} which allows any uppercase letter followed by
13
+ * uppercase or lowercase letters.
14
+ *
15
+ * As for the type definition: We are using a (not-so-elegant) trick called
16
+ * "tagged-type" to annotate the plain-vanilla `string` type to be the
17
+ * `CurrencyCode` (_poor man's newtype_). Note that during the runtime, all
18
+ * `CurrencyCode` values are simply a `string` values.
19
+ */
20
+ export type CurrencyCode = string & {
21
+ readonly __tag: unique symbol;
22
+ };
23
+ /**
24
+ * Regular expression for currency codes in our concept.
11
25
  */
12
- export type CurrencyCode = NewTypeWithPhantom<'CurrencyCode', string>;
26
+ export declare const REGEXP_CURRENCY_CODE: RegExp;
13
27
  /**
14
28
  * Attempts to create a {@link CurrencyCode} value with the given currency code.
15
29
  *
16
- * This function returns a `Maybe` value. For the version that throws an
17
- * error, see {@link mkCurrencyCodeError}.
30
+ * This function returns a `Maybe` value. For the
31
+ * version that throws an error, see {@link mkCurrencyCodeError}.
18
32
  *
19
33
  * @param x A currency code represented as string.
20
34
  * @returns If the argument has leading or trailing spaces OR it is empty,
@@ -36,6 +50,8 @@ export declare function mkCurrencyCodeError(x: string): CurrencyCode;
36
50
  /**
37
51
  * Return the currency code as a string value.
38
52
  *
53
+ * In runtime, this is effectively the identity function.
54
+ *
39
55
  * @param x {@link CurrencyCode} to be extracted string from.
40
56
  * @returns Currency code as a string.
41
57
  */
@@ -5,20 +5,24 @@
5
5
  * @module
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.unCurrencyCode = exports.mkCurrencyCodeError = exports.mkCurrencyCode = void 0;
8
+ exports.unCurrencyCode = exports.mkCurrencyCodeError = exports.mkCurrencyCode = exports.REGEXP_CURRENCY_CODE = void 0;
9
9
  var prelude_1 = require("@telostat/prelude");
10
+ /**
11
+ * Regular expression for currency codes in our concept.
12
+ */
13
+ exports.REGEXP_CURRENCY_CODE = /^[A-Z][a-zA-Z]*$/;
10
14
  /**
11
15
  * Attempts to create a {@link CurrencyCode} value with the given currency code.
12
16
  *
13
- * This function returns a `Maybe` value. For the version that throws an
14
- * error, see {@link mkCurrencyCodeError}.
17
+ * This function returns a `Maybe` value. For the
18
+ * version that throws an error, see {@link mkCurrencyCodeError}.
15
19
  *
16
20
  * @param x A currency code represented as string.
17
21
  * @returns If the argument has leading or trailing spaces OR it is empty,
18
22
  * `Nothing` is retured, `Just` {@link CurrencyCode} otherwise.
19
23
  */
20
24
  function mkCurrencyCode(x) {
21
- return x !== x.trim() || x === '' ? prelude_1.Nothing : (0, prelude_1.Just)((0, prelude_1.mkPhantom)(x));
25
+ return exports.REGEXP_CURRENCY_CODE.test(x) ? (0, prelude_1.Just)(x) : prelude_1.Nothing;
22
26
  }
23
27
  exports.mkCurrencyCode = mkCurrencyCode;
24
28
  /**
@@ -34,17 +38,19 @@ exports.mkCurrencyCode = mkCurrencyCode;
34
38
  */
35
39
  function mkCurrencyCodeError(x) {
36
40
  return mkCurrencyCode(x).orDefaultLazy(function () {
37
- throw new Error("Invalid currency code: \"".concat(x, "\""));
41
+ throw new Error("Invalid currency code: ".concat(x));
38
42
  });
39
43
  }
40
44
  exports.mkCurrencyCodeError = mkCurrencyCodeError;
41
45
  /**
42
46
  * Return the currency code as a string value.
43
47
  *
48
+ * In runtime, this is effectively the identity function.
49
+ *
44
50
  * @param x {@link CurrencyCode} to be extracted string from.
45
51
  * @returns Currency code as a string.
46
52
  */
47
53
  function unCurrencyCode(x) {
48
- return (0, prelude_1.unPhantom)(x);
54
+ return x;
49
55
  }
50
56
  exports.unCurrencyCode = unCurrencyCode;
@@ -5,7 +5,7 @@ export type DateType = 'commitment' | 'settlement';
5
5
  /**
6
6
  * Translation table for DECAF FINREA action date types.
7
7
  */
8
- export declare const dateTypes: {
8
+ export declare const DATE_TYPES: {
9
9
  label: string;
10
10
  value: DateType;
11
11
  }[];
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dateTypes = void 0;
3
+ exports.DATE_TYPES = void 0;
4
4
  /**
5
5
  * Translation table for DECAF FINREA action date types.
6
6
  */
7
- exports.dateTypes = [
7
+ exports.DATE_TYPES = [
8
8
  { label: 'Trade Date', value: 'commitment' },
9
9
  { label: 'Value Date', value: 'settlement' },
10
10
  ];
package/commons/-id.d.ts CHANGED
@@ -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/commons/-id.js CHANGED
@@ -1,2 +1,75 @@
1
1
  "use strict";
2
+ /**
3
+ * This module provides a collection of DECAF record identifier type
4
+ * definitions. It is not exhaustive and it will be improved on an ongoing
5
+ * basis.
6
+ *
7
+ * Typically, a DECAF record identifier is either number or string. Some DECAF
8
+ * API endoints can consume string values even though a number is expected. We
9
+ * are sticking here to the original type: No `number | string` definitions.
10
+ *
11
+ * Methodologically, we are using a type trick to emulate newtypes in this
12
+ * module: For example, DECAF artifact identifier type is defined as:
13
+ *
14
+ * ```ts
15
+ * export type DecafArtifactId = number & { readonly __tag: unique symbol };
16
+ * ```
17
+ *
18
+ * In runtime, there is only a number. The `& { readonly __tag: unique symbol }`
19
+ * is provided to the compiler to distinguish in between `number` identifier
20
+ * values which are representing different DECAF record types.
21
+ *
22
+ * The construction and deconstruction of DECAF record identifiers are done via,
23
+ * respecively, `mkDecafRecordId` and `unDecafRecordId`:
24
+ *
25
+ * ```ts
26
+ * const exampleDecafArtifactIdValue: number = unDecafRecordId(exampleDecafArtifactId);
27
+ * const exampleDecafArtifactId: DecafArtifactId = mkDecafRecordId(42);
28
+ * expect(exampleDecafArtifactIdValue).toBe(42);
29
+ *
30
+ * const exampleDecafActionId: DecafActionId = mkDecafRecordId(42);
31
+ * const exampleDecafActionIdValue: number = unDecafRecordId(exampleDecafActionId);
32
+ * expect(exampleDecafActionIdValue).toBe(42);
33
+ *
34
+ * const exampleDecafArtifactTypeId: DecafArtifactTypeId = mkDecafRecordId('CCY');
35
+ * const exampleDecafArtifactTypeIdValue: string = unDecafRecordId(exampleDecafArtifactTypeId);
36
+ * expect(exampleDecafArtifactTypeIdValue).toBe('CCY');
37
+ * ```
38
+ *
39
+ * To re-iterate, the runtime representation is not affected by how DECAF record
40
+ * identifier types are defined:
41
+ *
42
+ * ```ts
43
+ * interface DecafArtifact {
44
+ * id: DecafArtifactId;
45
+ * type: DecafArtifactTypeId;
46
+ * }
47
+ *
48
+ * const exampleDecafArtifact: DecafArtifact = { id: mkDecafRecordId(10), type: mkDecafRecordId('CCY') };
49
+ * expect(exampleDecafArtifact).toStrictEqual({ id: 10, type: 'CCY' });
50
+ * ```
51
+ *
52
+ * @module
53
+ */
2
54
  Object.defineProperty(exports, "__esModule", { value: true });
55
+ exports.unDecafRecordId = exports.mkDecafRecordId = void 0;
56
+ /**
57
+ * Constructor for DECAF record identifiers.
58
+ *
59
+ * @param x Value to create DECAF record identifier from.
60
+ * @returns DECAF record identifier of type deduced from call-site usage.
61
+ */
62
+ function mkDecafRecordId(x) {
63
+ return x;
64
+ }
65
+ exports.mkDecafRecordId = mkDecafRecordId;
66
+ /**
67
+ * Deconstructor for DECAF record identifiers.
68
+ *
69
+ * @param x DECAF record identifier.
70
+ * @returns Value of the DECAF record identifier (deduced from call-site usage).
71
+ */
72
+ function unDecafRecordId(x) {
73
+ return x;
74
+ }
75
+ exports.unDecafRecordId = unDecafRecordId;
@@ -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/commons/index.js CHANGED
@@ -10,10 +10,26 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
13
18
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
19
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
20
  };
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
16
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.id = exports.datetype = exports.currency = void 0;
17
30
  __exportStar(require("./-currency"), exports);
18
- __exportStar(require("./-date-type"), exports);
31
+ exports.currency = __importStar(require("./-currency"));
32
+ __exportStar(require("./-datetype"), exports);
33
+ exports.datetype = __importStar(require("./-datetype"));
19
34
  __exportStar(require("./-id"), exports);
35
+ exports.id = __importStar(require("./-id"));
@@ -3,18 +3,32 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { Maybe, NewTypeWithPhantom } from '@telostat/prelude';
6
+ import { Maybe } from '@telostat/prelude';
7
7
  /**
8
- * Type encoding for currency code values.
8
+ * Type definition for currency code values.
9
9
  *
10
- * A currency code is (typically) defined as all-uppercase, three letters.
10
+ * A currency code is (typically) defined as all-uppercase, three-letter
11
+ * `string`. In this library, we are particularly using the regular expression
12
+ * {@link REGEXP_CURRENCY_CODE} which allows any uppercase letter followed by
13
+ * uppercase or lowercase letters.
14
+ *
15
+ * As for the type definition: We are using a (not-so-elegant) trick called
16
+ * "tagged-type" to annotate the plain-vanilla `string` type to be the
17
+ * `CurrencyCode` (_poor man's newtype_). Note that during the runtime, all
18
+ * `CurrencyCode` values are simply a `string` values.
19
+ */
20
+ export type CurrencyCode = string & {
21
+ readonly __tag: unique symbol;
22
+ };
23
+ /**
24
+ * Regular expression for currency codes in our concept.
11
25
  */
12
- export type CurrencyCode = NewTypeWithPhantom<'CurrencyCode', string>;
26
+ export declare const REGEXP_CURRENCY_CODE: RegExp;
13
27
  /**
14
28
  * Attempts to create a {@link CurrencyCode} value with the given currency code.
15
29
  *
16
- * This function returns a `Maybe` value. For the version that throws an
17
- * error, see {@link mkCurrencyCodeError}.
30
+ * This function returns a `Maybe` value. For the
31
+ * version that throws an error, see {@link mkCurrencyCodeError}.
18
32
  *
19
33
  * @param x A currency code represented as string.
20
34
  * @returns If the argument has leading or trailing spaces OR it is empty,
@@ -36,6 +50,8 @@ export declare function mkCurrencyCodeError(x: string): CurrencyCode;
36
50
  /**
37
51
  * Return the currency code as a string value.
38
52
  *
53
+ * In runtime, this is effectively the identity function.
54
+ *
39
55
  * @param x {@link CurrencyCode} to be extracted string from.
40
56
  * @returns Currency code as a string.
41
57
  */
@@ -3,19 +3,23 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { Just, mkPhantom, Nothing, unPhantom } from '@telostat/prelude';
6
+ import { Just, Nothing } from '@telostat/prelude';
7
+ /**
8
+ * Regular expression for currency codes in our concept.
9
+ */
10
+ export const REGEXP_CURRENCY_CODE = /^[A-Z][a-zA-Z]*$/;
7
11
  /**
8
12
  * Attempts to create a {@link CurrencyCode} value with the given currency code.
9
13
  *
10
- * This function returns a `Maybe` value. For the version that throws an
11
- * error, see {@link mkCurrencyCodeError}.
14
+ * This function returns a `Maybe` value. For the
15
+ * version that throws an error, see {@link mkCurrencyCodeError}.
12
16
  *
13
17
  * @param x A currency code represented as string.
14
18
  * @returns If the argument has leading or trailing spaces OR it is empty,
15
19
  * `Nothing` is retured, `Just` {@link CurrencyCode} otherwise.
16
20
  */
17
21
  export function mkCurrencyCode(x) {
18
- return x !== x.trim() || x === '' ? Nothing : Just(mkPhantom(x));
22
+ return REGEXP_CURRENCY_CODE.test(x) ? Just(x) : Nothing;
19
23
  }
20
24
  /**
21
25
  * (Unsafely) attempts to create a {@link CurrencyCode} value with the given
@@ -30,15 +34,17 @@ export function mkCurrencyCode(x) {
30
34
  */
31
35
  export function mkCurrencyCodeError(x) {
32
36
  return mkCurrencyCode(x).orDefaultLazy(() => {
33
- throw new Error(`Invalid currency code: "${x}"`);
37
+ throw new Error(`Invalid currency code: ${x}`);
34
38
  });
35
39
  }
36
40
  /**
37
41
  * Return the currency code as a string value.
38
42
  *
43
+ * In runtime, this is effectively the identity function.
44
+ *
39
45
  * @param x {@link CurrencyCode} to be extracted string from.
40
46
  * @returns Currency code as a string.
41
47
  */
42
48
  export function unCurrencyCode(x) {
43
- return unPhantom(x);
49
+ return x;
44
50
  }
@@ -5,7 +5,7 @@ export type DateType = 'commitment' | 'settlement';
5
5
  /**
6
6
  * Translation table for DECAF FINREA action date types.
7
7
  */
8
- export declare const dateTypes: {
8
+ export declare const DATE_TYPES: {
9
9
  label: string;
10
10
  value: DateType;
11
11
  }[];
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Translation table for DECAF FINREA action date types.
3
3
  */
4
- export const dateTypes = [
4
+ export const DATE_TYPES = [
5
5
  { label: 'Trade Date', value: 'commitment' },
6
6
  { label: 'Value Date', value: 'settlement' },
7
7
  ];